blob: 073606f19d5e41e273481165849f4ea97384424d [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070047import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070052import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070053import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080058import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070059import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080060import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080061import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070062import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070063import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080064import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070066import android.telephony.CellInfoGsm;
67import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070068import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070070import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070071import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080072import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070073import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070075import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080076import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080077import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070078import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080079import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070080import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080082import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700100import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsMmTelFeature;
102import android.telephony.ims.aidl.IImsRcsFeature;
103import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800105import android.telephony.ims.feature.MmTelFeature;
106import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800107import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800111import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700173import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800174import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Michelecea4cf22018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdeviaf9a5b92018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu6dac5ab2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1328 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001333 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 publish();
1336 }
1337
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001338 private Phone getDefaultPhone() {
1339 Phone thePhone = getPhone(getDefaultSubscription());
1340 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 private void publish() {
1344 if (DBG) log("publish: " + this);
1345
1346 ServiceManager.addService("phone", this);
1347 }
1348
Stuart Scott584921c2015-01-15 17:10:34 -08001349 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001350 if (request.phone != null) {
1351 return request.phone;
1352 } else {
1353 return getPhoneFromSubId(request.subId);
1354 }
1355 }
1356
1357 private Phone getPhoneFromSubId(int subId) {
1358 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1359 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001360 }
1361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001362 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1363 Phone phone = getPhoneFromRequest(request);
1364 return phone == null ? null :
1365 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1366 }
1367
Wink Saville36469e72014-06-11 15:17:00 -07001368 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001370 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 if (DBG) log("dial: " + number);
1379 // No permission check needed here: This is just a wrapper around the
1380 // ACTION_DIAL intent, which is available to any app since it puts up
1381 // the UI before it does anything.
1382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001383 final long identity = Binder.clearCallingIdentity();
1384 try {
1385 String url = createTelUrl(number);
1386 if (url == null) {
1387 return;
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001390 // PENDING: should we just silently fail if phone is offhook or ringing?
1391 PhoneConstants.State state = mCM.getState(subId);
1392 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1393 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1394 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1395 mApp.startActivity(intent);
1396 }
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 }
1401
1402 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 if (DBG) log("call: " + number);
1408
1409 // This is just a wrapper around the ACTION_CALL intent, but we still
1410 // need to do a permission check since we're calling startActivity()
1411 // from the context of the phone app.
1412 enforceCallPermission();
1413
1414 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1415 != AppOpsManager.MODE_ALLOWED) {
1416 return;
1417 }
1418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 String url = createTelUrl(number);
1422 if (url == null) {
1423 return;
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001426 boolean isValid = false;
1427 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1428 if (slist != null) {
1429 for (SubscriptionInfo subInfoRecord : slist) {
1430 if (subInfoRecord.getSubscriptionId() == subId) {
1431 isValid = true;
1432 break;
1433 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001434 }
Wink Saville08874612014-08-31 19:19:58 -07001435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1441 intent.putExtra(SUBSCRIPTION_KEY, subId);
1442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1443 mApp.startActivity(intent);
1444 } finally {
1445 Binder.restoreCallingIdentity(identity);
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001455 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1456 }
1457
1458 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1465 }
1466
1467 /** {@hide} */
1468 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1478 checkSimPin.start();
1479 return checkSimPin.unlockSim(null, pin);
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Wink Saville9de0f752013-10-22 19:04:03 -07001485 /** {@hide} */
1486 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1496 checkSimPuk.start();
1497 return checkSimPuk.unlockSim(puk, pin);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001504 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 * a synchronous one.
1506 */
1507 private static class UnlockSim extends Thread {
1508
1509 private final IccCard mSimCard;
1510
1511 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001512 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1513 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 // For replies from SimCard interface
1516 private Handler mHandler;
1517
1518 // For async handler to identify request type
1519 private static final int SUPPLY_PIN_COMPLETE = 100;
1520
1521 public UnlockSim(IccCard simCard) {
1522 mSimCard = simCard;
1523 }
1524
1525 @Override
1526 public void run() {
1527 Looper.prepare();
1528 synchronized (UnlockSim.this) {
1529 mHandler = new Handler() {
1530 @Override
1531 public void handleMessage(Message msg) {
1532 AsyncResult ar = (AsyncResult) msg.obj;
1533 switch (msg.what) {
1534 case SUPPLY_PIN_COMPLETE:
1535 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1536 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001537 mRetryCount = msg.arg1;
1538 if (ar.exception != null) {
1539 if (ar.exception instanceof CommandException &&
1540 ((CommandException)(ar.exception)).getCommandError()
1541 == CommandException.Error.PASSWORD_INCORRECT) {
1542 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1543 } else {
1544 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1545 }
1546 } else {
1547 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 mDone = true;
1550 UnlockSim.this.notifyAll();
1551 }
1552 break;
1553 }
1554 }
1555 };
1556 UnlockSim.this.notifyAll();
1557 }
1558 Looper.loop();
1559 }
1560
1561 /*
1562 * Use PIN or PUK to unlock SIM card
1563 *
1564 * If PUK is null, unlock SIM card with PIN
1565 *
1566 * If PUK is not null, unlock SIM card with PUK and set PIN code
1567 */
Wink Saville9de0f752013-10-22 19:04:03 -07001568 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569
1570 while (mHandler == null) {
1571 try {
1572 wait();
1573 } catch (InterruptedException e) {
1574 Thread.currentThread().interrupt();
1575 }
1576 }
1577 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1578
1579 if (puk == null) {
1580 mSimCard.supplyPin(pin, callback);
1581 } else {
1582 mSimCard.supplyPuk(puk, pin, callback);
1583 }
1584
1585 while (!mDone) {
1586 try {
1587 Log.d(LOG_TAG, "wait for done");
1588 wait();
1589 } catch (InterruptedException e) {
1590 // Restore the interrupted status
1591 Thread.currentThread().interrupt();
1592 }
1593 }
1594 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001595 int[] resultArray = new int[2];
1596 resultArray[0] = mResult;
1597 resultArray[1] = mRetryCount;
1598 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600 }
1601
1602 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604
1605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 // No permission check needed here: this call is harmless, and it's
1609 // needed for the ServiceState.requestStateUpdate() call (which is
1610 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.updateServiceLocation();
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001622 @Override
1623 public boolean isRadioOn(String callingPackage) {
1624 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 @Override
1628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001630 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 return false;
1632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 return isRadioOnForSubscriber(subId);
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
1639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001640 }
1641
1642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1648 } else {
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
1655
1656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
1674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Wink Savilleb564aae2014-10-23 10:18:09 -07001678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone phone = getPhone(subId);
1684 if (phone == null) {
1685 return false;
1686 }
1687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1688 toggleRadioOnOffForSubscriber(subId);
1689 }
1690 return true;
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
Wink Saville36469e72014-06-11 15:17:00 -07001695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001696 public boolean needMobileRadioShutdown() {
1697 /*
1698 * If any of the Radios are available, it will need to be
1699 * shutdown. So return true if any Radio is available.
1700 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1704 Phone phone = PhoneFactory.getPhone(i);
1705 if (phone != null && phone.isRadioAvailable()) return true;
1706 }
1707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1708 return false;
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
1713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 enforceModifyPermission();
1717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1721 logv("Shutting down Phone " + i);
1722 shutdownRadioUsingPhoneId(i);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 }
1727 }
1728
1729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null && phone.isRadioAvailable()) {
1732 phone.shutdownRadio();
1733 }
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1742 if (defaultPhone != null) {
1743 defaultPhone.setRadioPower(turnOn);
1744 return true;
1745 } else {
1746 loge("There's no default phone.");
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(turnOn);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Wink Saville36469e72014-06-11 15:17:00 -07001771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public boolean enableDataConnectivity() {
1774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 int subId = mSubscriptionController.getDefaultDataSubId();
1779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 return true;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Saville36469e72014-06-11 15:17:00 -07001791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public boolean disableDataConnectivity() {
1794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 int subId = mSubscriptionController.getDefaultDataSubId();
1799 final Phone phone = getPhone(subId);
1800 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 return true;
1803 } else {
1804 return false;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001812 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001818 } else {
1819 return false;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001827 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
pkanwarae03a6b2016-11-06 20:37:09 -08001830 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 enforceCallPermission();
1832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1836 return;
1837 }
1838 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1839 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
pkanwar32d516d2016-10-14 19:37:38 -07001843 };
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1851 return false;
1852 }
1853 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1854 } finally {
1855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001860 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 Phone phone = PhoneFactory.getPhone(slotIndex);
1867 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1868 PhoneConstantConversions.convertCallState(phone.getState());
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public int getDataState() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001876 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1877 }
1878
1879 @Override
1880 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 if (phone != null) {
1885 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1886 } else {
1887 return PhoneConstantConversions.convertDataState(
1888 PhoneConstants.DataState.DISCONNECTED);
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 public int getDataActivity() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001897 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1898 }
1899
1900 @Override
1901 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001904 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905 if (phone != null) {
1906 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1907 } else {
1908 return TelephonyManager.DATA_ACTIVITY_NONE;
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001916 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001917 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001918 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001919
1920 LocationAccessPolicy.LocationPermissionResult locationResult =
1921 LocationAccessPolicy.checkLocationPermission(mApp,
1922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1923 .setCallingPackage(callingPackage)
1924 .setCallingPid(Binder.getCallingPid())
1925 .setCallingUid(Binder.getCallingUid())
1926 .setMethod("getCellLocation")
1927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1928 .build());
1929 switch (locationResult) {
1930 case DENIED_HARD:
1931 throw new SecurityException("Not allowed to access cell location");
1932 case DENIED_SOFT:
1933 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001936 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 if (DBG_LOC) log("getCellLocation: is active user");
1940 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001941 int subId = mSubscriptionController.getDefaultDataSubId();
1942 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1943 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944 return data;
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
1947 }
Svetoslav64fad262015-04-14 14:35:21 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 public String getNetworkCountryIsoForPhone(int phoneId) {
1952 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1953 // registered cell info, so return a NULL country instead.
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001956 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1957 // Get default phone in this case.
1958 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1959 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001960 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001961 // Todo: fix this when we can get the actual cellular network info when the device
1962 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001963 if (TelephonyManager.NETWORK_TYPE_IWLAN
1964 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1965 return "";
1966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 Phone phone = PhoneFactory.getPhone(phoneId);
1968 if (phone != null) {
1969 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07001970 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 if (sst != null) {
1972 LocaleTracker lt = sst.getLocaleTracker();
1973 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07001974 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1975 return lt.getCurrentCountry();
1976 } else if (emergencyNumberTracker != null) {
1977 return emergencyNumberTracker.getEmergencyCountryIso();
1978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 }
1980 }
1981 }
1982 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001983 } finally {
1984 Binder.restoreCallingIdentity(identity);
1985 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001986 }
1987
1988 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001990 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001991 }
1992
Sanket Padawe356d7632015-06-22 14:03:32 -07001993 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001994 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 mApp.enforceCallingOrSelfPermission(
1996 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997
1998 final long identity = Binder.clearCallingIdentity();
1999 try {
2000 final Phone phone = getPhone(subId);
2001 if (phone != null) {
2002 phone.enableLocationUpdates();
2003 }
2004 } finally {
2005 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007 }
2008
2009 @Override
2010 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002011 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002012 }
2013
Sanket Padawe356d7632015-06-22 14:03:32 -07002014 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002015 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002016 mApp.enforceCallingOrSelfPermission(
2017 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002018
2019 final long identity = Binder.clearCallingIdentity();
2020 try {
2021 final Phone phone = getPhone(subId);
2022 if (phone != null) {
2023 phone.disableLocationUpdates();
2024 }
2025 } finally {
2026 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002027 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002028 }
2029
Nathan Harold31d7ff32018-10-15 20:20:30 -07002030 /**
2031 * Returns the target SDK version number for a given package name.
2032 *
2033 * @return target SDK if the package is found or INT_MAX.
2034 */
2035 private int getTargetSdk(String packageName) {
2036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002037 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2038 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002039 if (ai != null) return ai.targetSdkVersion;
2040 } catch (PackageManager.NameNotFoundException unexpected) {
2041 }
2042 return Integer.MAX_VALUE;
2043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 @Override
2046 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002047 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2048 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2050 throw new SecurityException(
2051 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2052 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002053
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2055 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2056 return null;
2057 }
Svetoslav64fad262015-04-14 14:35:21 -07002058
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002059 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060
Nathan Haroldf180aac2018-06-01 18:43:55 -07002061 List<CellInfo> info = getAllCellInfo(callingPackage);
2062 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063
Nathan Haroldf180aac2018-06-01 18:43:55 -07002064 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2065 for (CellInfo ci : info) {
2066 if (ci instanceof CellInfoGsm) {
2067 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2068 } else if (ci instanceof CellInfoWcdma) {
2069 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002072 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
2074
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002075 private List<CellInfo> getCachedCellInfo() {
2076 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2077 for (Phone phone : PhoneFactory.getPhones()) {
2078 List<CellInfo> info = phone.getAllCellInfo();
2079 if (info != null) cellInfos.addAll(info);
2080 }
2081 return cellInfos;
2082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083
2084 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002085 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002086 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002087 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002088
2089 LocationAccessPolicy.LocationPermissionResult locationResult =
2090 LocationAccessPolicy.checkLocationPermission(mApp,
2091 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2092 .setCallingPackage(callingPackage)
2093 .setCallingPid(Binder.getCallingPid())
2094 .setCallingUid(Binder.getCallingUid())
2095 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002096 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2098 .build());
2099 switch (locationResult) {
2100 case DENIED_HARD:
2101 throw new SecurityException("Not allowed to access cell info");
2102 case DENIED_SOFT:
2103 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 }
2105
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002106 final int targetSdk = getTargetSdk(callingPackage);
2107 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2108 return getCachedCellInfo();
2109 }
2110
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002111 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2116 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002117 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002118 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119 if (info != null) cellInfos.addAll(info);
2120 }
2121 return cellInfos;
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125 }
2126
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002127 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002128 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2129 requestCellInfoUpdateInternal(
2130 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2131 }
2132
2133 @Override
2134 public void requestCellInfoUpdateWithWorkSource(
2135 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2136 enforceModifyPermission();
2137 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2138 }
2139
2140 private void requestCellInfoUpdateInternal(
2141 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002142 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002143 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002144
2145 LocationAccessPolicy.LocationPermissionResult locationResult =
2146 LocationAccessPolicy.checkLocationPermission(mApp,
2147 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2148 .setCallingPackage(callingPackage)
2149 .setCallingPid(Binder.getCallingPid())
2150 .setCallingUid(Binder.getCallingUid())
2151 .setMethod("requestCellInfoUpdate")
2152 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2153 .build());
2154 switch (locationResult) {
2155 case DENIED_HARD:
2156 throw new SecurityException("Not allowed to access cell info");
2157 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002158 try {
2159 cb.onCellInfo(new ArrayList<CellInfo>());
2160 } catch (RemoteException re) {
2161 // Drop without consequences
2162 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002163 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002164 }
2165
Nathan Harold32e84c42019-05-09 10:13:47 -07002166
2167 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002168 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2169
2170 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2171 }
2172
2173 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002175 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002180 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 } finally {
2182 Binder.restoreCallingIdentity(identity);
2183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002188 Phone phone = PhoneFactory.getPhone(slotIndex);
2189 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 return null;
2191 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002192 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002193 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2194 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 return null;
2196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 return phone.getImei();
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002204 }
2205
2206 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002207 public String getTypeAllocationCodeForSlot(int slotIndex) {
2208 Phone phone = PhoneFactory.getPhone(slotIndex);
2209 String tac = null;
2210 if (phone != null) {
2211 String imei = phone.getImei();
2212 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2213 }
2214 return tac;
2215 }
2216
2217 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002218 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 Phone phone = PhoneFactory.getPhone(slotIndex);
2220 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002221 return null;
2222 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002223
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002225 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2226 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 return null;
2228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229
2230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 return phone.getMeid();
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
2235 }
Jack Yu2af8d712017-03-15 17:14:14 -07002236 }
2237
2238 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002239 public String getManufacturerCodeForSlot(int slotIndex) {
2240 Phone phone = PhoneFactory.getPhone(slotIndex);
2241 String manufacturerCode = null;
2242 if (phone != null) {
2243 String meid = phone.getMeid();
2244 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2245 }
2246 return manufacturerCode;
2247 }
2248
2249 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002250 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002251 Phone phone = PhoneFactory.getPhone(slotIndex);
2252 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002253 return null;
2254 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002255 int subId = phone.getSubId();
2256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2257 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2258 return null;
2259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 return phone.getDeviceSvn();
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002267 }
2268
fionaxu43304da2017-11-27 22:51:16 -08002269 @Override
2270 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 final Phone phone = getPhone(subId);
2274 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
2277 }
fionaxu43304da2017-11-27 22:51:16 -08002278 }
2279
2280 @Override
2281 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 final Phone phone = getPhone(subId);
2285 return phone == null ? null : phone.getCarrierName();
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
fionaxu43304da2017-11-27 22:51:16 -08002289 }
2290
calvinpanffe225e2018-11-01 19:43:06 +08002291 @Override
chen xu0026ca62019-03-06 15:28:50 -08002292 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
2296 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002297 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
2301 }
2302
2303 @Override
chen xu0026ca62019-03-06 15:28:50 -08002304 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002308 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
2312 }
2313
chen xu651eec72018-11-11 19:03:44 -08002314 @Override
chen xu864e11c2018-12-06 22:10:03 -08002315 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2316 if (!isSubscriptionMccMnc) {
2317 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2318 }
chen xu651eec72018-11-11 19:03:44 -08002319 final Phone phone = PhoneFactory.getPhone(slotIndex);
2320 if (phone == null) {
2321 return TelephonyManager.UNKNOWN_CARRIER_ID;
2322 }
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 //
2332 // Internal helper methods.
2333 //
2334
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002335 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2337 *
2338 * @throws SecurityException if the caller does not have the required permission
2339 */
2340 private void enforceModifyPermission() {
2341 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2342 }
2343
2344 /**
2345 * Make sure the caller has the CALL_PHONE permission.
2346 *
2347 * @throws SecurityException if the caller does not have the required permission
2348 */
2349 private void enforceCallPermission() {
2350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2351 }
2352
Stuart Scott8eef64f2015-04-08 15:13:54 -07002353 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002355 "ConnectivityService");
2356 }
2357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 private String createTelUrl(String number) {
2359 if (TextUtils.isEmpty(number)) {
2360 return null;
2361 }
2362
Jake Hambye994d462014-02-03 13:10:13 -08002363 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
Ihab Awadf9e92732013-12-05 18:02:52 -08002366 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2368 }
2369
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002370 private static void logv(String msg) {
2371 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2372 }
2373
Ihab Awadf9e92732013-12-05 18:02:52 -08002374 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2376 }
2377
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002378 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002380 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002384 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = PhoneFactory.getPhone(slotIndex);
2388 if (phone == null) {
2389 return PhoneConstants.PHONE_TYPE_NONE;
2390 } else {
2391 return phone.getPhoneType();
2392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 }
2397
2398 /**
2399 * Returns the CDMA ERI icon index to display
2400 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 @Override
2402 public int getCdmaEriIconIndex(String callingPackage) {
2403 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002404 }
2405
Sanket Padawe356d7632015-06-22 14:03:32 -07002406 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002410 return -1;
2411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 final Phone phone = getPhone(subId);
2416 if (phone != null) {
2417 return phone.getCdmaEriIconIndex();
2418 } else {
2419 return -1;
2420 }
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
2426 /**
2427 * Returns the CDMA ERI icon mode,
2428 * 0 - ON
2429 * 1 - FLASHING
2430 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002431 @Override
2432 public int getCdmaEriIconMode(String callingPackage) {
2433 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002434 }
2435
Sanket Padawe356d7632015-06-22 14:03:32 -07002436 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002437 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002439 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 return -1;
2441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
2445 final Phone phone = getPhone(subId);
2446 if (phone != null) {
2447 return phone.getCdmaEriIconMode();
2448 } else {
2449 return -1;
2450 }
2451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
2456 /**
2457 * Returns the CDMA ERI text,
2458 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002459 @Override
2460 public String getCdmaEriText(String callingPackage) {
2461 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002462 }
2463
Sanket Padawe356d7632015-06-22 14:03:32 -07002464 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002467 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 return null;
2469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470
2471 final long identity = Binder.clearCallingIdentity();
2472 try {
2473 final Phone phone = getPhone(subId);
2474 if (phone != null) {
2475 return phone.getCdmaEriText();
2476 } else {
2477 return null;
2478 }
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
2484 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002485 * Returns the CDMA MDN.
2486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2490 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002495 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 return phone.getLine1Number();
2497 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002498 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 return null;
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002503 }
2504 }
2505
2506 /**
2507 * Returns the CDMA MIN.
2508 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002510 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2512 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone phone = getPhone(subId);
2517 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2518 return phone.getCdmaMin();
2519 } else {
2520 return null;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002524 }
2525 }
2526
Hall Liud892bec2018-11-30 14:51:45 -08002527 @Override
2528 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2529 INumberVerificationCallback callback, String callingPackage) {
2530 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2531 != PERMISSION_GRANTED) {
2532 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2533 }
2534 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2535
2536 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2537 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2538 throw new SecurityException("Calling package must be configured in the device config");
2539 }
2540
2541 if (range == null) {
2542 throw new NullPointerException("Range must be non-null");
2543 }
2544
2545 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002546 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002547
2548 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2549 }
2550
Junda Liuca05d5d2014-08-14 22:36:34 -07002551 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 * Returns true if CDMA provisioning needs to run.
2553 */
2554 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002557 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 } finally {
2559 Binder.restoreCallingIdentity(identity);
2560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
2562
2563 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002564 * Sets the voice mail number of a given subId.
2565 */
2566 @Override
2567 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2573 new Pair<String, String>(alphaTag, number), new Integer(subId));
2574 return success;
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002578 }
2579
Ta-wei Yen87c49842016-05-13 21:19:52 -07002580 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002581 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002583 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002584 if (!TextUtils.equals(callingPackage, systemDialer)) {
2585 throw new SecurityException("caller must be system dialer");
2586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2591 if (phoneAccountHandle == null) {
2592 return null;
2593 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002597 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002598 }
2599
2600 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002601 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002602 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002604 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002605 return null;
2606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002608 final long identity = Binder.clearCallingIdentity();
2609 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002610 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002614 }
2615
2616 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002617 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2618 VisualVoicemailSmsFilterSettings settings) {
2619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002628 }
2629
2630 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002631 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002637 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002641 }
2642
2643 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002644 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2645 String callingPackage, int subId) {
2646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002655 }
2656
2657 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002658 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002659 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002664 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002668 }
2669
2670 @Override
2671 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2672 String number, int port, String text, PendingIntent sentIntent) {
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002674 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002675 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002676 SmsController smsController = PhoneFactory.getSmsController();
2677 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2678 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002679 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002680
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002681 /**
fionaxu0152e512016-11-14 13:36:14 -08002682 * Sets the voice activation state of a given subId.
2683 */
2684 @Override
2685 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2687 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 final Phone phone = getPhone(subId);
2692 if (phone != null) {
2693 phone.setVoiceActivationState(activationState);
2694 } else {
2695 loge("setVoiceActivationState fails with invalid subId: " + subId);
2696 }
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002699 }
2700 }
2701
2702 /**
2703 * Sets the data activation state of a given subId.
2704 */
2705 @Override
2706 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2708 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 final Phone phone = getPhone(subId);
2713 if (phone != null) {
2714 phone.setDataActivationState(activationState);
2715 } else {
2716 loge("setVoiceActivationState fails with invalid subId: " + subId);
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002720 }
2721 }
2722
2723 /**
2724 * Returns the voice activation state of a given subId.
2725 */
2726 @Override
2727 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002728 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
fionaxu0152e512016-11-14 13:36:14 -08002730 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 if (phone != null) {
2734 return phone.getVoiceActivationState();
2735 } else {
2736 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002740 }
2741 }
2742
2743 /**
2744 * Returns the data activation state of a given subId.
2745 */
2746 @Override
2747 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002748 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
fionaxu0152e512016-11-14 13:36:14 -08002750 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 if (phone != null) {
2754 return phone.getDataActivationState();
2755 } else {
2756 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002760 }
2761 }
2762
2763 /**
Wink Saville36469e72014-06-11 15:17:00 -07002764 * Returns the unread count of voicemails for a subId
2765 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002767 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2769 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2770 return 0;
2771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 final Phone phone = getPhone(subId);
2775 if (phone != null) {
2776 return phone.getVoiceMessageCount();
2777 } else {
2778 return 0;
2779 }
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
2785 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002786 * returns true, if the device is in a state where both voice and data
2787 * are supported simultaneously. This can change based on location or network condition.
2788 */
2789 @Override
2790 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002798 }
2799
2800 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002801 * Send the dialer code if called from the current default dialer or the caller has
2802 * carrier privilege.
2803 * @param inputCode The dialer code to send
2804 */
2805 @Override
2806 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002807 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002809 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2810 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002811 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002812 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2813 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002818 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
fionaxu235cc5e2017-03-06 22:25:57 -08002822 }
2823
Pengquan Menga1bb6272018-09-06 09:59:22 -07002824 @Override
2825 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002826 if (!isActiveSubscription(subId)) {
2827 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2828 }
2829
Pengquan Menga1bb6272018-09-06 09:59:22 -07002830 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2831 }
2832
Brad Ebinger35c841c2018-10-01 10:40:55 -07002833 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002834 public boolean isInEmergencySmsMode() {
2835 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 for (Phone phone : PhoneFactory.getPhones()) {
2839 if (phone.isInEmergencySmsMode()) {
2840 return true;
2841 }
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 return false;
2847 }
2848
2849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002850 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2851 throws RemoteException {
2852 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002853 final long token = Binder.clearCallingIdentity();
2854 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 .addRegistrationCallbackForSubscription(c, subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(token);
2860 }
2861 }
2862
2863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002864 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2865 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002866 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2867 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2868 }
2869 Binder.withCleanCallingIdentity(() -> {
2870 try {
2871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002873 .removeRegistrationCallbackForSubscription(c, subId);
2874 } catch (IllegalArgumentException e) {
2875 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2876 + "is inactive, ignoring unregister.");
2877 // If the subscription is no longer active, just return, since the callback
2878 // will already have been removed internally.
2879 }
2880 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 }
2882
2883 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002884 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2885 throws RemoteException {
2886 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2888 final long token = Binder.clearCallingIdentity();
2889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002890 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 .addCapabilitiesCallbackForSubscription(c, subId);
2892 } finally {
2893 Binder.restoreCallingIdentity(token);
2894 }
2895 }
2896
2897 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002898 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2899 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002900
2901 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2902 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2903 }
2904 Binder.withCleanCallingIdentity(() -> {
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002908 .removeCapabilitiesCallbackForSubscription(c, subId);
2909 } catch (IllegalArgumentException e) {
2910 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2911 + "is inactive, ignoring unregister.");
2912 // If the subscription is no longer active, just return, since the callback
2913 // will already have been removed internally.
2914 }
2915 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 }
2917
2918 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002919 public boolean isCapable(int subId, int capability, int regTech) {
2920 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 final long token = Binder.clearCallingIdentity();
2923 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002924 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2926 } catch (ImsException e) {
2927 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2928 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002929 } catch (IllegalArgumentException e) {
2930 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2931 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002932 } finally {
2933 Binder.restoreCallingIdentity(token);
2934 }
2935 }
2936
2937 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002938 public boolean isAvailable(int subId, int capability, int regTech) {
2939 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002940 final long token = Binder.clearCallingIdentity();
2941 try {
2942 Phone phone = getPhone(subId);
2943 if (phone == null) return false;
2944 return phone.isImsCapabilityAvailable(capability, regTech);
2945 } finally {
2946 Binder.restoreCallingIdentity(token);
2947 }
2948 }
2949
2950 @Override
2951 public boolean isAdvancedCallingSettingEnabled(int subId) {
2952 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2954 final long token = Binder.clearCallingIdentity();
2955 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002956 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2958 } finally {
2959 Binder.restoreCallingIdentity(token);
2960 }
2961 }
2962
2963 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002964 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002966 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002970 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002978 public boolean isVtSettingEnabled(int subId) {
2979 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 getSlotIndexOrException(subId)).isVtEnabledByUser();
2985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002991 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002993 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002997 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
3001 }
3002
3003 @Override
3004 public boolean isVoWiFiSettingEnabled(int subId) {
3005 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003009 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
3014 }
3015
3016 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003017 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003019 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
3030 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3031 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
3040 }
3041
3042 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003043 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003045 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003050 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3051 } finally {
3052 Binder.restoreCallingIdentity(identity);
3053 }
3054 }
3055
3056 @Override
3057 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3059 "setVoWiFiNonPersistent");
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003064 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
3071 public int getVoWiFiModeSetting(int subId) {
3072 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public void setVoWiFiModeSetting(int subId, int mode) {
3085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3086 "setVoWiFiModeSetting");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
3098 public int getVoWiFiRoamingModeSetting(int subId) {
3099 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 @Override
3111 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3112 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3113 "setVoWiFiRoamingModeSetting");
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003117 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003118 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
3125 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3127 "setRttCapabilityEnabled");
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003131 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
3138 @Override
3139 public boolean isTtyOverVolteEnabled(int subId) {
3140 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3146 } finally {
3147 Binder.restoreCallingIdentity(identity);
3148 }
3149 }
3150
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003151 @Override
3152 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3153 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003157 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003158 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003159 } finally {
3160 Binder.restoreCallingIdentity(identity);
3161 }
3162 }
3163
3164 @Override
3165 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3166 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3167 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003168 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3169 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3170 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003171 try {
3172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003173 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003174 .removeProvisioningCallbackForSubscription(callback, subId);
3175 } catch (IllegalArgumentException e) {
3176 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3177 + "is inactive, ignoring unregister.");
3178 // If the subscription is no longer active, just return, since the callback will already
3179 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
3183 }
3184
3185 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003186 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3187 boolean isProvisioned) {
3188 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3189 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3190 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3191 }
3192 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3193 "setProvisioningStatusForCapability");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3197 Phone phone = getPhone(subId);
3198 if (phone == null) {
3199 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3200 + subId);
3201 return;
3202 }
3203 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3204 return;
3205 }
3206
3207 // this capability requires provisioning, route to the correct API.
3208 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3209 switch (capability) {
3210 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3211 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3212 ims.setVolteProvisioned(isProvisioned);
3213 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3214 ims.setWfcProvisioned(isProvisioned);
3215 }
3216 break;
3217 }
3218 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3219 // There is currently no difference in VT provisioning type.
3220 ims.setVtProvisioned(isProvisioned);
3221 break;
3222 }
3223 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3224 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3225 // change the capability of the feature instead if needed.
3226 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3227 == isProvisioned) {
3228 // No change in provisioning.
3229 return;
3230 }
3231 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3232 try {
3233 ims.changeMmTelCapability(capability, tech, isProvisioned);
3234 } catch (ImsException e) {
3235 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3236 + ", Exception" + e.getMessage());
3237 }
3238 break;
3239 }
3240 default: {
3241 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3242 + capability + "', which does not require provisioning.");
3243 }
3244 }
3245
3246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
3249 }
3250
3251 @Override
3252 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3253 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3254 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3255 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3256 }
3257 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3261 Phone phone = getPhone(subId);
3262 if (phone == null) {
3263 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3264 + subId);
3265 // We will fail with "true" as the provisioning status because this is the default
3266 // if we do not require provisioning.
3267 return true;
3268 }
3269
3270 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3271 return true;
3272 }
3273
3274 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3275 switch (capability) {
3276 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3277 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3278 return ims.isVolteProvisionedOnDevice();
3279 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3280 return ims.isWfcProvisionedOnDevice();
3281 }
3282 // This should never happen, since we are checking tech above to make sure it
3283 // is either LTE or IWLAN.
3284 throw new IllegalArgumentException("Invalid radio technology for voice "
3285 + "capability.");
3286 }
3287 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3288 // There is currently no difference in VT provisioning type.
3289 return ims.isVtProvisionedOnDevice();
3290 }
3291 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3292 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3293 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3294 }
3295 default: {
3296 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3297 + capability + "', which does not require provisioning.");
3298 }
3299 }
3300
3301 } finally {
3302 Binder.restoreCallingIdentity(identity);
3303 }
3304 }
3305
3306 @Override
3307 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3308 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3309 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3310 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3311 }
3312 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3313 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3314 return (provisionedBits & capability) > 0;
3315 }
3316
3317 @Override
3318 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3319 boolean isProvisioned) {
3320 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3321 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3322 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3323 }
3324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3325 "setProvisioningStatusForCapability");
3326 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3327 // If the current provisioning status for capability already matches isProvisioned,
3328 // do nothing.
3329 if (((provisionedBits & capability) > 0) == isProvisioned) {
3330 return;
3331 }
3332 if (isProvisioned) {
3333 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3334 } else {
3335 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3336 }
3337 }
3338
3339 /**
3340 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3341 * technology. The bitfield should mirror the bitfield defined by
3342 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3343 */
3344 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3345 String key = getMmTelProvisioningKey(subId, tech);
3346 // Default is no capabilities are provisioned.
3347 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3348 }
3349
3350 /**
3351 * Sets the MmTel capability provisioning bitfield (defined by
3352 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3353 * technology specified.
3354 *
3355 * Note: This is a synchronous command and should not be called on UI thread.
3356 */
3357 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3358 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3359 String key = getMmTelProvisioningKey(subId, tech);
3360 editor.putInt(key, newField);
3361 editor.commit();
3362 }
3363
3364 private static String getMmTelProvisioningKey(int subId, int tech) {
3365 // resulting key is provision_ims_mmtel_{subId}_{tech}
3366 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3367 }
3368
3369 /**
3370 * Query CarrierConfig to see if the specified capability requires provisioning for the
3371 * carrier associated with the subscription id.
3372 */
3373 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3374 int capability) {
3375 CarrierConfigManager configManager = new CarrierConfigManager(context);
3376 PersistableBundle c = configManager.getConfigForSubId(subId);
3377 boolean requireUtProvisioning = c.getBoolean(
3378 // By default, this config is true (even if there is no SIM). We also check to make
3379 // sure the subscription needs provisioning here, so we do not need to check for
3380 // the no-SIM case, where we would normally shortcut this to false.
3381 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3382 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3383 false);
3384 boolean requireVoiceVtProvisioning = c.getBoolean(
3385 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3386
3387 // First check to make sure that the capability requires provisioning.
3388 switch (capability) {
3389 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3390 // intentional fallthrough
3391 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3392 if (requireVoiceVtProvisioning) {
3393 // Voice and Video requires provisioning
3394 return true;
3395 }
3396 break;
3397 }
3398 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3399 if (requireUtProvisioning) {
3400 // UT requires provisioning
3401 return true;
3402 }
3403 break;
3404 }
3405 }
3406 return false;
3407 }
3408
3409 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003410 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3412 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3413 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003414 enforceReadPrivilegedPermission("getImsProvisioningInt");
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003418 int slotId = getSlotIndex(subId);
3419 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3420 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3421 + subId + "' for key:" + key);
3422 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3423 }
3424 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003425 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003426 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3427 + subId + "' for key:" + key);
3428 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
3434 @Override
3435 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3437 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3438 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 enforceReadPrivilegedPermission("getImsProvisioningString");
3440 final long identity = Binder.clearCallingIdentity();
3441 try {
3442 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003443 int slotId = getSlotIndex(subId);
3444 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3445 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3446 + subId + "' for key:" + key);
3447 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3448 }
3449 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003451 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3452 + subId + "' for key:" + key);
3453 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
3457 }
3458
3459 @Override
3460 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003461 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3462 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3463 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3465 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 int slotId = getSlotIndex(subId);
3470 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3471 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3472 + subId + "' for key:" + key);
3473 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3474 }
3475 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3478 + "' for key:" + key);
3479 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 } finally {
3481 Binder.restoreCallingIdentity(identity);
3482 }
3483 }
3484
3485 @Override
3486 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3488 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3489 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003490 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3491 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003492 final long identity = Binder.clearCallingIdentity();
3493 try {
3494 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003495 int slotId = getSlotIndex(subId);
3496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3497 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3498 + subId + "' for key:" + key);
3499 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3500 }
3501 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003502 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003503 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3504 + "' for key:" + key);
3505 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
3509 }
3510
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3512 int slotId = SubscriptionManager.getSlotIndex(subId);
3513 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003514 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 }
3516 return slotId;
3517 }
3518
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003519 private int getSlotIndex(int subId) {
3520 int slotId = SubscriptionManager.getSlotIndex(subId);
3521 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3522 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3523 }
3524 return slotId;
3525 }
3526
Wink Saville36469e72014-06-11 15:17:00 -07003527 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003528 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003529 */
3530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003531 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003532 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3533 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3534 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3536 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.getServiceState().getDataNetworkType();
3543 } else {
3544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003549 }
3550
3551 /**
3552 * Returns the data network type
3553 */
3554 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003555 public int getDataNetworkType(String callingPackage) {
3556 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003557 }
3558
3559 /**
3560 * Returns the data network type for a subId
3561 */
3562 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003564 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003565 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003566 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3567 }
3568
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 final Phone phone = getPhone(subId);
3572 if (phone != null) {
3573 return phone.getServiceState().getDataNetworkType();
3574 } else {
3575 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3576 }
3577 } finally {
3578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 }
3581
3582 /**
Wink Saville36469e72014-06-11 15:17:00 -07003583 * Returns the Voice network type for a subId
3584 */
3585 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003586 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003587 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003588 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003589 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3590 }
3591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 final Phone phone = getPhone(subId);
3595 if (phone != null) {
3596 return phone.getServiceState().getVoiceNetworkType();
3597 } else {
3598 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3599 }
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003603 }
3604
3605 /**
3606 * @return true if a ICC card is present
3607 */
3608 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003609 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003610 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3611 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003612 }
3613
3614 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003615 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003616 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003617 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003618 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 final long identity = Binder.clearCallingIdentity();
3620 try {
3621 final Phone phone = PhoneFactory.getPhone(slotIndex);
3622 if (phone != null) {
3623 return phone.getIccCard().hasIccCard();
3624 } else {
3625 return false;
3626 }
3627 } finally {
3628 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003630 }
3631
3632 /**
3633 * Return if the current radio is LTE on CDMA. This
3634 * is a tri-state return value as for a period of time
3635 * the mode may be unknown.
3636 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003637 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003639 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003640 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003641 @Override
3642 public int getLteOnCdmaMode(String callingPackage) {
3643 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003644 }
3645
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003647 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003649 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003650 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3651 }
3652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 final Phone phone = getPhone(subId);
3656 if (phone == null) {
3657 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3658 } else {
3659 return phone.getLteOnCdmaMode();
3660 }
3661 } finally {
3662 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003663 }
Wink Saville36469e72014-06-11 15:17:00 -07003664 }
3665
Wink Saville36469e72014-06-11 15:17:00 -07003666 /**
3667 * {@hide}
3668 * Returns Default subId, 0 in the case of single standby.
3669 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003670 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003671 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003672 }
3673
Shishir Agrawala9f32182016-04-12 12:00:16 -07003674 private int getSlotForDefaultSubscription() {
3675 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3676 }
3677
Wink Savilleb564aae2014-10-23 10:18:09 -07003678 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003679 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003680 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003681
Pengquan Menge92a50d2018-09-21 15:54:48 -07003682 private boolean isActiveSubscription(int subId) {
3683 return mSubscriptionController.isActiveSubId(subId);
3684 }
3685
Ihab Awadf2177b72013-11-25 13:33:23 -08003686 /**
3687 * @see android.telephony.TelephonyManager.WifiCallingChoices
3688 */
3689 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003693 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3694 getWhenToMakeWifiCallsDefaultPreference());
3695 } finally {
3696 Binder.restoreCallingIdentity(identity);
3697 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003698 }
3699
3700 /**
3701 * @see android.telephony.TelephonyManager.WifiCallingChoices
3702 */
3703 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003707 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003708 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003712 }
3713
Sailesh Nepald1e68152013-12-12 19:08:02 -08003714 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003715 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003716 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003717 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003718
Jordan Liu4c733742019-02-28 12:03:40 -08003719 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3720 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3721 if (phoneId == -1) {
3722 throw new IllegalArgumentException("Given slot index: " + slotIndex
3723 + " does not correspond to an active phone");
3724 }
3725 return PhoneFactory.getPhone(phoneId);
3726 }
3727
Shishir Agrawal566b7612013-10-28 14:41:00 -07003728 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003729 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3730 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3732 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003734 if (DBG) {
3735 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3736 }
3737 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3738 p2);
3739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003740
Jordan Liu4c733742019-02-28 12:03:40 -08003741
3742 @Override
3743 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3744 int slotIndex, String callingPackage, String aid, int p2) {
3745 enforceModifyPermission();
3746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3747 if (DBG) {
3748 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3749 }
3750 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3751 callingPackage, aid, p2);
3752 }
3753
3754 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3755 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 if (TextUtils.equals(ISDR_AID, aid)) {
3759 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3761 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003762 if (bestComponent == null
3763 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3764 loge("The calling package is not allowed to access ISD-R.");
3765 throw new SecurityException(
3766 "The calling package is not allowed to access ISD-R.");
3767 }
Derek Tan740e1672017-06-27 14:56:27 -07003768 }
Derek Tan740e1672017-06-27 14:56:27 -07003769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003770 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003771 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3772 null /* workSource */);
3773 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 return response;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
3777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
3779
3780 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003781 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3783 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003784 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3785 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3786 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003787
Jordan Liu4c733742019-02-28 12:03:40 -08003788 @Override
3789 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3790 enforceModifyPermission();
3791 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3792 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3793 channel);
3794 }
3795
3796 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 if (channel < 0) {
3800 return false;
3801 }
Jordan Liu4c733742019-02-28 12:03:40 -08003802 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3803 null /* workSource */);
3804 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 return success;
3806 } finally {
3807 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003808 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003809 }
3810
3811 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003812 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003814 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3815 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003816 if (DBG) {
3817 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3818 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3819 + p3 + " data=" + data);
3820 }
3821 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3822 command, p1, p2, p3, data);
3823 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003824
Jordan Liu4c733742019-02-28 12:03:40 -08003825 @Override
3826 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3827 int command, int p1, int p2, int p3, String data) {
3828 enforceModifyPermission();
3829 if (DBG) {
3830 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3831 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3832 + p3 + " data=" + data);
3833 }
3834 return iccTransmitApduLogicalChannelWithPermission(
3835 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3836 data);
3837 }
3838
3839 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3840 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003841 final long identity = Binder.clearCallingIdentity();
3842 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003843 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 return "";
3845 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003848 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3849 null /* workSource */);
3850 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003851
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003852 // Append the returned status code to the end of the response payload.
3853 String s = Integer.toHexString(
3854 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3855 if (response.payload != null) {
3856 s = IccUtils.bytesToHexString(response.payload) + s;
3857 }
3858 return s;
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003861 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003862 }
Jake Hambye994d462014-02-03 13:10:13 -08003863
Evan Charltonc66da362014-05-16 14:06:40 -07003864 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003865 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3866 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3868 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003870 if (DBG) {
3871 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3872 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3873 }
3874 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3875 cla, command, p1, p2, p3, data);
3876 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003877
Jordan Liu4c733742019-02-28 12:03:40 -08003878 @Override
3879 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3880 int command, int p1, int p2, int p3, String data) {
3881 enforceModifyPermission();
3882 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3883 if (DBG) {
3884 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3885 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3886 + " data=" + data);
3887 }
3888
3889 return iccTransmitApduBasicChannelWithPermission(
3890 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3891 p2, p3, data);
3892 }
3893
3894 // open APDU basic channel assuming the caller has sufficient permissions
3895 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3896 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 final long identity = Binder.clearCallingIdentity();
3898 try {
3899 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3900 && TextUtils.equals(ISDR_AID, data)) {
3901 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3903 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 if (bestComponent == null
3905 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3906 loge("The calling package is not allowed to select ISD-R.");
3907 throw new SecurityException(
3908 "The calling package is not allowed to select ISD-R.");
3909 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003910 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003913 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3914 null /* workSource */);
3915 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 // Append the returned status code to the end of the response payload.
3918 String s = Integer.toHexString(
3919 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3920 if (response.payload != null) {
3921 s = IccUtils.bytesToHexString(response.payload) + s;
3922 }
3923 return s;
3924 } finally {
3925 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003926 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003927 }
3928
3929 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003930 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003931 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3933 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 if (DBG) {
3938 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3939 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3940 }
3941
3942 IccIoResult response =
3943 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3944 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3945 subId);
3946
3947 if (DBG) {
3948 log("Exchange SIM_IO [R]" + response);
3949 }
3950
3951 byte[] result = null;
3952 int length = 2;
3953 if (response.payload != null) {
3954 length = 2 + response.payload.length;
3955 result = new byte[length];
3956 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3957 } else {
3958 result = new byte[length];
3959 }
3960
3961 result[length - 1] = (byte) response.sw2;
3962 result[length - 2] = (byte) response.sw1;
3963 return result;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003966 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003967 }
3968
Nathan Haroldb3014052017-01-25 15:57:32 -08003969 /**
3970 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3971 * on a particular subscription
3972 */
sqianb6e41952018-03-12 14:54:01 -07003973 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3975 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3976 return null;
3977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978
3979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 if (appType != TelephonyManager.APPTYPE_USIM
3982 && appType != TelephonyManager.APPTYPE_SIM) {
3983 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3984 return null;
3985 }
3986 Object response = sendRequest(
3987 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3988 if (response instanceof String[]) {
3989 return (String[]) response;
3990 }
3991 // Response is an Exception of some kind,
3992 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003993 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003994 } finally {
3995 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003996 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003997 }
3998
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003999 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004000 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4002 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004003
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 final long identity = Binder.clearCallingIdentity();
4005 try {
4006 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4007 if (response.payload == null) {
4008 return "";
4009 }
Evan Charltonc66da362014-05-16 14:06:40 -07004010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 // Append the returned status code to the end of the response payload.
4012 String s = Integer.toHexString(
4013 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4014 s = IccUtils.bytesToHexString(response.payload) + s;
4015 return s;
4016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
Evan Charltonc66da362014-05-16 14:06:40 -07004019 }
4020
Jake Hambye994d462014-02-03 13:10:13 -08004021 /**
4022 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4023 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4024 *
4025 * @param itemID the ID of the item to read
4026 * @return the NV item as a String, or null on error.
4027 */
4028 @Override
4029 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004030 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004037 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004038 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4039 return value;
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Jake Hambye994d462014-02-03 13:10:13 -08004043 }
4044
4045 /**
4046 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4047 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4048 *
4049 * @param itemID the ID of the item to read
4050 * @param itemValue the value to write, as a String
4051 * @return true on success; false on any failure
4052 */
4053 @Override
4054 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004055 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004056 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4057 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058
4059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4062 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004063 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4065 return success;
4066 } finally {
4067 Binder.restoreCallingIdentity(identity);
4068 }
Jake Hambye994d462014-02-03 13:10:13 -08004069 }
4070
4071 /**
4072 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4073 * Used for device configuration by some CDMA operators.
4074 *
4075 * @param preferredRoamingList byte array containing the new PRL
4076 * @return true on success; false on any failure
4077 */
4078 @Override
4079 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4081 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004082
4083 final long identity = Binder.clearCallingIdentity();
4084 try {
4085 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4086 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4087 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4088 return success;
4089 } finally {
4090 Binder.restoreCallingIdentity(identity);
4091 }
Jake Hambye994d462014-02-03 13:10:13 -08004092 }
4093
4094 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004095 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004096 * Used for device configuration by some CDMA operators.
4097 *
chen xu6dac5ab2018-10-26 17:39:23 -07004098 * @param slotIndex - device slot.
4099 *
Jake Hambye994d462014-02-03 13:10:13 -08004100 * @return true on success; false on any failure
4101 */
4102 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004103 public boolean resetModemConfig(int slotIndex) {
4104 Phone phone = PhoneFactory.getPhone(slotIndex);
4105 if (phone != null) {
4106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4107 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004108
chen xu6dac5ab2018-10-26 17:39:23 -07004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4112 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4113 return success;
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
4116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117 }
chen xu6dac5ab2018-10-26 17:39:23 -07004118 return false;
4119 }
4120
4121 /**
4122 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4123 *
4124 * @param slotIndex - device slot.
4125 *
4126 * @return true on success; false on any failure
4127 */
4128 @Override
4129 public boolean rebootModem(int slotIndex) {
4130 Phone phone = PhoneFactory.getPhone(slotIndex);
4131 if (phone != null) {
4132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4133 mApp, phone.getSubId(), "rebootModem");
4134
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4138 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4139 return success;
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
4143 }
4144 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004145 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004146
Svet Ganovb320e182015-04-16 12:30:10 -07004147 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004148 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004151 return new String[0];
4152 }
4153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004154 final long identity = Binder.clearCallingIdentity();
4155 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004156 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Wink Saville36469e72014-06-11 15:17:00 -07004160 }
4161
Brad Ebinger51f743a2017-01-23 13:50:20 -08004162 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004163 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4164 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004165 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004166 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004167 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004171 ImsResolver resolver = PhoneFactory.getImsResolver();
4172 if (resolver == null) {
4173 // may happen if the device does not support IMS.
4174 return;
4175 }
4176 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 } finally {
4178 Binder.restoreCallingIdentity(identity);
4179 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004180 }
4181
4182 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004183 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4184 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004185 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004186 public void disableIms(int slotId) {
4187 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188
4189 final long identity = Binder.clearCallingIdentity();
4190 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004191 ImsResolver resolver = PhoneFactory.getImsResolver();
4192 if (resolver == null) {
4193 // may happen if the device does not support IMS.
4194 return;
4195 }
4196 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 } finally {
4198 Binder.restoreCallingIdentity(identity);
4199 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004200 }
4201
4202 /**
4203 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4204 * feature or {@link null} if the service is not available. If the feature is available, the
4205 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4206 */
4207 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004208 IImsServiceFeatureCallback callback) {
4209 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210
4211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004213 ImsResolver resolver = PhoneFactory.getImsResolver();
4214 if (resolver == null) {
4215 // may happen if the device does not support IMS.
4216 return null;
4217 }
4218 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004222 }
4223
4224 /**
4225 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4226 * feature during emergency calling or {@link null} if the service is not available. If the
4227 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4228 * listener for feature updates.
4229 */
4230 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4231 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232
4233 final long identity = Binder.clearCallingIdentity();
4234 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004235 ImsResolver resolver = PhoneFactory.getImsResolver();
4236 if (resolver == null) {
4237 // may happen if the device does not support IMS.
4238 return null;
4239 }
4240 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004241 } finally {
4242 Binder.restoreCallingIdentity(identity);
4243 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004244 }
4245
Brad Ebinger5f64b052017-12-14 14:26:15 -08004246 /**
4247 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004248 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004249 */
4250 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4251 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252
4253 final long identity = Binder.clearCallingIdentity();
4254 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004255 ImsResolver resolver = PhoneFactory.getImsResolver();
4256 if (resolver == null) {
4257 // may happen if the device does not support IMS.
4258 return null;
4259 }
4260 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 } finally {
4262 Binder.restoreCallingIdentity(identity);
4263 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004264 }
4265
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004266 /**
4267 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004268 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004269 */
4270 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4271 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272
4273 final long identity = Binder.clearCallingIdentity();
4274 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004275 ImsResolver resolver = PhoneFactory.getImsResolver();
4276 if (resolver == null) {
4277 // may happen if the device does not support IMS.
4278 return null;
4279 }
4280 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004284 }
4285
Brad Ebinger884c07b2018-02-15 16:17:40 -08004286 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004287 * Sets the ImsService Package Name that Telephony will bind to.
4288 *
4289 * @param slotId the slot ID that the ImsService should bind for.
4290 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4291 * ImsService is the device default ImsService.
4292 * @param packageName The package name of the application that contains the ImsService to bind
4293 * to.
4294 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4295 * @hide
4296 */
4297 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004298 int[] subIds = SubscriptionManager.getSubId(slotId);
4299 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4300 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4301 "setImsService");
4302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 final long identity = Binder.clearCallingIdentity();
4304 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004305 ImsResolver resolver = PhoneFactory.getImsResolver();
4306 if (resolver == null) {
4307 // may happen if the device does not support IMS.
4308 return false;
4309 }
4310 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4311 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004315 }
4316
4317 /**
4318 * Return the ImsService configuration.
4319 *
4320 * @param slotId The slot that the ImsService is associated with.
4321 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4322 * the device default.
4323 * @return the package name of the ImsService configuration.
4324 */
4325 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004326 int[] subIds = SubscriptionManager.getSubId(slotId);
4327 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4328 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4329 "getImsService");
4330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004333 ImsResolver resolver = PhoneFactory.getImsResolver();
4334 if (resolver == null) {
4335 // may happen if the device does not support IMS.
4336 return "";
4337 }
4338 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004342 }
4343
Wink Saville36469e72014-06-11 15:17:00 -07004344 public void setImsRegistrationState(boolean registered) {
4345 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346
4347 final long identity = Binder.clearCallingIdentity();
4348 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004349 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 } finally {
4351 Binder.restoreCallingIdentity(identity);
4352 }
Wink Saville36469e72014-06-11 15:17:00 -07004353 }
4354
4355 /**
Stuart Scott54788802015-03-30 13:18:01 -07004356 * Set the network selection mode to automatic.
4357 *
4358 */
4359 @Override
4360 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004361 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4362 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363
Pengquan Menge92a50d2018-09-21 15:54:48 -07004364 if (!isActiveSubscription(subId)) {
4365 return;
4366 }
4367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4371 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
Stuart Scott54788802015-03-30 13:18:01 -07004375 }
4376
Pengquan Mengea84e042018-09-20 14:57:26 -07004377 /**
4378 * Ask the radio to connect to the input network and change selection mode to manual.
4379 *
4380 * @param subId the id of the subscription.
4381 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4382 * the operator to attach to.
4383 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4384 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4385 * normal network selection next time.
4386 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004387 */
4388 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004389 public boolean setNetworkSelectionModeManual(
4390 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004393
4394 if (!isActiveSubscription(subId)) {
4395 return false;
4396 }
4397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398 final long identity = Binder.clearCallingIdentity();
4399 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004400 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004402 if (DBG) {
4403 log("setNetworkSelectionModeManual: subId: " + subId
4404 + " operator: " + operatorInfo);
4405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004410 }
4411
4412 /**
4413 * Scans for available networks.
4414 */
4415 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004416 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4418 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004419 LocationAccessPolicy.LocationPermissionResult locationResult =
4420 LocationAccessPolicy.checkLocationPermission(mApp,
4421 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4422 .setCallingPackage(callingPackage)
4423 .setCallingPid(Binder.getCallingPid())
4424 .setCallingUid(Binder.getCallingUid())
4425 .setMethod("getCellNetworkScanResults")
4426 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4427 .build());
4428 switch (locationResult) {
4429 case DENIED_HARD:
4430 throw new SecurityException("Not allowed to access scan results -- location");
4431 case DENIED_SOFT:
4432 return null;
4433 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434
Pengquan Menga1bb6272018-09-06 09:59:22 -07004435 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 try {
4437 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004438 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004440 } finally {
4441 Binder.restoreCallingIdentity(identity);
4442 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004443 }
4444
4445 /**
yinxub1bed742017-04-17 11:45:04 -07004446 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004447 *
yinxub1bed742017-04-17 11:45:04 -07004448 * @param subId id of the subscription
4449 * @param request contains the radio access networks with bands/channels to scan
4450 * @param messenger callback messenger for scan results or errors
4451 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004452 * @return the id of the requested scan which can be used to stop the scan.
4453 */
4454 @Override
4455 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004456 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004457 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4458 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004459 LocationAccessPolicy.LocationPermissionResult locationResult =
4460 LocationAccessPolicy.checkLocationPermission(mApp,
4461 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4462 .setCallingPackage(callingPackage)
4463 .setCallingPid(Binder.getCallingPid())
4464 .setCallingUid(Binder.getCallingUid())
4465 .setMethod("requestNetworkScan")
4466 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4467 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004468 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004469 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004470 if (e != null) {
4471 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4472 throw e;
4473 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004474 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004475 return TelephonyScanManager.INVALID_SCAN_ID;
4476 }
4477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 }
Hall Liu912dfd32019-04-25 14:02:26 -07004479 int callingUid = Binder.getCallingUid();
4480 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 return mNetworkScanRequestTracker.startNetworkScan(
4484 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004485 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004486 } finally {
4487 Binder.restoreCallingIdentity(identity);
4488 }
yinxu504e1392017-04-12 16:03:22 -07004489 }
4490
Hall Liub2ac8ef2019-02-28 15:56:23 -08004491 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004492 NetworkScanRequest request, int subId) {
4493 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4494 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4495 boolean hasNetworkScanPermission =
4496 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4497 == PERMISSION_GRANTED;
4498
4499 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4500 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4501 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004502 }
4503
4504 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4505 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004506 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4507 return new SecurityException("Specific channels must not be"
4508 + " scanned without location access.");
4509 }
4510 }
4511 }
4512
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 return null;
4514 }
4515
yinxu504e1392017-04-12 16:03:22 -07004516 /**
4517 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004518 *
4519 * @param subId id of the subscription
4520 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004521 */
4522 @Override
4523 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526
Hall Liu912dfd32019-04-25 14:02:26 -07004527 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 final long identity = Binder.clearCallingIdentity();
4529 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004530 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
yinxu504e1392017-04-12 16:03:22 -07004534 }
4535
4536 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004537 * Get the calculated preferred network type.
4538 * Used for debugging incorrect network type.
4539 *
4540 * @return the preferred network type, defined in RILConstants.java.
4541 */
4542 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004543 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004544 final Phone defaultPhone = getDefaultPhone();
4545 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4546 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004547 return RILConstants.PREFERRED_NETWORK_MODE;
4548 }
4549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004550 final long identity = Binder.clearCallingIdentity();
4551 try {
4552 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004553 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
Junda Liu84d15a22014-07-02 11:21:04 -07004557 }
4558
4559 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004560 * Get the preferred network type.
4561 * Used for device configuration by some CDMA operators.
4562 *
4563 * @return the preferred network type, defined in RILConstants.java.
4564 */
4565 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004566 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004567 TelephonyPermissions
4568 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4569 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 if (DBG) log("getPreferredNetworkType");
4574 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4575 int networkType = (result != null ? result[0] : -1);
4576 if (DBG) log("getPreferredNetworkType: " + networkType);
4577 return networkType;
4578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004581 }
4582
4583 /**
4584 * Set the preferred network type.
4585 * Used for device configuration by some CDMA operators.
4586 *
4587 * @param networkType the preferred network type, defined in RILConstants.java.
4588 * @return true on success; false on any failure.
4589 */
4590 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004591 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004592 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4593 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594
4595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4598 Boolean success = (Boolean) sendRequest(
4599 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4600 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4601 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004602 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004603 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4604 }
4605 return success;
4606 } finally {
4607 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004608 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004609 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004610
4611 /**
Miaoa84611c2019-03-15 09:21:10 +08004612 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004613 *
Miaoa84611c2019-03-15 09:21:10 +08004614 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004615 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004616 * @hide
4617 */
4618 @Override
Miaoa84611c2019-03-15 09:21:10 +08004619 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004620 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004622 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004623 try {
Miaoa84611c2019-03-15 09:21:10 +08004624 if (phone != null) {
4625 return phone.hasMatchedTetherApnSetting();
4626 } else {
4627 return false;
4628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629 } finally {
4630 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004631 }
Junda Liu475951f2014-11-07 16:45:03 -08004632 }
4633
4634 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004635 * Set mobile data enabled
4636 * Used by the user through settings etc to turn on/off mobile data
4637 *
4638 * @param enable {@code true} turn turn data on, else {@code false}
4639 */
4640 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004641 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4643 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644
4645 final long identity = Binder.clearCallingIdentity();
4646 try {
4647 int phoneId = mSubscriptionController.getPhoneId(subId);
4648 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4649 Phone phone = PhoneFactory.getPhone(phoneId);
4650 if (phone != null) {
4651 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004652 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004654 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004658 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004659 }
4660
4661 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004662 * Get the user enabled state of Mobile Data.
4663 *
4664 * TODO: remove and use isUserDataEnabled.
4665 * This can't be removed now because some vendor codes
4666 * calls through ITelephony directly while they should
4667 * use TelephonyManager.
4668 *
4669 * @return true on enabled
4670 */
4671 @Override
4672 public boolean getDataEnabled(int subId) {
4673 return isUserDataEnabled(subId);
4674 }
4675
4676 /**
4677 * Get whether mobile data is enabled per user setting.
4678 *
4679 * There are other factors deciding whether mobile data is actually enabled, but they are
4680 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004681 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004682 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004683 *
4684 * @return {@code true} if data is enabled else {@code false}
4685 */
4686 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004687 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004688 try {
4689 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4690 null);
4691 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4693 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004694 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 int phoneId = mSubscriptionController.getPhoneId(subId);
4699 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4700 Phone phone = PhoneFactory.getPhone(phoneId);
4701 if (phone != null) {
4702 boolean retVal = phone.isUserDataEnabled();
4703 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4704 return retVal;
4705 } else {
4706 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4707 return false;
4708 }
4709 } finally {
4710 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004711 }
4712 }
4713
4714 /**
4715 * Get whether mobile data is enabled.
4716 *
4717 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4718 * whether mobile data is actually enabled.
4719 *
4720 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4721 *
4722 * @return {@code true} if data is enabled else {@code false}
4723 */
4724 @Override
4725 public boolean isDataEnabled(int subId) {
4726 try {
4727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4728 null);
4729 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4731 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 int phoneId = mSubscriptionController.getPhoneId(subId);
4737 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4738 Phone phone = PhoneFactory.getPhone(phoneId);
4739 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004740 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4742 return retVal;
4743 } else {
4744 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4745 return false;
4746 }
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004749 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004750 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004751
4752 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004753 public int getCarrierPrivilegeStatus(int subId) {
4754 final Phone phone = getPhone(subId);
4755 if (phone == null) {
4756 loge("getCarrierPrivilegeStatus: Invalid subId");
4757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4758 }
4759 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004760 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004761 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004762 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4763 }
4764 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004765 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004766 }
Junda Liu29340342014-07-10 15:23:27 -07004767
4768 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4770 final Phone phone = getPhone(subId);
4771 if (phone == null) {
4772 loge("getCarrierPrivilegeStatus: Invalid subId");
4773 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4774 }
4775 UiccProfile profile =
4776 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4777 if (profile == null) {
4778 loge("getCarrierPrivilegeStatus: No UICC");
4779 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4780 }
4781 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4782 }
4783
4784 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004785 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4786 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004787 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004788 }
4789
4790 int phoneId = SubscriptionManager.getPhoneId(subId);
4791 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004792 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004793 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004794 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4795 }
chen xuf7e9fe82019-05-09 19:31:02 -07004796
4797 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004798 }
4799
4800 @Override
4801 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004802 if (TextUtils.isEmpty(pkgName))
4803 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004804 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4805 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4806 UiccCard card = UiccController.getInstance().getUiccCard(i);
4807 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004808 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004809 continue;
4810 }
4811
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004812 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004813 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4814 break;
4815 }
4816 }
4817
4818 return result;
Junda Liu29340342014-07-10 15:23:27 -07004819 }
Derek Tan89e89d42014-07-08 17:00:10 -07004820
4821 @Override
Junda Liue64de782015-04-16 17:19:16 -07004822 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4823 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4824 loge("phoneId " + phoneId + " is not valid.");
4825 return null;
4826 }
4827 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004828 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004829 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004830 return null ;
4831 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004832 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004833 }
4834
Amith Yamasani6e118872016-02-19 12:53:51 -08004835 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004836 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004837 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004838 List<String> privilegedPackages = new ArrayList<>();
4839 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004840 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4841 // has UICC in that slot.
4842 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004843 if (card.hasCarrierPrivilegeRules()) {
4844 if (packages == null) {
4845 // Only check packages in user 0 for now
4846 packages = pm.getInstalledPackagesAsUser(
4847 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004848 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4849 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004850 }
4851 for (int p = packages.size() - 1; p >= 0; p--) {
4852 PackageInfo pkgInfo = packages.get(p);
4853 if (pkgInfo != null && pkgInfo.packageName != null
4854 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004855 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004856 privilegedPackages.add(pkgInfo.packageName);
4857 }
4858 }
4859 }
4860 }
4861 return privilegedPackages;
4862 }
4863
chen xuf7e9fe82019-05-09 19:31:02 -07004864 @Override
4865 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4866 List<String> privilegedPackages = new ArrayList<>();
4867 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4868 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4869 }
4870 return privilegedPackages;
4871 }
4872
Wink Savilleb564aae2014-10-23 10:18:09 -07004873 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004874 final Phone phone = getPhone(subId);
4875 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004876 if (card == null) {
4877 loge("getIccId: No UICC");
4878 return null;
4879 }
4880 String iccId = card.getIccId();
4881 if (TextUtils.isEmpty(iccId)) {
4882 loge("getIccId: ICC ID is null or empty.");
4883 return null;
4884 }
4885 return iccId;
4886 }
4887
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004888 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004889 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4890 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004891 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4892 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 final String iccId = getIccId(subId);
4897 final Phone phone = getPhone(subId);
4898 if (phone == null) {
4899 return false;
4900 }
4901 final String subscriberId = phone.getSubscriberId();
4902
4903 if (DBG_MERGE) {
4904 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4905 + subscriberId + " to " + number);
4906 }
4907
4908 if (TextUtils.isEmpty(iccId)) {
4909 return false;
4910 }
4911
4912 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4913
4914 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4915 if (alphaTag == null) {
4916 editor.remove(alphaTagPrefKey);
4917 } else {
4918 editor.putString(alphaTagPrefKey, alphaTag);
4919 }
4920
4921 // Record both the line number and IMSI for this ICCID, since we need to
4922 // track all merged IMSIs based on line number
4923 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4924 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4925 if (number == null) {
4926 editor.remove(numberPrefKey);
4927 editor.remove(subscriberPrefKey);
4928 } else {
4929 editor.putString(numberPrefKey, number);
4930 editor.putString(subscriberPrefKey, subscriberId);
4931 }
4932
4933 editor.commit();
4934 return true;
4935 } finally {
4936 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004937 }
Derek Tan7226c842014-07-02 17:42:23 -07004938 }
4939
4940 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004941 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004942 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004944 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004945 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004946 return null;
4947 }
Derek Tan97ebb422014-09-05 16:55:38 -07004948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 String iccId = getIccId(subId);
4952 if (iccId != null) {
4953 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4954 if (DBG_MERGE) {
4955 log("getLine1NumberForDisplay returning "
4956 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4957 }
4958 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004959 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004960 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4961 return null;
4962 } finally {
4963 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004964 }
Derek Tan7226c842014-07-02 17:42:23 -07004965 }
4966
4967 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004968 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004970 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004971 return null;
4972 }
Derek Tan97ebb422014-09-05 16:55:38 -07004973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 final long identity = Binder.clearCallingIdentity();
4975 try {
4976 String iccId = getIccId(subId);
4977 if (iccId != null) {
4978 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4979 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4980 }
4981 return null;
4982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004984 }
Derek Tan7226c842014-07-02 17:42:23 -07004985 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004986
4987 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004988 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004989 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4990 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004992 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4993 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004994 return null;
4995 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004996
Jordan Liub49b04b2019-05-06 14:45:15 -07004997 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4998 // the process, where TelephonyManager was instantiated.
4999 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005000 final long identity = Binder.clearCallingIdentity();
5001 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005002 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 final TelephonyManager tele = TelephonyManager.from(context);
5004 final SubscriptionManager sub = SubscriptionManager.from(context);
5005
5006 // Figure out what subscribers are currently active
5007 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005008
Jordan Liub49b04b2019-05-06 14:45:15 -07005009 // Only consider subs which match the current subId
5010 // This logic can be simplified. See b/131189269 for progress.
5011 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005012 activeSubscriberIds.add(tele.getSubscriberId(subId));
5013 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014
5015 // First pass, find a number override for an active subscriber
5016 String mergeNumber = null;
5017 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5018 for (String key : prefs.keySet()) {
5019 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5020 final String subscriberId = (String) prefs.get(key);
5021 if (activeSubscriberIds.contains(subscriberId)) {
5022 final String iccId = key.substring(
5023 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5024 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5025 mergeNumber = (String) prefs.get(numberKey);
5026 if (DBG_MERGE) {
5027 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5028 + " for active subscriber " + subscriberId);
5029 }
5030 if (!TextUtils.isEmpty(mergeNumber)) {
5031 break;
5032 }
5033 }
5034 }
5035 }
5036
5037 // Shortcut when no active merged subscribers
5038 if (TextUtils.isEmpty(mergeNumber)) {
5039 return null;
5040 }
5041
5042 // Second pass, find all subscribers under that line override
5043 final ArraySet<String> result = new ArraySet<>();
5044 for (String key : prefs.keySet()) {
5045 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5046 final String number = (String) prefs.get(key);
5047 if (mergeNumber.equals(number)) {
5048 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5049 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5050 final String subscriberId = (String) prefs.get(subscriberKey);
5051 if (!TextUtils.isEmpty(subscriberId)) {
5052 result.add(subscriberId);
5053 }
5054 }
5055 }
5056 }
5057
5058 final String[] resultArray = result.toArray(new String[result.size()]);
5059 Arrays.sort(resultArray);
5060 if (DBG_MERGE) {
5061 Slog.d(LOG_TAG,
5062 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5063 }
5064 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005067 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005068 }
5069
5070 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005071 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5072 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5073
5074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 final TelephonyManager telephonyManager = mApp.getSystemService(
5077 TelephonyManager.class);
5078 String subscriberId = telephonyManager.getSubscriberId(subId);
5079 if (subscriberId == null) {
5080 if (DBG) {
5081 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5082 + subId);
5083 }
5084 return null;
5085 }
5086
5087 final SubscriptionInfo info = SubscriptionController.getInstance()
5088 .getSubscriptionInfo(subId);
5089 final ParcelUuid groupUuid = info.getGroupUuid();
5090 // If it doesn't belong to any group, return just subscriberId of itself.
5091 if (groupUuid == null) {
5092 return new String[]{subscriberId};
5093 }
5094
5095 // Get all subscriberIds from the group.
5096 final List<String> mergedSubscriberIds = new ArrayList<>();
5097 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5098 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5099 for (SubscriptionInfo subInfo : groupInfos) {
5100 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5101 if (subscriberId != null) {
5102 mergedSubscriberIds.add(subscriberId);
5103 }
5104 }
5105
5106 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5107 } finally {
5108 Binder.restoreCallingIdentity(identity);
5109
5110 }
5111 }
5112
5113 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005114 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005115 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5116 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005117
5118 final long identity = Binder.clearCallingIdentity();
5119 try {
5120 final Phone phone = getPhone(subId);
5121 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005125 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005126
5127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005129 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5130 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005131 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132
5133 final long identity = Binder.clearCallingIdentity();
5134 try {
5135 final Phone phone = getPhone(subId);
5136 if (phone == null) {
5137 return false;
5138 }
5139 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5140 cdmaNonRoamingList);
5141 } finally {
5142 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005143 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005144 }
5145
5146 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005147 @Deprecated
5148 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5149 enforceModifyPermission();
5150
5151 int returnValue = 0;
5152 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005153 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005154 if(result.exception == null) {
5155 if (result.result != null) {
5156 byte[] responseData = (byte[])(result.result);
5157 if(responseData.length > oemResp.length) {
5158 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5159 responseData.length + "bytes. Buffer Size is " +
5160 oemResp.length + "bytes.");
5161 }
5162 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5163 returnValue = responseData.length;
5164 }
5165 } else {
5166 CommandException ex = (CommandException) result.exception;
5167 returnValue = ex.getCommandError().ordinal();
5168 if(returnValue > 0) returnValue *= -1;
5169 }
5170 } catch (RuntimeException e) {
5171 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5172 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5173 if(returnValue > 0) returnValue *= -1;
5174 }
5175
5176 return returnValue;
5177 }
5178
5179 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005180 public void setRadioCapability(RadioAccessFamily[] rafs) {
5181 try {
5182 ProxyController.getInstance().setRadioCapability(rafs);
5183 } catch (RuntimeException e) {
5184 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5185 }
5186 }
5187
5188 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005189 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005190 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005191 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005192 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005193 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 final long identity = Binder.clearCallingIdentity();
5196 try {
chen xub97461a2018-10-26 14:17:57 -07005197 TelephonyPermissions
5198 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5199 mApp, phone.getSubId(), "getRadioAccessFamily");
5200 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 } finally {
5202 Binder.restoreCallingIdentity(identity);
5203 }
chen xub97461a2018-10-26 14:17:57 -07005204 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005205 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005206
5207 @Override
5208 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211
5212 final long identity = Binder.clearCallingIdentity();
5213 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005214 ImsManager.getInstance(defaultPhone.getContext(),
5215 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005219 }
5220
5221 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005222 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005223 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005226 return false;
5227 }
Svet Ganovb320e182015-04-16 12:30:10 -07005228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 // Check the user preference and the system-level IMS setting. Even if the user has
5232 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5233 // In the long run, we may instead need to check if there exists a connection service
5234 // which can support video calling.
5235 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005236 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 return imsManager.isVtEnabledByPlatform()
5238 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5239 && imsManager.isVtEnabledByUser();
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
5242 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005243 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005244
Andrew Leea1239f22015-03-02 17:44:07 -08005245 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5247 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5248 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5249 return false;
5250 }
5251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 CarrierConfigManager configManager =
5255 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005256 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Andrew Leea1239f22015-03-02 17:44:07 -08005261 }
5262
5263 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 public boolean isWorldPhone(int subId, String callingPackage) {
5265 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5266 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5267 return false;
5268 }
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 CarrierConfigManager configManager =
5273 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005274 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005275 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
5278 }
Andrew Leea1239f22015-03-02 17:44:07 -08005279 }
5280
Andrew Lee9431b832015-03-09 18:46:45 -07005281 @Override
5282 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005283 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005284 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005285 }
5286
5287 @Override
5288 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 final long identity = Binder.clearCallingIdentity();
5290 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005291 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 } finally {
5293 Binder.restoreCallingIdentity(identity);
5294 }
Andrew Lee9431b832015-03-09 18:46:45 -07005295 }
5296
Hall Liuf6668912018-10-31 17:05:23 -07005297 /**
5298 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5299 * support for the feature and device firmware support.
5300 *
5301 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5302 */
5303 @Override
5304 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005306 final Phone phone = getPhone(subscriptionId);
5307 if (phone == null) {
5308 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5309 return false;
5310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005312 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5314 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005315 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 return isCarrierSupported && isDeviceSupported;
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
5319 }
Hall Liu98187582018-01-22 19:15:32 -08005320 }
5321
Hall Liuf6668912018-10-31 17:05:23 -07005322 /**
5323 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5324 * both also support RTT.
5325 */
5326 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 final long identity = Binder.clearCallingIdentity();
5328 try {
Hall Liuf6668912018-10-31 17:05:23 -07005329 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005330 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005334 }
5335
Sanket Padawe7310cc72015-01-14 09:53:20 -08005336 /**
5337 * Returns the unique device ID of phone, for example, the IMEI for
5338 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5339 *
5340 * <p>Requires Permission:
5341 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5342 */
5343 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005344 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005345 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005346 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005347 return null;
5348 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005349 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005350 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5351 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005352 return null;
5353 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354
5355 final long identity = Binder.clearCallingIdentity();
5356 try {
5357 return phone.getDeviceId();
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005361 }
5362
Ping Sunc67b7c22016-03-02 19:16:45 +08005363 /**
5364 * {@hide}
5365 * Returns the IMS Registration Status on a particular subid
5366 *
5367 * @param subId
5368 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005369 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005370 Phone phone = getPhone(subId);
5371 if (phone != null) {
5372 return phone.isImsRegistered();
5373 } else {
5374 return false;
5375 }
5376 }
5377
Santos Cordon7a1885b2015-02-03 11:15:19 -08005378 @Override
5379 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 final long identity = Binder.clearCallingIdentity();
5381 try {
5382 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005386 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005387
Tyler Gunnf70ed162019-04-03 15:28:53 -07005388 @Override
5389 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 Phone phone = getPhone(subscriptionId);
5393 if (phone == null) {
5394 return null;
5395 }
5396 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
5400 }
5401
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005402 /**
5403 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005404 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005405 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 final long identity = Binder.clearCallingIdentity();
5407 try {
5408 Phone phone = getPhone(subId);
5409 if (phone != null) {
5410 return phone.isWifiCallingEnabled();
5411 } else {
5412 return false;
5413 }
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005416 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005417 }
5418
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005419 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005420 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005421 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005422 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 Phone phone = getPhone(subId);
5426 if (phone != null) {
5427 return phone.isVideoEnabled();
5428 } else {
5429 return false;
5430 }
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005433 }
5434 }
5435
5436 /**
5437 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5438 * defined in {@link ImsRegistrationImplBase}.
5439 */
5440 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 Phone phone = getPhone(subId);
5444 if (phone != null) {
5445 return phone.getImsRegistrationTech();
5446 } else {
5447 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5448 }
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005451 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005452 }
5453
Stuart Scott8eef64f2015-04-08 15:13:54 -07005454 @Override
5455 public void factoryReset(int subId) {
5456 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005457 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5458 return;
5459 }
5460
Svet Ganovcc087f82015-05-12 20:35:54 -07005461 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005462
Svet Ganovcc087f82015-05-12 20:35:54 -07005463 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005464 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5465 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005466 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005467 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005468 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005469 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5470 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005471 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005472 // There has been issues when Sms raw table somehow stores orphan
5473 // fragments. They lead to garbled message when new fragments come
5474 // in and combined with those stale ones. In case this happens again,
5475 // user can reset all network settings which will clean up this table.
5476 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005477 } finally {
5478 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005479 }
5480 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005481
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005482 private void cleanUpSmsRawTable(Context context) {
5483 ContentResolver resolver = context.getContentResolver();
5484 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5485 resolver.delete(uri, null, null);
5486 }
5487
Narayan Kamath1c496c22015-04-16 14:40:19 +01005488 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005489 public String getSimLocaleForSubscriber(int subId) {
5490 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5491 final Phone phone = getPhone(subId);
5492 if (phone == null) {
5493 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005494 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005495 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 final long identity = Binder.clearCallingIdentity();
5497 try {
chen xu5d3637b2019-01-21 23:31:38 -08005498 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5499 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005500 if (info == null) {
5501 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5502 return null;
5503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 // Try and fetch the locale from the carrier properties or from the SIM language
5505 // preferences (EF-PL and EF-LI)...
5506 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005507 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005508 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5509 if (localeFromDefaultSim != null) {
5510 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5511 if (DBG) log("Using locale from subId: " + subId + " locale: "
5512 + localeFromDefaultSim);
5513 return localeFromDefaultSim.toLanguageTag();
5514 } else {
5515 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 }
5517 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005518
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 // The SIM language preferences only store a language (e.g. fr = French), not an
5520 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5521 // the SIM and carrier preferences does not include a country we add the country
5522 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005523 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005524 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005525 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 return mccLocale.toLanguageTag();
5527 }
5528
5529 if (DBG) log("No locale found - returning null");
5530 return null;
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005534 }
5535
5536 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005537 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005538 }
5539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 /**
5541 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5542 */
5543 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005544 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005545 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005546
Chenjie Yu1ba97252018-01-11 18:16:20 -08005547 private final ModemActivityInfo mLastModemActivityInfo =
5548 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5549
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005550 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005551 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5552 * representing the state of the modem.
5553 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005554 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5555 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005556 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005557 */
5558 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005559 public void requestModemActivityInfo(ResultReceiver result) {
5560 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005561 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 ModemActivityInfo ret = null;
5566 synchronized (mLastModemActivityInfo) {
5567 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5568 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005569 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005570 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005571 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5572 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005573 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5574 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 }
5576 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5578 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 mLastModemActivityInfo.setIdleTimeMillis(
5580 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5581 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5582 mLastModemActivityInfo.setRxTimeMillis(
5583 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5584 mLastModemActivityInfo.setEnergyUsed(
5585 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5588 mLastModemActivityInfo.getSleepTimeMillis(),
5589 mLastModemActivityInfo.getIdleTimeMillis(),
5590 mLastModemActivityInfo.getTxTimeMillis(),
5591 mLastModemActivityInfo.getRxTimeMillis(),
5592 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 Bundle bundle = new Bundle();
5595 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5596 result.send(0, bundle);
5597 } finally {
5598 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005599 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005600 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005601
Siddharth Rayb8114062018-06-17 15:02:38 -07005602 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5603 // less than total activity duration.
5604 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5605 if (info == null) {
5606 return false;
5607 }
5608 int activityDurationMs =
5609 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5610 int totalTxTimeMs = 0;
5611 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5612 totalTxTimeMs += info.getTxTimeMillis()[i];
5613 }
5614 return (info.isValid()
5615 && (info.getSleepTimeMillis() <= activityDurationMs)
5616 && (info.getIdleTimeMillis() <= activityDurationMs)
5617 && (info.getRxTimeMillis() <= activityDurationMs)
5618 && (totalTxTimeMs <= activityDurationMs));
5619 }
5620
Jack Yu85bd38a2015-11-09 11:34:32 -08005621 /**
5622 * {@hide}
5623 * Returns the service state information on specified subscription.
5624 */
5625 @Override
5626 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005628 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005629 return null;
5630 }
5631
Hall Liuf19c44f2018-11-27 14:38:17 -08005632 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5633 LocationAccessPolicy.checkLocationPermission(mApp,
5634 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5635 .setCallingPackage(callingPackage)
5636 .setCallingPid(Binder.getCallingPid())
5637 .setCallingUid(Binder.getCallingUid())
5638 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005639 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005640 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5641 .build());
5642
5643 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5644 LocationAccessPolicy.checkLocationPermission(mApp,
5645 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5646 .setCallingPackage(callingPackage)
5647 .setCallingPid(Binder.getCallingPid())
5648 .setCallingUid(Binder.getCallingUid())
5649 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005650 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005651 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5652 .build());
5653 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5654 boolean hasFinePermission =
5655 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5656 boolean hasCoarsePermission =
5657 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 final Phone phone = getPhone(subId);
5662 if (phone == null) {
5663 return null;
5664 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005665
Hall Liuf19c44f2018-11-27 14:38:17 -08005666 ServiceState ss = phone.getServiceState();
5667
5668 // Scrub out the location info in ServiceState depending on what level of access
5669 // the caller has.
5670 if (hasFinePermission) return ss;
5671 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5672 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005676 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005677
5678 /**
5679 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5680 *
5681 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5682 * voicemail ringtone.
5683 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5684 * PhoneAccount.
5685 */
5686 @Override
5687 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 final long identity = Binder.clearCallingIdentity();
5689 try {
5690 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5691 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005692 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005694
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5696 } finally {
5697 Binder.restoreCallingIdentity(identity);
5698 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005699 }
5700
5701 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005702 * Sets the per-account voicemail ringtone.
5703 *
5704 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5705 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5706 *
5707 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5708 * voicemail ringtone.
5709 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5710 * PhoneAccount.
5711 */
5712 @Override
5713 public void setVoicemailRingtoneUri(String callingPackage,
5714 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005715 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005716 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5717 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005718 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5720 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5721 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723
5724 final long identity = Binder.clearCallingIdentity();
5725 try {
5726 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5727 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005728 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729 }
5730 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005733 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005734 }
5735
5736 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005737 * Returns whether vibration is set for voicemail notification in Phone settings.
5738 *
5739 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5740 * voicemail vibration setting.
5741 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5742 */
5743 @Override
5744 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5748 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005749 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005750 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5753 } finally {
5754 Binder.restoreCallingIdentity(identity);
5755 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005756 }
5757
Youhan Wange64578a2016-05-02 15:32:42 -07005758 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005759 * Sets the per-account voicemail vibration.
5760 *
5761 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5762 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5763 *
5764 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5765 * voicemail vibration setting.
5766 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5767 * specific PhoneAccount.
5768 */
5769 @Override
5770 public void setVoicemailVibrationEnabled(String callingPackage,
5771 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005772 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5774 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005775 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5777 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5778 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005779 }
5780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 final long identity = Binder.clearCallingIdentity();
5782 try {
5783 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5784 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005785 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 }
5787 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005790 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005791 }
5792
5793 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005794 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5795 *
5796 * @throws SecurityException if the caller does not have the required permission
5797 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005798 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005799 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005800 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005801 }
5802
5803 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005804 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5805 * permission.
5806 *
5807 * @throws SecurityException if the caller does not have the required permission
5808 */
5809 private void enforceSendSmsPermission() {
5810 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5811 }
5812
5813 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005814 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005815 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005816 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005817 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005818 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005819 final long identity = Binder.clearCallingIdentity();
5820 try {
5821 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005822 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823 if (componentName == null) {
5824 throw new SecurityException(
5825 "Caller not current active visual voicemail package[null]");
5826 }
5827 String vvmPackage = componentName.getPackageName();
5828 if (!callingPackage.equals(vvmPackage)) {
5829 throw new SecurityException("Caller not current active visual voicemail package["
5830 + vvmPackage + "]");
5831 }
5832 } finally {
5833 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005834 }
5835 }
5836
5837 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005838 * Return the application ID for the app type.
5839 *
5840 * @param subId the subscription ID that this request applies to.
5841 * @param appType the uicc app type.
5842 * @return Application ID for specificied app type, or null if no uicc.
5843 */
5844 @Override
5845 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005846 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005847 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848
5849 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005850 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 if (phone == null) {
5852 return null;
5853 }
5854 String aid = null;
5855 try {
5856 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5857 .getApplicationByType(appType).getAid();
5858 } catch (Exception e) {
5859 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5860 }
5861 return aid;
5862 } finally {
5863 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005864 }
Youhan Wange64578a2016-05-02 15:32:42 -07005865 }
5866
Youhan Wang4001d252016-05-11 10:29:41 -07005867 /**
5868 * Return the Electronic Serial Number.
5869 *
5870 * @param subId the subscription ID that this request applies to.
5871 * @return ESN or null if error.
5872 */
5873 @Override
5874 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005875 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005876 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877
5878 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005879 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005880 if (phone == null) {
5881 return null;
5882 }
5883 String esn = null;
5884 try {
5885 esn = phone.getEsn();
5886 } catch (Exception e) {
5887 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5888 }
5889 return esn;
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005892 }
Youhan Wang4001d252016-05-11 10:29:41 -07005893 }
5894
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005895 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005896 * Return the Preferred Roaming List Version.
5897 *
5898 * @param subId the subscription ID that this request applies to.
5899 * @return PRLVersion or null if error.
5900 */
5901 @Override
5902 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005903 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005904 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005905
5906 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005907 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 if (phone == null) {
5909 return null;
5910 }
5911 String cdmaPrlVersion = null;
5912 try {
5913 cdmaPrlVersion = phone.getCdmaPrlVersion();
5914 } catch (Exception e) {
5915 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5916 }
5917 return cdmaPrlVersion;
5918 } finally {
5919 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005920 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005921 }
5922
5923 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005924 * Get snapshot of Telephony histograms
5925 * @return List of Telephony histograms
5926 * @hide
5927 */
5928 @Override
5929 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5931 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 return RIL.getTelephonyRILTimingHistograms();
5936 } finally {
5937 Binder.restoreCallingIdentity(identity);
5938 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005939 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005940
5941 /**
5942 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005943 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5944 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005945 * Require system privileges. In the future we may add this to carrier APIs.
5946 *
Michele Berionne482f8202018-11-27 18:57:59 -08005947 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005948 */
5949 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005950 @TelephonyManager.SetCarrierRestrictionResult
5951 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005952 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005954
Michele Berionne482f8202018-11-27 18:57:59 -08005955 if (carrierRestrictionRules == null) {
5956 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005957 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 final long identity = Binder.clearCallingIdentity();
5960 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005961 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005962 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005966 }
5967
5968 /**
5969 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005970 * Get the allowed carrier list and the excluded carrier list, including the priority between
5971 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005972 * Require system privileges. In the future we may add this to carrier APIs.
5973 *
Michele Berionne482f8202018-11-27 18:57:59 -08005974 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005975 */
5976 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005977 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005978 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
5982 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005983 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5984 if (response instanceof CarrierRestrictionRules) {
5985 return (CarrierRestrictionRules) response;
5986 }
5987 // Response is an Exception of some kind,
5988 // which is signalled to the user as a NULL retval
5989 return null;
5990 } catch (Exception e) {
5991 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5992 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005993 } finally {
5994 Binder.restoreCallingIdentity(identity);
5995 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005996 }
5997
fionaxu59545b42016-05-25 15:53:37 -07005998 /**
5999 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6000 * @param subId the subscription ID that this action applies to.
6001 * @param enabled control enable or disable metered apns.
6002 * {@hide}
6003 */
6004 @Override
6005 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6006 enforceModifyPermission();
6007 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006010 if (phone == null) {
6011 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6012 return;
6013 }
6014 try {
6015 phone.carrierActionSetMeteredApnsEnabled(enabled);
6016 } catch (Exception e) {
6017 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006020 }
6021 }
6022
6023 /**
6024 * Action set from carrier signalling broadcast receivers to enable/disable radio
6025 * @param subId the subscription ID that this action applies to.
6026 * @param enabled control enable or disable radio.
6027 * {@hide}
6028 */
6029 @Override
6030 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6031 enforceModifyPermission();
6032 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006035 if (phone == null) {
6036 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6037 return;
6038 }
6039 try {
6040 phone.carrierActionSetRadioEnabled(enabled);
6041 } catch (Exception e) {
6042 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043 } finally {
6044 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006045 }
6046 }
6047
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006048 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006049 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6050 * network status based on which carrier apps could apply actions accordingly,
6051 * enable/disable default url handler for example.
6052 *
6053 * @param subId the subscription ID that this action applies to.
6054 * @param report control start/stop reporting the default network status.
6055 * {@hide}
6056 */
6057 @Override
6058 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6059 enforceModifyPermission();
6060 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061
6062 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006063 if (phone == null) {
6064 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6065 return;
6066 }
6067 try {
6068 phone.carrierActionReportDefaultNetworkStatus(report);
6069 } catch (Exception e) {
6070 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 } finally {
6072 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006073 }
6074 }
6075
6076 /**
fionaxud9622282017-07-17 17:51:30 -07006077 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6078 * @param subId the subscription ID that this action applies to.
6079 * {@hide}
6080 */
6081 @Override
6082 public void carrierActionResetAll(int subId) {
6083 enforceModifyPermission();
6084 final Phone phone = getPhone(subId);
6085 if (phone == null) {
6086 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6087 return;
6088 }
6089 try {
6090 phone.carrierActionResetAll();
6091 } catch (Exception e) {
6092 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6093 }
6094 }
6095
6096 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006097 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6098 * bug report is being generated.
6099 */
6100 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006101 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006102 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6103 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006104 writer.println("Permission Denial: can't dump Phone from pid="
6105 + Binder.getCallingPid()
6106 + ", uid=" + Binder.getCallingUid()
6107 + "without permission "
6108 + android.Manifest.permission.DUMP);
6109 return;
6110 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006111 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006112 }
Jack Yueb89b242016-06-22 13:27:47 -07006113
Brad Ebingerdac2f002018-04-03 15:17:52 -07006114 @Override
6115 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6116 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6117 throws RemoteException {
6118 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6119 }
6120
Jack Yueb89b242016-06-22 13:27:47 -07006121 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006122 * Get aggregated video call data usage since boot.
6123 *
6124 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6125 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006126 * {@hide}
6127 */
6128 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006129 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006130 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6131 null);
6132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 // NetworkStatsService keeps tracking the active network interface and identity. It
6136 // records the delta with the corresponding network identity.
6137 // We just return the total video call data usage snapshot since boot.
6138 Phone phone = getPhone(subId);
6139 if (phone != null) {
6140 return phone.getVtDataUsage(perUidStats);
6141 }
6142 return null;
6143 } finally {
6144 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006145 }
Jack Yueb89b242016-06-22 13:27:47 -07006146 }
Jack Yu75ab2952016-07-08 14:29:33 -07006147
6148 /**
6149 * Policy control of data connection. Usually used when data limit is passed.
6150 * @param enabled True if enabling the data, otherwise disabling.
6151 * @param subId Subscription index
6152 * {@hide}
6153 */
6154 @Override
6155 public void setPolicyDataEnabled(boolean enabled, int subId) {
6156 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157
6158 final long identity = Binder.clearCallingIdentity();
6159 try {
6160 Phone phone = getPhone(subId);
6161 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006162 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 }
6164 } finally {
6165 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006166 }
6167 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006168
6169 /**
6170 * Get Client request stats
6171 * @return List of Client Request Stats
6172 * @hide
6173 */
6174 @Override
6175 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006177 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006178 return null;
6179 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006180 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 if (phone != null) {
6185 return phone.getClientRequestStats();
6186 }
6187
6188 return null;
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006192 }
6193
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006194 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006195 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006196 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006197 }
Jack Yueb4124c2017-02-16 15:32:43 -08006198
6199 /**
Grace Chen70990072017-03-24 17:21:30 -07006200 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006201 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006202 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006203 * @param state State of SIM (power down, power up, pass through)
6204 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6205 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6206 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006207 *
6208 **/
6209 @Override
Grace Chen70990072017-03-24 17:21:30 -07006210 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006211 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006212 Phone phone = PhoneFactory.getPhone(slotIndex);
6213
vagdeviaf9a5b92018-08-15 16:01:53 -07006214 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006219 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006220 }
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006223 }
6224 }
Shuo Qiandd210312017-04-12 22:11:33 +00006225
Tyler Gunn65d45c22017-06-05 11:22:26 -07006226 private boolean isUssdApiAllowed(int subId) {
6227 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006228 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006229 if (configManager == null) {
6230 return false;
6231 }
6232 PersistableBundle pb = configManager.getConfigForSubId(subId);
6233 if (pb == null) {
6234 return false;
6235 }
6236 return pb.getBoolean(
6237 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6238 }
6239
Shuo Qiandd210312017-04-12 22:11:33 +00006240 /**
6241 * Check if phone is in emergency callback mode
6242 * @return true if phone is in emergency callback mode
6243 * @param subId sub id
6244 */
goneil9c5f4872017-12-05 14:07:56 -08006245 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006246 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006247 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006248 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 if (phone != null) {
6253 return phone.isInEcm();
6254 } else {
6255 return false;
6256 }
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006259 }
6260 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006261
6262 /**
6263 * Get the current signal strength information for the given subscription.
6264 * Because this information is not updated when the device is in a low power state
6265 * it should not be relied-upon to be current.
6266 * @param subId Subscription index
6267 * @return the most recent cached signal strength info from the modem
6268 */
6269 @Override
6270 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 final long identity = Binder.clearCallingIdentity();
6272 try {
6273 Phone p = getPhone(subId);
6274 if (p == null) {
6275 return null;
6276 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278 return p.getSignalStrength();
6279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006282 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006283
Pengquan Meng77b7f132018-08-22 14:49:57 -07006284 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006285 * Get the current modem radio state for the given slot.
6286 * @param slotIndex slot index.
6287 * @param callingPackage the name of the package making the call.
6288 * @return the current radio power state from the modem
6289 */
6290 @Override
6291 public int getRadioPowerState(int slotIndex, String callingPackage) {
6292 Phone phone = PhoneFactory.getPhone(slotIndex);
6293 if (phone != null) {
6294 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6295 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6296 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6297 }
6298
6299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 return phone.getRadioPowerState();
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
6304 }
6305 }
6306 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6307 }
6308
6309 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006310 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6311 *
6312 * <p>Requires one of the following permissions:
6313 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6314 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6315 * privileges.
6316 *
6317 * @param subId subscription id
6318 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6319 * {@code false}.
6320 */
6321 @Override
6322 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6324 null /* message */);
6325
Pengquan Menga1bb6272018-09-06 09:59:22 -07006326 boolean isEnabled = false;
6327 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006328 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006329 Phone phone = getPhone(subId);
6330 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006331 } catch (Exception e) {
6332 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6333 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006334 } finally {
6335 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006337 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006338 }
6339
6340
6341 /**
6342 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6343 *
6344 * <p> Requires permission:
6345 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6346 * privileges.
6347 *
6348 * @param subId subscription id
6349 * @param isEnabled {@code true} means enable, {@code false} means disable.
6350 */
6351 @Override
6352 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, subId, "setDataRoamingEnabled");
6355
Pengquan Menga1bb6272018-09-06 09:59:22 -07006356 final long identity = Binder.clearCallingIdentity();
6357 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006358 Phone phone = getPhone(subId);
6359 if (phone != null) {
6360 phone.setDataRoamingEnabled(isEnabled);
6361 }
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006364 }
6365 }
6366
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006367 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006368 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006369 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6370 mApp, subId, "isManualNetworkSelectionAllowed");
6371
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006372 boolean isAllowed = true;
6373 final long identity = Binder.clearCallingIdentity();
6374 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006375 Phone phone = getPhone(subId);
6376 if (phone != null) {
6377 isAllowed = phone.isCspPlmnEnabled();
6378 }
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
6382 return isAllowed;
6383 }
6384
6385 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006386 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006387 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006388 try {
6389 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006390 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006391 } catch (SecurityException e) {
6392 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6393 // has carrier privileges on an active UICC
6394 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6395 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006396 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006397 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006398 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006402 UiccController uiccController = UiccController.getInstance();
6403 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006404 if (hasReadPermission) {
6405 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006406 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006407
6408 // Remove private info if the caller doesn't have access
6409 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6410 for (UiccCardInfo cardInfo : cardInfos) {
6411 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6412 // is available
6413 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6414 if (card == null || card.getUiccProfile() == null) {
6415 // assume no access if the card or profile is unavailable
6416 filteredInfos.add(cardInfo.getUnprivileged());
6417 continue;
6418 }
6419 UiccProfile profile = card.getUiccProfile();
6420 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6421 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6422 filteredInfos.add(cardInfo);
6423 } else {
6424 filteredInfos.add(cardInfo.getUnprivileged());
6425 }
6426 }
6427 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006428 } finally {
6429 Binder.restoreCallingIdentity(identity);
6430 }
6431 }
6432
6433 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006434 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006435 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 final long identity = Binder.clearCallingIdentity();
6438 try {
6439 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6440 if (slots == null) {
6441 Rlog.i(LOG_TAG, "slots is null.");
6442 return null;
6443 }
6444
6445 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6446 for (int i = 0; i < slots.length; i++) {
6447 UiccSlot slot = slots[i];
6448 if (slot == null) {
6449 continue;
6450 }
6451
Jordan Liu7be7e652019-05-06 18:55:02 +00006452 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 UiccCard card = slot.getUiccCard();
6454 if (card != null) {
6455 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006456 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 cardId = slot.getIccId();
6458 }
6459
6460 int cardState = 0;
6461 switch (slot.getCardState()) {
6462 case CARDSTATE_ABSENT:
6463 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6464 break;
6465 case CARDSTATE_PRESENT:
6466 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6467 break;
6468 case CARDSTATE_ERROR:
6469 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6470 break;
6471 case CARDSTATE_RESTRICTED:
6472 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6473 break;
6474 default:
6475 break;
6476
6477 }
6478
6479 infos[i] = new UiccSlotInfo(
6480 slot.isActive(),
6481 slot.isEuicc(),
6482 cardId,
6483 cardState,
6484 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006485 slot.isExtendedApduSupported(),
6486 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 }
6488 return infos;
6489 } finally {
6490 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006491 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006492 }
6493
6494 @Override
6495 public boolean switchSlots(int[] physicalSlots) {
6496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006497
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006504 }
Jack Yu4c988042018-02-27 15:30:01 -08006505
6506 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006507 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 return UiccController.getInstance().getCardIdForDefaultEuicc();
6511 } finally {
6512 Binder.restoreCallingIdentity(identity);
6513 }
6514 }
6515
6516 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006517 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6518 enforceModifyPermission();
6519 final Phone phone = getPhone(subId);
6520 if (phone == null) {
6521 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6522 return;
6523 }
6524
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 final long identity = Binder.clearCallingIdentity();
6526 try {
6527 phone.setRadioIndicationUpdateMode(filters, mode);
6528 } finally {
6529 Binder.restoreCallingIdentity(identity);
6530 }
Jack Yu4c988042018-02-27 15:30:01 -08006531 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006532
6533 /**
goneil47ffb6e2018-04-06 15:40:58 -07006534 * A test API to reload the UICC profile.
6535 *
6536 * <p>Requires that the calling app has permission
6537 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6538 * @hide
6539 */
6540 @Override
6541 public void refreshUiccProfile(int subId) {
6542 enforceModifyPermission();
6543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 Phone phone = getPhone(subId);
6547 if (phone == null) {
6548 return;
6549 }
6550 UiccCard uiccCard = phone.getUiccCard();
6551 if (uiccCard == null) {
6552 return;
6553 }
6554 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6555 if (uiccProfile == null) {
6556 return;
6557 }
6558 uiccProfile.refresh();
6559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
6562 }
6563
6564 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006565 * Returns false if the mobile data is disabled by default, otherwise return true.
6566 */
6567 private boolean getDefaultDataEnabled() {
6568 return "true".equalsIgnoreCase(
6569 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6570 }
6571
6572 /**
6573 * Returns true if the data roaming is enabled by default, i.e the system property
6574 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6575 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6576 */
6577 private boolean getDefaultDataRoamingEnabled(int subId) {
6578 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006579 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006580 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6581 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6582 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6583 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6584 return isDataRoamingEnabled;
6585 }
6586
6587 /**
6588 * Returns the default network type for the given {@code subId}, if the default network type is
6589 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6590 */
6591 private int getDefaultNetworkType(int subId) {
6592 return Integer.parseInt(
6593 TelephonyManager.getTelephonyProperty(
6594 mSubscriptionController.getPhoneId(subId),
6595 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6596 String.valueOf(Phone.PREFERRED_NT_MODE)));
6597 }
fionaxua13278b2018-03-21 00:08:13 -07006598
6599 @Override
6600 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006601 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006602 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 final Phone phone = getPhone(subId);
6607 if (phone == null) {
6608 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6609 return;
6610 }
chen xueaba88a2019-03-15 13:15:10 -07006611 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6612 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 } finally {
6614 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006615 }
fionaxua13278b2018-03-21 00:08:13 -07006616 }
6617
6618 @Override
6619 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006620 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621
6622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 final Phone phone = getPhone(subId);
6625 if (phone == null) {
6626 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6627 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6628 }
6629 return phone.getCarrierIdListVersion();
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006632 }
fionaxua13278b2018-03-21 00:08:13 -07006633 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006634
6635 @Override
6636 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6637 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6638 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6639 return -1;
6640 }
6641
6642 final long identity = Binder.clearCallingIdentity();
6643 try {
6644 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6645 } finally {
6646 Binder.restoreCallingIdentity(identity);
6647 }
6648 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006649
6650 @Override
6651 public int getCdmaRoamingMode(int subId) {
6652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6653 mApp, subId, "getCdmaRoamingMode");
6654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
6661 }
6662
6663 @Override
6664 public boolean setCdmaRoamingMode(int subId, int mode) {
6665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6666 mApp, subId, "setCdmaRoamingMode");
6667
6668 final long identity = Binder.clearCallingIdentity();
6669 try {
6670 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
6676 @Override
6677 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6679 mApp, subId, "setCdmaSubscriptionMode");
6680
6681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6684 } finally {
6685 Binder.restoreCallingIdentity(identity);
6686 }
6687 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006688
6689 private void ensureUserRunning(int userId) {
6690 if (!mUserManager.isUserRunning(userId)) {
6691 throw new IllegalStateException("User " + userId + " does not exist or not running");
6692 }
6693 }
6694
6695 /**
6696 * Returns a list of SMS apps on a given user.
6697 *
6698 * Only the shell user (UID 2000 or 0) can call it.
6699 * Target user must be running.
6700 */
6701 @Override
6702 public String[] getSmsApps(int userId) {
6703 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6704 ensureUserRunning(userId);
6705
6706 final Collection<SmsApplicationData> apps =
6707 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6708
6709 String[] ret = new String[apps.size()];
6710 int i = 0;
6711 for (SmsApplicationData app : apps) {
6712 ret[i++] = app.mPackageName;
6713 }
6714 return ret;
6715 }
6716
6717 /**
6718 * Returns the default SMS app package name on a given user.
6719 *
6720 * Only the shell user (UID 2000 or 0) can call it.
6721 * Target user must be running.
6722 */
6723 @Override
6724 public String getDefaultSmsApp(int userId) {
6725 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6726 ensureUserRunning(userId);
6727
6728 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6729 /* updateIfNeeded= */ true, userId);
6730 return cn == null ? null : cn.getPackageName();
6731 }
6732
6733 /**
6734 * Set a package as the default SMS app on a given user.
6735 *
6736 * Only the shell user (UID 2000 or 0) can call it.
6737 * Target user must be running.
6738 */
6739 @Override
6740 public void setDefaultSmsApp(int userId, String packageName) {
6741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6742 ensureUserRunning(userId);
6743
6744 boolean found = false;
6745 for (String pkg : getSmsApps(userId)) {
6746 if (TextUtils.equals(packageName, pkg)) {
6747 found = true;
6748 break;
6749 }
6750 }
6751 if (!found) {
6752 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6753 }
6754
6755 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6756 }
sqianc5eccab2018-10-19 18:46:41 -07006757
6758 @Override
sqian8c685422019-02-22 15:55:18 -08006759 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006760 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006762 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006763 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6764 }
6765 final long identity = Binder.clearCallingIdentity();
6766 try {
sqian854d44b2018-12-12 16:48:18 -08006767 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6768 for (Phone phone: PhoneFactory.getPhones()) {
6769 if (phone.getEmergencyNumberTracker() != null
6770 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6771 emergencyNumberListInternal.put(
6772 phone.getSubId(),
6773 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6774 }
sqian11b7a0e2018-12-05 18:48:28 -08006775 }
sqian854d44b2018-12-12 16:48:18 -08006776 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006777 } finally {
6778 Binder.restoreCallingIdentity(identity);
6779 }
sqianc5eccab2018-10-19 18:46:41 -07006780 }
6781
6782 @Override
sqian8c685422019-02-22 15:55:18 -08006783 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006784 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006785 if (!exactMatch) {
6786 TelephonyPermissions
6787 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006788 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006789 }
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
sqian854d44b2018-12-12 16:48:18 -08006792 for (Phone phone: PhoneFactory.getPhones()) {
6793 if (phone.getEmergencyNumberTracker() != null
6794 && phone.getEmergencyNumberTracker() != null) {
6795 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6796 number, exactMatch)) {
6797 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006798 }
6799 }
sqian11b7a0e2018-12-05 18:48:28 -08006800 }
6801 return false;
6802 } finally {
6803 Binder.restoreCallingIdentity(identity);
6804 }
6805 }
6806
sqianf4ca7ed2019-01-15 18:32:07 -08006807 /**
6808 * Update emergency number list for test mode.
6809 */
6810 @Override
6811 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6812 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6813 "updateEmergencyNumberListTestMode");
6814
6815 final long identity = Binder.clearCallingIdentity();
6816 try {
6817 for (Phone phone: PhoneFactory.getPhones()) {
6818 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6819 if (tracker != null) {
6820 tracker.executeEmergencyNumberTestModeCommand(action, num);
6821 }
6822 }
6823 } finally {
6824 Binder.restoreCallingIdentity(identity);
6825 }
6826 }
6827
6828 /**
6829 * Get the full emergency number list for test mode.
6830 */
6831 @Override
6832 public List<String> getEmergencyNumberListTestMode() {
6833 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6834 "getEmergencyNumberListTestMode");
6835
6836 final long identity = Binder.clearCallingIdentity();
6837 try {
6838 Set<String> emergencyNumbers = new HashSet<>();
6839 for (Phone phone: PhoneFactory.getPhones()) {
6840 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6841 if (tracker != null) {
6842 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6843 emergencyNumbers.add(num.getNumber());
6844 }
6845 }
6846 }
6847 return new ArrayList<>(emergencyNumbers);
6848 } finally {
6849 Binder.restoreCallingIdentity(identity);
6850 }
6851 }
6852
chen xud6b45bd2018-10-30 22:27:10 -07006853 @Override
6854 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6855 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6856 Phone phone = getPhone(subId);
6857 if (phone == null) {
6858 return null;
6859 }
6860 final long identity = Binder.clearCallingIdentity();
6861 try {
6862 UiccProfile profile = UiccController.getInstance()
6863 .getUiccProfileForPhone(phone.getPhoneId());
6864 if (profile != null) {
6865 return profile.getCertsFromCarrierPrivilegeAccessRules();
6866 }
6867 } finally {
6868 Binder.restoreCallingIdentity(identity);
6869 }
6870 return null;
6871 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006872
6873 /**
6874 * Enable or disable a modem stack.
6875 */
6876 @Override
6877 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6878 enforceModifyPermission();
6879
6880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 Phone phone = PhoneFactory.getPhone(slotIndex);
6883 if (phone == null) {
6884 return false;
6885 } else {
6886 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6887 }
6888 } finally {
6889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
Michelecea4cf22018-12-21 15:00:11 -08006892
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006893 /**
6894 * Whether a modem stack is enabled or not.
6895 */
6896 @Override
6897 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6898 Phone phone = PhoneFactory.getPhone(slotIndex);
6899 if (phone == null) return false;
6900
6901 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6902 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6903 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6904 }
6905
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006908 try {
6909 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6910 } catch (NoSuchElementException ex) {
6911 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6912 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006913 } finally {
6914 Binder.restoreCallingIdentity(identity);
6915 }
6916 }
6917
Michelecea4cf22018-12-21 15:00:11 -08006918 @Override
Michele0ea7d782019-03-19 14:58:42 -07006919 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006920 enforceModifyPermission();
6921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006925 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006926 .commit();
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
6929 }
6930 }
6931
6932 @Override
Michele0ea7d782019-03-19 14:58:42 -07006933 @TelephonyManager.IsMultiSimSupportedResult
6934 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006936 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6937 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006938 }
Michelecea4cf22018-12-21 15:00:11 -08006939
6940 final long identity = Binder.clearCallingIdentity();
6941 try {
Michele0ea7d782019-03-19 14:58:42 -07006942 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006947
Michele0ea7d782019-03-19 14:58:42 -07006948 @TelephonyManager.IsMultiSimSupportedResult
6949 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006950 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6951 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6952 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006953 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6954 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006955 }
6956 // Check if the hardware supports multisim functionality. If usage of multisim is not
6957 // supported by the modem, indicate that it is restricted.
6958 PhoneCapability staticCapability =
6959 mPhoneConfigurationManager.getStaticPhoneCapability();
6960 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006961 loge("isMultiSimSupportedInternal: no static configuration available");
6962 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006963 }
6964 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006965 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006967 }
6968 // Check if support of multiple SIMs is restricted by carrier
6969 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006970 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006971 }
6972
Michele0ea7d782019-03-19 14:58:42 -07006973 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006974 }
6975
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006976 /**
6977 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006978 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6979 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6980 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006981 * @param numOfSims number of active sims we want to switch to
6982 */
6983 @Override
6984 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006985 if (numOfSims == 1) {
6986 enforceModifyPermission();
6987 } else {
6988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6989 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6990 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006991 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006992
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006993 try {
Michele30b57b22019-03-01 12:01:14 -08006994 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006995 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006996 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6997 return;
6998 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006999 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
7003 }
7004
7005 /**
chen xub4baa772019-04-03 10:23:41 -07007006 * Get whether making changes to modem configurations will trigger reboot.
7007 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007008 */
7009 @Override
chen xub4baa772019-04-03 10:23:41 -07007010 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7012 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7013 return false;
7014 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 }
7022
Nathan Harold29f5f052019-02-15 13:41:57 -08007023 private void updateModemStateMetrics() {
7024 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7025 // TODO: check the state for each modem if the api is ready.
7026 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7027 }
7028
Pengquan Meng3889a572019-01-23 11:16:29 -08007029 @Override
7030 public int[] getSlotsMapping() {
7031 enforceReadPrivilegedPermission("getSlotsMapping");
7032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7036 // All logical slots should have a mapping to a physical slot.
7037 int[] logicalSlotsMapping = new int[phoneCount];
7038 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7039 for (int i = 0; i < slotInfos.length; i++) {
7040 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7041 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7042 }
7043 }
7044 return logicalSlotsMapping;
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
7048 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007049
7050 /**
7051 * Get the IRadio HAL Version
7052 */
7053 @Override
7054 public int getRadioHalVersion() {
7055 Phone phone = getDefaultPhone();
7056 if (phone == null) return -1;
7057 HalVersion hv = phone.getHalVersion();
7058 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7059 return hv.major * 100 + hv.minor;
7060 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007061
7062 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007063 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7064 * corresponding network requests on a subId.
7065 *
7066 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007067 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007068 * 2) APN is un-metered for this subscription, or
7069 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7070 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7071 *
7072 * @return whether data is allowed for a apn type.
7073 *
7074 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007075 */
7076 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007077 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007079 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7080 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007081 }
7082
7083 // Now that all security checks passes, perform the operation as ourselves.
7084 final long identity = Binder.clearCallingIdentity();
7085 try {
7086 Phone phone = getPhone(subId);
7087 if (phone == null) return false;
7088
Jack Yu41407ee2019-05-13 16:54:09 -07007089 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007090 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
7094 }
7095
7096 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007097 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007098 enforceReadPrivilegedPermission("isApnMetered");
7099
7100 // Now that all security checks passes, perform the operation as ourselves.
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 Phone phone = getPhone(subId);
7104 if (phone == null) return true; // By default return true.
7105
Jack Yu41407ee2019-05-13 16:54:09 -07007106 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
7109 }
7110 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007111
7112 @Override
7113 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7114 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7115 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7116 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7117 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7118 }
7119 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7120 Intent intent = new Intent();
7121 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7122 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7123 // Bring up choose default SMS subscription dialog right now
7124 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7125 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7126 mApp.startActivity(intent);
7127 }
chen xud5ca2d52019-05-28 15:20:57 -07007128
7129 @Override
7130 public String getMmsUAProfUrl(int subId) {
7131 //TODO investigate if this API should require proper permission check in R b/133791609
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7135 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7136 } finally {
7137 Binder.restoreCallingIdentity(identity);
7138 }
7139 }
7140
7141 @Override
7142 public String getMmsUserAgent(int subId) {
7143 //TODO investigate if this API should require proper permission check in R b/133791609
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7147 .getString(com.android.internal.R.string.config_mms_user_agent);
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
7150 }
7151 }
Jack Yub07d4972019-05-28 16:12:25 -07007152
7153 @Override
7154 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7155 enforceModifyPermission();
7156
7157 // Now that all security checks passes, perform the operation as ourselves.
7158 final long identity = Binder.clearCallingIdentity();
7159 try {
7160 Phone phone = getPhone(subId);
7161 if (phone == null) return false;
7162
7163 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7164 } finally {
7165 Binder.restoreCallingIdentity(identity);
7166 }
7167 }
7168
7169 @Override
7170 public boolean isDataAllowedInVoiceCall(int subId) {
7171 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7172
7173 // Now that all security checks passes, perform the operation as ourselves.
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 Phone phone = getPhone(subId);
7177 if (phone == null) return false;
7178
7179 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7180 } finally {
7181 Binder.restoreCallingIdentity(identity);
7182 }
7183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007184}