blob: 2b5af82710f8d38f3928a8e5619216e03c3d1aef [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 Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070064import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070065import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080066import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070067import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070068import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070069import android.telephony.CellInfoGsm;
70import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070071import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070072import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070073import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070074import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080075import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070076import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080077import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070078import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080079import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080080import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070081import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080082import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070083import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070084import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080085import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080086import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080087import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070088import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070089import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080091import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000092import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070093import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070095import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.data.ApnSetting;
97import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070098import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070099import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800100import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700101import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800102import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700103import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsMmTelFeature;
105import android.telephony.ims.aidl.IImsRcsFeature;
106import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700107import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800108import android.telephony.ims.feature.MmTelFeature;
109import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800110import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700111import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700113import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800114import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800116
Andrew Lee312e8172014-10-23 17:01:36 -0700117import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800118import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700119import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700120import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700121import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800122import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700123import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800126import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700127import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800128import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800130import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700131import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100132import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700133import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700134import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700136import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800137import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700138import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700139import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700140import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700141import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700142import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700143import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700144import com.android.internal.telephony.SmsApplication;
145import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700146import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800148import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800149import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700150import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800151import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700152import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800153import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800154import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700155import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700156import com.android.internal.telephony.uicc.IccIoResult;
157import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800158import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700159import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800160import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800162import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000163import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700164import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800165import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700166import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700167import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800168import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700169import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700170import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800171
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700172import java.io.FileDescriptor;
173import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800175import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700176import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800177import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800178import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800179import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100180import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700182import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700184
185/**
186 * Implementation of the ITelephony interface.
187 */
Santos Cordon117fee72014-05-16 17:56:12 -0700188public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189 private static final String LOG_TAG = "PhoneInterfaceManager";
190 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
191 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700193
194 // Message codes used with mMainThreadHandler
195 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700196 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
197 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700198 private static final int CMD_OPEN_CHANNEL = 9;
199 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
200 private static final int CMD_CLOSE_CHANNEL = 11;
201 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800202 private static final int CMD_NV_READ_ITEM = 13;
203 private static final int EVENT_NV_READ_ITEM_DONE = 14;
204 private static final int CMD_NV_WRITE_ITEM = 15;
205 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
206 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
207 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700208 private static final int CMD_RESET_MODEM_CONFIG = 19;
209 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800210 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
211 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
212 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
213 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800214 private static final int CMD_SEND_ENVELOPE = 25;
215 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000216 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
217 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700218 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
219 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
220 private static final int CMD_EXCHANGE_SIM_IO = 31;
221 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800222 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
223 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700224 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
225 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700226 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
227 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700228 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
229 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
230 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
231 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700232 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
233 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
234 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
235 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700236 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800237 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
238 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000239 private static final int CMD_SWITCH_SLOTS = 50;
240 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700241 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
242 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
243 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
244 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
245 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
246 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
247 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
248 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700249 private static final int CMD_GET_ALL_CELL_INFO = 60;
250 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
251 private static final int CMD_GET_CELL_LOCATION = 62;
252 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700253 private static final int CMD_MODEM_REBOOT = 64;
254 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700255 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
256 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800257 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
258 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700259 private static final int CMD_GET_MODEM_STATUS = 70;
260 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700261 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
262 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700263
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800264 // Parameters of select command.
265 private static final int SELECT_COMMAND = 0xA4;
266 private static final int SELECT_P1 = 0x04;
267 private static final int SELECT_P2 = 0;
268 private static final int SELECT_P3 = 0x10;
269
Pengquan Meng85728fb2018-03-12 16:31:21 -0700270 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
271 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
272 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /** The singleton instance. */
275 private static PhoneInterfaceManager sInstance;
276
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700279 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private AppOpsManager mAppOps;
281 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800282 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800283 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700284 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700285
Derek Tan97ebb422014-09-05 16:55:38 -0700286 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
287 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800288 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800289 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700290
Michelecea4cf22018-12-21 15:00:11 -0800291 // String to store multi SIM allowed
292 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
293
Derek Tan740e1672017-06-27 14:56:27 -0700294 // The AID of ISD-R.
295 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
296
yinxub1bed742017-04-17 11:45:04 -0700297 private NetworkScanRequestTracker mNetworkScanRequestTracker;
298
David Kelly5e06a7f2018-03-12 14:10:59 +0000299 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
300 private static final int MANUFACTURER_CODE_LENGTH = 8;
301
Derek Tan89e89d42014-07-08 17:00:10 -0700302 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700303 * A request object to use for transmitting data to an ICC.
304 */
305 private static final class IccAPDUArgument {
306 public int channel, cla, command, p1, p2, p3;
307 public String data;
308
309 public IccAPDUArgument(int channel, int cla, int command,
310 int p1, int p2, int p3, String data) {
311 this.channel = channel;
312 this.cla = cla;
313 this.command = command;
314 this.p1 = p1;
315 this.p2 = p2;
316 this.p3 = p3;
317 this.data = data;
318 }
319 }
320
321 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700322 * A request object to use for transmitting data to an ICC.
323 */
324 private static final class ManualNetworkSelectionArgument {
325 public OperatorInfo operatorInfo;
326 public boolean persistSelection;
327
328 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
329 this.operatorInfo = operatorInfo;
330 this.persistSelection = persistSelection;
331 }
332 }
333
334 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
336 * request after sending. The main thread will notify the request when it is complete.
337 */
338 private static final class MainThreadRequest {
339 /** The argument to use for the request */
340 public Object argument;
341 /** The result of the request that is run on the main thread */
342 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800343 // The subscriber id that this request applies to. Defaults to
344 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
345 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700346
Nathan Harold92bed182018-10-12 18:16:49 -0700347 // In cases where subId is unavailable, the caller needs to specify the phone.
348 public Phone phone;
349
vagdeviaf9a5b92018-08-15 16:01:53 -0700350 public WorkSource workSource;
351
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 public MainThreadRequest(Object argument) {
353 this.argument = argument;
354 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800355
Nathan Harold92bed182018-10-12 18:16:49 -0700356 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
357 this.argument = argument;
358 if (phone != null) {
359 this.phone = phone;
360 }
361 this.workSource = workSource;
362 }
363
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800366 if (subId != null) {
367 this.subId = subId;
368 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700369 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800370 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 }
372
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800373 private static final class IncomingThirdPartyCallArgs {
374 public final ComponentName component;
375 public final String callId;
376 public final String callerDisplayName;
377
378 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
379 String callerDisplayName) {
380 this.component = component;
381 this.callId = callId;
382 this.callerDisplayName = callerDisplayName;
383 }
384 }
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 /**
387 * A handler that processes messages on the main thread in the phone process. Since many
388 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
389 * inbound binder threads to the main thread in the phone process. The Binder thread
390 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
391 * on, which will be notified when the operation completes and will contain the result of the
392 * request.
393 *
394 * <p>If a MainThreadRequest object is provided in the msg.obj field,
395 * note that request.result must be set to something non-null for the calling thread to
396 * unblock.
397 */
398 private final class MainThreadHandler extends Handler {
399 @Override
400 public void handleMessage(Message msg) {
401 MainThreadRequest request;
402 Message onCompleted;
403 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800404 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700405 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800406 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407
408 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700409 case CMD_HANDLE_USSD_REQUEST: {
410 request = (MainThreadRequest) msg.obj;
411 final Phone phone = getPhoneFromRequest(request);
412 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
413 String ussdRequest = ussdObject.first;
414 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700415
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 if (!isUssdApiAllowed(request.subId)) {
417 // Carrier does not support use of this API, return failure.
418 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
419 UssdResponse response = new UssdResponse(ussdRequest, null);
420 Bundle returnData = new Bundle();
421 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
422 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 request.result = true;
425 notifyRequester(request);
426 return;
427 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700428
Pengquan Menga1bb6272018-09-06 09:59:22 -0700429 try {
430 request.result = phone != null
431 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
432 } catch (CallStateException cse) {
433 request.result = false;
434 }
435 // Wake up the requesting thread
436 notifyRequester(request);
437 break;
pkanwar32d516d2016-10-14 19:37:38 -0700438 }
439
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 final Phone phone = getPhoneFromRequest(request);
443 request.result = phone != null ?
444 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
445 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800454 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700455 if (uiccCard == null) {
456 loge("iccTransmitApduLogicalChannel: No UICC");
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
461 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700463 iccArgument.channel, iccArgument.cla, iccArgument.command,
464 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 break;
468
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 ar = (AsyncResult) msg.obj;
471 request = (MainThreadRequest) ar.userObj;
472 if (ar.exception == null && ar.result != null) {
473 request.result = ar.result;
474 } else {
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
476 if (ar.result == null) {
477 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800478 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800480 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 } else {
482 loge("iccTransmitApduLogicalChannel: Unknown exception");
483 }
484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 break;
487
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
489 request = (MainThreadRequest) msg.obj;
490 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800491 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 if (uiccCard == null) {
493 loge("iccTransmitApduBasicChannel: No UICC");
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700495 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 } else {
497 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
498 request);
499 uiccCard.iccTransmitApduBasicChannel(
500 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
501 iccArgument.p3, iccArgument.data, onCompleted);
502 }
503 break;
504
505 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduBasicChannel: Empty response");
514 } else if (ar.exception instanceof CommandException) {
515 loge("iccTransmitApduBasicChannel: CommandException: " +
516 ar.exception);
517 } else {
518 loge("iccTransmitApduBasicChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 break;
523
524 case CMD_EXCHANGE_SIM_IO:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccExchangeSimIO: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
534 request);
535 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
536 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
537 iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_EXCHANGE_SIM_IO_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6f, 0, (byte[])null);
548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700550 break;
551
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 case CMD_SEND_ENVELOPE:
553 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 if (uiccCard == null) {
556 loge("sendEnvelopeWithStatus: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
561 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
562 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 break;
564
565 case EVENT_SEND_ENVELOPE_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
572 if (ar.result == null) {
573 loge("sendEnvelopeWithStatus: Empty response");
574 } else if (ar.exception instanceof CommandException) {
575 loge("sendEnvelopeWithStatus: CommandException: " +
576 ar.exception);
577 } else {
578 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
579 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700581 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 break;
583
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 case CMD_OPEN_CHANNEL:
585 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800586 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800587 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 if (uiccCard == null) {
589 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800590 request.result = new IccOpenLogicalChannelResponse(-1,
591 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
596 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 break;
599
600 case EVENT_OPEN_CHANNEL_DONE:
601 ar = (AsyncResult) msg.obj;
602 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700604 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 int[] result = (int[]) ar.result;
606 int channelId = result[0];
607 byte[] selectResponse = null;
608 if (result.length > 1) {
609 selectResponse = new byte[result.length - 1];
610 for (int i = 1; i < result.length; ++i) {
611 selectResponse[i - 1] = (byte) result[i];
612 }
613 }
614 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 if (ar.result == null) {
618 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700620 if (ar.exception != null) {
621 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
622 }
623
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700625 if (ar.exception instanceof CommandException) {
626 CommandException.Error error =
627 ((CommandException) (ar.exception)).getCommandError();
628 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700630 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700632 }
633 }
634 openChannelResp = new IccOpenLogicalChannelResponse(
635 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700637 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700638 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700639 break;
640
641 case CMD_CLOSE_CHANNEL:
642 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800643 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 if (uiccCard == null) {
645 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900646 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700647 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700648 } else {
649 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
650 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
651 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 break;
653
654 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800655 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
656 break;
657
658 case CMD_NV_READ_ITEM:
659 request = (MainThreadRequest) msg.obj;
660 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800661 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
662 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800663 break;
664
665 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 ar = (AsyncResult) msg.obj;
667 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800668 if (ar.exception == null && ar.result != null) {
669 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800671 request.result = "";
672 if (ar.result == null) {
673 loge("nvReadItem: Empty response");
674 } else if (ar.exception instanceof CommandException) {
675 loge("nvReadItem: CommandException: " +
676 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 }
680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
Jake Hambye994d462014-02-03 13:10:13 -0800684 case CMD_NV_WRITE_ITEM:
685 request = (MainThreadRequest) msg.obj;
686 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
687 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800688 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700689 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800690 break;
691
692 case EVENT_NV_WRITE_ITEM_DONE:
693 handleNullReturnEvent(msg, "nvWriteItem");
694 break;
695
696 case CMD_NV_WRITE_CDMA_PRL:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
702 case EVENT_NV_WRITE_CDMA_PRL_DONE:
703 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
704 break;
705
chen xu6dac5ab2018-10-26 17:39:23 -0700706 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800707 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700708 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800709 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
chen xu6dac5ab2018-10-26 17:39:23 -0700712 case EVENT_RESET_MODEM_CONFIG_DONE:
713 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 case CMD_GET_PREFERRED_NETWORK_TYPE:
717 request = (MainThreadRequest) msg.obj;
718 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700719 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
723 ar = (AsyncResult) msg.obj;
724 request = (MainThreadRequest) ar.userObj;
725 if (ar.exception == null && ar.result != null) {
726 request.result = ar.result; // Integer
727 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800728 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 if (ar.result == null) {
730 loge("getPreferredNetworkType: Empty response");
731 } else if (ar.exception instanceof CommandException) {
732 loge("getPreferredNetworkType: CommandException: " +
733 ar.exception);
734 } else {
735 loge("getPreferredNetworkType: Unknown exception");
736 }
737 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700738 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800739 break;
740
741 case CMD_SET_PREFERRED_NETWORK_TYPE:
742 request = (MainThreadRequest) msg.obj;
743 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
744 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700745 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
749 handleNullReturnEvent(msg, "setPreferredNetworkType");
750 break;
751
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000752 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
753 request = (MainThreadRequest)msg.obj;
754 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800755 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000756 break;
757
758 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
759 ar = (AsyncResult)msg.obj;
760 request = (MainThreadRequest)ar.userObj;
761 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800765 case CMD_SET_VOICEMAIL_NUMBER:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
768 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800769 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
770 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800771 break;
772
773 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
774 handleNullReturnEvent(msg, "setVoicemailNumber");
775 break;
776
Stuart Scott54788802015-03-30 13:18:01 -0700777 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
780 request);
781 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
782 break;
783
784 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
785 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
786 break;
787
Shishir Agrawal302c8692015-06-19 13:49:39 -0700788 case CMD_PERFORM_NETWORK_SCAN:
789 request = (MainThreadRequest) msg.obj;
790 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
791 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
792 break;
793
794 case EVENT_PERFORM_NETWORK_SCAN_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 CellNetworkScanResult cellScanResult;
798 if (ar.exception == null && ar.result != null) {
799 cellScanResult = new CellNetworkScanResult(
800 CellNetworkScanResult.STATUS_SUCCESS,
801 (List<OperatorInfo>) ar.result);
802 } else {
803 if (ar.result == null) {
804 loge("getCellNetworkScanResults: Empty response");
805 }
806 if (ar.exception != null) {
807 loge("getCellNetworkScanResults: Exception: " + ar.exception);
808 }
809 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
810 if (ar.exception instanceof CommandException) {
811 CommandException.Error error =
812 ((CommandException) (ar.exception)).getCommandError();
813 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
815 } else if (error == CommandException.Error.GENERIC_FAILURE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
817 }
818 }
819 cellScanResult = new CellNetworkScanResult(errorCode, null);
820 }
821 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700822 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700823 break;
824
825 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
826 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700827 ManualNetworkSelectionArgument selArg =
828 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
830 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700831 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
832 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700833 break;
834
835 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result = true;
840 } else {
841 request.result = false;
842 loge("setNetworkSelectionModeManual " + ar.exception);
843 }
844 notifyRequester(request);
845 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700846 break;
847
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700848 case CMD_GET_MODEM_ACTIVITY_INFO:
849 request = (MainThreadRequest) msg.obj;
850 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700851 if (defaultPhone != null) {
852 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
853 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700854 break;
855
856 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
857 ar = (AsyncResult) msg.obj;
858 request = (MainThreadRequest) ar.userObj;
859 if (ar.exception == null && ar.result != null) {
860 request.result = ar.result;
861 } else {
862 if (ar.result == null) {
863 loge("queryModemActivityInfo: Empty response");
864 } else if (ar.exception instanceof CommandException) {
865 loge("queryModemActivityInfo: CommandException: " +
866 ar.exception);
867 } else {
868 loge("queryModemActivityInfo: Unknown exception");
869 }
870 }
Amit Mahajand4766222016-01-28 15:28:28 -0800871 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
872 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700873 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800874 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700875 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700876 break;
877
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 case CMD_SET_ALLOWED_CARRIERS:
879 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800880 CarrierRestrictionRules argument =
881 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800883 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 break;
885
886 case EVENT_SET_ALLOWED_CARRIERS_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result;
891 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800892 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
893 if (ar.exception instanceof CommandException) {
894 loge("setAllowedCarriers: CommandException: " + ar.exception);
895 CommandException.Error error =
896 ((CommandException) (ar.exception)).getCommandError();
897 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
898 request.result =
899 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
900 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 } else {
902 loge("setAllowedCarriers: Unknown exception");
903 }
904 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700905 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 break;
907
908 case CMD_GET_ALLOWED_CARRIERS:
909 request = (MainThreadRequest) msg.obj;
910 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800911 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 break;
913
914 case EVENT_GET_ALLOWED_CARRIERS_DONE:
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result;
919 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800920 request.result = new IllegalStateException(
921 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700922 if (ar.result == null) {
923 loge("getAllowedCarriers: Empty response");
924 } else if (ar.exception instanceof CommandException) {
925 loge("getAllowedCarriers: CommandException: " +
926 ar.exception);
927 } else {
928 loge("getAllowedCarriers: Unknown exception");
929 }
930 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700931 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700932 break;
933
Nathan Haroldb3014052017-01-25 15:57:32 -0800934 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
935 ar = (AsyncResult) msg.obj;
936 request = (MainThreadRequest) ar.userObj;
937 if (ar.exception == null && ar.result != null) {
938 request.result = ar.result;
939 } else {
940 request.result = new IllegalArgumentException(
941 "Failed to retrieve Forbidden Plmns");
942 if (ar.result == null) {
943 loge("getForbiddenPlmns: Empty response");
944 } else {
945 loge("getForbiddenPlmns: Unknown exception");
946 }
947 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700948 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800949 break;
950
951 case CMD_GET_FORBIDDEN_PLMNS:
952 request = (MainThreadRequest) msg.obj;
953 uiccCard = getUiccCardFromRequest(request);
954 if (uiccCard == null) {
955 loge("getForbiddenPlmns() UiccCard is null");
956 request.result = new IllegalArgumentException(
957 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700958 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800959 break;
960 }
961 Integer appType = (Integer) request.argument;
962 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
963 if (uiccApp == null) {
964 loge("getForbiddenPlmns() no app with specified type -- "
965 + appType);
966 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700967 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800968 break;
969 } else {
970 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
971 + " specified type -- " + appType);
972 }
973 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
974 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
975 onCompleted);
976 break;
977
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000978 case CMD_SWITCH_SLOTS:
979 request = (MainThreadRequest) msg.obj;
980 int[] physicalSlots = (int[]) request.argument;
981 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
982 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
983 break;
984
985 case EVENT_SWITCH_SLOTS_DONE:
986 ar = (AsyncResult) msg.obj;
987 request = (MainThreadRequest) ar.userObj;
988 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700989 notifyRequester(request);
990 break;
991 case CMD_GET_NETWORK_SELECTION_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
994 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
995 break;
996
997 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception != null) {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1002 } else {
1003 int mode = ((int[]) ar.result)[0];
1004 if (mode == 0) {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1006 } else {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1008 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001009 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001010 notifyRequester(request);
1011 break;
1012 case CMD_GET_CDMA_ROAMING_MODE:
1013 request = (MainThreadRequest) msg.obj;
1014 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1015 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1016 break;
1017 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 if (ar.exception != null) {
1021 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1022 } else {
1023 request.result = ((int[]) ar.result)[0];
1024 }
1025 notifyRequester(request);
1026 break;
1027 case CMD_SET_CDMA_ROAMING_MODE:
1028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1030 int mode = (int) request.argument;
1031 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1032 break;
1033 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1034 ar = (AsyncResult) msg.obj;
1035 request = (MainThreadRequest) ar.userObj;
1036 request.result = ar.exception == null;
1037 notifyRequester(request);
1038 break;
1039 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1040 request = (MainThreadRequest) msg.obj;
1041 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1042 int subscriptionMode = (int) request.argument;
1043 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1044 break;
1045 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1046 ar = (AsyncResult) msg.obj;
1047 request = (MainThreadRequest) ar.userObj;
1048 request.result = ar.exception == null;
1049 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case CMD_GET_ALL_CELL_INFO:
1052 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001054 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001056 case EVENT_GET_ALL_CELL_INFO_DONE:
1057 ar = (AsyncResult) msg.obj;
1058 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001059 // If a timeout occurs, the response will be null
1060 request.result = (ar.exception == null && ar.result != null)
1061 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 synchronized (request) {
1063 request.notifyAll();
1064 }
1065 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001066 case CMD_REQUEST_CELL_INFO_UPDATE:
1067 request = (MainThreadRequest) msg.obj;
1068 request.phone.requestCellInfoUpdate(request.workSource,
1069 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1070 break;
1071 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1072 ar = (AsyncResult) msg.obj;
1073 request = (MainThreadRequest) ar.userObj;
1074 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1075 try {
1076 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001078 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1079 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001082 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else {
1084 // use the result as returned
1085 cb.onCellInfo((List<CellInfo>) ar.result);
1086 }
1087 } catch (RemoteException re) {
1088 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1089 }
1090 break;
1091 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 request = (MainThreadRequest) msg.obj;
1093 WorkSource ws = (WorkSource) request.argument;
1094 Phone phone = getPhoneFromRequest(request);
1095 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1096 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = ar.result;
1102 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001103 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1105 ? new CdmaCellLocation() : new GsmCellLocation();
1106 }
1107
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case CMD_MODEM_REBOOT:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001116 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001117 case EVENT_CMD_MODEM_REBOOT_DONE:
1118 handleNullReturnEvent(msg, "rebootModem");
1119 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 case CMD_REQUEST_ENABLE_MODEM:
1121 request = (MainThreadRequest) msg.obj;
1122 boolean enable = (boolean) request.argument;
1123 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001125 PhoneConfigurationManager.getInstance()
1126 .enablePhone(request.phone, enable, onCompleted);
1127 break;
1128 case EVENT_ENABLE_MODEM_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001132 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 if ((boolean) request.result) {
1135 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1136 updateModemStateMetrics();
1137 } else {
1138 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1139 + ar.exception);
1140 }
1141 notifyRequester(request);
1142 break;
1143 case CMD_GET_MODEM_STATUS:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1146 PhoneConfigurationManager.getInstance()
1147 .getPhoneStatusFromModem(request.phone, onCompleted);
1148 break;
1149 case EVENT_GET_MODEM_STATUS_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 int id = request.phone.getPhoneId();
1153 if (ar.exception == null && ar.result != null) {
1154 request.result = ar.result;
1155 //update the cache as modem status has changed
1156 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1157 (boolean) request.result);
1158 } else {
1159 // Return true if modem status cannot be retrieved. For most cases,
1160 // modem status is on. And for older version modems, GET_MODEM_STATUS
1161 // and disable modem are not supported. Modem is always on.
1162 // TODO: this should be fixed in R to support a third
1163 // status UNKNOWN b/131631629
1164 request.result = true;
1165 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1166 + ar.exception);
1167 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001168 notifyRequester(request);
1169 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001170 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null && ar.result != null) {
1174 request.result = ar.result;
1175 } else {
1176 request.result = -1;
1177 loge("Failed to set Forbidden Plmns");
1178 if (ar.result == null) {
1179 loge("setForbidenPlmns: Empty response");
1180 } else if (ar.exception != null) {
1181 loge("setForbiddenPlmns: Exception: " + ar.exception);
1182 request.result = -1;
1183 } else {
1184 loge("setForbiddenPlmns: Unknown exception");
1185 }
1186 }
1187 notifyRequester(request);
1188 break;
1189 case CMD_SET_FORBIDDEN_PLMNS:
1190 request = (MainThreadRequest) msg.obj;
1191 uiccCard = getUiccCardFromRequest(request);
1192 if (uiccCard == null) {
1193 loge("setForbiddenPlmns: UiccCard is null");
1194 request.result = -1;
1195 notifyRequester(request);
1196 break;
1197 }
1198 Pair<Integer, List<String>> setFplmnsArgs =
1199 (Pair<Integer, List<String>>) request.argument;
1200 appType = setFplmnsArgs.first;
1201 List<String> fplmns = setFplmnsArgs.second;
1202 uiccApp = uiccCard.getApplicationByType(appType);
1203 if (uiccApp == null) {
1204 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1205 request.result = -1;
1206 loge("Failed to get UICC App");
1207 notifyRequester(request);
1208 } else {
1209 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1210 ((SIMRecords) uiccApp.getIccRecords())
1211 .setForbiddenPlmns(onCompleted, fplmns);
1212 }
1213 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 default:
1215 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1216 break;
1217 }
1218 }
Jake Hambye994d462014-02-03 13:10:13 -08001219
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 private void notifyRequester(MainThreadRequest request) {
1221 synchronized (request) {
1222 request.notifyAll();
1223 }
1224 }
1225
Jake Hambye994d462014-02-03 13:10:13 -08001226 private void handleNullReturnEvent(Message msg, String command) {
1227 AsyncResult ar = (AsyncResult) msg.obj;
1228 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception == null) {
1230 request.result = true;
1231 } else {
1232 request.result = false;
1233 if (ar.exception instanceof CommandException) {
1234 loge(command + ": CommandException: " + ar.exception);
1235 } else {
1236 loge(command + ": Unknown exception");
1237 }
1238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001249 return sendRequest(
1250 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001251 }
1252
1253 /**
1254 * Posts the specified command to be executed on the main thread,
1255 * waits for the request to complete, and returns the result.
1256 * @see #sendRequestAsync
1257 */
1258 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1259 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001260 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001268 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
Nathan Harold92bed182018-10-12 18:16:49 -07001277 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1278 return sendRequest(command, argument, subId, null, workSource);
1279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
1286 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1287 return sendRequest(
1288 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
1296 private Object sendRequest(
1297 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1299 throw new RuntimeException("This method will deadlock if called from the main thread.");
1300 }
1301
Nathan Harold92bed182018-10-12 18:16:49 -07001302 MainThreadRequest request = null;
1303 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1304 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1305 } else if (phone != null) {
1306 request = new MainThreadRequest(argument, phone, workSource);
1307 } else {
1308 request = new MainThreadRequest(argument, subId, workSource);
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 Message msg = mMainThreadHandler.obtainMessage(command, request);
1312 msg.sendToTarget();
1313
1314 // Wait for the request to complete
1315 synchronized (request) {
1316 while (request.result == null) {
1317 try {
1318 request.wait();
1319 } catch (InterruptedException e) {
1320 // Do nothing, go back and wait until the request is complete
1321 }
1322 }
1323 }
1324 return request.result;
1325 }
1326
1327 /**
1328 * Asynchronous ("fire and forget") version of sendRequest():
1329 * Posts the specified command to be executed on the main thread, and
1330 * returns immediately.
1331 * @see #sendRequest
1332 */
1333 private void sendRequestAsync(int command) {
1334 mMainThreadHandler.sendEmptyMessage(command);
1335 }
1336
1337 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001338 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001339 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 */
1341 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 sendRequestAsync(command, argument, null, null);
1343 }
1344
1345 /**
1346 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1347 * @see {@link #sendRequest(int,Object)}
1348 */
1349 private void sendRequestAsync(
1350 int command, Object argument, Phone phone, WorkSource workSource) {
1351 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001352 Message msg = mMainThreadHandler.obtainMessage(command, request);
1353 msg.sendToTarget();
1354 }
1355
1356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 * Initialize the singleton PhoneInterfaceManager instance.
1358 * This is only done once, at startup, from PhoneApp.onCreate().
1359 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001360 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 synchronized (PhoneInterfaceManager.class) {
1362 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 } else {
1365 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1366 }
1367 return sInstance;
1368 }
1369 }
1370
1371 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001372 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001375 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1377 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001378 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 mTelephonySharedPreferences =
1380 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001381 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001382 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 publish();
1385 }
1386
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001387 private Phone getDefaultPhone() {
1388 Phone thePhone = getPhone(getDefaultSubscription());
1389 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1390 }
1391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 private void publish() {
1393 if (DBG) log("publish: " + this);
1394
1395 ServiceManager.addService("phone", this);
1396 }
1397
Stuart Scott584921c2015-01-15 17:10:34 -08001398 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001399 if (request.phone != null) {
1400 return request.phone;
1401 } else {
1402 return getPhoneFromSubId(request.subId);
1403 }
1404 }
1405
1406 private Phone getPhoneFromSubId(int subId) {
1407 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1408 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001409 }
1410
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001411 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1412 Phone phone = getPhoneFromRequest(request);
1413 return phone == null ? null :
1414 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1415 }
1416
Wink Saville36469e72014-06-11 15:17:00 -07001417 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001419 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
1422 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 if (DBG) log("dial: " + number);
1428 // No permission check needed here: This is just a wrapper around the
1429 // ACTION_DIAL intent, which is available to any app since it puts up
1430 // the UI before it does anything.
1431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 String url = createTelUrl(number);
1435 if (url == null) {
1436 return;
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 // PENDING: should we just silently fail if phone is offhook or ringing?
1440 PhoneConstants.State state = mCM.getState(subId);
1441 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1442 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 }
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449 }
1450
1451 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Wink Savilleb564aae2014-10-23 10:18:09 -07001455 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 if (DBG) log("call: " + number);
1457
1458 // This is just a wrapper around the ACTION_CALL intent, but we still
1459 // need to do a permission check since we're calling startActivity()
1460 // from the context of the phone app.
1461 enforceCallPermission();
1462
Jordan Liu1617b712019-07-10 15:06:26 -07001463 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 != AppOpsManager.MODE_ALLOWED) {
1465 return;
1466 }
1467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 String url = createTelUrl(number);
1471 if (url == null) {
1472 return;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475 boolean isValid = false;
1476 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1477 if (slist != null) {
1478 for (SubscriptionInfo subInfoRecord : slist) {
1479 if (subInfoRecord.getSubscriptionId() == subId) {
1480 isValid = true;
1481 break;
1482 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001483 }
Wink Saville08874612014-08-31 19:19:58 -07001484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001485 if (!isValid) {
1486 return;
1487 }
Wink Saville08874612014-08-31 19:19:58 -07001488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1490 intent.putExtra(SUBSCRIPTION_KEY, subId);
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 } finally {
1494 Binder.restoreCallingIdentity(identity);
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001504 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1505 }
1506
1507 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
Wink Savilleb564aae2014-10-23 10:18:09 -07001511 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001513 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1514 }
1515
1516 /** {@hide} */
1517 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523
1524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1527 checkSimPin.start();
1528 return checkSimPin.unlockSim(null, pin);
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Wink Saville9de0f752013-10-22 19:04:03 -07001534 /** {@hide} */
1535 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001541
1542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1545 checkSimPuk.start();
1546 return checkSimPuk.unlockSim(puk, pin);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
1552 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001553 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 * a synchronous one.
1555 */
1556 private static class UnlockSim extends Thread {
1557
1558 private final IccCard mSimCard;
1559
1560 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001561 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1562 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563
1564 // For replies from SimCard interface
1565 private Handler mHandler;
1566
1567 // For async handler to identify request type
1568 private static final int SUPPLY_PIN_COMPLETE = 100;
1569
1570 public UnlockSim(IccCard simCard) {
1571 mSimCard = simCard;
1572 }
1573
1574 @Override
1575 public void run() {
1576 Looper.prepare();
1577 synchronized (UnlockSim.this) {
1578 mHandler = new Handler() {
1579 @Override
1580 public void handleMessage(Message msg) {
1581 AsyncResult ar = (AsyncResult) msg.obj;
1582 switch (msg.what) {
1583 case SUPPLY_PIN_COMPLETE:
1584 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1585 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001586 mRetryCount = msg.arg1;
1587 if (ar.exception != null) {
1588 if (ar.exception instanceof CommandException &&
1589 ((CommandException)(ar.exception)).getCommandError()
1590 == CommandException.Error.PASSWORD_INCORRECT) {
1591 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1592 } else {
1593 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 }
1595 } else {
1596 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 mDone = true;
1599 UnlockSim.this.notifyAll();
1600 }
1601 break;
1602 }
1603 }
1604 };
1605 UnlockSim.this.notifyAll();
1606 }
1607 Looper.loop();
1608 }
1609
1610 /*
1611 * Use PIN or PUK to unlock SIM card
1612 *
1613 * If PUK is null, unlock SIM card with PIN
1614 *
1615 * If PUK is not null, unlock SIM card with PUK and set PIN code
1616 */
Wink Saville9de0f752013-10-22 19:04:03 -07001617 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618
1619 while (mHandler == null) {
1620 try {
1621 wait();
1622 } catch (InterruptedException e) {
1623 Thread.currentThread().interrupt();
1624 }
1625 }
1626 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1627
1628 if (puk == null) {
1629 mSimCard.supplyPin(pin, callback);
1630 } else {
1631 mSimCard.supplyPuk(puk, pin, callback);
1632 }
1633
1634 while (!mDone) {
1635 try {
1636 Log.d(LOG_TAG, "wait for done");
1637 wait();
1638 } catch (InterruptedException e) {
1639 // Restore the interrupted status
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001644 int[] resultArray = new int[2];
1645 resultArray[0] = mResult;
1646 resultArray[1] = mRetryCount;
1647 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649 }
1650
1651 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001652 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001653
1654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 // No permission check needed here: this call is harmless, and it's
1658 // needed for the ServiceState.requestStateUpdate() call (which is
1659 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone phone = getPhone(subId);
1663 if (phone != null) {
1664 phone.updateServiceLocation();
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001671 @Override
1672 public boolean isRadioOn(String callingPackage) {
1673 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
1675
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001676 @Override
1677 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001679 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 return false;
1681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001682
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 return isRadioOnForSubscriber(subId);
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
1688 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 }
1690
1691 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1697 } else {
1698 return false;
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001706 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
Wink Saville36469e72014-06-11 15:17:00 -07001708
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
1723 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001724 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
Wink Savilleb564aae2014-10-23 10:18:09 -07001727 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 final Phone phone = getPhone(subId);
1733 if (phone == null) {
1734 return false;
1735 }
1736 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1737 toggleRadioOnOffForSubscriber(subId);
1738 }
1739 return true;
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
Wink Saville36469e72014-06-11 15:17:00 -07001744
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001745 public boolean needMobileRadioShutdown() {
1746 /*
1747 * If any of the Radios are available, it will need to be
1748 * shutdown. So return true if any Radio is available.
1749 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1753 Phone phone = PhoneFactory.getPhone(i);
1754 if (phone != null && phone.isRadioAvailable()) return true;
1755 }
1756 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1757 return false;
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001760 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001761 }
1762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 enforceModifyPermission();
1766
1767 final long identity = Binder.clearCallingIdentity();
1768 try {
1769 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1770 logv("Shutting down Phone " + i);
1771 shutdownRadioUsingPhoneId(i);
1772 }
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001775 }
1776 }
1777
1778 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 Phone phone = PhoneFactory.getPhone(phoneId);
1780 if (phone != null && phone.isRadioAvailable()) {
1781 phone.shutdownRadio();
1782 }
1783 }
1784
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1791 if (defaultPhone != null) {
1792 defaultPhone.setRadioPower(turnOn);
1793 return true;
1794 } else {
1795 loge("There's no default phone.");
1796 return false;
1797 }
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001800 }
Wink Saville36469e72014-06-11 15:17:00 -07001801 }
1802
Wink Savilleb564aae2014-10-23 10:18:09 -07001803 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 final Phone phone = getPhone(subId);
1809 if (phone != null) {
1810 phone.setRadioPower(turnOn);
1811 return true;
1812 } else {
1813 return false;
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Wink Saville36469e72014-06-11 15:17:00 -07001820 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 public boolean enableDataConnectivity() {
1823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824
1825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 int subId = mSubscriptionController.getDefaultDataSubId();
1828 final Phone phone = getPhone(subId);
1829 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001830 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 return true;
1832 } else {
1833 return false;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
Wink Saville36469e72014-06-11 15:17:00 -07001840 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 public boolean disableDataConnectivity() {
1843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001844
1845 final long identity = Binder.clearCallingIdentity();
1846 try {
1847 int subId = mSubscriptionController.getDefaultDataSubId();
1848 final Phone phone = getPhone(subId);
1849 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001850 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851 return true;
1852 } else {
1853 return false;
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001861 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001866 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
1875 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001876 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
pkanwarae03a6b2016-11-06 20:37:09 -08001879 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 enforceCallPermission();
1881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1885 return;
1886 }
1887 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1888 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
1891 }
pkanwar32d516d2016-10-14 19:37:38 -07001892 };
1893
Wink Savilleb564aae2014-10-23 10:18:09 -07001894 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1900 return false;
1901 }
1902 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001909 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001912 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 Phone phone = PhoneFactory.getPhone(slotIndex);
1916 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1917 PhoneConstantConversions.convertCallState(phone.getState());
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
1920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001924 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001925 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1926 }
1927
1928 @Override
1929 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001932 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 if (phone != null) {
1934 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1935 } else {
1936 return PhoneConstantConversions.convertDataState(
1937 PhoneConstants.DataState.DISCONNECTED);
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001945 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001946 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1947 }
1948
1949 @Override
1950 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 if (phone != null) {
1955 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1956 } else {
1957 return TelephonyManager.DATA_ACTIVITY_NONE;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
1964 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001965 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001966 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001967 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001968
1969 LocationAccessPolicy.LocationPermissionResult locationResult =
1970 LocationAccessPolicy.checkLocationPermission(mApp,
1971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1972 .setCallingPackage(callingPackage)
1973 .setCallingPid(Binder.getCallingPid())
1974 .setCallingUid(Binder.getCallingUid())
1975 .setMethod("getCellLocation")
1976 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1977 .build());
1978 switch (locationResult) {
1979 case DENIED_HARD:
1980 throw new SecurityException("Not allowed to access cell location");
1981 case DENIED_SOFT:
1982 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 if (DBG_LOC) log("getCellLocation: is active user");
1989 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001990 int subId = mSubscriptionController.getDefaultDataSubId();
1991 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1992 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 return data;
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Svetoslav64fad262015-04-14 14:35:21 -07001997 }
1998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002000 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2001 if (!TextUtils.isEmpty(callingPackage)) {
2002 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2004 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2005 return "";
2006 }
2007 }
2008
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002009 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2010 // registered cell info, so return a NULL country instead.
2011 final long identity = Binder.clearCallingIdentity();
2012 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002013 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2014 // Get default phone in this case.
2015 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2016 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002017 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002018 // Todo: fix this when we can get the actual cellular network info when the device
2019 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002020 if (TelephonyManager.NETWORK_TYPE_IWLAN
2021 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2022 return "";
2023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 Phone phone = PhoneFactory.getPhone(phoneId);
2025 if (phone != null) {
2026 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002027 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 if (sst != null) {
2029 LocaleTracker lt = sst.getLocaleTracker();
2030 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002031 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2032 return lt.getCurrentCountry();
2033 } else if (emergencyNumberTracker != null) {
2034 return emergencyNumberTracker.getEmergencyCountryIso();
2035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 }
2037 }
2038 }
2039 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 }
2044
2045 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002047 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002048 }
2049
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002051 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 mApp.enforceCallingOrSelfPermission(
2053 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 final Phone phone = getPhone(subId);
2058 if (phone != null) {
2059 phone.enableLocationUpdates();
2060 }
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 }
2065
2066 @Override
2067 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002068 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
2070
Sanket Padawe356d7632015-06-22 14:03:32 -07002071 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002072 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 mApp.enforceCallingOrSelfPermission(
2074 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 final Phone phone = getPhone(subId);
2079 if (phone != null) {
2080 phone.disableLocationUpdates();
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Nathan Harold31d7ff32018-10-15 20:20:30 -07002087 /**
2088 * Returns the target SDK version number for a given package name.
2089 *
Nathan Haroldec184742019-07-10 17:04:16 -07002090 * This call MUST be invoked before clearing the calling UID.
2091 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002092 * @return target SDK if the package is found or INT_MAX.
2093 */
2094 private int getTargetSdk(String packageName) {
2095 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002096 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002097 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002098 if (ai != null) return ai.targetSdkVersion;
2099 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002100 loge("Failed to get package info for pkg="
2101 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002102 }
2103 return Integer.MAX_VALUE;
2104 }
2105
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 @Override
2107 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002108 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2109 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2111 throw new SecurityException(
2112 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2113 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002114
Jordan Liu1617b712019-07-10 15:06:26 -07002115 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2117 return null;
2118 }
Svetoslav64fad262015-04-14 14:35:21 -07002119
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002120 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121
Nathan Haroldf180aac2018-06-01 18:43:55 -07002122 List<CellInfo> info = getAllCellInfo(callingPackage);
2123 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124
Nathan Haroldf180aac2018-06-01 18:43:55 -07002125 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2126 for (CellInfo ci : info) {
2127 if (ci instanceof CellInfoGsm) {
2128 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2129 } else if (ci instanceof CellInfoWcdma) {
2130 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002133 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002136 private List<CellInfo> getCachedCellInfo() {
2137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2138 for (Phone phone : PhoneFactory.getPhones()) {
2139 List<CellInfo> info = phone.getAllCellInfo();
2140 if (info != null) cellInfos.addAll(info);
2141 }
2142 return cellInfos;
2143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144
2145 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002146 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002147 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002149
2150 LocationAccessPolicy.LocationPermissionResult locationResult =
2151 LocationAccessPolicy.checkLocationPermission(mApp,
2152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2153 .setCallingPackage(callingPackage)
2154 .setCallingPid(Binder.getCallingPid())
2155 .setCallingUid(Binder.getCallingUid())
2156 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002158 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2159 .build());
2160 switch (locationResult) {
2161 case DENIED_HARD:
2162 throw new SecurityException("Not allowed to access cell info");
2163 case DENIED_SOFT:
2164 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002167 final int targetSdk = getTargetSdk(callingPackage);
2168 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2169 return getCachedCellInfo();
2170 }
2171
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002172 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2177 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002178 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002179 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180 if (info != null) cellInfos.addAll(info);
2181 }
2182 return cellInfos;
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186 }
2187
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002188 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002189 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2190 requestCellInfoUpdateInternal(
2191 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2192 }
2193
2194 @Override
2195 public void requestCellInfoUpdateWithWorkSource(
2196 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2197 enforceModifyPermission();
2198 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2199 }
2200
2201 private void requestCellInfoUpdateInternal(
2202 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002203 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002204 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002205
2206 LocationAccessPolicy.LocationPermissionResult locationResult =
2207 LocationAccessPolicy.checkLocationPermission(mApp,
2208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2209 .setCallingPackage(callingPackage)
2210 .setCallingPid(Binder.getCallingPid())
2211 .setCallingUid(Binder.getCallingUid())
2212 .setMethod("requestCellInfoUpdate")
2213 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2214 .build());
2215 switch (locationResult) {
2216 case DENIED_HARD:
2217 throw new SecurityException("Not allowed to access cell info");
2218 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002219 try {
2220 cb.onCellInfo(new ArrayList<CellInfo>());
2221 } catch (RemoteException re) {
2222 // Drop without consequences
2223 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002224 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 }
2226
Nathan Harolda939a962019-05-09 10:13:47 -07002227
2228 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002229 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2230
2231 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2232 }
2233
2234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002236 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 } finally {
2243 Binder.restoreCallingIdentity(identity);
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Shishir Agrawala9f32182016-04-12 12:00:16 -07002247 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002248 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 Phone phone = PhoneFactory.getPhone(slotIndex);
2250 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 return null;
2252 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002253 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002254 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2255 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002256 return null;
2257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return phone.getImei();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002265 }
2266
2267 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002268 public String getTypeAllocationCodeForSlot(int slotIndex) {
2269 Phone phone = PhoneFactory.getPhone(slotIndex);
2270 String tac = null;
2271 if (phone != null) {
2272 String imei = phone.getImei();
2273 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2274 }
2275 return tac;
2276 }
2277
2278 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002279 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 Phone phone = PhoneFactory.getPhone(slotIndex);
2281 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002282 return null;
2283 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002286 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2287 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 return null;
2289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 return phone.getMeid();
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Jack Yu2af8d712017-03-15 17:14:14 -07002297 }
2298
2299 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002300 public String getManufacturerCodeForSlot(int slotIndex) {
2301 Phone phone = PhoneFactory.getPhone(slotIndex);
2302 String manufacturerCode = null;
2303 if (phone != null) {
2304 String meid = phone.getMeid();
2305 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2306 }
2307 return manufacturerCode;
2308 }
2309
2310 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002311 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 Phone phone = PhoneFactory.getPhone(slotIndex);
2313 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002314 return null;
2315 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 int subId = phone.getSubId();
2317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2318 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2319 return null;
2320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 return phone.getDeviceSvn();
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002328 }
2329
fionaxu43304da2017-11-27 22:51:16 -08002330 @Override
2331 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
fionaxu43304da2017-11-27 22:51:16 -08002339 }
2340
2341 @Override
2342 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 final Phone phone = getPhone(subId);
2346 return phone == null ? null : phone.getCarrierName();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
fionaxu43304da2017-11-27 22:51:16 -08002350 }
2351
calvinpanffe225e2018-11-01 19:43:06 +08002352 @Override
chen xu0026ca62019-03-06 15:28:50 -08002353 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 final Phone phone = getPhone(subId);
2357 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002358 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
2362 }
2363
2364 @Override
chen xu0026ca62019-03-06 15:28:50 -08002365 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002369 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
2373 }
2374
chen xu651eec72018-11-11 19:03:44 -08002375 @Override
chen xu864e11c2018-12-06 22:10:03 -08002376 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2377 if (!isSubscriptionMccMnc) {
2378 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2379 }
chen xu651eec72018-11-11 19:03:44 -08002380 final Phone phone = PhoneFactory.getPhone(slotIndex);
2381 if (phone == null) {
2382 return TelephonyManager.UNKNOWN_CARRIER_ID;
2383 }
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
2389 }
2390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 //
2393 // Internal helper methods.
2394 //
2395
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002396 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2398 *
2399 * @throws SecurityException if the caller does not have the required permission
2400 */
2401 private void enforceModifyPermission() {
2402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2403 }
2404
2405 /**
2406 * Make sure the caller has the CALL_PHONE permission.
2407 *
2408 * @throws SecurityException if the caller does not have the required permission
2409 */
2410 private void enforceCallPermission() {
2411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2412 }
2413
Stuart Scott8eef64f2015-04-08 15:13:54 -07002414 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002415 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002416 "ConnectivityService");
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 private String createTelUrl(String number) {
2420 if (TextUtils.isEmpty(number)) {
2421 return null;
2422 }
2423
Jake Hambye994d462014-02-03 13:10:13 -08002424 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Ihab Awadf9e92732013-12-05 18:02:52 -08002427 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2429 }
2430
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002431 private static void logv(String msg) {
2432 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Ihab Awadf9e92732013-12-05 18:02:52 -08002435 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2437 }
2438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002441 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002445 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = PhoneFactory.getPhone(slotIndex);
2449 if (phone == null) {
2450 return PhoneConstants.PHONE_TYPE_NONE;
2451 } else {
2452 return phone.getPhoneType();
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
2459 /**
2460 * Returns the CDMA ERI icon index to display
2461 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 @Override
2463 public int getCdmaEriIconIndex(String callingPackage) {
2464 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002465 }
2466
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002470 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 return -1;
2472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 return phone.getCdmaEriIconIndex();
2479 } else {
2480 return -1;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 /**
2488 * Returns the CDMA ERI icon mode,
2489 * 0 - ON
2490 * 1 - FLASHING
2491 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 @Override
2493 public int getCdmaEriIconMode(String callingPackage) {
2494 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002500 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 return -1;
2502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 final Phone phone = getPhone(subId);
2507 if (phone != null) {
2508 return phone.getCdmaEriIconMode();
2509 } else {
2510 return -1;
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
2518 * Returns the CDMA ERI text,
2519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
2521 public String getCdmaEriText(String callingPackage) {
2522 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002526 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002529 return null;
2530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 final Phone phone = getPhone(subId);
2535 if (phone != null) {
2536 return phone.getCdmaEriText();
2537 } else {
2538 return null;
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 }
2544
2545 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002546 * Returns the CDMA MDN.
2547 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002549 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2551 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 return phone.getLine1Number();
2558 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002559 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 return null;
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002564 }
2565 }
2566
2567 /**
2568 * Returns the CDMA MIN.
2569 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2579 return phone.getCdmaMin();
2580 } else {
2581 return null;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002585 }
2586 }
2587
Hall Liud892bec2018-11-30 14:51:45 -08002588 @Override
2589 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2590 INumberVerificationCallback callback, String callingPackage) {
2591 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2592 != PERMISSION_GRANTED) {
2593 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2594 }
2595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2596
2597 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2598 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2599 throw new SecurityException("Calling package must be configured in the device config");
2600 }
2601
2602 if (range == null) {
2603 throw new NullPointerException("Range must be non-null");
2604 }
2605
2606 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002607 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002608
2609 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2610 }
2611
Junda Liuca05d5d2014-08-14 22:36:34 -07002612 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 * Returns true if CDMA provisioning needs to run.
2614 */
2615 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
2624 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002625 * Sets the voice mail number of a given subId.
2626 */
2627 @Override
2628 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2634 new Pair<String, String>(alphaTag, number), new Integer(subId));
2635 return success;
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002639 }
2640
Ta-wei Yen87c49842016-05-13 21:19:52 -07002641 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002642 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002644 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002645 if (!TextUtils.equals(callingPackage, systemDialer)) {
2646 throw new SecurityException("caller must be system dialer");
2647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2652 if (phoneAccountHandle == null) {
2653 return null;
2654 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002655 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002658 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002659 }
2660
2661 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002662 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002665 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002666 return null;
2667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002669 final long identity = Binder.clearCallingIdentity();
2670 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002671 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002675 }
2676
2677 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002678 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2679 VisualVoicemailSmsFilterSettings settings) {
2680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002685 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002689 }
2690
2691 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002692 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002698 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002702 }
2703
2704 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002705 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2706 String callingPackage, int subId) {
2707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002716 }
2717
2718 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002719 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002720 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002729 }
2730
2731 @Override
2732 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2733 String number, int port, String text, PendingIntent sentIntent) {
2734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002735 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002736 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002737 SmsController smsController = PhoneFactory.getSmsController();
2738 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2739 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002740 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002741
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002742 /**
fionaxu0152e512016-11-14 13:36:14 -08002743 * Sets the voice activation state of a given subId.
2744 */
2745 @Override
2746 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2748 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone != null) {
2754 phone.setVoiceActivationState(activationState);
2755 } else {
2756 loge("setVoiceActivationState fails with invalid subId: " + subId);
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002760 }
2761 }
2762
2763 /**
2764 * Sets the data activation state of a given subId.
2765 */
2766 @Override
2767 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2769 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770
2771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 final Phone phone = getPhone(subId);
2774 if (phone != null) {
2775 phone.setDataActivationState(activationState);
2776 } else {
2777 loge("setVoiceActivationState fails with invalid subId: " + subId);
2778 }
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002781 }
2782 }
2783
2784 /**
2785 * Returns the voice activation state of a given subId.
2786 */
2787 @Override
2788 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002789 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
fionaxu0152e512016-11-14 13:36:14 -08002791 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 if (phone != null) {
2795 return phone.getVoiceActivationState();
2796 } else {
2797 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002801 }
2802 }
2803
2804 /**
2805 * Returns the data activation state of a given subId.
2806 */
2807 @Override
2808 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002809 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
fionaxu0152e512016-11-14 13:36:14 -08002811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 if (phone != null) {
2815 return phone.getDataActivationState();
2816 } else {
2817 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002821 }
2822 }
2823
2824 /**
Wink Saville36469e72014-06-11 15:17:00 -07002825 * Returns the unread count of voicemails for a subId
2826 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002828 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2830 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2831 return 0;
2832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 return phone.getVoiceMessageCount();
2838 } else {
2839 return 0;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
2846 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002847 * returns true, if the device is in a state where both voice and data
2848 * are supported simultaneously. This can change based on location or network condition.
2849 */
2850 @Override
2851 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 final Phone phone = getPhone(subId);
2855 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002859 }
2860
2861 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002862 * Send the dialer code if called from the current default dialer or the caller has
2863 * carrier privilege.
2864 * @param inputCode The dialer code to send
2865 */
2866 @Override
2867 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2871 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002872 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2874 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
fionaxu235cc5e2017-03-06 22:25:57 -08002883 }
2884
Pengquan Menga1bb6272018-09-06 09:59:22 -07002885 @Override
2886 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002887 if (!isActiveSubscription(subId)) {
2888 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2889 }
2890
Pengquan Menga1bb6272018-09-06 09:59:22 -07002891 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2892 }
2893
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002895 public boolean isInEmergencySmsMode() {
2896 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 for (Phone phone : PhoneFactory.getPhones()) {
2900 if (phone.isInEmergencySmsMode()) {
2901 return true;
2902 }
2903 }
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 return false;
2908 }
2909
2910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002911 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2912 throws RemoteException {
2913 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002914 final long token = Binder.clearCallingIdentity();
2915 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002919 } catch (ImsException e) {
2920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002921 } finally {
2922 Binder.restoreCallingIdentity(token);
2923 }
2924 }
2925
2926 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002927 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2928 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002929 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2930 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2931 }
Meng Wangafbc5852019-09-19 17:37:13 -07002932 final long token = Binder.clearCallingIdentity();
2933 try {
2934 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2935 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2936 .removeRegistrationCallbackForSubscription(c, subId);
2937 } catch (ImsException e) {
2938 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2939 + "is inactive, ignoring unregister.");
2940 // If the subscription is no longer active, just return, since the callback
2941 // will already have been removed internally.
2942 } finally {
2943 Binder.restoreCallingIdentity(token);
2944 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002945 }
2946
2947 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002948 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2949 throws RemoteException {
2950 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2952 final long token = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002955 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002956 } catch (ImsException e) {
2957 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 } finally {
2959 Binder.restoreCallingIdentity(token);
2960 }
2961 }
2962
2963 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002964 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2965 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002966 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2967 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2968 }
Meng Wangafbc5852019-09-19 17:37:13 -07002969
2970 final long token = Binder.clearCallingIdentity();
2971 try {
2972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002974 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002975 } catch (ImsException e) {
2976 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2977 + "is inactive, ignoring unregister.");
2978 // If the subscription is no longer active, just return, since the callback
2979 // will already have been removed internally.
2980 } finally {
2981 Binder.restoreCallingIdentity(token);
2982 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public boolean isCapable(int subId, int capability, int regTech) {
2987 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2989 final long token = Binder.clearCallingIdentity();
2990 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002991 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002993 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2995 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002996 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002997 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2998 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(token);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003005 public boolean isAvailable(int subId, int capability, int regTech) {
3006 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 final long token = Binder.clearCallingIdentity();
3008 try {
3009 Phone phone = getPhone(subId);
3010 if (phone == null) return false;
3011 return phone.isImsCapabilityAvailable(capability, regTech);
3012 } finally {
3013 Binder.restoreCallingIdentity(token);
3014 }
3015 }
3016
3017 @Override
3018 public boolean isAdvancedCallingSettingEnabled(int subId) {
3019 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3020 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3021 final long token = Binder.clearCallingIdentity();
3022 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003023 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003025 } catch (ImsException e) {
3026 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 } finally {
3028 Binder.restoreCallingIdentity(token);
3029 }
3030 }
3031
3032 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003033 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003035 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003039 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003041 } catch (ImsException e) {
3042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003043 } finally {
3044 Binder.restoreCallingIdentity(identity);
3045 }
3046 }
3047
3048 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003049 public boolean isVtSettingEnabled(int subId) {
3050 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003054 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3055 } catch (ImsException e) {
3056 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
3060 }
3061
3062 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003063 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003065 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003069 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003070 } catch (ImsException e) {
3071 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
3078 public boolean isVoWiFiSettingEnabled(int subId) {
3079 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003083 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003084 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003085 } catch (ImsException e) {
3086 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
3092 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003093 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003095 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003100 } catch (ImsException e) {
3101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
3107 @Override
3108 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3109 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003113 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003115 } catch (ImsException e) {
3116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003123 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003125 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003129 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003131 } catch (ImsException e) {
3132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
3138 @Override
3139 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3141 "setVoWiFiNonPersistent");
3142 final long identity = Binder.clearCallingIdentity();
3143 try {
3144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003145 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003146 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003147 } catch (ImsException e) {
3148 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 } finally {
3150 Binder.restoreCallingIdentity(identity);
3151 }
3152 }
3153
3154 @Override
3155 public int getVoWiFiModeSetting(int subId) {
3156 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003160 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003162 } catch (ImsException e) {
3163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
3167 }
3168
3169 @Override
3170 public void setVoWiFiModeSetting(int subId, int mode) {
3171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3172 "setVoWiFiModeSetting");
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003176 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003178 } catch (ImsException e) {
3179 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 } finally {
3181 Binder.restoreCallingIdentity(identity);
3182 }
3183 }
3184
3185 @Override
3186 public int getVoWiFiRoamingModeSetting(int subId) {
3187 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003193 } catch (ImsException e) {
3194 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 } finally {
3196 Binder.restoreCallingIdentity(identity);
3197 }
3198 }
3199
3200 @Override
3201 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3203 "setVoWiFiRoamingModeSetting");
3204 final long identity = Binder.clearCallingIdentity();
3205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003209 } catch (ImsException e) {
3210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 } finally {
3212 Binder.restoreCallingIdentity(identity);
3213 }
3214 }
3215
3216 @Override
3217 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3219 "setRttCapabilityEnabled");
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3224 } catch (ImsException e) {
3225 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 } finally {
3227 Binder.restoreCallingIdentity(identity);
3228 }
3229 }
3230
3231 @Override
3232 public boolean isTtyOverVolteEnabled(int subId) {
3233 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003237 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003239 } catch (ImsException e) {
3240 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003246 @Override
3247 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3248 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3249 final long identity = Binder.clearCallingIdentity();
3250 try {
3251 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003252 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003253 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003254 } catch (ImsException e) {
3255 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003256 } finally {
3257 Binder.restoreCallingIdentity(identity);
3258 }
3259 }
3260
3261 @Override
3262 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3263 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3264 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003265 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3266 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3267 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003268 try {
3269 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003270 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003271 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003272 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003273 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3274 + "is inactive, ignoring unregister.");
3275 // If the subscription is no longer active, just return, since the callback will already
3276 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003277 } finally {
3278 Binder.restoreCallingIdentity(identity);
3279 }
3280 }
3281
3282 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003283 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3284 boolean isProvisioned) {
3285 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3286 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3287 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3288 }
3289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3290 "setProvisioningStatusForCapability");
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3294 Phone phone = getPhone(subId);
3295 if (phone == null) {
3296 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3297 + subId);
3298 return;
3299 }
3300 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3301 return;
3302 }
3303
3304 // this capability requires provisioning, route to the correct API.
3305 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3306 switch (capability) {
3307 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3308 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3309 ims.setVolteProvisioned(isProvisioned);
3310 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3311 ims.setWfcProvisioned(isProvisioned);
3312 }
3313 break;
3314 }
3315 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3316 // There is currently no difference in VT provisioning type.
3317 ims.setVtProvisioned(isProvisioned);
3318 break;
3319 }
3320 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3321 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3322 // change the capability of the feature instead if needed.
3323 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3324 == isProvisioned) {
3325 // No change in provisioning.
3326 return;
3327 }
3328 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3329 try {
3330 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003332 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3333 + ", Exception" + e.getMessage());
3334 }
3335 break;
3336 }
3337 default: {
3338 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3339 + capability + "', which does not require provisioning.");
3340 }
3341 }
3342
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
3348 @Override
3349 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3350 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3351 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3352 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3353 }
3354 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3355 final long identity = Binder.clearCallingIdentity();
3356 try {
3357 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3358 Phone phone = getPhone(subId);
3359 if (phone == null) {
3360 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3361 + subId);
3362 // We will fail with "true" as the provisioning status because this is the default
3363 // if we do not require provisioning.
3364 return true;
3365 }
3366
3367 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3368 return true;
3369 }
3370
3371 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3372 switch (capability) {
3373 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3374 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3375 return ims.isVolteProvisionedOnDevice();
3376 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3377 return ims.isWfcProvisionedOnDevice();
3378 }
3379 // This should never happen, since we are checking tech above to make sure it
3380 // is either LTE or IWLAN.
3381 throw new IllegalArgumentException("Invalid radio technology for voice "
3382 + "capability.");
3383 }
3384 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3385 // There is currently no difference in VT provisioning type.
3386 return ims.isVtProvisionedOnDevice();
3387 }
3388 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3389 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3390 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3391 }
3392 default: {
3393 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3394 + capability + "', which does not require provisioning.");
3395 }
3396 }
3397
3398 } finally {
3399 Binder.restoreCallingIdentity(identity);
3400 }
3401 }
3402
3403 @Override
3404 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3405 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3406 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3407 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3408 }
3409 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3410 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3411 return (provisionedBits & capability) > 0;
3412 }
3413
3414 @Override
3415 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3416 boolean isProvisioned) {
3417 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3418 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3419 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3420 }
3421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3422 "setProvisioningStatusForCapability");
3423 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3424 // If the current provisioning status for capability already matches isProvisioned,
3425 // do nothing.
3426 if (((provisionedBits & capability) > 0) == isProvisioned) {
3427 return;
3428 }
3429 if (isProvisioned) {
3430 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3431 } else {
3432 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3433 }
3434 }
3435
3436 /**
3437 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3438 * technology. The bitfield should mirror the bitfield defined by
3439 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3440 */
3441 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3442 String key = getMmTelProvisioningKey(subId, tech);
3443 // Default is no capabilities are provisioned.
3444 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3445 }
3446
3447 /**
3448 * Sets the MmTel capability provisioning bitfield (defined by
3449 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3450 * technology specified.
3451 *
3452 * Note: This is a synchronous command and should not be called on UI thread.
3453 */
3454 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3455 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3456 String key = getMmTelProvisioningKey(subId, tech);
3457 editor.putInt(key, newField);
3458 editor.commit();
3459 }
3460
3461 private static String getMmTelProvisioningKey(int subId, int tech) {
3462 // resulting key is provision_ims_mmtel_{subId}_{tech}
3463 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3464 }
3465
3466 /**
3467 * Query CarrierConfig to see if the specified capability requires provisioning for the
3468 * carrier associated with the subscription id.
3469 */
3470 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3471 int capability) {
3472 CarrierConfigManager configManager = new CarrierConfigManager(context);
3473 PersistableBundle c = configManager.getConfigForSubId(subId);
3474 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003475 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003476 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3477 false);
3478 boolean requireVoiceVtProvisioning = c.getBoolean(
3479 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3480
3481 // First check to make sure that the capability requires provisioning.
3482 switch (capability) {
3483 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3484 // intentional fallthrough
3485 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3486 if (requireVoiceVtProvisioning) {
3487 // Voice and Video requires provisioning
3488 return true;
3489 }
3490 break;
3491 }
3492 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3493 if (requireUtProvisioning) {
3494 // UT requires provisioning
3495 return true;
3496 }
3497 break;
3498 }
3499 }
3500 return false;
3501 }
3502
3503 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003504 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003505 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3506 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3507 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003508 enforceReadPrivilegedPermission("getImsProvisioningInt");
3509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003512 int slotId = getSlotIndex(subId);
3513 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3514 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3515 + subId + "' for key:" + key);
3516 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3517 }
3518 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003520 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3521 + subId + "' for key:" + key);
3522 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003523 } finally {
3524 Binder.restoreCallingIdentity(identity);
3525 }
3526 }
3527
3528 @Override
3529 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003530 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3531 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3532 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003533 enforceReadPrivilegedPermission("getImsProvisioningString");
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003537 int slotId = getSlotIndex(subId);
3538 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3539 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3540 + subId + "' for key:" + key);
3541 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3542 }
3543 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003544 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003545 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3546 + subId + "' for key:" + key);
3547 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
3553 @Override
3554 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003555 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3556 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3557 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3559 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003563 int slotId = getSlotIndex(subId);
3564 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3565 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3566 + subId + "' for key:" + key);
3567 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3568 }
3569 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003570 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003571 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3572 + "' for key:" + key);
3573 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
3579 @Override
3580 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003581 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3582 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3583 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3585 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003589 int slotId = getSlotIndex(subId);
3590 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3591 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3592 + subId + "' for key:" + key);
3593 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3594 }
3595 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003596 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003597 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3598 + "' for key:" + key);
3599 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003600 } finally {
3601 Binder.restoreCallingIdentity(identity);
3602 }
3603 }
3604
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003605 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 int slotId = SubscriptionManager.getSlotIndex(subId);
3607 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3609 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 }
3611 return slotId;
3612 }
3613
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003614 private int getSlotIndex(int subId) {
3615 int slotId = SubscriptionManager.getSlotIndex(subId);
3616 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3617 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3618 }
3619 return slotId;
3620 }
3621
Wink Saville36469e72014-06-11 15:17:00 -07003622 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003623 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003624 */
3625 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003626 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003627 final int targetSdk = getTargetSdk(callingPackage);
3628 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3629 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3630 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003631 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3632 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3634 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003636 final long identity = Binder.clearCallingIdentity();
3637 try {
3638 final Phone phone = getPhone(subId);
3639 if (phone != null) {
3640 return phone.getServiceState().getDataNetworkType();
3641 } else {
3642 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3643 }
3644 } finally {
3645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 }
3648
3649 /**
3650 * Returns the data network type
3651 */
3652 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003653 public int getDataNetworkType(String callingPackage) {
3654 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003655 }
3656
3657 /**
3658 * Returns the data network type for a subId
3659 */
3660 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003661 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003663 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003664 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3665 }
3666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 final Phone phone = getPhone(subId);
3670 if (phone != null) {
3671 return phone.getServiceState().getDataNetworkType();
3672 } else {
3673 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3674 }
3675 } finally {
3676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003677 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003678 }
3679
3680 /**
Wink Saville36469e72014-06-11 15:17:00 -07003681 * Returns the Voice network type for a subId
3682 */
3683 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003684 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003685 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003686 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003687 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3688 }
3689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003690 final long identity = Binder.clearCallingIdentity();
3691 try {
3692 final Phone phone = getPhone(subId);
3693 if (phone != null) {
3694 return phone.getServiceState().getVoiceNetworkType();
3695 } else {
3696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3697 }
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003701 }
3702
3703 /**
3704 * @return true if a ICC card is present
3705 */
3706 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003707 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003708 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3709 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003710 }
3711
3712 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003713 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003714 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003715 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003716 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 final Phone phone = PhoneFactory.getPhone(slotIndex);
3720 if (phone != null) {
3721 return phone.getIccCard().hasIccCard();
3722 } else {
3723 return false;
3724 }
3725 } finally {
3726 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003728 }
3729
3730 /**
3731 * Return if the current radio is LTE on CDMA. This
3732 * is a tri-state return value as for a period of time
3733 * the mode may be unknown.
3734 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003735 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003736 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003737 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003738 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003739 @Override
3740 public int getLteOnCdmaMode(String callingPackage) {
3741 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003742 }
3743
Sanket Padawe356d7632015-06-22 14:03:32 -07003744 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003745 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003746 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003747 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003748 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3749 }
3750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 final Phone phone = getPhone(subId);
3754 if (phone == null) {
3755 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3756 } else {
3757 return phone.getLteOnCdmaMode();
3758 }
3759 } finally {
3760 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003761 }
Wink Saville36469e72014-06-11 15:17:00 -07003762 }
3763
Wink Saville36469e72014-06-11 15:17:00 -07003764 /**
3765 * {@hide}
3766 * Returns Default subId, 0 in the case of single standby.
3767 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003768 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003769 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003770 }
3771
Shishir Agrawala9f32182016-04-12 12:00:16 -07003772 private int getSlotForDefaultSubscription() {
3773 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3774 }
3775
Wink Savilleb564aae2014-10-23 10:18:09 -07003776 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003777 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003778 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003779
Pengquan Menge92a50d2018-09-21 15:54:48 -07003780 private boolean isActiveSubscription(int subId) {
3781 return mSubscriptionController.isActiveSubId(subId);
3782 }
3783
Ihab Awadf2177b72013-11-25 13:33:23 -08003784 /**
3785 * @see android.telephony.TelephonyManager.WifiCallingChoices
3786 */
3787 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003788 final long identity = Binder.clearCallingIdentity();
3789 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003790 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3792 getWhenToMakeWifiCallsDefaultPreference());
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
3795 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003796 }
3797
3798 /**
3799 * @see android.telephony.TelephonyManager.WifiCallingChoices
3800 */
3801 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003802 final long identity = Binder.clearCallingIdentity();
3803 try {
3804 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003806 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3807 } finally {
3808 Binder.restoreCallingIdentity(identity);
3809 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003810 }
3811
Sailesh Nepald1e68152013-12-12 19:08:02 -08003812 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003813 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003814 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003815 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003816
Jordan Liu4c733742019-02-28 12:03:40 -08003817 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3818 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3819 if (phoneId == -1) {
3820 throw new IllegalArgumentException("Given slot index: " + slotIndex
3821 + " does not correspond to an active phone");
3822 }
3823 return PhoneFactory.getPhone(phoneId);
3824 }
3825
Shishir Agrawal566b7612013-10-28 14:41:00 -07003826 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003827 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3828 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3830 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003832 if (DBG) {
3833 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3834 }
3835 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3836 p2);
3837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003838
Jordan Liu4c733742019-02-28 12:03:40 -08003839
3840 @Override
3841 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3842 int slotIndex, String callingPackage, String aid, int p2) {
3843 enforceModifyPermission();
3844 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3845 if (DBG) {
3846 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3847 }
3848 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3849 callingPackage, aid, p2);
3850 }
3851
3852 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3853 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 if (TextUtils.equals(ISDR_AID, aid)) {
3857 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003858 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3859 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 if (bestComponent == null
3861 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3862 loge("The calling package is not allowed to access ISD-R.");
3863 throw new SecurityException(
3864 "The calling package is not allowed to access ISD-R.");
3865 }
Derek Tan740e1672017-06-27 14:56:27 -07003866 }
Derek Tan740e1672017-06-27 14:56:27 -07003867
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003868 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003869 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3870 null /* workSource */);
3871 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003872 return response;
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003876 }
3877
3878 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003879 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3881 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003882 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3883 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3884 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003885
Jordan Liu4c733742019-02-28 12:03:40 -08003886 @Override
3887 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3888 enforceModifyPermission();
3889 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3890 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3891 channel);
3892 }
3893
3894 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 final long identity = Binder.clearCallingIdentity();
3896 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 if (channel < 0) {
3898 return false;
3899 }
Jordan Liu4c733742019-02-28 12:03:40 -08003900 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3901 null /* workSource */);
3902 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 return success;
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003906 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003907 }
3908
3909 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003910 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003911 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3913 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003914 if (DBG) {
3915 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3916 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3917 + p3 + " data=" + data);
3918 }
3919 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3920 command, p1, p2, p3, data);
3921 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003922
Jordan Liu4c733742019-02-28 12:03:40 -08003923 @Override
3924 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3925 int command, int p1, int p2, int p3, String data) {
3926 enforceModifyPermission();
3927 if (DBG) {
3928 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3929 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3930 + p3 + " data=" + data);
3931 }
3932 return iccTransmitApduLogicalChannelWithPermission(
3933 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3934 data);
3935 }
3936
3937 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3938 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 final long identity = Binder.clearCallingIdentity();
3940 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003941 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 return "";
3943 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003946 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3947 null /* workSource */);
3948 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 // Append the returned status code to the end of the response payload.
3951 String s = Integer.toHexString(
3952 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3953 if (response.payload != null) {
3954 s = IccUtils.bytesToHexString(response.payload) + s;
3955 }
3956 return s;
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003959 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003960 }
Jake Hambye994d462014-02-03 13:10:13 -08003961
Evan Charltonc66da362014-05-16 14:06:40 -07003962 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003963 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3964 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3966 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003968 if (DBG) {
3969 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3970 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3971 }
3972 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3973 cla, command, p1, p2, p3, data);
3974 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975
Jordan Liu4c733742019-02-28 12:03:40 -08003976 @Override
3977 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3978 int command, int p1, int p2, int p3, String data) {
3979 enforceModifyPermission();
3980 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3981 if (DBG) {
3982 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3983 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3984 + " data=" + data);
3985 }
3986
3987 return iccTransmitApduBasicChannelWithPermission(
3988 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3989 p2, p3, data);
3990 }
3991
3992 // open APDU basic channel assuming the caller has sufficient permissions
3993 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3994 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3998 && TextUtils.equals(ISDR_AID, data)) {
3999 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004000 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4001 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 if (bestComponent == null
4003 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4004 loge("The calling package is not allowed to select ISD-R.");
4005 throw new SecurityException(
4006 "The calling package is not allowed to select ISD-R.");
4007 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004008 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004009
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004010 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004011 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4012 null /* workSource */);
4013 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 // Append the returned status code to the end of the response payload.
4016 String s = Integer.toHexString(
4017 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4018 if (response.payload != null) {
4019 s = IccUtils.bytesToHexString(response.payload) + s;
4020 }
4021 return s;
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004024 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004025 }
4026
4027 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004028 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004029 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4031 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 if (DBG) {
4036 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4037 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4038 }
4039
4040 IccIoResult response =
4041 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4042 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4043 subId);
4044
4045 if (DBG) {
4046 log("Exchange SIM_IO [R]" + response);
4047 }
4048
4049 byte[] result = null;
4050 int length = 2;
4051 if (response.payload != null) {
4052 length = 2 + response.payload.length;
4053 result = new byte[length];
4054 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4055 } else {
4056 result = new byte[length];
4057 }
4058
4059 result[length - 1] = (byte) response.sw2;
4060 result[length - 2] = (byte) response.sw1;
4061 return result;
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004064 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004065 }
4066
Nathan Haroldb3014052017-01-25 15:57:32 -08004067 /**
4068 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4069 * on a particular subscription
4070 */
sqianb6e41952018-03-12 14:54:01 -07004071 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4073 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4074 return null;
4075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 if (appType != TelephonyManager.APPTYPE_USIM
4080 && appType != TelephonyManager.APPTYPE_SIM) {
4081 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4082 return null;
4083 }
4084 Object response = sendRequest(
4085 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4086 if (response instanceof String[]) {
4087 return (String[]) response;
4088 }
yincheng zhao2737e882019-09-06 17:06:54 -07004089 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004090 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004091 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004092 } finally {
4093 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004094 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004095 }
4096
yincheng zhao2737e882019-09-06 17:06:54 -07004097 /**
4098 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4099 * subscription.
4100 *
4101 * @param subId the id of the subscription.
4102 * @param appType the uicc app type, must be USIM or SIM.
4103 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4104 * @param callingPackage the op Package name.
4105 * @return number of fplmns that is successfully written to the SIM.
4106 */
4107 public int setForbiddenPlmns(
4108 int subId, int appType, List<String> fplmns, String callingPackage) {
4109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4110 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4111 if (DBG) logv("no permissions for setForbiddenplmns");
4112 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4113 }
4114 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4115 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4116 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4117 }
4118 if (fplmns == null) {
4119 throw new IllegalArgumentException("Fplmn List provided is null");
4120 }
4121 for (String fplmn : fplmns) {
4122 if (!CellIdentity.isValidPlmn(fplmn)) {
4123 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4124 }
4125 }
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 Object response = sendRequest(
4129 CMD_SET_FORBIDDEN_PLMNS,
4130 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4131 subId);
4132 return (int) response;
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
4135 }
4136 }
4137
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004138 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004139 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4141 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4146 if (response.payload == null) {
4147 return "";
4148 }
Evan Charltonc66da362014-05-16 14:06:40 -07004149
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004150 // Append the returned status code to the end of the response payload.
4151 String s = Integer.toHexString(
4152 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4153 s = IccUtils.bytesToHexString(response.payload) + s;
4154 return s;
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
Evan Charltonc66da362014-05-16 14:06:40 -07004158 }
4159
Jake Hambye994d462014-02-03 13:10:13 -08004160 /**
4161 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4162 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4163 *
4164 * @param itemID the ID of the item to read
4165 * @return the NV item as a String, or null on error.
4166 */
4167 @Override
4168 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004170 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4171 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172
4173 final long identity = Binder.clearCallingIdentity();
4174 try {
4175 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004176 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4178 return value;
4179 } finally {
4180 Binder.restoreCallingIdentity(identity);
4181 }
Jake Hambye994d462014-02-03 13:10:13 -08004182 }
4183
4184 /**
4185 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4186 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4187 *
4188 * @param itemID the ID of the item to read
4189 * @param itemValue the value to write, as a String
4190 * @return true on success; false on any failure
4191 */
4192 @Override
4193 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004194 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004195 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4196 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197
4198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4201 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004202 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4204 return success;
4205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
Jake Hambye994d462014-02-03 13:10:13 -08004208 }
4209
4210 /**
4211 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4212 * Used for device configuration by some CDMA operators.
4213 *
4214 * @param preferredRoamingList byte array containing the new PRL
4215 * @return true on success; false on any failure
4216 */
4217 @Override
4218 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4220 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
4224 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4225 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4226 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4227 return success;
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Jake Hambye994d462014-02-03 13:10:13 -08004231 }
4232
4233 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004234 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004235 * Used for device configuration by some CDMA operators.
4236 *
chen xu6dac5ab2018-10-26 17:39:23 -07004237 * @param slotIndex - device slot.
4238 *
Jake Hambye994d462014-02-03 13:10:13 -08004239 * @return true on success; false on any failure
4240 */
4241 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004242 public boolean resetModemConfig(int slotIndex) {
4243 Phone phone = PhoneFactory.getPhone(slotIndex);
4244 if (phone != null) {
4245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4246 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247
chen xu6dac5ab2018-10-26 17:39:23 -07004248 final long identity = Binder.clearCallingIdentity();
4249 try {
4250 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4251 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4252 return success;
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 }
chen xu6dac5ab2018-10-26 17:39:23 -07004257 return false;
4258 }
4259
4260 /**
4261 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4262 *
4263 * @param slotIndex - device slot.
4264 *
4265 * @return true on success; false on any failure
4266 */
4267 @Override
4268 public boolean rebootModem(int slotIndex) {
4269 Phone phone = PhoneFactory.getPhone(slotIndex);
4270 if (phone != null) {
4271 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4272 mApp, phone.getSubId(), "rebootModem");
4273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4277 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4278 return success;
4279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
4282 }
4283 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004284 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004285
Svet Ganovb320e182015-04-16 12:30:10 -07004286 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004287 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004289 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004290 return new String[0];
4291 }
4292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004295 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Wink Saville36469e72014-06-11 15:17:00 -07004299 }
4300
Brad Ebinger51f743a2017-01-23 13:50:20 -08004301 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004302 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4303 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004304 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004305 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004306 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004310 ImsResolver resolver = PhoneFactory.getImsResolver();
4311 if (resolver == null) {
4312 // may happen if the device does not support IMS.
4313 return;
4314 }
4315 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004319 }
4320
4321 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004322 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4323 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004324 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004325 public void disableIms(int slotId) {
4326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004330 ImsResolver resolver = PhoneFactory.getImsResolver();
4331 if (resolver == null) {
4332 // may happen if the device does not support IMS.
4333 return;
4334 }
4335 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004339 }
4340
4341 /**
4342 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4343 * feature or {@link null} if the service is not available. If the feature is available, the
4344 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4345 */
4346 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004347 IImsServiceFeatureCallback callback) {
4348 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349
4350 final long identity = Binder.clearCallingIdentity();
4351 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004352 ImsResolver resolver = PhoneFactory.getImsResolver();
4353 if (resolver == null) {
4354 // may happen if the device does not support IMS.
4355 return null;
4356 }
4357 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004361 }
4362
4363 /**
4364 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4365 * feature during emergency calling or {@link null} if the service is not available. If the
4366 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4367 * listener for feature updates.
4368 */
4369 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4370 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004371
4372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004374 ImsResolver resolver = PhoneFactory.getImsResolver();
4375 if (resolver == null) {
4376 // may happen if the device does not support IMS.
4377 return null;
4378 }
4379 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004383 }
4384
Brad Ebinger5f64b052017-12-14 14:26:15 -08004385 /**
4386 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004387 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004388 */
4389 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4390 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004394 ImsResolver resolver = PhoneFactory.getImsResolver();
4395 if (resolver == null) {
4396 // may happen if the device does not support IMS.
4397 return null;
4398 }
4399 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004400 } finally {
4401 Binder.restoreCallingIdentity(identity);
4402 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004403 }
4404
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004405 /**
4406 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004407 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004408 */
4409 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4410 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411
4412 final long identity = Binder.clearCallingIdentity();
4413 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004414 ImsResolver resolver = PhoneFactory.getImsResolver();
4415 if (resolver == null) {
4416 // may happen if the device does not support IMS.
4417 return null;
4418 }
4419 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004420 } finally {
4421 Binder.restoreCallingIdentity(identity);
4422 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004423 }
4424
Brad Ebinger884c07b2018-02-15 16:17:40 -08004425 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004426 * Sets the ImsService Package Name that Telephony will bind to.
4427 *
4428 * @param slotId the slot ID that the ImsService should bind for.
4429 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4430 * ImsService is the device default ImsService.
4431 * @param packageName The package name of the application that contains the ImsService to bind
4432 * to.
4433 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4434 * @hide
4435 */
4436 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004437 int[] subIds = SubscriptionManager.getSubId(slotId);
4438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4439 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4440 "setImsService");
4441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 final long identity = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004444 ImsResolver resolver = PhoneFactory.getImsResolver();
4445 if (resolver == null) {
4446 // may happen if the device does not support IMS.
4447 return false;
4448 }
4449 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4450 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004454 }
4455
4456 /**
4457 * Return the ImsService configuration.
4458 *
4459 * @param slotId The slot that the ImsService is associated with.
4460 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4461 * the device default.
4462 * @return the package name of the ImsService configuration.
4463 */
4464 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004465 int[] subIds = SubscriptionManager.getSubId(slotId);
4466 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4467 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4468 "getImsService");
4469
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004472 ImsResolver resolver = PhoneFactory.getImsResolver();
4473 if (resolver == null) {
4474 // may happen if the device does not support IMS.
4475 return "";
4476 }
4477 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004481 }
4482
Wink Saville36469e72014-06-11 15:17:00 -07004483 public void setImsRegistrationState(boolean registered) {
4484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004488 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489 } finally {
4490 Binder.restoreCallingIdentity(identity);
4491 }
Wink Saville36469e72014-06-11 15:17:00 -07004492 }
4493
4494 /**
Stuart Scott54788802015-03-30 13:18:01 -07004495 * Set the network selection mode to automatic.
4496 *
4497 */
4498 @Override
4499 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4501 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502
Pengquan Menge92a50d2018-09-21 15:54:48 -07004503 if (!isActiveSubscription(subId)) {
4504 return;
4505 }
4506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004507 final long identity = Binder.clearCallingIdentity();
4508 try {
4509 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4510 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Stuart Scott54788802015-03-30 13:18:01 -07004514 }
4515
Pengquan Mengea84e042018-09-20 14:57:26 -07004516 /**
4517 * Ask the radio to connect to the input network and change selection mode to manual.
4518 *
4519 * @param subId the id of the subscription.
4520 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4521 * the operator to attach to.
4522 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4523 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4524 * normal network selection next time.
4525 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004526 */
4527 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004528 public boolean setNetworkSelectionModeManual(
4529 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4531 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004532
4533 if (!isActiveSubscription(subId)) {
4534 return false;
4535 }
4536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004539 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004541 if (DBG) {
4542 log("setNetworkSelectionModeManual: subId: " + subId
4543 + " operator: " + operatorInfo);
4544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4546 } finally {
4547 Binder.restoreCallingIdentity(identity);
4548 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004549 }
4550
4551 /**
4552 * Scans for available networks.
4553 */
4554 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004555 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4557 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004558 LocationAccessPolicy.LocationPermissionResult locationResult =
4559 LocationAccessPolicy.checkLocationPermission(mApp,
4560 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4561 .setCallingPackage(callingPackage)
4562 .setCallingPid(Binder.getCallingPid())
4563 .setCallingUid(Binder.getCallingUid())
4564 .setMethod("getCellNetworkScanResults")
4565 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4566 .build());
4567 switch (locationResult) {
4568 case DENIED_HARD:
4569 throw new SecurityException("Not allowed to access scan results -- location");
4570 case DENIED_SOFT:
4571 return null;
4572 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573
Pengquan Menga1bb6272018-09-06 09:59:22 -07004574 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 try {
4576 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004577 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 } finally {
4580 Binder.restoreCallingIdentity(identity);
4581 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004582 }
4583
4584 /**
yinxub1bed742017-04-17 11:45:04 -07004585 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004586 *
yinxub1bed742017-04-17 11:45:04 -07004587 * @param subId id of the subscription
4588 * @param request contains the radio access networks with bands/channels to scan
4589 * @param messenger callback messenger for scan results or errors
4590 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004591 * @return the id of the requested scan which can be used to stop the scan.
4592 */
4593 @Override
4594 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004595 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004598 LocationAccessPolicy.LocationPermissionResult locationResult =
4599 LocationAccessPolicy.checkLocationPermission(mApp,
4600 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4601 .setCallingPackage(callingPackage)
4602 .setCallingPid(Binder.getCallingPid())
4603 .setCallingUid(Binder.getCallingUid())
4604 .setMethod("requestNetworkScan")
4605 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4606 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004607 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004608 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004609 if (e != null) {
4610 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4611 throw e;
4612 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004613 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004614 return TelephonyScanManager.INVALID_SCAN_ID;
4615 }
4616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004617 }
Hall Liu912dfd32019-04-25 14:02:26 -07004618 int callingUid = Binder.getCallingUid();
4619 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 return mNetworkScanRequestTracker.startNetworkScan(
4623 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004624 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004625 } finally {
4626 Binder.restoreCallingIdentity(identity);
4627 }
yinxu504e1392017-04-12 16:03:22 -07004628 }
4629
Hall Liub2ac8ef2019-02-28 15:56:23 -08004630 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004631 NetworkScanRequest request, int subId) {
4632 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4633 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4634 boolean hasNetworkScanPermission =
4635 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4636 == PERMISSION_GRANTED;
4637
4638 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4639 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4640 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004641 }
4642
4643 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4644 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004645 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4646 return new SecurityException("Specific channels must not be"
4647 + " scanned without location access.");
4648 }
4649 }
4650 }
4651
Hall Liub2ac8ef2019-02-28 15:56:23 -08004652 return null;
4653 }
4654
yinxu504e1392017-04-12 16:03:22 -07004655 /**
4656 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004657 *
4658 * @param subId id of the subscription
4659 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004660 */
4661 @Override
4662 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4664 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665
Hall Liu912dfd32019-04-25 14:02:26 -07004666 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 final long identity = Binder.clearCallingIdentity();
4668 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004669 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
4672 }
yinxu504e1392017-04-12 16:03:22 -07004673 }
4674
4675 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004676 * Get the calculated preferred network type.
4677 * Used for debugging incorrect network type.
4678 *
4679 * @return the preferred network type, defined in RILConstants.java.
4680 */
4681 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004682 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004683 final Phone defaultPhone = getDefaultPhone();
4684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4685 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004686 return RILConstants.PREFERRED_NETWORK_MODE;
4687 }
4688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
4691 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004692 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
Junda Liu84d15a22014-07-02 11:21:04 -07004696 }
4697
4698 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004699 * Get the preferred network type.
4700 * Used for device configuration by some CDMA operators.
4701 *
4702 * @return the preferred network type, defined in RILConstants.java.
4703 */
4704 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004705 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004706 TelephonyPermissions
4707 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4708 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004709
4710 final long identity = Binder.clearCallingIdentity();
4711 try {
4712 if (DBG) log("getPreferredNetworkType");
4713 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4714 int networkType = (result != null ? result[0] : -1);
4715 if (DBG) log("getPreferredNetworkType: " + networkType);
4716 return networkType;
4717 } finally {
4718 Binder.restoreCallingIdentity(identity);
4719 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004720 }
4721
4722 /**
4723 * Set the preferred network type.
4724 * Used for device configuration by some CDMA operators.
4725 *
4726 * @param networkType the preferred network type, defined in RILConstants.java.
4727 * @return true on success; false on any failure.
4728 */
4729 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004730 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004731 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4732 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733
4734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4737 Boolean success = (Boolean) sendRequest(
4738 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4739 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4740 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004741 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4743 }
4744 return success;
4745 } finally {
4746 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004747 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004748 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004749
4750 /**
Miaoa84611c2019-03-15 09:21:10 +08004751 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004752 *
Miaoa84611c2019-03-15 09:21:10 +08004753 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004754 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004755 * @hide
4756 */
4757 @Override
Miaoa84611c2019-03-15 09:21:10 +08004758 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004761 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 try {
Miaoa84611c2019-03-15 09:21:10 +08004763 if (phone != null) {
4764 return phone.hasMatchedTetherApnSetting();
4765 } else {
4766 return false;
4767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768 } finally {
4769 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004770 }
Junda Liu475951f2014-11-07 16:45:03 -08004771 }
4772
4773 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004774 * Set mobile data enabled
4775 * Used by the user through settings etc to turn on/off mobile data
4776 *
4777 * @param enable {@code true} turn turn data on, else {@code false}
4778 */
4779 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004780 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4782 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783
4784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 int phoneId = mSubscriptionController.getPhoneId(subId);
4787 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4788 Phone phone = PhoneFactory.getPhone(phoneId);
4789 if (phone != null) {
4790 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004791 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004793 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794 }
4795 } finally {
4796 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004797 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004798 }
4799
4800 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004801 * Get the user enabled state of Mobile Data.
4802 *
4803 * TODO: remove and use isUserDataEnabled.
4804 * This can't be removed now because some vendor codes
4805 * calls through ITelephony directly while they should
4806 * use TelephonyManager.
4807 *
4808 * @return true on enabled
4809 */
4810 @Override
4811 public boolean getDataEnabled(int subId) {
4812 return isUserDataEnabled(subId);
4813 }
4814
4815 /**
4816 * Get whether mobile data is enabled per user setting.
4817 *
4818 * There are other factors deciding whether mobile data is actually enabled, but they are
4819 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004820 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004821 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004822 *
4823 * @return {@code true} if data is enabled else {@code false}
4824 */
4825 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004826 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004827 try {
4828 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4829 null);
4830 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4832 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834
4835 final long identity = Binder.clearCallingIdentity();
4836 try {
4837 int phoneId = mSubscriptionController.getPhoneId(subId);
4838 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4839 Phone phone = PhoneFactory.getPhone(phoneId);
4840 if (phone != null) {
4841 boolean retVal = phone.isUserDataEnabled();
4842 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4843 return retVal;
4844 } else {
4845 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4846 return false;
4847 }
4848 } finally {
4849 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004850 }
4851 }
4852
4853 /**
4854 * Get whether mobile data is enabled.
4855 *
4856 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4857 * whether mobile data is actually enabled.
4858 *
4859 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4860 *
4861 * @return {@code true} if data is enabled else {@code false}
4862 */
4863 @Override
4864 public boolean isDataEnabled(int subId) {
4865 try {
4866 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4867 null);
4868 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004869 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4870 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004871 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004872
4873 final long identity = Binder.clearCallingIdentity();
4874 try {
4875 int phoneId = mSubscriptionController.getPhoneId(subId);
4876 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4877 Phone phone = PhoneFactory.getPhone(phoneId);
4878 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004879 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4881 return retVal;
4882 } else {
4883 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4884 return false;
4885 }
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004888 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004889 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004890
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004891 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4892 Phone phone) {
4893 //load access rules from carrier configs, and check those as well: b/139133814
4894 SubscriptionController subController = SubscriptionController.getInstance();
4895 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4896 || subController == null) return privilegeFromSim;
4897
4898 int uid = Binder.getCallingUid();
4899 PackageManager pkgMgr = phone.getContext().getPackageManager();
4900 String[] packages = pkgMgr.getPackagesForUid(uid);
4901
4902 final long identity = Binder.clearCallingIdentity();
4903 try {
4904 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4905 SubscriptionManager subManager = (SubscriptionManager)
4906 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4907 for (String pkg : packages) {
4908 if (subManager.canManageSubscription(subInfo, pkg)) {
4909 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4910 }
4911 }
4912 return privilegeFromSim;
4913 } finally {
4914 Binder.restoreCallingIdentity(identity);
4915 }
4916 }
4917
4918 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4919 String pkgName) {
4920 //load access rules from carrier configs, and check those as well: b/139133814
4921 SubscriptionController subController = SubscriptionController.getInstance();
4922 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4923 || subController == null) return privilegeFromSim;
4924
4925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4928 SubscriptionManager subManager = (SubscriptionManager)
4929 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4930 return subManager.canManageSubscription(subInfo, pkgName)
4931 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
4935 }
4936
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004937 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004938 public int getCarrierPrivilegeStatus(int subId) {
4939 final Phone phone = getPhone(subId);
4940 if (phone == null) {
4941 loge("getCarrierPrivilegeStatus: Invalid subId");
4942 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4943 }
4944 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004945 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004946 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004947 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4948 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004949
4950 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4951 card.getCarrierPrivilegeStatusForCurrentTransaction(
4952 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004953 }
Junda Liu29340342014-07-10 15:23:27 -07004954
4955 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004956 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4957 final Phone phone = getPhone(subId);
4958 if (phone == null) {
4959 loge("getCarrierPrivilegeStatus: Invalid subId");
4960 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4961 }
4962 UiccProfile profile =
4963 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4964 if (profile == null) {
4965 loge("getCarrierPrivilegeStatus: No UICC");
4966 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4967 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004968 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4969 profile.getCarrierPrivilegeStatusForUid(
4970 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004971 }
4972
4973 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004974 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4975 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004976 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004977 }
4978
4979 int phoneId = SubscriptionManager.getPhoneId(subId);
4980 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004981 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004982 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004983 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4984 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004985 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4986 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4987 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004988 }
4989
4990 @Override
4991 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004992 if (TextUtils.isEmpty(pkgName))
4993 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004994 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4995 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4996 UiccCard card = UiccController.getInstance().getUiccCard(i);
4997 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004998 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004999 continue;
5000 }
5001
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005002 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5003 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5004 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005005 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5006 break;
5007 }
5008 }
5009
5010 return result;
Junda Liu29340342014-07-10 15:23:27 -07005011 }
Derek Tan89e89d42014-07-08 17:00:10 -07005012
5013 @Override
Junda Liue64de782015-04-16 17:19:16 -07005014 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5015 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5016 loge("phoneId " + phoneId + " is not valid.");
5017 return null;
5018 }
5019 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005020 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07005021 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005022 return null ;
5023 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005024 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005025 }
5026
Amith Yamasani6e118872016-02-19 12:53:51 -08005027 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005028 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005029 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005030 List<String> privilegedPackages = new ArrayList<>();
5031 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005032 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5033 // has UICC in that slot.
5034 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005035 if (card.hasCarrierPrivilegeRules()) {
5036 if (packages == null) {
5037 // Only check packages in user 0 for now
5038 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005039 PackageManager.MATCH_DISABLED_COMPONENTS
5040 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005041 | PackageManager.GET_SIGNING_CERTIFICATES,
5042 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005043 }
5044 for (int p = packages.size() - 1; p >= 0; p--) {
5045 PackageInfo pkgInfo = packages.get(p);
5046 if (pkgInfo != null && pkgInfo.packageName != null
5047 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005048 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005049 privilegedPackages.add(pkgInfo.packageName);
5050 }
5051 }
5052 }
5053 }
5054 return privilegedPackages;
5055 }
5056
chen xuf7e9fe82019-05-09 19:31:02 -07005057 @Override
5058 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5059 List<String> privilegedPackages = new ArrayList<>();
5060 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5061 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5062 }
5063 return privilegedPackages;
5064 }
5065
Wink Savilleb564aae2014-10-23 10:18:09 -07005066 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005067 final Phone phone = getPhone(subId);
5068 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005069 if (card == null) {
5070 loge("getIccId: No UICC");
5071 return null;
5072 }
5073 String iccId = card.getIccId();
5074 if (TextUtils.isEmpty(iccId)) {
5075 loge("getIccId: ICC ID is null or empty.");
5076 return null;
5077 }
5078 return iccId;
5079 }
5080
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005081 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005082 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5083 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005084 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5085 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 final String iccId = getIccId(subId);
5090 final Phone phone = getPhone(subId);
5091 if (phone == null) {
5092 return false;
5093 }
5094 final String subscriberId = phone.getSubscriberId();
5095
5096 if (DBG_MERGE) {
5097 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5098 + subscriberId + " to " + number);
5099 }
5100
5101 if (TextUtils.isEmpty(iccId)) {
5102 return false;
5103 }
5104
5105 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5106
5107 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5108 if (alphaTag == null) {
5109 editor.remove(alphaTagPrefKey);
5110 } else {
5111 editor.putString(alphaTagPrefKey, alphaTag);
5112 }
5113
5114 // Record both the line number and IMSI for this ICCID, since we need to
5115 // track all merged IMSIs based on line number
5116 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5117 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5118 if (number == null) {
5119 editor.remove(numberPrefKey);
5120 editor.remove(subscriberPrefKey);
5121 } else {
5122 editor.putString(numberPrefKey, number);
5123 editor.putString(subscriberPrefKey, subscriberId);
5124 }
5125
5126 editor.commit();
5127 return true;
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005130 }
Derek Tan7226c842014-07-02 17:42:23 -07005131 }
5132
5133 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005134 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005135 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005136 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005137 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005138 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005139 return null;
5140 }
Derek Tan97ebb422014-09-05 16:55:38 -07005141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
5144 String iccId = getIccId(subId);
5145 if (iccId != null) {
5146 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5147 if (DBG_MERGE) {
5148 log("getLine1NumberForDisplay returning "
5149 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5150 }
5151 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005152 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005153 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5154 return null;
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005157 }
Derek Tan7226c842014-07-02 17:42:23 -07005158 }
5159
5160 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005161 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005162 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005163 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005164 return null;
5165 }
Derek Tan97ebb422014-09-05 16:55:38 -07005166
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 String iccId = getIccId(subId);
5170 if (iccId != null) {
5171 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5172 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5173 }
5174 return null;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005177 }
Derek Tan7226c842014-07-02 17:42:23 -07005178 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005179
5180 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005181 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005182 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5183 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005185 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5186 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005187 return null;
5188 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005189
Jordan Liub49b04b2019-05-06 14:45:15 -07005190 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5191 // the process, where TelephonyManager was instantiated.
5192 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005193 final long identity = Binder.clearCallingIdentity();
5194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005195 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 final TelephonyManager tele = TelephonyManager.from(context);
5197 final SubscriptionManager sub = SubscriptionManager.from(context);
5198
5199 // Figure out what subscribers are currently active
5200 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201
Jordan Liub49b04b2019-05-06 14:45:15 -07005202 // Only consider subs which match the current subId
5203 // This logic can be simplified. See b/131189269 for progress.
5204 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005205 activeSubscriberIds.add(tele.getSubscriberId(subId));
5206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207
5208 // First pass, find a number override for an active subscriber
5209 String mergeNumber = null;
5210 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5211 for (String key : prefs.keySet()) {
5212 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5213 final String subscriberId = (String) prefs.get(key);
5214 if (activeSubscriberIds.contains(subscriberId)) {
5215 final String iccId = key.substring(
5216 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5217 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5218 mergeNumber = (String) prefs.get(numberKey);
5219 if (DBG_MERGE) {
5220 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5221 + " for active subscriber " + subscriberId);
5222 }
5223 if (!TextUtils.isEmpty(mergeNumber)) {
5224 break;
5225 }
5226 }
5227 }
5228 }
5229
5230 // Shortcut when no active merged subscribers
5231 if (TextUtils.isEmpty(mergeNumber)) {
5232 return null;
5233 }
5234
5235 // Second pass, find all subscribers under that line override
5236 final ArraySet<String> result = new ArraySet<>();
5237 for (String key : prefs.keySet()) {
5238 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5239 final String number = (String) prefs.get(key);
5240 if (mergeNumber.equals(number)) {
5241 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5242 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5243 final String subscriberId = (String) prefs.get(subscriberKey);
5244 if (!TextUtils.isEmpty(subscriberId)) {
5245 result.add(subscriberId);
5246 }
5247 }
5248 }
5249 }
5250
5251 final String[] resultArray = result.toArray(new String[result.size()]);
5252 Arrays.sort(resultArray);
5253 if (DBG_MERGE) {
5254 Slog.d(LOG_TAG,
5255 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5256 }
5257 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005260 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005261 }
5262
5263 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005264 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5265 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5266
5267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 final TelephonyManager telephonyManager = mApp.getSystemService(
5270 TelephonyManager.class);
5271 String subscriberId = telephonyManager.getSubscriberId(subId);
5272 if (subscriberId == null) {
5273 if (DBG) {
5274 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5275 + subId);
5276 }
5277 return null;
5278 }
5279
5280 final SubscriptionInfo info = SubscriptionController.getInstance()
5281 .getSubscriptionInfo(subId);
5282 final ParcelUuid groupUuid = info.getGroupUuid();
5283 // If it doesn't belong to any group, return just subscriberId of itself.
5284 if (groupUuid == null) {
5285 return new String[]{subscriberId};
5286 }
5287
5288 // Get all subscriberIds from the group.
5289 final List<String> mergedSubscriberIds = new ArrayList<>();
5290 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5291 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5292 for (SubscriptionInfo subInfo : groupInfos) {
5293 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5294 if (subscriberId != null) {
5295 mergedSubscriberIds.add(subscriberId);
5296 }
5297 }
5298
5299 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302
5303 }
5304 }
5305
5306 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005307 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005308 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5309 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310
5311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 final Phone phone = getPhone(subId);
5314 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005318 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005319
5320 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005321 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005322 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5323 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005324 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325
5326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 final Phone phone = getPhone(subId);
5329 if (phone == null) {
5330 return false;
5331 }
5332 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5333 cdmaNonRoamingList);
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005336 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005337 }
5338
5339 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005340 @Deprecated
5341 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5342 enforceModifyPermission();
5343
5344 int returnValue = 0;
5345 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005346 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005347 if(result.exception == null) {
5348 if (result.result != null) {
5349 byte[] responseData = (byte[])(result.result);
5350 if(responseData.length > oemResp.length) {
5351 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5352 responseData.length + "bytes. Buffer Size is " +
5353 oemResp.length + "bytes.");
5354 }
5355 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5356 returnValue = responseData.length;
5357 }
5358 } else {
5359 CommandException ex = (CommandException) result.exception;
5360 returnValue = ex.getCommandError().ordinal();
5361 if(returnValue > 0) returnValue *= -1;
5362 }
5363 } catch (RuntimeException e) {
5364 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5365 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5366 if(returnValue > 0) returnValue *= -1;
5367 }
5368
5369 return returnValue;
5370 }
5371
5372 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005373 public void setRadioCapability(RadioAccessFamily[] rafs) {
5374 try {
5375 ProxyController.getInstance().setRadioCapability(rafs);
5376 } catch (RuntimeException e) {
5377 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5378 }
5379 }
5380
5381 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005382 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005383 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005384 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005385 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005386 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005387 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
chen xub97461a2018-10-26 14:17:57 -07005390 TelephonyPermissions
5391 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5392 mApp, phone.getSubId(), "getRadioAccessFamily");
5393 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 } finally {
5395 Binder.restoreCallingIdentity(identity);
5396 }
chen xub97461a2018-10-26 14:17:57 -07005397 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005398 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005399
5400 @Override
5401 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005402 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005403 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404
5405 final long identity = Binder.clearCallingIdentity();
5406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005407 ImsManager.getInstance(defaultPhone.getContext(),
5408 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005412 }
5413
5414 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005415 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005416 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005417 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005419 return false;
5420 }
Svet Ganovb320e182015-04-16 12:30:10 -07005421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 // Check the user preference and the system-level IMS setting. Even if the user has
5425 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5426 // In the long run, we may instead need to check if there exists a connection service
5427 // which can support video calling.
5428 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 return imsManager.isVtEnabledByPlatform()
5431 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5432 && imsManager.isVtEnabledByUser();
5433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005436 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005437
Andrew Leea1239f22015-03-02 17:44:07 -08005438 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5441 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5442 return false;
5443 }
5444
5445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 CarrierConfigManager configManager =
5448 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Andrew Leea1239f22015-03-02 17:44:07 -08005454 }
5455
5456 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 public boolean isWorldPhone(int subId, String callingPackage) {
5458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5459 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5460 return false;
5461 }
5462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 CarrierConfigManager configManager =
5466 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005467 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5469 } finally {
5470 Binder.restoreCallingIdentity(identity);
5471 }
Andrew Leea1239f22015-03-02 17:44:07 -08005472 }
5473
Andrew Lee9431b832015-03-09 18:46:45 -07005474 @Override
5475 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005476 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005477 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005478 }
5479
5480 @Override
5481 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Andrew Lee9431b832015-03-09 18:46:45 -07005488 }
5489
Hall Liuf6668912018-10-31 17:05:23 -07005490 /**
5491 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5492 * support for the feature and device firmware support.
5493 *
5494 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5495 */
5496 @Override
5497 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005499 final Phone phone = getPhone(subscriptionId);
5500 if (phone == null) {
5501 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5502 return false;
5503 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005505 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5507 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005508 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005509 return isCarrierSupported && isDeviceSupported;
5510 } finally {
5511 Binder.restoreCallingIdentity(identity);
5512 }
Hall Liu98187582018-01-22 19:15:32 -08005513 }
5514
Hall Liuf6668912018-10-31 17:05:23 -07005515 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005516 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5517 * RTT setting, will return true if the device and carrier both support RTT.
5518 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005519 */
5520 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 final long identity = Binder.clearCallingIdentity();
5522 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005523 boolean isRttSupported = isRttSupported(subscriptionId);
5524 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005525 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005526 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5527 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5528 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005529 } finally {
5530 Binder.restoreCallingIdentity(identity);
5531 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005532 }
5533
Sanket Padawe7310cc72015-01-14 09:53:20 -08005534 /**
5535 * Returns the unique device ID of phone, for example, the IMEI for
5536 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5537 *
5538 * <p>Requires Permission:
5539 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5540 */
5541 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005542 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005543 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005544 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005545 return null;
5546 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005547 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005548 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5549 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005550 return null;
5551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
5555 return phone.getDeviceId();
5556 } finally {
5557 Binder.restoreCallingIdentity(identity);
5558 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005559 }
5560
Ping Sunc67b7c22016-03-02 19:16:45 +08005561 /**
5562 * {@hide}
5563 * Returns the IMS Registration Status on a particular subid
5564 *
5565 * @param subId
5566 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005567 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005568 Phone phone = getPhone(subId);
5569 if (phone != null) {
5570 return phone.isImsRegistered();
5571 } else {
5572 return false;
5573 }
5574 }
5575
Santos Cordon7a1885b2015-02-03 11:15:19 -08005576 @Override
5577 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005584 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005585
Tyler Gunnf70ed162019-04-03 15:28:53 -07005586 @Override
5587 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5588 final long identity = Binder.clearCallingIdentity();
5589 try {
5590 Phone phone = getPhone(subscriptionId);
5591 if (phone == null) {
5592 return null;
5593 }
5594 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
5598 }
5599
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005600 /**
5601 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005602 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005603 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 Phone phone = getPhone(subId);
5607 if (phone != null) {
5608 return phone.isWifiCallingEnabled();
5609 } else {
5610 return false;
5611 }
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005614 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005615 }
5616
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005617 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005618 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005619 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005620 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 Phone phone = getPhone(subId);
5624 if (phone != null) {
5625 return phone.isVideoEnabled();
5626 } else {
5627 return false;
5628 }
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005631 }
5632 }
5633
5634 /**
5635 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5636 * defined in {@link ImsRegistrationImplBase}.
5637 */
5638 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 Phone phone = getPhone(subId);
5642 if (phone != null) {
5643 return phone.getImsRegistrationTech();
5644 } else {
5645 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5646 }
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005649 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005650 }
5651
Stuart Scott8eef64f2015-04-08 15:13:54 -07005652 @Override
5653 public void factoryReset(int subId) {
5654 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005655 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5656 return;
5657 }
5658
Svet Ganovcc087f82015-05-12 20:35:54 -07005659 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660
Svet Ganovcc087f82015-05-12 20:35:54 -07005661 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005662 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5663 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005664 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005665 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005666 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005667 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5668 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005669 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005670 // There has been issues when Sms raw table somehow stores orphan
5671 // fragments. They lead to garbled message when new fragments come
5672 // in and combined with those stale ones. In case this happens again,
5673 // user can reset all network settings which will clean up this table.
5674 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005677 }
5678 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005679
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005680 private void cleanUpSmsRawTable(Context context) {
5681 ContentResolver resolver = context.getContentResolver();
5682 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5683 resolver.delete(uri, null, null);
5684 }
5685
Narayan Kamath1c496c22015-04-16 14:40:19 +01005686 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005687 public String getSimLocaleForSubscriber(int subId) {
5688 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5689 final Phone phone = getPhone(subId);
5690 if (phone == null) {
5691 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005692 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
chen xu5d3637b2019-01-21 23:31:38 -08005696 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5697 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005698 if (info == null) {
5699 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5700 return null;
5701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 // Try and fetch the locale from the carrier properties or from the SIM language
5703 // preferences (EF-PL and EF-LI)...
5704 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005706 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5707 if (localeFromDefaultSim != null) {
5708 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5709 if (DBG) log("Using locale from subId: " + subId + " locale: "
5710 + localeFromDefaultSim);
5711 return localeFromDefaultSim.toLanguageTag();
5712 } else {
5713 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 }
5715 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 // The SIM language preferences only store a language (e.g. fr = French), not an
5718 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5719 // the SIM and carrier preferences does not include a country we add the country
5720 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005721 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005723 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 return mccLocale.toLanguageTag();
5725 }
5726
5727 if (DBG) log("No locale found - returning null");
5728 return null;
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005732 }
5733
5734 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005735 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005736 }
5737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 /**
5739 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5740 */
5741 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005742 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005743 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005744
Chenjie Yu1ba97252018-01-11 18:16:20 -08005745 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005746 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005747
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005748 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005749 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5750 * representing the state of the modem.
5751 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005752 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5753 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005754 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005755 */
5756 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005757 public void requestModemActivityInfo(ResultReceiver result) {
5758 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005759 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760
5761 final long identity = Binder.clearCallingIdentity();
5762 try {
5763 ModemActivityInfo ret = null;
5764 synchronized (mLastModemActivityInfo) {
5765 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5766 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005767 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005768 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005770 int[] txTimeMs = info.getTransmitTimeMillis();
5771 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005773 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 }
5775 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005776 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5777 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 mLastModemActivityInfo.setIdleTimeMillis(
5779 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005780 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5781 mLastModemActivityInfo.setReceiveTimeMillis(
5782 info.getReceiveTimeMillis() + mLastModemActivityInfo
5783 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005784 }
Chen Xud78231e2019-09-10 18:49:52 -07005785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5787 mLastModemActivityInfo.getSleepTimeMillis(),
5788 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005789 mLastModemActivityInfo.getTransmitTimeMillis(),
5790 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005791 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 Bundle bundle = new Bundle();
5793 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5794 result.send(0, bundle);
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005797 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005798 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005799
Siddharth Rayb8114062018-06-17 15:02:38 -07005800 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5801 // less than total activity duration.
5802 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5803 if (info == null) {
5804 return false;
5805 }
5806 int activityDurationMs =
5807 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5808 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005809 int[] txTimeMs = info.getTransmitTimeMillis();
5810 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5811 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005812 }
5813 return (info.isValid()
5814 && (info.getSleepTimeMillis() <= activityDurationMs)
5815 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005816 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005817 && (totalTxTimeMs <= activityDurationMs));
5818 }
5819
Jack Yu85bd38a2015-11-09 11:34:32 -08005820 /**
5821 * {@hide}
5822 * Returns the service state information on specified subscription.
5823 */
5824 @Override
5825 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005827 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005828 return null;
5829 }
5830
Hall Liuf19c44f2018-11-27 14:38:17 -08005831 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5832 LocationAccessPolicy.checkLocationPermission(mApp,
5833 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5834 .setCallingPackage(callingPackage)
5835 .setCallingPid(Binder.getCallingPid())
5836 .setCallingUid(Binder.getCallingUid())
5837 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005838 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005839 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5840 .build());
5841
5842 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5843 LocationAccessPolicy.checkLocationPermission(mApp,
5844 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5845 .setCallingPackage(callingPackage)
5846 .setCallingPid(Binder.getCallingPid())
5847 .setCallingUid(Binder.getCallingUid())
5848 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005849 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005850 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5851 .build());
5852 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5853 boolean hasFinePermission =
5854 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5855 boolean hasCoarsePermission =
5856 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 final Phone phone = getPhone(subId);
5861 if (phone == null) {
5862 return null;
5863 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005864
Hall Liuf19c44f2018-11-27 14:38:17 -08005865 ServiceState ss = phone.getServiceState();
5866
5867 // Scrub out the location info in ServiceState depending on what level of access
5868 // the caller has.
5869 if (hasFinePermission) return ss;
5870 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5871 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 } finally {
5873 Binder.restoreCallingIdentity(identity);
5874 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005875 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005876
5877 /**
5878 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5879 *
5880 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5881 * voicemail ringtone.
5882 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5883 * PhoneAccount.
5884 */
5885 @Override
5886 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 final long identity = Binder.clearCallingIdentity();
5888 try {
5889 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5890 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005891 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005893
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5895 } finally {
5896 Binder.restoreCallingIdentity(identity);
5897 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005898 }
5899
5900 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005901 * Sets the per-account voicemail ringtone.
5902 *
5903 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5904 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5905 *
5906 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5907 * voicemail ringtone.
5908 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5909 * PhoneAccount.
5910 */
5911 @Override
5912 public void setVoicemailRingtoneUri(String callingPackage,
5913 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005914 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5916 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005917 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5919 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5920 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922
5923 final long identity = Binder.clearCallingIdentity();
5924 try {
5925 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5926 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005927 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 }
5929 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005932 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005933 }
5934
5935 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005936 * Returns whether vibration is set for voicemail notification in Phone settings.
5937 *
5938 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5939 * voicemail vibration setting.
5940 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5941 */
5942 @Override
5943 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 final long identity = Binder.clearCallingIdentity();
5945 try {
5946 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5947 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005948 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
5954 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005955 }
5956
Youhan Wange64578a2016-05-02 15:32:42 -07005957 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005958 * Sets the per-account voicemail vibration.
5959 *
5960 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5961 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5962 *
5963 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5964 * voicemail vibration setting.
5965 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5966 * specific PhoneAccount.
5967 */
5968 @Override
5969 public void setVoicemailVibrationEnabled(String callingPackage,
5970 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005971 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005972 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5973 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005974 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5976 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5977 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005978 }
5979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5983 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005984 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 }
5986 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005989 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005990 }
5991
5992 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005993 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5994 *
5995 * @throws SecurityException if the caller does not have the required permission
5996 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005997 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005998 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005999 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006000 }
6001
6002 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006003 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6004 * permission.
6005 *
6006 * @throws SecurityException if the caller does not have the required permission
6007 */
6008 private void enforceSendSmsPermission() {
6009 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6010 }
6011
6012 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006013 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006014 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006015 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006016 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006017 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006018 final long identity = Binder.clearCallingIdentity();
6019 try {
6020 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006021 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006022 if (componentName == null) {
6023 throw new SecurityException(
6024 "Caller not current active visual voicemail package[null]");
6025 }
6026 String vvmPackage = componentName.getPackageName();
6027 if (!callingPackage.equals(vvmPackage)) {
6028 throw new SecurityException("Caller not current active visual voicemail package["
6029 + vvmPackage + "]");
6030 }
6031 } finally {
6032 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006033 }
6034 }
6035
6036 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006037 * Return the application ID for the app type.
6038 *
6039 * @param subId the subscription ID that this request applies to.
6040 * @param appType the uicc app type.
6041 * @return Application ID for specificied app type, or null if no uicc.
6042 */
6043 @Override
6044 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006045 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006046 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047
6048 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006049 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 if (phone == null) {
6051 return null;
6052 }
6053 String aid = null;
6054 try {
6055 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6056 .getApplicationByType(appType).getAid();
6057 } catch (Exception e) {
6058 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6059 }
6060 return aid;
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006063 }
Youhan Wange64578a2016-05-02 15:32:42 -07006064 }
6065
Youhan Wang4001d252016-05-11 10:29:41 -07006066 /**
6067 * Return the Electronic Serial Number.
6068 *
6069 * @param subId the subscription ID that this request applies to.
6070 * @return ESN or null if error.
6071 */
6072 @Override
6073 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006074 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006075 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076
6077 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006078 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 if (phone == null) {
6080 return null;
6081 }
6082 String esn = null;
6083 try {
6084 esn = phone.getEsn();
6085 } catch (Exception e) {
6086 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6087 }
6088 return esn;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006091 }
Youhan Wang4001d252016-05-11 10:29:41 -07006092 }
6093
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006094 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006095 * Return the Preferred Roaming List Version.
6096 *
6097 * @param subId the subscription ID that this request applies to.
6098 * @return PRLVersion or null if error.
6099 */
6100 @Override
6101 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006102 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006103 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104
6105 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006106 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 if (phone == null) {
6108 return null;
6109 }
6110 String cdmaPrlVersion = null;
6111 try {
6112 cdmaPrlVersion = phone.getCdmaPrlVersion();
6113 } catch (Exception e) {
6114 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6115 }
6116 return cdmaPrlVersion;
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006119 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006120 }
6121
6122 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006123 * Get snapshot of Telephony histograms
6124 * @return List of Telephony histograms
6125 * @hide
6126 */
6127 @Override
6128 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6130 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006131
6132 final long identity = Binder.clearCallingIdentity();
6133 try {
6134 return RIL.getTelephonyRILTimingHistograms();
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
6137 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006138 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006139
6140 /**
6141 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006142 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6143 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006144 * Require system privileges. In the future we may add this to carrier APIs.
6145 *
Michele Berionne482f8202018-11-27 18:57:59 -08006146 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006147 */
6148 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006149 @TelephonyManager.SetCarrierRestrictionResult
6150 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006151 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006152 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006153
Michele Berionne482f8202018-11-27 18:57:59 -08006154 if (carrierRestrictionRules == null) {
6155 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006156 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 final long identity = Binder.clearCallingIdentity();
6159 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006160 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006161 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 } finally {
6163 Binder.restoreCallingIdentity(identity);
6164 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006165 }
6166
6167 /**
6168 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006169 * Get the allowed carrier list and the excluded carrier list, including the priority between
6170 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006171 * Require system privileges. In the future we may add this to carrier APIs.
6172 *
Michele Berionne482f8202018-11-27 18:57:59 -08006173 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006174 */
6175 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006176 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006177 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006178 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006182 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6183 if (response instanceof CarrierRestrictionRules) {
6184 return (CarrierRestrictionRules) response;
6185 }
6186 // Response is an Exception of some kind,
6187 // which is signalled to the user as a NULL retval
6188 return null;
6189 } catch (Exception e) {
6190 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6191 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006195 }
6196
fionaxu59545b42016-05-25 15:53:37 -07006197 /**
6198 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6199 * @param subId the subscription ID that this action applies to.
6200 * @param enabled control enable or disable metered apns.
6201 * {@hide}
6202 */
6203 @Override
6204 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6205 enforceModifyPermission();
6206 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207
6208 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006209 if (phone == null) {
6210 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6211 return;
6212 }
6213 try {
6214 phone.carrierActionSetMeteredApnsEnabled(enabled);
6215 } catch (Exception e) {
6216 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 } finally {
6218 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006219 }
6220 }
6221
6222 /**
6223 * Action set from carrier signalling broadcast receivers to enable/disable radio
6224 * @param subId the subscription ID that this action applies to.
6225 * @param enabled control enable or disable radio.
6226 * {@hide}
6227 */
6228 @Override
6229 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6230 enforceModifyPermission();
6231 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
6233 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006234 if (phone == null) {
6235 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6236 return;
6237 }
6238 try {
6239 phone.carrierActionSetRadioEnabled(enabled);
6240 } catch (Exception e) {
6241 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 } finally {
6243 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006244 }
6245 }
6246
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006247 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006248 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6249 * network status based on which carrier apps could apply actions accordingly,
6250 * enable/disable default url handler for example.
6251 *
6252 * @param subId the subscription ID that this action applies to.
6253 * @param report control start/stop reporting the default network status.
6254 * {@hide}
6255 */
6256 @Override
6257 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6258 enforceModifyPermission();
6259 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260
6261 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006262 if (phone == null) {
6263 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6264 return;
6265 }
6266 try {
6267 phone.carrierActionReportDefaultNetworkStatus(report);
6268 } catch (Exception e) {
6269 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 } finally {
6271 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006272 }
6273 }
6274
6275 /**
fionaxud9622282017-07-17 17:51:30 -07006276 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6277 * @param subId the subscription ID that this action applies to.
6278 * {@hide}
6279 */
6280 @Override
6281 public void carrierActionResetAll(int subId) {
6282 enforceModifyPermission();
6283 final Phone phone = getPhone(subId);
6284 if (phone == null) {
6285 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6286 return;
6287 }
6288 try {
6289 phone.carrierActionResetAll();
6290 } catch (Exception e) {
6291 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6292 }
6293 }
6294
6295 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006296 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6297 * bug report is being generated.
6298 */
6299 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006300 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006301 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6302 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006303 writer.println("Permission Denial: can't dump Phone from pid="
6304 + Binder.getCallingPid()
6305 + ", uid=" + Binder.getCallingUid()
6306 + "without permission "
6307 + android.Manifest.permission.DUMP);
6308 return;
6309 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006311 }
Jack Yueb89b242016-06-22 13:27:47 -07006312
Brad Ebingerdac2f002018-04-03 15:17:52 -07006313 @Override
6314 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6315 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6316 throws RemoteException {
6317 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6318 }
6319
Jack Yueb89b242016-06-22 13:27:47 -07006320 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006321 * Get aggregated video call data usage since boot.
6322 *
6323 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6324 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006325 * {@hide}
6326 */
6327 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006328 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6330 null);
6331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 // NetworkStatsService keeps tracking the active network interface and identity. It
6335 // records the delta with the corresponding network identity.
6336 // We just return the total video call data usage snapshot since boot.
6337 Phone phone = getPhone(subId);
6338 if (phone != null) {
6339 return phone.getVtDataUsage(perUidStats);
6340 }
6341 return null;
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006344 }
Jack Yueb89b242016-06-22 13:27:47 -07006345 }
Jack Yu75ab2952016-07-08 14:29:33 -07006346
6347 /**
6348 * Policy control of data connection. Usually used when data limit is passed.
6349 * @param enabled True if enabling the data, otherwise disabling.
6350 * @param subId Subscription index
6351 * {@hide}
6352 */
6353 @Override
6354 public void setPolicyDataEnabled(boolean enabled, int subId) {
6355 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356
6357 final long identity = Binder.clearCallingIdentity();
6358 try {
6359 Phone phone = getPhone(subId);
6360 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006361 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362 }
6363 } finally {
6364 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006365 }
6366 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006367
6368 /**
6369 * Get Client request stats
6370 * @return List of Client Request Stats
6371 * @hide
6372 */
6373 @Override
6374 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006376 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006377 return null;
6378 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006379 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 if (phone != null) {
6384 return phone.getClientRequestStats();
6385 }
6386
6387 return null;
6388 } finally {
6389 Binder.restoreCallingIdentity(identity);
6390 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006391 }
6392
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006393 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006394 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006395 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006396 }
Jack Yueb4124c2017-02-16 15:32:43 -08006397
6398 /**
Grace Chen70990072017-03-24 17:21:30 -07006399 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006400 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006401 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006402 * @param state State of SIM (power down, power up, pass through)
6403 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6404 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6405 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006406 *
6407 **/
6408 @Override
Grace Chen70990072017-03-24 17:21:30 -07006409 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006410 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006411 Phone phone = PhoneFactory.getPhone(slotIndex);
6412
vagdeviaf9a5b92018-08-15 16:01:53 -07006413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6414
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 final long identity = Binder.clearCallingIdentity();
6416 try {
6417 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006418 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 }
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006422 }
6423 }
Shuo Qiandd210312017-04-12 22:11:33 +00006424
Tyler Gunn65d45c22017-06-05 11:22:26 -07006425 private boolean isUssdApiAllowed(int subId) {
6426 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006428 if (configManager == null) {
6429 return false;
6430 }
6431 PersistableBundle pb = configManager.getConfigForSubId(subId);
6432 if (pb == null) {
6433 return false;
6434 }
6435 return pb.getBoolean(
6436 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6437 }
6438
Shuo Qiandd210312017-04-12 22:11:33 +00006439 /**
6440 * Check if phone is in emergency callback mode
6441 * @return true if phone is in emergency callback mode
6442 * @param subId sub id
6443 */
goneil9c5f4872017-12-05 14:07:56 -08006444 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006445 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006446 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006447 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
6451 if (phone != null) {
6452 return phone.isInEcm();
6453 } else {
6454 return false;
6455 }
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006458 }
6459 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006460
6461 /**
6462 * Get the current signal strength information for the given subscription.
6463 * Because this information is not updated when the device is in a low power state
6464 * it should not be relied-upon to be current.
6465 * @param subId Subscription index
6466 * @return the most recent cached signal strength info from the modem
6467 */
6468 @Override
6469 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 final long identity = Binder.clearCallingIdentity();
6471 try {
6472 Phone p = getPhone(subId);
6473 if (p == null) {
6474 return null;
6475 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006476
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 return p.getSignalStrength();
6478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006481 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006482
Pengquan Meng77b7f132018-08-22 14:49:57 -07006483 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006484 * Get the current modem radio state for the given slot.
6485 * @param slotIndex slot index.
6486 * @param callingPackage the name of the package making the call.
6487 * @return the current radio power state from the modem
6488 */
6489 @Override
6490 public int getRadioPowerState(int slotIndex, String callingPackage) {
6491 Phone phone = PhoneFactory.getPhone(slotIndex);
6492 if (phone != null) {
6493 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6494 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6495 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6496 }
6497
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
6500 return phone.getRadioPowerState();
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
6503 }
6504 }
6505 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6506 }
6507
6508 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006509 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6510 *
6511 * <p>Requires one of the following permissions:
6512 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6513 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6514 * privileges.
6515 *
6516 * @param subId subscription id
6517 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6518 * {@code false}.
6519 */
6520 @Override
6521 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006522 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6523 null /* message */);
6524
Pengquan Menga1bb6272018-09-06 09:59:22 -07006525 boolean isEnabled = false;
6526 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006527 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006528 Phone phone = getPhone(subId);
6529 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006530 } catch (Exception e) {
6531 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6532 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006533 } finally {
6534 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006535 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006536 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006537 }
6538
6539
6540 /**
6541 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6542 *
6543 * <p> Requires permission:
6544 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6545 * privileges.
6546 *
6547 * @param subId subscription id
6548 * @param isEnabled {@code true} means enable, {@code false} means disable.
6549 */
6550 @Override
6551 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6553 mApp, subId, "setDataRoamingEnabled");
6554
Pengquan Menga1bb6272018-09-06 09:59:22 -07006555 final long identity = Binder.clearCallingIdentity();
6556 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006557 Phone phone = getPhone(subId);
6558 if (phone != null) {
6559 phone.setDataRoamingEnabled(isEnabled);
6560 }
6561 } finally {
6562 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006563 }
6564 }
6565
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006566 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006567 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006568 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6569 mApp, subId, "isManualNetworkSelectionAllowed");
6570
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006571 boolean isAllowed = true;
6572 final long identity = Binder.clearCallingIdentity();
6573 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006574 Phone phone = getPhone(subId);
6575 if (phone != null) {
6576 isAllowed = phone.isCspPlmnEnabled();
6577 }
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 return isAllowed;
6582 }
6583
6584 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006585 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006586 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006587 try {
6588 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006589 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006590 } catch (SecurityException e) {
6591 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6592 // has carrier privileges on an active UICC
6593 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6594 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006595 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006596 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006597 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006601 UiccController uiccController = UiccController.getInstance();
6602 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006603 if (hasReadPermission) {
6604 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006605 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006606
6607 // Remove private info if the caller doesn't have access
6608 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6609 for (UiccCardInfo cardInfo : cardInfos) {
6610 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6611 // is available
6612 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6613 if (card == null || card.getUiccProfile() == null) {
6614 // assume no access if the card or profile is unavailable
6615 filteredInfos.add(cardInfo.getUnprivileged());
6616 continue;
6617 }
6618 UiccProfile profile = card.getUiccProfile();
6619 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6620 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6621 filteredInfos.add(cardInfo);
6622 } else {
6623 filteredInfos.add(cardInfo.getUnprivileged());
6624 }
6625 }
6626 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006627 } finally {
6628 Binder.restoreCallingIdentity(identity);
6629 }
6630 }
6631
6632 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006633 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006634 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 final long identity = Binder.clearCallingIdentity();
6637 try {
6638 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6639 if (slots == null) {
6640 Rlog.i(LOG_TAG, "slots is null.");
6641 return null;
6642 }
6643
6644 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6645 for (int i = 0; i < slots.length; i++) {
6646 UiccSlot slot = slots[i];
6647 if (slot == null) {
6648 continue;
6649 }
6650
Jordan Liu7be7e652019-05-06 18:55:02 +00006651 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 UiccCard card = slot.getUiccCard();
6653 if (card != null) {
6654 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006655 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006656 cardId = slot.getEid();
6657 if (TextUtils.isEmpty(cardId)) {
6658 cardId = slot.getIccId();
6659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006660 }
6661
Jordan Liu857451f2019-05-09 16:35:35 -07006662 if (cardId != null) {
6663 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6664 // if cardId is an EID, it's all digits so this is fine
6665 cardId = IccUtils.stripTrailingFs(cardId);
6666 }
6667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 int cardState = 0;
6669 switch (slot.getCardState()) {
6670 case CARDSTATE_ABSENT:
6671 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6672 break;
6673 case CARDSTATE_PRESENT:
6674 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6675 break;
6676 case CARDSTATE_ERROR:
6677 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6678 break;
6679 case CARDSTATE_RESTRICTED:
6680 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6681 break;
6682 default:
6683 break;
6684
6685 }
6686
6687 infos[i] = new UiccSlotInfo(
6688 slot.isActive(),
6689 slot.isEuicc(),
6690 cardId,
6691 cardState,
6692 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006693 slot.isExtendedApduSupported(),
6694 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 }
6696 return infos;
6697 } finally {
6698 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006699 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006700 }
6701
6702 @Override
6703 public boolean switchSlots(int[] physicalSlots) {
6704 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705
6706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6709 } finally {
6710 Binder.restoreCallingIdentity(identity);
6711 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006712 }
Jack Yu4c988042018-02-27 15:30:01 -08006713
6714 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006715 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 return UiccController.getInstance().getCardIdForDefaultEuicc();
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
6721 }
6722 }
6723
6724 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006725 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6726 enforceModifyPermission();
6727 final Phone phone = getPhone(subId);
6728 if (phone == null) {
6729 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6730 return;
6731 }
6732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 final long identity = Binder.clearCallingIdentity();
6734 try {
6735 phone.setRadioIndicationUpdateMode(filters, mode);
6736 } finally {
6737 Binder.restoreCallingIdentity(identity);
6738 }
Jack Yu4c988042018-02-27 15:30:01 -08006739 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006740
6741 /**
goneil47ffb6e2018-04-06 15:40:58 -07006742 * A test API to reload the UICC profile.
6743 *
6744 * <p>Requires that the calling app has permission
6745 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6746 * @hide
6747 */
6748 @Override
6749 public void refreshUiccProfile(int subId) {
6750 enforceModifyPermission();
6751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 Phone phone = getPhone(subId);
6755 if (phone == null) {
6756 return;
6757 }
6758 UiccCard uiccCard = phone.getUiccCard();
6759 if (uiccCard == null) {
6760 return;
6761 }
6762 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6763 if (uiccProfile == null) {
6764 return;
6765 }
6766 uiccProfile.refresh();
6767 } finally {
6768 Binder.restoreCallingIdentity(identity);
6769 }
6770 }
6771
6772 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006773 * Returns false if the mobile data is disabled by default, otherwise return true.
6774 */
6775 private boolean getDefaultDataEnabled() {
6776 return "true".equalsIgnoreCase(
6777 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6778 }
6779
6780 /**
6781 * Returns true if the data roaming is enabled by default, i.e the system property
6782 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6783 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6784 */
6785 private boolean getDefaultDataRoamingEnabled(int subId) {
6786 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006787 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006788 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6789 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6790 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6791 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6792 return isDataRoamingEnabled;
6793 }
6794
6795 /**
6796 * Returns the default network type for the given {@code subId}, if the default network type is
6797 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6798 */
6799 private int getDefaultNetworkType(int subId) {
6800 return Integer.parseInt(
6801 TelephonyManager.getTelephonyProperty(
6802 mSubscriptionController.getPhoneId(subId),
6803 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6804 String.valueOf(Phone.PREFERRED_NT_MODE)));
6805 }
fionaxua13278b2018-03-21 00:08:13 -07006806
6807 @Override
6808 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006809 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006810 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 final Phone phone = getPhone(subId);
6815 if (phone == null) {
6816 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6817 return;
6818 }
chen xueaba88a2019-03-15 13:15:10 -07006819 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6820 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 } finally {
6822 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006823 }
fionaxua13278b2018-03-21 00:08:13 -07006824 }
6825
6826 @Override
6827 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006828 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006829
6830 final long identity = Binder.clearCallingIdentity();
6831 try {
6832 final Phone phone = getPhone(subId);
6833 if (phone == null) {
6834 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6835 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6836 }
6837 return phone.getCarrierIdListVersion();
6838 } finally {
6839 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006840 }
fionaxua13278b2018-03-21 00:08:13 -07006841 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006842
6843 @Override
6844 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6846 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6847 return -1;
6848 }
6849
6850 final long identity = Binder.clearCallingIdentity();
6851 try {
6852 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
6856 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006857
6858 @Override
6859 public int getCdmaRoamingMode(int subId) {
6860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6861 mApp, subId, "getCdmaRoamingMode");
6862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
6869 }
6870
6871 @Override
6872 public boolean setCdmaRoamingMode(int subId, int mode) {
6873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6874 mApp, subId, "setCdmaRoamingMode");
6875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6879 } finally {
6880 Binder.restoreCallingIdentity(identity);
6881 }
6882 }
6883
6884 @Override
6885 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6887 mApp, subId, "setCdmaSubscriptionMode");
6888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
6891 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
6895 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006896
6897 private void ensureUserRunning(int userId) {
6898 if (!mUserManager.isUserRunning(userId)) {
6899 throw new IllegalStateException("User " + userId + " does not exist or not running");
6900 }
6901 }
6902
6903 /**
6904 * Returns a list of SMS apps on a given user.
6905 *
6906 * Only the shell user (UID 2000 or 0) can call it.
6907 * Target user must be running.
6908 */
6909 @Override
6910 public String[] getSmsApps(int userId) {
6911 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6912 ensureUserRunning(userId);
6913
6914 final Collection<SmsApplicationData> apps =
6915 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6916
6917 String[] ret = new String[apps.size()];
6918 int i = 0;
6919 for (SmsApplicationData app : apps) {
6920 ret[i++] = app.mPackageName;
6921 }
6922 return ret;
6923 }
6924
6925 /**
6926 * Returns the default SMS app package name on a given user.
6927 *
6928 * Only the shell user (UID 2000 or 0) can call it.
6929 * Target user must be running.
6930 */
6931 @Override
6932 public String getDefaultSmsApp(int userId) {
6933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6934 ensureUserRunning(userId);
6935
6936 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6937 /* updateIfNeeded= */ true, userId);
6938 return cn == null ? null : cn.getPackageName();
6939 }
6940
6941 /**
6942 * Set a package as the default SMS app on a given user.
6943 *
6944 * Only the shell user (UID 2000 or 0) can call it.
6945 * Target user must be running.
6946 */
6947 @Override
6948 public void setDefaultSmsApp(int userId, String packageName) {
6949 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6950 ensureUserRunning(userId);
6951
6952 boolean found = false;
6953 for (String pkg : getSmsApps(userId)) {
6954 if (TextUtils.equals(packageName, pkg)) {
6955 found = true;
6956 break;
6957 }
6958 }
6959 if (!found) {
6960 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6961 }
6962
6963 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6964 }
sqianc5eccab2018-10-19 18:46:41 -07006965
6966 @Override
sqian8c685422019-02-22 15:55:18 -08006967 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006968 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006970 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006971 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6972 }
6973 final long identity = Binder.clearCallingIdentity();
6974 try {
sqian854d44b2018-12-12 16:48:18 -08006975 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6976 for (Phone phone: PhoneFactory.getPhones()) {
6977 if (phone.getEmergencyNumberTracker() != null
6978 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6979 emergencyNumberListInternal.put(
6980 phone.getSubId(),
6981 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6982 }
sqian11b7a0e2018-12-05 18:48:28 -08006983 }
sqian854d44b2018-12-12 16:48:18 -08006984 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
sqianc5eccab2018-10-19 18:46:41 -07006988 }
6989
6990 @Override
sqian8c685422019-02-22 15:55:18 -08006991 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006992 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006993 if (!exactMatch) {
6994 TelephonyPermissions
6995 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006996 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006997 }
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
sqian854d44b2018-12-12 16:48:18 -08007000 for (Phone phone: PhoneFactory.getPhones()) {
7001 if (phone.getEmergencyNumberTracker() != null
7002 && phone.getEmergencyNumberTracker() != null) {
7003 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7004 number, exactMatch)) {
7005 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007006 }
7007 }
sqian11b7a0e2018-12-05 18:48:28 -08007008 }
7009 return false;
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 }
7014
sqianf4ca7ed2019-01-15 18:32:07 -08007015 /**
7016 * Update emergency number list for test mode.
7017 */
7018 @Override
7019 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7020 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7021 "updateEmergencyNumberListTestMode");
7022
7023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 for (Phone phone: PhoneFactory.getPhones()) {
7026 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7027 if (tracker != null) {
7028 tracker.executeEmergencyNumberTestModeCommand(action, num);
7029 }
7030 }
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
7036 /**
7037 * Get the full emergency number list for test mode.
7038 */
7039 @Override
7040 public List<String> getEmergencyNumberListTestMode() {
7041 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7042 "getEmergencyNumberListTestMode");
7043
7044 final long identity = Binder.clearCallingIdentity();
7045 try {
7046 Set<String> emergencyNumbers = new HashSet<>();
7047 for (Phone phone: PhoneFactory.getPhones()) {
7048 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7049 if (tracker != null) {
7050 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7051 emergencyNumbers.add(num.getNumber());
7052 }
7053 }
7054 }
7055 return new ArrayList<>(emergencyNumbers);
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
7060
chen xud6b45bd2018-10-30 22:27:10 -07007061 @Override
7062 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7063 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7064 Phone phone = getPhone(subId);
7065 if (phone == null) {
7066 return null;
7067 }
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 UiccProfile profile = UiccController.getInstance()
7071 .getUiccProfileForPhone(phone.getPhoneId());
7072 if (profile != null) {
7073 return profile.getCertsFromCarrierPrivilegeAccessRules();
7074 }
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 return null;
7079 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007080
7081 /**
7082 * Enable or disable a modem stack.
7083 */
7084 @Override
7085 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7086 enforceModifyPermission();
7087
7088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = PhoneFactory.getPhone(slotIndex);
7091 if (phone == null) {
7092 return false;
7093 } else {
7094 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7095 }
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
7099 }
Michelecea4cf22018-12-21 15:00:11 -08007100
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007101 /**
7102 * Whether a modem stack is enabled or not.
7103 */
7104 @Override
7105 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7106 Phone phone = PhoneFactory.getPhone(slotIndex);
7107 if (phone == null) return false;
7108
7109 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7110 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7111 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7112 }
7113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007116 try {
7117 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7118 } catch (NoSuchElementException ex) {
7119 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7120 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
7124 }
7125
Michelecea4cf22018-12-21 15:00:11 -08007126 @Override
Michele0ea7d782019-03-19 14:58:42 -07007127 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007128 enforceModifyPermission();
7129
7130 final long identity = Binder.clearCallingIdentity();
7131 try {
7132 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007133 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007134 .commit();
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
7137 }
7138 }
7139
7140 @Override
Michele0ea7d782019-03-19 14:58:42 -07007141 @TelephonyManager.IsMultiSimSupportedResult
7142 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007144 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7145 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007146 }
Michelecea4cf22018-12-21 15:00:11 -08007147
7148 final long identity = Binder.clearCallingIdentity();
7149 try {
Michele0ea7d782019-03-19 14:58:42 -07007150 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
7154 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007155
Michele0ea7d782019-03-19 14:58:42 -07007156 @TelephonyManager.IsMultiSimSupportedResult
7157 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007158 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7159 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7160 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007161 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7162 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007163 }
7164 // Check if the hardware supports multisim functionality. If usage of multisim is not
7165 // supported by the modem, indicate that it is restricted.
7166 PhoneCapability staticCapability =
7167 mPhoneConfigurationManager.getStaticPhoneCapability();
7168 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007169 loge("isMultiSimSupportedInternal: no static configuration available");
7170 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007171 }
7172 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007173 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7174 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007175 }
7176 // Check if support of multiple SIMs is restricted by carrier
7177 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007178 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007179 }
7180
Michele0ea7d782019-03-19 14:58:42 -07007181 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007182 }
7183
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007184 /**
7185 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007186 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7187 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7188 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007189 * @param numOfSims number of active sims we want to switch to
7190 */
7191 @Override
7192 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007193 if (numOfSims == 1) {
7194 enforceModifyPermission();
7195 } else {
7196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7197 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7198 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007199 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007200
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007201 try {
Michele30b57b22019-03-01 12:01:14 -08007202 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007203 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007204 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7205 return;
7206 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007207 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
7211 }
7212
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007213 @Override
7214 public boolean isApplicationOnUicc(int subId, int appType) {
7215 enforceReadPrivilegedPermission("isApplicationOnUicc");
7216 Phone phone = getPhone(subId);
7217 if (phone == null) {
7218 return false;
7219 }
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
7222 UiccCard uiccCard = phone.getUiccCard();
7223 if (uiccCard == null) {
7224 return false;
7225 }
7226 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7227 if (uiccProfile == null) {
7228 return false;
7229 }
7230 if (TelephonyManager.APPTYPE_SIM <= appType
7231 && appType <= TelephonyManager.APPTYPE_ISIM) {
7232 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7233 }
7234 return false;
7235 } finally {
7236 Binder.restoreCallingIdentity(identity);
7237 }
7238 }
7239
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007240 /**
chen xub4baa772019-04-03 10:23:41 -07007241 * Get whether making changes to modem configurations will trigger reboot.
7242 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007243 */
7244 @Override
chen xub4baa772019-04-03 10:23:41 -07007245 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7246 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7247 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7248 return false;
7249 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007250 final long identity = Binder.clearCallingIdentity();
7251 try {
7252 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7253 } finally {
7254 Binder.restoreCallingIdentity(identity);
7255 }
7256 }
7257
Nathan Harold29f5f052019-02-15 13:41:57 -08007258 private void updateModemStateMetrics() {
7259 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7260 // TODO: check the state for each modem if the api is ready.
7261 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7262 }
7263
Pengquan Meng3889a572019-01-23 11:16:29 -08007264 @Override
7265 public int[] getSlotsMapping() {
7266 enforceReadPrivilegedPermission("getSlotsMapping");
7267
7268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7271 // All logical slots should have a mapping to a physical slot.
7272 int[] logicalSlotsMapping = new int[phoneCount];
7273 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7274 for (int i = 0; i < slotInfos.length; i++) {
7275 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7276 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7277 }
7278 }
7279 return logicalSlotsMapping;
7280 } finally {
7281 Binder.restoreCallingIdentity(identity);
7282 }
7283 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007284
7285 /**
7286 * Get the IRadio HAL Version
7287 */
7288 @Override
7289 public int getRadioHalVersion() {
7290 Phone phone = getDefaultPhone();
7291 if (phone == null) return -1;
7292 HalVersion hv = phone.getHalVersion();
7293 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7294 return hv.major * 100 + hv.minor;
7295 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007296
7297 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007298 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7299 * corresponding network requests on a subId.
7300 *
7301 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007302 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007303 * 2) APN is un-metered for this subscription, or
7304 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7305 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7306 *
7307 * @return whether data is allowed for a apn type.
7308 *
7309 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007310 */
7311 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007312 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007314 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7315 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007316 }
7317
7318 // Now that all security checks passes, perform the operation as ourselves.
7319 final long identity = Binder.clearCallingIdentity();
7320 try {
7321 Phone phone = getPhone(subId);
7322 if (phone == null) return false;
7323
Jack Yu41407ee2019-05-13 16:54:09 -07007324 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007325 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
7329 }
7330
7331 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007332 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007333 enforceReadPrivilegedPermission("isApnMetered");
7334
7335 // Now that all security checks passes, perform the operation as ourselves.
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
7338 Phone phone = getPhone(subId);
7339 if (phone == null) return true; // By default return true.
7340
Jack Yu41407ee2019-05-13 16:54:09 -07007341 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007346
7347 @Override
7348 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7349 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7350 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7351 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7352 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7353 }
7354 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7355 Intent intent = new Intent();
7356 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7357 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7358 // Bring up choose default SMS subscription dialog right now
7359 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7360 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7361 mApp.startActivity(intent);
7362 }
chen xud5ca2d52019-05-28 15:20:57 -07007363
7364 @Override
7365 public String getMmsUAProfUrl(int subId) {
7366 //TODO investigate if this API should require proper permission check in R b/133791609
7367 final long identity = Binder.clearCallingIdentity();
7368 try {
7369 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7370 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
7373 }
7374 }
7375
7376 @Override
7377 public String getMmsUserAgent(int subId) {
7378 //TODO investigate if this API should require proper permission check in R b/133791609
7379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7382 .getString(com.android.internal.R.string.config_mms_user_agent);
7383 } finally {
7384 Binder.restoreCallingIdentity(identity);
7385 }
7386 }
Jack Yub07d4972019-05-28 16:12:25 -07007387
7388 @Override
7389 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7390 enforceModifyPermission();
7391
7392 // Now that all security checks passes, perform the operation as ourselves.
7393 final long identity = Binder.clearCallingIdentity();
7394 try {
7395 Phone phone = getPhone(subId);
7396 if (phone == null) return false;
7397
7398 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
7402 }
7403
7404 @Override
7405 public boolean isDataAllowedInVoiceCall(int subId) {
7406 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7407
7408 // Now that all security checks passes, perform the operation as ourselves.
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 Phone phone = getPhone(subId);
7412 if (phone == null) return false;
7413
7414 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7415 } finally {
7416 Binder.restoreCallingIdentity(identity);
7417 }
7418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007419}