blob: cafa5bec2e0129b09061c1c56b43d565c3ed8ccc [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100135import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Pengquan Meng85728fb2018-03-12 16:31:21 -0700272 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
273 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
274 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 * A request object to use for transmitting data to an ICC.
306 */
307 private static final class IccAPDUArgument {
308 public int channel, cla, command, p1, p2, p3;
309 public String data;
310
311 public IccAPDUArgument(int channel, int cla, int command,
312 int p1, int p2, int p3, String data) {
313 this.channel = channel;
314 this.cla = cla;
315 this.command = command;
316 this.p1 = p1;
317 this.p2 = p2;
318 this.p3 = p3;
319 this.data = data;
320 }
321 }
322
323 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700324 * A request object to use for transmitting data to an ICC.
325 */
326 private static final class ManualNetworkSelectionArgument {
327 public OperatorInfo operatorInfo;
328 public boolean persistSelection;
329
330 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
331 this.operatorInfo = operatorInfo;
332 this.persistSelection = persistSelection;
333 }
334 }
335
336 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
338 * request after sending. The main thread will notify the request when it is complete.
339 */
340 private static final class MainThreadRequest {
341 /** The argument to use for the request */
342 public Object argument;
343 /** The result of the request that is run on the main thread */
344 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800345 // The subscriber id that this request applies to. Defaults to
346 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
347 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Nathan Harold92bed182018-10-12 18:16:49 -0700349 // In cases where subId is unavailable, the caller needs to specify the phone.
350 public Phone phone;
351
vagdeviaf9a5b92018-08-15 16:01:53 -0700352 public WorkSource workSource;
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 public MainThreadRequest(Object argument) {
355 this.argument = argument;
356 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
359 this.argument = argument;
360 if (phone != null) {
361 this.phone = phone;
362 }
363 this.workSource = workSource;
364 }
365
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800368 if (subId != null) {
369 this.subId = subId;
370 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 }
374
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800375 private static final class IncomingThirdPartyCallArgs {
376 public final ComponentName component;
377 public final String callId;
378 public final String callerDisplayName;
379
380 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
381 String callerDisplayName) {
382 this.component = component;
383 this.callId = callId;
384 this.callerDisplayName = callerDisplayName;
385 }
386 }
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 /**
389 * A handler that processes messages on the main thread in the phone process. Since many
390 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
391 * inbound binder threads to the main thread in the phone process. The Binder thread
392 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
393 * on, which will be notified when the operation completes and will contain the result of the
394 * request.
395 *
396 * <p>If a MainThreadRequest object is provided in the msg.obj field,
397 * note that request.result must be set to something non-null for the calling thread to
398 * unblock.
399 */
400 private final class MainThreadHandler extends Handler {
401 @Override
402 public void handleMessage(Message msg) {
403 MainThreadRequest request;
404 Message onCompleted;
405 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800406 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800408 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
410 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 case CMD_HANDLE_USSD_REQUEST: {
412 request = (MainThreadRequest) msg.obj;
413 final Phone phone = getPhoneFromRequest(request);
414 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
415 String ussdRequest = ussdObject.first;
416 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 if (!isUssdApiAllowed(request.subId)) {
419 // Carrier does not support use of this API, return failure.
420 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
421 UssdResponse response = new UssdResponse(ussdRequest, null);
422 Bundle returnData = new Bundle();
423 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
424 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 request.result = true;
427 notifyRequester(request);
428 return;
429 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 try {
432 request.result = phone != null
433 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
434 } catch (CallStateException cse) {
435 request.result = false;
436 }
437 // Wake up the requesting thread
438 notifyRequester(request);
439 break;
pkanwar32d516d2016-10-14 19:37:38 -0700440 }
441
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 final Phone phone = getPhoneFromRequest(request);
445 request.result = phone != null ?
446 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
447 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduLogicalChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
463 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 iccArgument.channel, iccArgument.cla, iccArgument.command,
466 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 break;
470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800480 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800482 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 } else {
484 loge("iccTransmitApduLogicalChannel: Unknown exception");
485 }
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 break;
489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
491 request = (MainThreadRequest) msg.obj;
492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 if (uiccCard == null) {
495 loge("iccTransmitApduBasicChannel: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 } else {
499 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
500 request);
501 uiccCard.iccTransmitApduBasicChannel(
502 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
503 iccArgument.p3, iccArgument.data, onCompleted);
504 }
505 break;
506
507 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduBasicChannel: Empty response");
516 } else if (ar.exception instanceof CommandException) {
517 loge("iccTransmitApduBasicChannel: CommandException: " +
518 ar.exception);
519 } else {
520 loge("iccTransmitApduBasicChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 break;
525
526 case CMD_EXCHANGE_SIM_IO:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccExchangeSimIO: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
536 request);
537 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
538 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
539 iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_EXCHANGE_SIM_IO_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6f, 0, (byte[])null);
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 case CMD_SEND_ENVELOPE:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("sendEnvelopeWithStatus: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
563 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 break;
566
567 case EVENT_SEND_ENVELOPE_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("sendEnvelopeWithStatus: Empty response");
576 } else if (ar.exception instanceof CommandException) {
577 loge("sendEnvelopeWithStatus: CommandException: " +
578 ar.exception);
579 } else {
580 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
581 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 break;
585
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 case CMD_OPEN_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800592 request.result = new IccOpenLogicalChannelResponse(-1,
593 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
598 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
602 case EVENT_OPEN_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 int[] result = (int[]) ar.result;
608 int channelId = result[0];
609 byte[] selectResponse = null;
610 if (result.length > 1) {
611 selectResponse = new byte[result.length - 1];
612 for (int i = 1; i < result.length; ++i) {
613 selectResponse[i - 1] = (byte) result[i];
614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 if (ar.result == null) {
620 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (ar.exception != null) {
623 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
624 }
625
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700627 if (ar.exception instanceof CommandException) {
628 CommandException.Error error =
629 ((CommandException) (ar.exception)).getCommandError();
630 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700632 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 }
635 }
636 openChannelResp = new IccOpenLogicalChannelResponse(
637 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700639 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
643 case CMD_CLOSE_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800645 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 if (uiccCard == null) {
647 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900648 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800663 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
664 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 request.result = "";
674 if (ar.result == null) {
675 loge("nvReadItem: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("nvReadItem: CommandException: " +
678 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
Jake Hambye994d462014-02-03 13:10:13 -0800686 case CMD_NV_WRITE_ITEM:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
689 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800709 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700710 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800711 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case EVENT_RESET_MODEM_CONFIG_DONE:
715 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case CMD_SET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
746 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700747 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
751 handleNullReturnEvent(msg, "setPreferredNetworkType");
752 break;
753
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
755 request = (MainThreadRequest)msg.obj;
756 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
760 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
761 ar = (AsyncResult)msg.obj;
762 request = (MainThreadRequest)ar.userObj;
763 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700824 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
827 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
828 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 ManualNetworkSelectionArgument selArg =
830 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
832 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700833 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
834 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
842 } else {
843 request.result = false;
844 loge("setNetworkSelectionModeManual " + ar.exception);
845 }
846 notifyRequester(request);
847 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700853 if (defaultPhone != null) {
854 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
855 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 break;
857
858 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
864 if (ar.result == null) {
865 loge("queryModemActivityInfo: Empty response");
866 } else if (ar.exception instanceof CommandException) {
867 loge("queryModemActivityInfo: CommandException: " +
868 ar.exception);
869 } else {
870 loge("queryModemActivityInfo: Unknown exception");
871 }
872 }
Amit Mahajand4766222016-01-28 15:28:28 -0800873 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
874 if (request.result == null) {
875 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
876 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700877 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800882 CarrierRestrictionRules argument =
883 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800885 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800894 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
895 if (ar.exception instanceof CommandException) {
896 loge("setAllowedCarriers: CommandException: " + ar.exception);
897 CommandException.Error error =
898 ((CommandException) (ar.exception)).getCommandError();
899 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
900 request.result =
901 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
902 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 } else {
904 loge("setAllowedCarriers: Unknown exception");
905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case CMD_GET_ALLOWED_CARRIERS:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case EVENT_GET_ALLOWED_CARRIERS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800922 request.result = new IllegalStateException(
923 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700934 break;
935
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null && ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = new IllegalArgumentException(
943 "Failed to retrieve Forbidden Plmns");
944 if (ar.result == null) {
945 loge("getForbiddenPlmns: Empty response");
946 } else {
947 loge("getForbiddenPlmns: Unknown exception");
948 }
949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 } else {
972 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
973 + " specified type -- " + appType);
974 }
975 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
976 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
977 onCompleted);
978 break;
979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000980 case CMD_SWITCH_SLOTS:
981 request = (MainThreadRequest) msg.obj;
982 int[] physicalSlots = (int[]) request.argument;
983 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
984 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
985 break;
986
987 case EVENT_SWITCH_SLOTS_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700991 notifyRequester(request);
992 break;
993 case CMD_GET_NETWORK_SELECTION_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
996 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
997 break;
998
999 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1004 } else {
1005 int mode = ((int[]) ar.result)[0];
1006 if (mode == 0) {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1008 } else {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001011 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001012 notifyRequester(request);
1013 break;
1014 case CMD_GET_CDMA_ROAMING_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1017 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1018 break;
1019 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception != null) {
1023 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1024 } else {
1025 request.result = ((int[]) ar.result)[0];
1026 }
1027 notifyRequester(request);
1028 break;
1029 case CMD_SET_CDMA_ROAMING_MODE:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1032 int mode = (int) request.argument;
1033 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1034 break;
1035 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 request.result = ar.exception == null;
1039 notifyRequester(request);
1040 break;
1041 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1044 int subscriptionMode = (int) request.argument;
1045 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1046 break;
1047 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 request.result = ar.exception == null;
1051 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case CMD_GET_ALL_CELL_INFO:
1054 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001056 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case EVENT_GET_ALL_CELL_INFO_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001061 // If a timeout occurs, the response will be null
1062 request.result = (ar.exception == null && ar.result != null)
1063 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 case CMD_REQUEST_CELL_INFO_UPDATE:
1069 request = (MainThreadRequest) msg.obj;
1070 request.phone.requestCellInfoUpdate(request.workSource,
1071 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1072 break;
1073 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1077 try {
1078 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001080 cb.onError(
1081 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1082 ar.exception.getClass().getName(),
1083 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001086 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 } else {
1088 // use the result as returned
1089 cb.onCellInfo((List<CellInfo>) ar.result);
1090 }
1091 } catch (RemoteException re) {
1092 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1093 }
1094 break;
1095 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 request = (MainThreadRequest) msg.obj;
1097 WorkSource ws = (WorkSource) request.argument;
1098 Phone phone = getPhoneFromRequest(request);
1099 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1100 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null) {
1105 request.result = ar.result;
1106 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1109 ? new CdmaCellLocation() : new GsmCellLocation();
1110 }
1111
1112 synchronized (request) {
1113 request.notifyAll();
1114 }
1115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case CMD_MODEM_REBOOT:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001119 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case EVENT_CMD_MODEM_REBOOT_DONE:
1122 handleNullReturnEvent(msg, "rebootModem");
1123 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 case CMD_REQUEST_ENABLE_MODEM:
1125 request = (MainThreadRequest) msg.obj;
1126 boolean enable = (boolean) request.argument;
1127 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 PhoneConfigurationManager.getInstance()
1130 .enablePhone(request.phone, enable, onCompleted);
1131 break;
1132 case EVENT_ENABLE_MODEM_DONE:
1133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
1135 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001138 if ((boolean) request.result) {
1139 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1140 updateModemStateMetrics();
1141 } else {
1142 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1143 + ar.exception);
1144 }
1145 notifyRequester(request);
1146 break;
1147 case CMD_GET_MODEM_STATUS:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1150 PhoneConfigurationManager.getInstance()
1151 .getPhoneStatusFromModem(request.phone, onCompleted);
1152 break;
1153 case EVENT_GET_MODEM_STATUS_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 int id = request.phone.getPhoneId();
1157 if (ar.exception == null && ar.result != null) {
1158 request.result = ar.result;
1159 //update the cache as modem status has changed
1160 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1161 (boolean) request.result);
1162 } else {
1163 // Return true if modem status cannot be retrieved. For most cases,
1164 // modem status is on. And for older version modems, GET_MODEM_STATUS
1165 // and disable modem are not supported. Modem is always on.
1166 // TODO: this should be fixed in R to support a third
1167 // status UNKNOWN b/131631629
1168 request.result = true;
1169 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1170 + ar.exception);
1171 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001172 notifyRequester(request);
1173 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001174 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null && ar.result != null) {
1178 request.result = ar.result;
1179 } else {
1180 request.result = -1;
1181 loge("Failed to set Forbidden Plmns");
1182 if (ar.result == null) {
1183 loge("setForbidenPlmns: Empty response");
1184 } else if (ar.exception != null) {
1185 loge("setForbiddenPlmns: Exception: " + ar.exception);
1186 request.result = -1;
1187 } else {
1188 loge("setForbiddenPlmns: Unknown exception");
1189 }
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_FORBIDDEN_PLMNS:
1194 request = (MainThreadRequest) msg.obj;
1195 uiccCard = getUiccCardFromRequest(request);
1196 if (uiccCard == null) {
1197 loge("setForbiddenPlmns: UiccCard is null");
1198 request.result = -1;
1199 notifyRequester(request);
1200 break;
1201 }
1202 Pair<Integer, List<String>> setFplmnsArgs =
1203 (Pair<Integer, List<String>>) request.argument;
1204 appType = setFplmnsArgs.first;
1205 List<String> fplmns = setFplmnsArgs.second;
1206 uiccApp = uiccCard.getApplicationByType(appType);
1207 if (uiccApp == null) {
1208 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1209 request.result = -1;
1210 loge("Failed to get UICC App");
1211 notifyRequester(request);
1212 } else {
1213 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1214 ((SIMRecords) uiccApp.getIccRecords())
1215 .setForbiddenPlmns(onCompleted, fplmns);
1216 }
1217 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 default:
1219 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1220 break;
1221 }
1222 }
Jake Hambye994d462014-02-03 13:10:13 -08001223
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 private void notifyRequester(MainThreadRequest request) {
1225 synchronized (request) {
1226 request.notifyAll();
1227 }
1228 }
1229
Jake Hambye994d462014-02-03 13:10:13 -08001230 private void handleNullReturnEvent(Message msg, String command) {
1231 AsyncResult ar = (AsyncResult) msg.obj;
1232 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1233 if (ar.exception == null) {
1234 request.result = true;
1235 } else {
1236 request.result = false;
1237 if (ar.exception instanceof CommandException) {
1238 loge(command + ": CommandException: " + ar.exception);
1239 } else {
1240 loge(command + ": Unknown exception");
1241 }
1242 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 /**
1248 * Posts the specified command to be executed on the main thread,
1249 * waits for the request to complete, and returns the result.
1250 * @see #sendRequestAsync
1251 */
1252 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001253 return sendRequest(
1254 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001255 }
1256
1257 /**
1258 * Posts the specified command to be executed on the main thread,
1259 * waits for the request to complete, and returns the result.
1260 * @see #sendRequestAsync
1261 */
1262 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1263 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001264 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001265 }
1266
1267 /**
1268 * Posts the specified command to be executed on the main thread,
1269 * waits for the request to complete, and returns the result.
1270 * @see #sendRequestAsync
1271 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001272 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001273 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001274 }
1275
1276 /**
1277 * Posts the specified command to be executed on the main thread,
1278 * waits for the request to complete, and returns the result.
1279 * @see #sendRequestAsync
1280 */
Nathan Harold92bed182018-10-12 18:16:49 -07001281 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1282 return sendRequest(command, argument, subId, null, workSource);
1283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
1290 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1291 return sendRequest(
1292 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1293 }
1294
1295 /**
1296 * Posts the specified command to be executed on the main thread,
1297 * waits for the request to complete, and returns the result.
1298 * @see #sendRequestAsync
1299 */
1300 private Object sendRequest(
1301 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1303 throw new RuntimeException("This method will deadlock if called from the main thread.");
1304 }
1305
Nathan Harold92bed182018-10-12 18:16:49 -07001306 MainThreadRequest request = null;
1307 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1308 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1309 } else if (phone != null) {
1310 request = new MainThreadRequest(argument, phone, workSource);
1311 } else {
1312 request = new MainThreadRequest(argument, subId, workSource);
1313 }
1314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 Message msg = mMainThreadHandler.obtainMessage(command, request);
1316 msg.sendToTarget();
1317
1318 // Wait for the request to complete
1319 synchronized (request) {
1320 while (request.result == null) {
1321 try {
1322 request.wait();
1323 } catch (InterruptedException e) {
1324 // Do nothing, go back and wait until the request is complete
1325 }
1326 }
1327 }
1328 return request.result;
1329 }
1330
1331 /**
1332 * Asynchronous ("fire and forget") version of sendRequest():
1333 * Posts the specified command to be executed on the main thread, and
1334 * returns immediately.
1335 * @see #sendRequest
1336 */
1337 private void sendRequestAsync(int command) {
1338 mMainThreadHandler.sendEmptyMessage(command);
1339 }
1340
1341 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001344 */
1345 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001346 sendRequestAsync(command, argument, null, null);
1347 }
1348
1349 /**
1350 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1351 * @see {@link #sendRequest(int,Object)}
1352 */
1353 private void sendRequestAsync(
1354 int command, Object argument, Phone phone, WorkSource workSource) {
1355 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 Message msg = mMainThreadHandler.obtainMessage(command, request);
1357 msg.sendToTarget();
1358 }
1359
1360 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 * Initialize the singleton PhoneInterfaceManager instance.
1362 * This is only done once, at startup, from PhoneApp.onCreate().
1363 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001364 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 synchronized (PhoneInterfaceManager.class) {
1366 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001367 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 } else {
1369 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1370 }
1371 return sInstance;
1372 }
1373 }
1374
1375 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001379 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1381 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001382 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 mTelephonySharedPreferences =
1384 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001385 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001386 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 publish();
1389 }
1390
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private Phone getDefaultPhone() {
1392 Phone thePhone = getPhone(getDefaultSubscription());
1393 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1394 }
1395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 private void publish() {
1397 if (DBG) log("publish: " + this);
1398
1399 ServiceManager.addService("phone", this);
1400 }
1401
Stuart Scott584921c2015-01-15 17:10:34 -08001402 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001403 if (request.phone != null) {
1404 return request.phone;
1405 } else {
1406 return getPhoneFromSubId(request.subId);
1407 }
1408 }
1409
1410 private Phone getPhoneFromSubId(int subId) {
1411 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1412 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001413 }
1414
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001415 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1416 Phone phone = getPhoneFromRequest(request);
1417 return phone == null ? null :
1418 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1419 }
1420
Wink Saville36469e72014-06-11 15:17:00 -07001421 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001423 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 if (DBG) log("dial: " + number);
1432 // No permission check needed here: This is just a wrapper around the
1433 // ACTION_DIAL intent, which is available to any app since it puts up
1434 // the UI before it does anything.
1435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 final long identity = Binder.clearCallingIdentity();
1437 try {
1438 String url = createTelUrl(number);
1439 if (url == null) {
1440 return;
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001443 // PENDING: should we just silently fail if phone is offhook or ringing?
1444 PhoneConstants.State state = mCM.getState(subId);
1445 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1446 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1447 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1448 mApp.startActivity(intent);
1449 }
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453 }
1454
1455 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("call: " + number);
1461
1462 // This is just a wrapper around the ACTION_CALL intent, but we still
1463 // need to do a permission check since we're calling startActivity()
1464 // from the context of the phone app.
1465 enforceCallPermission();
1466
Jordan Liu1617b712019-07-10 15:06:26 -07001467 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 != AppOpsManager.MODE_ALLOWED) {
1469 return;
1470 }
1471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 String url = createTelUrl(number);
1475 if (url == null) {
1476 return;
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001479 boolean isValid = false;
1480 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1481 if (slist != null) {
1482 for (SubscriptionInfo subInfoRecord : slist) {
1483 if (subInfoRecord.getSubscriptionId() == subId) {
1484 isValid = true;
1485 break;
1486 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001487 }
Wink Saville08874612014-08-31 19:19:58 -07001488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 if (!isValid) {
1490 return;
1491 }
Wink Saville08874612014-08-31 19:19:58 -07001492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1494 intent.putExtra(SUBSCRIPTION_KEY, subId);
1495 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1496 mApp.startActivity(intent);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001504 }
1505
Wink Savilleb564aae2014-10-23 10:18:09 -07001506 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001508 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1509 }
1510
1511 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001517 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1518 }
1519
1520 /** {@hide} */
1521 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001527
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1531 checkSimPin.start();
1532 return checkSimPin.unlockSim(null, pin);
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville9de0f752013-10-22 19:04:03 -07001538 /** {@hide} */
1539 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPuk.start();
1550 return checkSimPuk.unlockSim(puk, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001557 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 * a synchronous one.
1559 */
1560 private static class UnlockSim extends Thread {
1561
1562 private final IccCard mSimCard;
1563
1564 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001565 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1566 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567
1568 // For replies from SimCard interface
1569 private Handler mHandler;
1570
1571 // For async handler to identify request type
1572 private static final int SUPPLY_PIN_COMPLETE = 100;
1573
1574 public UnlockSim(IccCard simCard) {
1575 mSimCard = simCard;
1576 }
1577
1578 @Override
1579 public void run() {
1580 Looper.prepare();
1581 synchronized (UnlockSim.this) {
1582 mHandler = new Handler() {
1583 @Override
1584 public void handleMessage(Message msg) {
1585 AsyncResult ar = (AsyncResult) msg.obj;
1586 switch (msg.what) {
1587 case SUPPLY_PIN_COMPLETE:
1588 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1589 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001590 mRetryCount = msg.arg1;
1591 if (ar.exception != null) {
1592 if (ar.exception instanceof CommandException &&
1593 ((CommandException)(ar.exception)).getCommandError()
1594 == CommandException.Error.PASSWORD_INCORRECT) {
1595 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1596 } else {
1597 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1598 }
1599 } else {
1600 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 mDone = true;
1603 UnlockSim.this.notifyAll();
1604 }
1605 break;
1606 }
1607 }
1608 };
1609 UnlockSim.this.notifyAll();
1610 }
1611 Looper.loop();
1612 }
1613
1614 /*
1615 * Use PIN or PUK to unlock SIM card
1616 *
1617 * If PUK is null, unlock SIM card with PIN
1618 *
1619 * If PUK is not null, unlock SIM card with PUK and set PIN code
1620 */
Wink Saville9de0f752013-10-22 19:04:03 -07001621 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622
1623 while (mHandler == null) {
1624 try {
1625 wait();
1626 } catch (InterruptedException e) {
1627 Thread.currentThread().interrupt();
1628 }
1629 }
1630 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1631
1632 if (puk == null) {
1633 mSimCard.supplyPin(pin, callback);
1634 } else {
1635 mSimCard.supplyPuk(puk, pin, callback);
1636 }
1637
1638 while (!mDone) {
1639 try {
1640 Log.d(LOG_TAG, "wait for done");
1641 wait();
1642 } catch (InterruptedException e) {
1643 // Restore the interrupted status
1644 Thread.currentThread().interrupt();
1645 }
1646 }
1647 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001648 int[] resultArray = new int[2];
1649 resultArray[0] = mResult;
1650 resultArray[1] = mRetryCount;
1651 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653 }
1654
1655 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001657
1658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 // No permission check needed here: this call is harmless, and it's
1662 // needed for the ServiceState.requestStateUpdate() call (which is
1663 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.updateServiceLocation();
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001675 @Override
1676 public boolean isRadioOn(String callingPackage) {
1677 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 @Override
1681 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001683 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001684 return false;
1685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 return isRadioOnForSubscriber(subId);
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001693 }
1694
1695 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1701 } else {
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001710 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
1727 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
Wink Savilleb564aae2014-10-23 10:18:09 -07001731 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone == null) {
1738 return false;
1739 }
1740 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1741 toggleRadioOnOffForSubscriber(subId);
1742 }
1743 return true;
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001749 public boolean needMobileRadioShutdown() {
1750 /*
1751 * If any of the Radios are available, it will need to be
1752 * shutdown. So return true if any Radio is available.
1753 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1757 Phone phone = PhoneFactory.getPhone(i);
1758 if (phone != null && phone.isRadioAvailable()) return true;
1759 }
1760 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1761 return false;
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001765 }
1766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001768 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 enforceModifyPermission();
1770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1774 logv("Shutting down Phone " + i);
1775 shutdownRadioUsingPhoneId(i);
1776 }
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 }
1780 }
1781
1782 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001783 Phone phone = PhoneFactory.getPhone(phoneId);
1784 if (phone != null && phone.isRadioAvailable()) {
1785 phone.shutdownRadio();
1786 }
1787 }
1788
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1795 if (defaultPhone != null) {
1796 defaultPhone.setRadioPower(turnOn);
1797 return true;
1798 } else {
1799 loge("There's no default phone.");
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001804 }
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809
1810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 final Phone phone = getPhone(subId);
1813 if (phone != null) {
1814 phone.setRadioPower(turnOn);
1815 return true;
1816 } else {
1817 return false;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Wink Saville36469e72014-06-11 15:17:00 -07001824 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public boolean enableDataConnectivity() {
1827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 final Phone phone = getPhone(subId);
1833 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001834 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 return true;
1836 } else {
1837 return false;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
Wink Saville36469e72014-06-11 15:17:00 -07001844 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public boolean disableDataConnectivity() {
1847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 int subId = mSubscriptionController.getDefaultDataSubId();
1852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001854 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 return true;
1856 } else {
1857 return false;
1858 }
1859 } finally {
1860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001865 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 final Phone phone = getPhone(subId);
1869 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001870 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871 } else {
1872 return false;
1873 }
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
1879 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001880 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001881 }
1882
pkanwarae03a6b2016-11-06 20:37:09 -08001883 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 enforceCallPermission();
1885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1889 return;
1890 }
1891 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1892 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
pkanwar32d516d2016-10-14 19:37:38 -07001896 };
1897
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
1903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1904 return false;
1905 }
1906 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001913 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001916 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 Phone phone = PhoneFactory.getPhone(slotIndex);
1920 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1921 PhoneConstantConversions.convertCallState(phone.getState());
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001928 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001929 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1930 }
1931
1932 @Override
1933 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001936 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 if (phone != null) {
1938 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1939 } else {
1940 return PhoneConstantConversions.convertDataState(
1941 PhoneConstants.DataState.DISCONNECTED);
1942 }
1943 } finally {
1944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001949 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001950 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1951 }
1952
1953 @Override
1954 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 if (phone != null) {
1959 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1960 } else {
1961 return TelephonyManager.DATA_ACTIVITY_NONE;
1962 }
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001972
1973 LocationAccessPolicy.LocationPermissionResult locationResult =
1974 LocationAccessPolicy.checkLocationPermission(mApp,
1975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1976 .setCallingPackage(callingPackage)
1977 .setCallingPid(Binder.getCallingPid())
1978 .setCallingUid(Binder.getCallingUid())
1979 .setMethod("getCellLocation")
1980 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1981 .build());
1982 switch (locationResult) {
1983 case DENIED_HARD:
1984 throw new SecurityException("Not allowed to access cell location");
1985 case DENIED_SOFT:
1986 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 if (DBG_LOC) log("getCellLocation: is active user");
1993 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001994 int subId = mSubscriptionController.getDefaultDataSubId();
1995 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1996 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 return data;
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001 }
2002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002004 public String getNetworkCountryIsoForPhone(int phoneId) {
2005 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2006 // registered cell info, so return a NULL country instead.
2007 final long identity = Binder.clearCallingIdentity();
2008 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002009 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2010 // Get default phone in this case.
2011 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2012 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002013 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002014 // Todo: fix this when we can get the actual cellular network info when the device
2015 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002016 if (TelephonyManager.NETWORK_TYPE_IWLAN
2017 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2018 return "";
2019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 Phone phone = PhoneFactory.getPhone(phoneId);
2021 if (phone != null) {
2022 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002023 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 if (sst != null) {
2025 LocaleTracker lt = sst.getLocaleTracker();
2026 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002027 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2028 return lt.getCurrentCountry();
2029 } else if (emergencyNumberTracker != null) {
2030 return emergencyNumberTracker.getEmergencyCountryIso();
2031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 }
2033 }
2034 }
2035 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002036 } finally {
2037 Binder.restoreCallingIdentity(identity);
2038 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002039 }
2040
2041 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002042 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002043 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002044 }
2045
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002047 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 mApp.enforceCallingOrSelfPermission(
2049 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050
2051 final long identity = Binder.clearCallingIdentity();
2052 try {
2053 final Phone phone = getPhone(subId);
2054 if (phone != null) {
2055 phone.enableLocationUpdates();
2056 }
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002059 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060 }
2061
2062 @Override
2063 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002064 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002068 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 mApp.enforceCallingOrSelfPermission(
2070 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002071
2072 final long identity = Binder.clearCallingIdentity();
2073 try {
2074 final Phone phone = getPhone(subId);
2075 if (phone != null) {
2076 phone.disableLocationUpdates();
2077 }
2078 } finally {
2079 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002080 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082
Nathan Harold31d7ff32018-10-15 20:20:30 -07002083 /**
2084 * Returns the target SDK version number for a given package name.
2085 *
Nathan Haroldec184742019-07-10 17:04:16 -07002086 * This call MUST be invoked before clearing the calling UID.
2087 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002088 * @return target SDK if the package is found or INT_MAX.
2089 */
2090 private int getTargetSdk(String packageName) {
2091 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002092 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002093 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002094 if (ai != null) return ai.targetSdkVersion;
2095 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002096 loge("Failed to get package info for pkg="
2097 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002098 }
2099 return Integer.MAX_VALUE;
2100 }
2101
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002102 @Override
2103 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002104 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2105 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002106 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2107 throw new SecurityException(
2108 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2109 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002110
Jordan Liu1617b712019-07-10 15:06:26 -07002111 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2113 return null;
2114 }
Svetoslav64fad262015-04-14 14:35:21 -07002115
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002116 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002117
Nathan Haroldf180aac2018-06-01 18:43:55 -07002118 List<CellInfo> info = getAllCellInfo(callingPackage);
2119 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120
Nathan Haroldf180aac2018-06-01 18:43:55 -07002121 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2122 for (CellInfo ci : info) {
2123 if (ci instanceof CellInfoGsm) {
2124 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2125 } else if (ci instanceof CellInfoWcdma) {
2126 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2127 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002129 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002132 private List<CellInfo> getCachedCellInfo() {
2133 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2134 for (Phone phone : PhoneFactory.getPhones()) {
2135 List<CellInfo> info = phone.getAllCellInfo();
2136 if (info != null) cellInfos.addAll(info);
2137 }
2138 return cellInfos;
2139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140
2141 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002142 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002143 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002144 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002145
2146 LocationAccessPolicy.LocationPermissionResult locationResult =
2147 LocationAccessPolicy.checkLocationPermission(mApp,
2148 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2149 .setCallingPackage(callingPackage)
2150 .setCallingPid(Binder.getCallingPid())
2151 .setCallingUid(Binder.getCallingUid())
2152 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002153 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002154 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2155 .build());
2156 switch (locationResult) {
2157 case DENIED_HARD:
2158 throw new SecurityException("Not allowed to access cell info");
2159 case DENIED_SOFT:
2160 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 }
2162
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 final int targetSdk = getTargetSdk(callingPackage);
2164 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2165 return getCachedCellInfo();
2166 }
2167
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002168 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002169 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2173 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002174 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002175 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 if (info != null) cellInfos.addAll(info);
2177 }
2178 return cellInfos;
2179 } finally {
2180 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
2182 }
2183
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002184 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2186 requestCellInfoUpdateInternal(
2187 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2188 }
2189
2190 @Override
2191 public void requestCellInfoUpdateWithWorkSource(
2192 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2193 enforceModifyPermission();
2194 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2195 }
2196
2197 private void requestCellInfoUpdateInternal(
2198 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002199 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002200 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002201
2202 LocationAccessPolicy.LocationPermissionResult locationResult =
2203 LocationAccessPolicy.checkLocationPermission(mApp,
2204 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2205 .setCallingPackage(callingPackage)
2206 .setCallingPid(Binder.getCallingPid())
2207 .setCallingUid(Binder.getCallingUid())
2208 .setMethod("requestCellInfoUpdate")
2209 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2210 .build());
2211 switch (locationResult) {
2212 case DENIED_HARD:
2213 throw new SecurityException("Not allowed to access cell info");
2214 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002215 try {
2216 cb.onCellInfo(new ArrayList<CellInfo>());
2217 } catch (RemoteException re) {
2218 // Drop without consequences
2219 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002220 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002221 }
2222
Nathan Harolda939a962019-05-09 10:13:47 -07002223
2224 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2226
2227 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2228 }
2229
2230 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002231 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002232 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002233 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002234
2235 final long identity = Binder.clearCallingIdentity();
2236 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238 } finally {
2239 Binder.restoreCallingIdentity(identity);
2240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002241 }
2242
Shishir Agrawala9f32182016-04-12 12:00:16 -07002243 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002244 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002247 return null;
2248 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002250 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2251 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002252 return null;
2253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254
2255 final long identity = Binder.clearCallingIdentity();
2256 try {
2257 return phone.getImei();
2258 } finally {
2259 Binder.restoreCallingIdentity(identity);
2260 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002261 }
2262
2263 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002264 public String getTypeAllocationCodeForSlot(int slotIndex) {
2265 Phone phone = PhoneFactory.getPhone(slotIndex);
2266 String tac = null;
2267 if (phone != null) {
2268 String imei = phone.getImei();
2269 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2270 }
2271 return tac;
2272 }
2273
2274 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002275 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002276 Phone phone = PhoneFactory.getPhone(slotIndex);
2277 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002278 return null;
2279 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002280
Jeff Davidson913390f2018-02-23 17:11:49 -08002281 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002282 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2283 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 return null;
2285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002286
2287 final long identity = Binder.clearCallingIdentity();
2288 try {
2289 return phone.getMeid();
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
2292 }
Jack Yu2af8d712017-03-15 17:14:14 -07002293 }
2294
2295 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002296 public String getManufacturerCodeForSlot(int slotIndex) {
2297 Phone phone = PhoneFactory.getPhone(slotIndex);
2298 String manufacturerCode = null;
2299 if (phone != null) {
2300 String meid = phone.getMeid();
2301 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2302 }
2303 return manufacturerCode;
2304 }
2305
2306 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 Phone phone = PhoneFactory.getPhone(slotIndex);
2309 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002310 return null;
2311 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 int subId = phone.getSubId();
2313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2314 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2315 return null;
2316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002317
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return phone.getDeviceSvn();
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002324 }
2325
fionaxu43304da2017-11-27 22:51:16 -08002326 @Override
2327 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 final Phone phone = getPhone(subId);
2331 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
fionaxu43304da2017-11-27 22:51:16 -08002335 }
2336
2337 @Override
2338 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 final long identity = Binder.clearCallingIdentity();
2340 try {
2341 final Phone phone = getPhone(subId);
2342 return phone == null ? null : phone.getCarrierName();
2343 } finally {
2344 Binder.restoreCallingIdentity(identity);
2345 }
fionaxu43304da2017-11-27 22:51:16 -08002346 }
2347
calvinpanffe225e2018-11-01 19:43:06 +08002348 @Override
chen xu0026ca62019-03-06 15:28:50 -08002349 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002354 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002355 } finally {
2356 Binder.restoreCallingIdentity(identity);
2357 }
2358 }
2359
2360 @Override
chen xu0026ca62019-03-06 15:28:50 -08002361 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002365 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
2369 }
2370
chen xu651eec72018-11-11 19:03:44 -08002371 @Override
chen xu864e11c2018-12-06 22:10:03 -08002372 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2373 if (!isSubscriptionMccMnc) {
2374 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2375 }
chen xu651eec72018-11-11 19:03:44 -08002376 final Phone phone = PhoneFactory.getPhone(slotIndex);
2377 if (phone == null) {
2378 return TelephonyManager.UNKNOWN_CARRIER_ID;
2379 }
2380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2383 } finally {
2384 Binder.restoreCallingIdentity(identity);
2385 }
2386 }
2387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 //
2389 // Internal helper methods.
2390 //
2391
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2394 *
2395 * @throws SecurityException if the caller does not have the required permission
2396 */
2397 private void enforceModifyPermission() {
2398 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2399 }
2400
2401 /**
2402 * Make sure the caller has the CALL_PHONE permission.
2403 *
2404 * @throws SecurityException if the caller does not have the required permission
2405 */
2406 private void enforceCallPermission() {
2407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2408 }
2409
Stuart Scott8eef64f2015-04-08 15:13:54 -07002410 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002412 "ConnectivityService");
2413 }
2414
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415 private String createTelUrl(String number) {
2416 if (TextUtils.isEmpty(number)) {
2417 return null;
2418 }
2419
Jake Hambye994d462014-02-03 13:10:13 -08002420 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421 }
2422
Ihab Awadf9e92732013-12-05 18:02:52 -08002423 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2425 }
2426
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002427 private static void logv(String msg) {
2428 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2429 }
2430
Ihab Awadf9e92732013-12-05 18:02:52 -08002431 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002437 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002438 }
2439
Sanket Padawe356d7632015-06-22 14:03:32 -07002440 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002441 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442 final long identity = Binder.clearCallingIdentity();
2443 try {
2444 final Phone phone = PhoneFactory.getPhone(slotIndex);
2445 if (phone == null) {
2446 return PhoneConstants.PHONE_TYPE_NONE;
2447 } else {
2448 return phone.getPhoneType();
2449 }
2450 } finally {
2451 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453 }
2454
2455 /**
2456 * Returns the CDMA ERI icon index to display
2457 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002458 @Override
2459 public int getCdmaEriIconIndex(String callingPackage) {
2460 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002461 }
2462
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002464 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002466 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 return -1;
2468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 final Phone phone = getPhone(subId);
2473 if (phone != null) {
2474 return phone.getCdmaEriIconIndex();
2475 } else {
2476 return -1;
2477 }
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482
2483 /**
2484 * Returns the CDMA ERI icon mode,
2485 * 0 - ON
2486 * 1 - FLASHING
2487 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002488 @Override
2489 public int getCdmaEriIconMode(String callingPackage) {
2490 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002491 }
2492
Sanket Padawe356d7632015-06-22 14:03:32 -07002493 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002494 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002496 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 return -1;
2498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
2503 if (phone != null) {
2504 return phone.getCdmaEriIconMode();
2505 } else {
2506 return -1;
2507 }
2508 } finally {
2509 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002511 }
2512
2513 /**
2514 * Returns the CDMA ERI text,
2515 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002516 @Override
2517 public String getCdmaEriText(String callingPackage) {
2518 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002522 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002524 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002525 return null;
2526 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone != null) {
2532 return phone.getCdmaEriText();
2533 } else {
2534 return null;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002539 }
2540
2541 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002542 * Returns the CDMA MDN.
2543 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002544 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002545 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2547 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 return phone.getLine1Number();
2554 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002555 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556 return null;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002560 }
2561 }
2562
2563 /**
2564 * Returns the CDMA MIN.
2565 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002567 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2569 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2575 return phone.getCdmaMin();
2576 } else {
2577 return null;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002581 }
2582 }
2583
Hall Liud892bec2018-11-30 14:51:45 -08002584 @Override
2585 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2586 INumberVerificationCallback callback, String callingPackage) {
2587 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2588 != PERMISSION_GRANTED) {
2589 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2590 }
2591 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2592
2593 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2594 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2595 throw new SecurityException("Calling package must be configured in the device config");
2596 }
2597
2598 if (range == null) {
2599 throw new NullPointerException("Range must be non-null");
2600 }
2601
2602 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002603 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002604
2605 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2606 }
2607
Junda Liuca05d5d2014-08-14 22:36:34 -07002608 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 * Returns true if CDMA provisioning needs to run.
2610 */
2611 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002621 * Sets the voice mail number of a given subId.
2622 */
2623 @Override
2624 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002625 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2630 new Pair<String, String>(alphaTag, number), new Integer(subId));
2631 return success;
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
2634 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002635 }
2636
Ta-wei Yen87c49842016-05-13 21:19:52 -07002637 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002638 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2639 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002640 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2641 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002642 if (!TextUtils.equals(callingPackage, systemDialer)) {
2643 throw new SecurityException("caller must be system dialer");
2644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002645
2646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2649 if (phoneAccountHandle == null) {
2650 return null;
2651 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002652 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002655 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002656 }
2657
2658 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002659 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002661 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002662 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002663 return null;
2664 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002666 final long identity = Binder.clearCallingIdentity();
2667 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002668 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002672 }
2673
2674 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002675 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2676 VisualVoicemailSmsFilterSettings settings) {
2677 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678
2679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002682 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 } finally {
2684 Binder.restoreCallingIdentity(identity);
2685 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002686 }
2687
2688 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002689 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2690 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691
2692 final long identity = Binder.clearCallingIdentity();
2693 try {
2694 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002695 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 } finally {
2697 Binder.restoreCallingIdentity(identity);
2698 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002699 }
2700
2701 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002702 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2703 String callingPackage, int subId) {
2704 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705
2706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002709 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002713 }
2714
2715 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002716 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002717 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002722 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 } finally {
2724 Binder.restoreCallingIdentity(identity);
2725 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002726 }
2727
2728 @Override
2729 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2730 String number, int port, String text, PendingIntent sentIntent) {
2731 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002732 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002733 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002734 SmsController smsController = PhoneFactory.getSmsController();
2735 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2736 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002737 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002738
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002739 /**
fionaxu0152e512016-11-14 13:36:14 -08002740 * Sets the voice activation state of a given subId.
2741 */
2742 @Override
2743 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2745 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746
2747 final long identity = Binder.clearCallingIdentity();
2748 try {
2749 final Phone phone = getPhone(subId);
2750 if (phone != null) {
2751 phone.setVoiceActivationState(activationState);
2752 } else {
2753 loge("setVoiceActivationState fails with invalid subId: " + subId);
2754 }
2755 } finally {
2756 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002757 }
2758 }
2759
2760 /**
2761 * Sets the data activation state of a given subId.
2762 */
2763 @Override
2764 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2766 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 final Phone phone = getPhone(subId);
2771 if (phone != null) {
2772 phone.setDataActivationState(activationState);
2773 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002774 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775 }
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002778 }
2779 }
2780
2781 /**
2782 * Returns the voice activation state of a given subId.
2783 */
2784 @Override
2785 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002786 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787
fionaxu0152e512016-11-14 13:36:14 -08002788 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002789 final long identity = Binder.clearCallingIdentity();
2790 try {
2791 if (phone != null) {
2792 return phone.getVoiceActivationState();
2793 } else {
2794 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2795 }
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002798 }
2799 }
2800
2801 /**
2802 * Returns the data activation state of a given subId.
2803 */
2804 @Override
2805 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002806 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002807
fionaxu0152e512016-11-14 13:36:14 -08002808 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002809 final long identity = Binder.clearCallingIdentity();
2810 try {
2811 if (phone != null) {
2812 return phone.getDataActivationState();
2813 } else {
2814 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2815 }
2816 } finally {
2817 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002818 }
2819 }
2820
2821 /**
Wink Saville36469e72014-06-11 15:17:00 -07002822 * Returns the unread count of voicemails for a subId
2823 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002824 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002825 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2827 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2828 return 0;
2829 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 return phone.getVoiceMessageCount();
2835 } else {
2836 return 0;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002844 * returns true, if the device is in a state where both voice and data
2845 * are supported simultaneously. This can change based on location or network condition.
2846 */
2847 @Override
2848 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849 final long identity = Binder.clearCallingIdentity();
2850 try {
2851 final Phone phone = getPhone(subId);
2852 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2853 } finally {
2854 Binder.restoreCallingIdentity(identity);
2855 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002856 }
2857
2858 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002859 * Send the dialer code if called from the current default dialer or the caller has
2860 * carrier privilege.
2861 * @param inputCode The dialer code to send
2862 */
2863 @Override
2864 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002865 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002866 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002867 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2868 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002869 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2871 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002872 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002873
2874 final long identity = Binder.clearCallingIdentity();
2875 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002877 } finally {
2878 Binder.restoreCallingIdentity(identity);
2879 }
fionaxu235cc5e2017-03-06 22:25:57 -08002880 }
2881
Pengquan Menga1bb6272018-09-06 09:59:22 -07002882 @Override
2883 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002884 if (!isActiveSubscription(subId)) {
2885 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2886 }
2887
Pengquan Menga1bb6272018-09-06 09:59:22 -07002888 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2889 }
2890
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002892 public boolean isInEmergencySmsMode() {
2893 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2894 final long identity = Binder.clearCallingIdentity();
2895 try {
2896 for (Phone phone : PhoneFactory.getPhones()) {
2897 if (phone.isInEmergencySmsMode()) {
2898 return true;
2899 }
2900 }
2901 } finally {
2902 Binder.restoreCallingIdentity(identity);
2903 }
2904 return false;
2905 }
2906
2907 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002908 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2909 throws RemoteException {
2910 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002911 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2912 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2913 "IMS not available on device.");
2914 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002915 final long token = Binder.clearCallingIdentity();
2916 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002920 } catch (ImsException e) {
2921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002922 } finally {
2923 Binder.restoreCallingIdentity(token);
2924 }
2925 }
2926
2927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002928 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2929 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002930 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2931 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2932 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07002933 final long token = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2936 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2937 .removeRegistrationCallbackForSubscription(c, subId);
2938 } catch (ImsException e) {
2939 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2940 + "is inactive, ignoring unregister.");
2941 // If the subscription is no longer active, just return, since the callback
2942 // will already have been removed internally.
2943 } finally {
2944 Binder.restoreCallingIdentity(token);
2945 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002946 }
2947
Brad Ebinger774ba362019-10-22 17:36:18 -07002948 /**
2949 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2950 */
2951 @Override
2952 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2953 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2954 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2955 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2956 "IMS not available on device.");
2957 }
2958 final long token = Binder.clearCallingIdentity();
2959 try {
2960 Phone phone = getPhone(subId);
2961 if (phone == null) {
2962 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2963 + subId + "'");
2964 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2965 }
2966 phone.getImsRegistrationState(regState -> {
2967 try {
2968 consumer.accept((regState == null)
2969 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2970 } catch (RemoteException e) {
2971 // Ignore if the remote process is no longer available to call back.
2972 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2973 }
2974 });
2975 } finally {
2976 Binder.restoreCallingIdentity(token);
2977 }
2978 }
2979
2980 /**
2981 * Get the transport type for the IMS service registration state.
2982 */
2983 @Override
2984 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2985 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2986 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2988 "IMS not available on device.");
2989 }
2990 final long token = Binder.clearCallingIdentity();
2991 try {
2992 Phone phone = getPhone(subId);
2993 if (phone == null) {
2994 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2995 + subId + "'");
2996 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2997 }
2998 phone.getImsRegistrationTech(regTech -> {
2999 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3000 int regTechConverted = (regTech == null)
3001 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3002 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3003 regTechConverted);
3004 try {
3005 consumer.accept(regTechConverted);
3006 } catch (RemoteException e) {
3007 // Ignore if the remote process is no longer available to call back.
3008 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3009 }
3010 });
3011 } finally {
3012 Binder.restoreCallingIdentity(token);
3013 }
3014 }
3015
Brad Ebinger35c841c2018-10-01 10:40:55 -07003016 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003017 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3018 throws RemoteException {
3019 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003020 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3021 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3022 "IMS not available on device.");
3023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3025 final long token = Binder.clearCallingIdentity();
3026 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003028 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003029 } catch (ImsException e) {
3030 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 } finally {
3032 Binder.restoreCallingIdentity(token);
3033 }
3034 }
3035
3036 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003037 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3038 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003039 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3040 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3041 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003042
3043 final long token = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3046 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003047 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003048 } catch (ImsException e) {
3049 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3050 + "is inactive, ignoring unregister.");
3051 // If the subscription is no longer active, just return, since the callback
3052 // will already have been removed internally.
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003056 }
3057
3058 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003059 public boolean isCapable(int subId, int capability, int regTech) {
3060 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3062 final long token = Binder.clearCallingIdentity();
3063 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003064 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003066 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3068 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003069 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003070 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3071 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
3075 }
3076
3077 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003078 public boolean isAvailable(int subId, int capability, int regTech) {
3079 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 final long token = Binder.clearCallingIdentity();
3081 try {
3082 Phone phone = getPhone(subId);
3083 if (phone == null) return false;
3084 return phone.isImsCapabilityAvailable(capability, regTech);
3085 } finally {
3086 Binder.restoreCallingIdentity(token);
3087 }
3088 }
3089
Brad Ebinger77b832e2019-10-17 17:03:22 -07003090 /**
3091 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3092 * subscription.
3093 * @param subId The subscription to use to check the configuration.
3094 * @param callback The callback that will be used to send the result.
3095 * @param capability The MmTelFeature capability that will be used to send the result.
3096 * @param transportType The transport type of the MmTelFeature capability.
3097 */
3098 @Override
3099 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3100 int transportType) {
3101 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3102 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3103 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3104 "IMS not available on device.");
3105 }
3106 final long token = Binder.clearCallingIdentity();
3107 try {
3108 int slotId = getSlotIndex(subId);
3109 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3110 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3111 + subId + "'");
3112 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3113 }
3114 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3115 transportType, aBoolean -> {
3116 try {
3117 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3118 } catch (RemoteException e) {
3119 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3120 + "running. Ignore");
3121 }
3122 });
3123 } finally {
3124 Binder.restoreCallingIdentity(token);
3125 }
3126 }
3127
Brad Ebinger35c841c2018-10-01 10:40:55 -07003128 @Override
3129 public boolean isAdvancedCallingSettingEnabled(int subId) {
3130 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3131 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3132 final long token = Binder.clearCallingIdentity();
3133 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003134 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003136 } catch (ImsException e) {
3137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 } finally {
3139 Binder.restoreCallingIdentity(token);
3140 }
3141 }
3142
3143 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003144 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003146 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003150 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003152 } catch (ImsException e) {
3153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
3159 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003160 public boolean isVtSettingEnabled(int subId) {
3161 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003165 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3166 } catch (ImsException e) {
3167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003168 } finally {
3169 Binder.restoreCallingIdentity(identity);
3170 }
3171 }
3172
3173 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003174 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003176 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003181 } catch (ImsException e) {
3182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 }
3187
3188 @Override
3189 public boolean isVoWiFiSettingEnabled(int subId) {
3190 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3191 final long identity = Binder.clearCallingIdentity();
3192 try {
3193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003194 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003195 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003196 } catch (ImsException e) {
3197 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003204 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003206 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003210 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(identity);
3215 }
3216 }
3217
3218 @Override
3219 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3220 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003226 } catch (ImsException e) {
3227 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 } finally {
3229 Binder.restoreCallingIdentity(identity);
3230 }
3231 }
3232
3233 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003234 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003236 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003240 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 } catch (ImsException e) {
3243 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 } finally {
3245 Binder.restoreCallingIdentity(identity);
3246 }
3247 }
3248
3249 @Override
3250 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3252 "setVoWiFiNonPersistent");
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003256 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003257 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003258 } catch (ImsException e) {
3259 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003260 } finally {
3261 Binder.restoreCallingIdentity(identity);
3262 }
3263 }
3264
3265 @Override
3266 public int getVoWiFiModeSetting(int subId) {
3267 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3268 final long identity = Binder.clearCallingIdentity();
3269 try {
3270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003273 } catch (ImsException e) {
3274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 } finally {
3276 Binder.restoreCallingIdentity(identity);
3277 }
3278 }
3279
3280 @Override
3281 public void setVoWiFiModeSetting(int subId, int mode) {
3282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3283 "setVoWiFiModeSetting");
3284 final long identity = Binder.clearCallingIdentity();
3285 try {
3286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003287 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003289 } catch (ImsException e) {
3290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
3297 public int getVoWiFiRoamingModeSetting(int subId) {
3298 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
3312 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3314 "setVoWiFiRoamingModeSetting");
3315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003318 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003320 } catch (ImsException e) {
3321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
3328 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3330 "setRttCapabilityEnabled");
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3335 } catch (ImsException e) {
3336 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003337 } finally {
3338 Binder.restoreCallingIdentity(identity);
3339 }
3340 }
3341
3342 @Override
3343 public boolean isTtyOverVolteEnabled(int subId) {
3344 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003349 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003350 } catch (ImsException e) {
3351 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 } finally {
3353 Binder.restoreCallingIdentity(identity);
3354 }
3355 }
3356
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003357 @Override
3358 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3359 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3360 final long identity = Binder.clearCallingIdentity();
3361 try {
3362 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003363 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003364 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003365 } catch (ImsException e) {
3366 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
3370 }
3371
3372 @Override
3373 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3374 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3375 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003376 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3377 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3378 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003379 try {
3380 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003381 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003382 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003383 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003384 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3385 + "is inactive, ignoring unregister.");
3386 // If the subscription is no longer active, just return, since the callback will already
3387 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 } finally {
3389 Binder.restoreCallingIdentity(identity);
3390 }
3391 }
3392
3393 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003394 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3395 boolean isProvisioned) {
3396 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3397 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3398 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3399 }
3400 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3401 "setProvisioningStatusForCapability");
3402 final long identity = Binder.clearCallingIdentity();
3403 try {
3404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3405 Phone phone = getPhone(subId);
3406 if (phone == null) {
3407 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3408 + subId);
3409 return;
3410 }
3411 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3412 return;
3413 }
3414
3415 // this capability requires provisioning, route to the correct API.
3416 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3417 switch (capability) {
3418 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3419 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3420 ims.setVolteProvisioned(isProvisioned);
3421 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3422 ims.setWfcProvisioned(isProvisioned);
3423 }
3424 break;
3425 }
3426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3427 // There is currently no difference in VT provisioning type.
3428 ims.setVtProvisioned(isProvisioned);
3429 break;
3430 }
3431 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3432 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3433 // change the capability of the feature instead if needed.
3434 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3435 == isProvisioned) {
3436 // No change in provisioning.
3437 return;
3438 }
3439 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3440 try {
3441 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003443 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3444 + ", Exception" + e.getMessage());
3445 }
3446 break;
3447 }
3448 default: {
3449 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3450 + capability + "', which does not require provisioning.");
3451 }
3452 }
3453
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
3456 }
3457 }
3458
3459 @Override
3460 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3461 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3462 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3463 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3464 }
3465 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3469 Phone phone = getPhone(subId);
3470 if (phone == null) {
3471 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3472 + subId);
3473 // We will fail with "true" as the provisioning status because this is the default
3474 // if we do not require provisioning.
3475 return true;
3476 }
3477
3478 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3479 return true;
3480 }
3481
3482 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3483 switch (capability) {
3484 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3485 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3486 return ims.isVolteProvisionedOnDevice();
3487 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3488 return ims.isWfcProvisionedOnDevice();
3489 }
3490 // This should never happen, since we are checking tech above to make sure it
3491 // is either LTE or IWLAN.
3492 throw new IllegalArgumentException("Invalid radio technology for voice "
3493 + "capability.");
3494 }
3495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3496 // There is currently no difference in VT provisioning type.
3497 return ims.isVtProvisionedOnDevice();
3498 }
3499 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3500 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3501 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3502 }
3503 default: {
3504 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3505 + capability + "', which does not require provisioning.");
3506 }
3507 }
3508
3509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
3512 }
3513
3514 @Override
3515 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3516 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3517 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3518 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3519 }
3520 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3521 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3522 return (provisionedBits & capability) > 0;
3523 }
3524
3525 @Override
3526 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3527 boolean isProvisioned) {
3528 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3529 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3530 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3531 }
3532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3533 "setProvisioningStatusForCapability");
3534 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3535 // If the current provisioning status for capability already matches isProvisioned,
3536 // do nothing.
3537 if (((provisionedBits & capability) > 0) == isProvisioned) {
3538 return;
3539 }
3540 if (isProvisioned) {
3541 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3542 } else {
3543 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3544 }
3545 }
3546
3547 /**
3548 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3549 * technology. The bitfield should mirror the bitfield defined by
3550 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3551 */
3552 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3553 String key = getMmTelProvisioningKey(subId, tech);
3554 // Default is no capabilities are provisioned.
3555 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3556 }
3557
3558 /**
3559 * Sets the MmTel capability provisioning bitfield (defined by
3560 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3561 * technology specified.
3562 *
3563 * Note: This is a synchronous command and should not be called on UI thread.
3564 */
3565 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3566 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3567 String key = getMmTelProvisioningKey(subId, tech);
3568 editor.putInt(key, newField);
3569 editor.commit();
3570 }
3571
3572 private static String getMmTelProvisioningKey(int subId, int tech) {
3573 // resulting key is provision_ims_mmtel_{subId}_{tech}
3574 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3575 }
3576
3577 /**
3578 * Query CarrierConfig to see if the specified capability requires provisioning for the
3579 * carrier associated with the subscription id.
3580 */
3581 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3582 int capability) {
3583 CarrierConfigManager configManager = new CarrierConfigManager(context);
3584 PersistableBundle c = configManager.getConfigForSubId(subId);
3585 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003586 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003587 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3588 false);
3589 boolean requireVoiceVtProvisioning = c.getBoolean(
3590 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3591
3592 // First check to make sure that the capability requires provisioning.
3593 switch (capability) {
3594 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3595 // intentional fallthrough
3596 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3597 if (requireVoiceVtProvisioning) {
3598 // Voice and Video requires provisioning
3599 return true;
3600 }
3601 break;
3602 }
3603 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3604 if (requireUtProvisioning) {
3605 // UT requires provisioning
3606 return true;
3607 }
3608 break;
3609 }
3610 }
3611 return false;
3612 }
3613
3614 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003615 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3617 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3618 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003619 enforceReadPrivilegedPermission("getImsProvisioningInt");
3620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003623 int slotId = getSlotIndex(subId);
3624 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3625 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3626 + subId + "' for key:" + key);
3627 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3628 }
3629 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003630 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003631 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3632 + subId + "' for key:" + key);
3633 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
3637 }
3638
3639 @Override
3640 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3642 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3643 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003644 enforceReadPrivilegedPermission("getImsProvisioningString");
3645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003648 int slotId = getSlotIndex(subId);
3649 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3650 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3651 + subId + "' for key:" + key);
3652 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3653 }
3654 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003655 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003656 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3657 + subId + "' for key:" + key);
3658 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003659 } finally {
3660 Binder.restoreCallingIdentity(identity);
3661 }
3662 }
3663
3664 @Override
3665 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003666 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3667 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3668 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3670 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003674 int slotId = getSlotIndex(subId);
3675 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3676 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3677 + subId + "' for key:" + key);
3678 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3679 }
3680 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003681 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003682 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3683 + "' for key:" + key);
3684 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
3688 }
3689
3690 @Override
3691 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3693 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3694 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3696 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 int slotId = getSlotIndex(subId);
3701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3702 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3703 + subId + "' for key:" + key);
3704 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3705 }
3706 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003707 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3709 + "' for key:" + key);
3710 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 int slotId = SubscriptionManager.getSlotIndex(subId);
3718 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3720 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 }
3722 return slotId;
3723 }
3724
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 private int getSlotIndex(int subId) {
3726 int slotId = SubscriptionManager.getSlotIndex(subId);
3727 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3728 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3729 }
3730 return slotId;
3731 }
3732
Wink Saville36469e72014-06-11 15:17:00 -07003733 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003734 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003735 */
3736 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003737 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003738 final int targetSdk = getTargetSdk(callingPackage);
3739 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3740 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3741 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003742 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3743 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003744 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3745 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 final Phone phone = getPhone(subId);
3750 if (phone != null) {
3751 return phone.getServiceState().getDataNetworkType();
3752 } else {
3753 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3754 }
3755 } finally {
3756 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003757 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003758 }
3759
3760 /**
3761 * Returns the data network type
3762 */
3763 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003764 public int getDataNetworkType(String callingPackage) {
3765 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003766 }
3767
3768 /**
3769 * Returns the data network type for a subId
3770 */
3771 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003773 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003774 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003775 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3776 }
3777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 final long identity = Binder.clearCallingIdentity();
3779 try {
3780 final Phone phone = getPhone(subId);
3781 if (phone != null) {
3782 return phone.getServiceState().getDataNetworkType();
3783 } else {
3784 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3785 }
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003789 }
3790
3791 /**
Wink Saville36469e72014-06-11 15:17:00 -07003792 * Returns the Voice network type for a subId
3793 */
3794 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003795 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003796 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003797 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003798 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3799 }
3800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 final Phone phone = getPhone(subId);
3804 if (phone != null) {
3805 return phone.getServiceState().getVoiceNetworkType();
3806 } else {
3807 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3808 }
3809 } finally {
3810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003812 }
3813
3814 /**
3815 * @return true if a ICC card is present
3816 */
3817 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003818 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003819 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3820 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003821 }
3822
3823 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003824 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003825 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003826 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003827 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003828 final long identity = Binder.clearCallingIdentity();
3829 try {
3830 final Phone phone = PhoneFactory.getPhone(slotIndex);
3831 if (phone != null) {
3832 return phone.getIccCard().hasIccCard();
3833 } else {
3834 return false;
3835 }
3836 } finally {
3837 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003838 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003839 }
3840
3841 /**
3842 * Return if the current radio is LTE on CDMA. This
3843 * is a tri-state return value as for a period of time
3844 * the mode may be unknown.
3845 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003846 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003847 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003848 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003849 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003850 @Override
3851 public int getLteOnCdmaMode(String callingPackage) {
3852 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003853 }
3854
Sanket Padawe356d7632015-06-22 14:03:32 -07003855 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003856 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003858 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003859 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3860 }
3861
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003862 final long identity = Binder.clearCallingIdentity();
3863 try {
3864 final Phone phone = getPhone(subId);
3865 if (phone == null) {
3866 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3867 } else {
3868 return phone.getLteOnCdmaMode();
3869 }
3870 } finally {
3871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003872 }
Wink Saville36469e72014-06-11 15:17:00 -07003873 }
3874
Wink Saville36469e72014-06-11 15:17:00 -07003875 /**
3876 * {@hide}
3877 * Returns Default subId, 0 in the case of single standby.
3878 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003879 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003880 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003881 }
3882
Shishir Agrawala9f32182016-04-12 12:00:16 -07003883 private int getSlotForDefaultSubscription() {
3884 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3885 }
3886
Wink Savilleb564aae2014-10-23 10:18:09 -07003887 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003888 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003889 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003890
Pengquan Menge92a50d2018-09-21 15:54:48 -07003891 private boolean isActiveSubscription(int subId) {
3892 return mSubscriptionController.isActiveSubId(subId);
3893 }
3894
Ihab Awadf2177b72013-11-25 13:33:23 -08003895 /**
3896 * @see android.telephony.TelephonyManager.WifiCallingChoices
3897 */
3898 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 final long identity = Binder.clearCallingIdentity();
3900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003901 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3903 getWhenToMakeWifiCallsDefaultPreference());
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
3906 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003907 }
3908
3909 /**
3910 * @see android.telephony.TelephonyManager.WifiCallingChoices
3911 */
3912 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003916 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
3920 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003921 }
3922
Sailesh Nepald1e68152013-12-12 19:08:02 -08003923 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003924 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003925 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003926 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003927
Jordan Liu4c733742019-02-28 12:03:40 -08003928 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3929 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3930 if (phoneId == -1) {
3931 throw new IllegalArgumentException("Given slot index: " + slotIndex
3932 + " does not correspond to an active phone");
3933 }
3934 return PhoneFactory.getPhone(phoneId);
3935 }
3936
Shishir Agrawal566b7612013-10-28 14:41:00 -07003937 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003938 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3939 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3941 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003943 if (DBG) {
3944 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3945 }
3946 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3947 p2);
3948 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003949
Jordan Liu4c733742019-02-28 12:03:40 -08003950
3951 @Override
3952 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3953 int slotIndex, String callingPackage, String aid, int p2) {
3954 enforceModifyPermission();
3955 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3956 if (DBG) {
3957 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3958 }
3959 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3960 callingPackage, aid, p2);
3961 }
3962
3963 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3964 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003965 final long identity = Binder.clearCallingIdentity();
3966 try {
3967 if (TextUtils.equals(ISDR_AID, aid)) {
3968 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3970 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 if (bestComponent == null
3972 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3973 loge("The calling package is not allowed to access ISD-R.");
3974 throw new SecurityException(
3975 "The calling package is not allowed to access ISD-R.");
3976 }
Derek Tan740e1672017-06-27 14:56:27 -07003977 }
Derek Tan740e1672017-06-27 14:56:27 -07003978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003980 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3981 null /* workSource */);
3982 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003983 return response;
3984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003987 }
3988
3989 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003990 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3992 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003993 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3994 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3995 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003996
Jordan Liu4c733742019-02-28 12:03:40 -08003997 @Override
3998 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3999 enforceModifyPermission();
4000 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4001 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4002 channel);
4003 }
4004
4005 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 final long identity = Binder.clearCallingIdentity();
4007 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004008 if (channel < 0) {
4009 return false;
4010 }
Jordan Liu4c733742019-02-28 12:03:40 -08004011 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4012 null /* workSource */);
4013 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 return success;
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004017 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004018 }
4019
4020 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004021 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004022 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4024 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004025 if (DBG) {
4026 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4027 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4028 + p3 + " data=" + data);
4029 }
4030 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4031 command, p1, p2, p3, data);
4032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004033
Jordan Liu4c733742019-02-28 12:03:40 -08004034 @Override
4035 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4036 int command, int p1, int p2, int p3, String data) {
4037 enforceModifyPermission();
4038 if (DBG) {
4039 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4040 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4041 + p3 + " data=" + data);
4042 }
4043 return iccTransmitApduLogicalChannelWithPermission(
4044 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4045 data);
4046 }
4047
4048 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4049 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004052 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 return "";
4054 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004057 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4058 null /* workSource */);
4059 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 // Append the returned status code to the end of the response payload.
4062 String s = Integer.toHexString(
4063 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4064 if (response.payload != null) {
4065 s = IccUtils.bytesToHexString(response.payload) + s;
4066 }
4067 return s;
4068 } finally {
4069 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004070 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004071 }
Jake Hambye994d462014-02-03 13:10:13 -08004072
Evan Charltonc66da362014-05-16 14:06:40 -07004073 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004074 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4075 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4077 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004079 if (DBG) {
4080 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4081 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4082 }
4083 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4084 cla, command, p1, p2, p3, data);
4085 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004086
Jordan Liu4c733742019-02-28 12:03:40 -08004087 @Override
4088 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4089 int command, int p1, int p2, int p3, String data) {
4090 enforceModifyPermission();
4091 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4092 if (DBG) {
4093 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4094 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4095 + " data=" + data);
4096 }
4097
4098 return iccTransmitApduBasicChannelWithPermission(
4099 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4100 p2, p3, data);
4101 }
4102
4103 // open APDU basic channel assuming the caller has sufficient permissions
4104 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4105 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4109 && TextUtils.equals(ISDR_AID, data)) {
4110 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004111 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4112 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 if (bestComponent == null
4114 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4115 loge("The calling package is not allowed to select ISD-R.");
4116 throw new SecurityException(
4117 "The calling package is not allowed to select ISD-R.");
4118 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004119 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004122 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4123 null /* workSource */);
4124 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004126 // Append the returned status code to the end of the response payload.
4127 String s = Integer.toHexString(
4128 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4129 if (response.payload != null) {
4130 s = IccUtils.bytesToHexString(response.payload) + s;
4131 }
4132 return s;
4133 } finally {
4134 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004135 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004136 }
4137
4138 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004139 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004140 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4142 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 if (DBG) {
4147 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4148 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4149 }
4150
4151 IccIoResult response =
4152 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4153 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4154 subId);
4155
4156 if (DBG) {
4157 log("Exchange SIM_IO [R]" + response);
4158 }
4159
4160 byte[] result = null;
4161 int length = 2;
4162 if (response.payload != null) {
4163 length = 2 + response.payload.length;
4164 result = new byte[length];
4165 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4166 } else {
4167 result = new byte[length];
4168 }
4169
4170 result[length - 1] = (byte) response.sw2;
4171 result[length - 2] = (byte) response.sw1;
4172 return result;
4173 } finally {
4174 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004175 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004176 }
4177
Nathan Haroldb3014052017-01-25 15:57:32 -08004178 /**
4179 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4180 * on a particular subscription
4181 */
sqianb6e41952018-03-12 14:54:01 -07004182 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4184 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4185 return null;
4186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004187
4188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 if (appType != TelephonyManager.APPTYPE_USIM
4191 && appType != TelephonyManager.APPTYPE_SIM) {
4192 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4193 return null;
4194 }
4195 Object response = sendRequest(
4196 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4197 if (response instanceof String[]) {
4198 return (String[]) response;
4199 }
yincheng zhaod698b842019-09-06 17:06:54 -07004200 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004202 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004205 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004206 }
4207
yincheng zhaod698b842019-09-06 17:06:54 -07004208 /**
4209 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4210 * subscription.
4211 *
4212 * @param subId the id of the subscription.
4213 * @param appType the uicc app type, must be USIM or SIM.
4214 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4215 * @param callingPackage the op Package name.
4216 * @return number of fplmns that is successfully written to the SIM.
4217 */
4218 public int setForbiddenPlmns(
4219 int subId, int appType, List<String> fplmns, String callingPackage) {
4220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4221 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4222 if (DBG) logv("no permissions for setForbiddenplmns");
4223 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4224 }
4225 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4226 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4227 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4228 }
4229 if (fplmns == null) {
4230 throw new IllegalArgumentException("Fplmn List provided is null");
4231 }
4232 for (String fplmn : fplmns) {
4233 if (!CellIdentity.isValidPlmn(fplmn)) {
4234 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4235 }
4236 }
4237 final long identity = Binder.clearCallingIdentity();
4238 try {
4239 Object response = sendRequest(
4240 CMD_SET_FORBIDDEN_PLMNS,
4241 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4242 subId);
4243 return (int) response;
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004249 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004250 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4252 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
4256 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4257 if (response.payload == null) {
4258 return "";
4259 }
Evan Charltonc66da362014-05-16 14:06:40 -07004260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 // Append the returned status code to the end of the response payload.
4262 String s = Integer.toHexString(
4263 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4264 s = IccUtils.bytesToHexString(response.payload) + s;
4265 return s;
4266 } finally {
4267 Binder.restoreCallingIdentity(identity);
4268 }
Evan Charltonc66da362014-05-16 14:06:40 -07004269 }
4270
Jake Hambye994d462014-02-03 13:10:13 -08004271 /**
4272 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4273 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4274 *
4275 * @param itemID the ID of the item to read
4276 * @return the NV item as a String, or null on error.
4277 */
4278 @Override
4279 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004280 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4282 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004287 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004288 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4289 return value;
4290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Jake Hambye994d462014-02-03 13:10:13 -08004293 }
4294
4295 /**
4296 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4297 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4298 *
4299 * @param itemID the ID of the item to read
4300 * @param itemValue the value to write, as a String
4301 * @return true on success; false on any failure
4302 */
4303 @Override
4304 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4307 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004308
4309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4312 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004313 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004314 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4315 return success;
4316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Jake Hambye994d462014-02-03 13:10:13 -08004319 }
4320
4321 /**
4322 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4323 * Used for device configuration by some CDMA operators.
4324 *
4325 * @param preferredRoamingList byte array containing the new PRL
4326 * @return true on success; false on any failure
4327 */
4328 @Override
4329 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4331 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332
4333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4336 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4337 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4338 return success;
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Jake Hambye994d462014-02-03 13:10:13 -08004342 }
4343
4344 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004345 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004346 * Used for device configuration by some CDMA operators.
4347 *
chen xu6dac5ab2018-10-26 17:39:23 -07004348 * @param slotIndex - device slot.
4349 *
Jake Hambye994d462014-02-03 13:10:13 -08004350 * @return true on success; false on any failure
4351 */
4352 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004353 public boolean resetModemConfig(int slotIndex) {
4354 Phone phone = PhoneFactory.getPhone(slotIndex);
4355 if (phone != null) {
4356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358
chen xu6dac5ab2018-10-26 17:39:23 -07004359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4362 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4363 return success;
4364 } finally {
4365 Binder.restoreCallingIdentity(identity);
4366 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367 }
chen xu6dac5ab2018-10-26 17:39:23 -07004368 return false;
4369 }
4370
4371 /**
4372 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4373 *
4374 * @param slotIndex - device slot.
4375 *
4376 * @return true on success; false on any failure
4377 */
4378 @Override
4379 public boolean rebootModem(int slotIndex) {
4380 Phone phone = PhoneFactory.getPhone(slotIndex);
4381 if (phone != null) {
4382 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4383 mApp, phone.getSubId(), "rebootModem");
4384
4385 final long identity = Binder.clearCallingIdentity();
4386 try {
4387 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4388 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4389 return success;
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
4393 }
4394 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004395 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004396
Svet Ganovb320e182015-04-16 12:30:10 -07004397 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004398 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004400 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004401 return new String[0];
4402 }
4403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 final long identity = Binder.clearCallingIdentity();
4405 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004406 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Wink Saville36469e72014-06-11 15:17:00 -07004410 }
4411
Brad Ebinger51f743a2017-01-23 13:50:20 -08004412 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004413 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4414 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004415 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004416 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004417 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004421 ImsResolver resolver = PhoneFactory.getImsResolver();
4422 if (resolver == null) {
4423 // may happen if the device does not support IMS.
4424 return;
4425 }
4426 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004430 }
4431
4432 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004433 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4434 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004435 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004436 public void disableIms(int slotId) {
4437 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004438
4439 final long identity = Binder.clearCallingIdentity();
4440 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004441 ImsResolver resolver = PhoneFactory.getImsResolver();
4442 if (resolver == null) {
4443 // may happen if the device does not support IMS.
4444 return;
4445 }
4446 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 } finally {
4448 Binder.restoreCallingIdentity(identity);
4449 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004450 }
4451
4452 /**
4453 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4454 * feature or {@link null} if the service is not available. If the feature is available, the
4455 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4456 */
4457 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004458 IImsServiceFeatureCallback callback) {
4459 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004460
4461 final long identity = Binder.clearCallingIdentity();
4462 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004463 ImsResolver resolver = PhoneFactory.getImsResolver();
4464 if (resolver == null) {
4465 // may happen if the device does not support IMS.
4466 return null;
4467 }
4468 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004472 }
4473
4474 /**
4475 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4476 * feature during emergency calling or {@link null} if the service is not available. If the
4477 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4478 * listener for feature updates.
4479 */
4480 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4481 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482
4483 final long identity = Binder.clearCallingIdentity();
4484 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004485 ImsResolver resolver = PhoneFactory.getImsResolver();
4486 if (resolver == null) {
4487 // may happen if the device does not support IMS.
4488 return null;
4489 }
4490 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004494 }
4495
Brad Ebinger5f64b052017-12-14 14:26:15 -08004496 /**
4497 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004498 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004499 */
4500 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4501 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502
4503 final long identity = Binder.clearCallingIdentity();
4504 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004505 ImsResolver resolver = PhoneFactory.getImsResolver();
4506 if (resolver == null) {
4507 // may happen if the device does not support IMS.
4508 return null;
4509 }
4510 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511 } finally {
4512 Binder.restoreCallingIdentity(identity);
4513 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004514 }
4515
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004516 /**
4517 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004518 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004519 */
4520 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4521 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522
4523 final long identity = Binder.clearCallingIdentity();
4524 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004525 ImsResolver resolver = PhoneFactory.getImsResolver();
4526 if (resolver == null) {
4527 // may happen if the device does not support IMS.
4528 return null;
4529 }
4530 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004534 }
4535
Brad Ebinger884c07b2018-02-15 16:17:40 -08004536 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004537 * Sets the ImsService Package Name that Telephony will bind to.
4538 *
4539 * @param slotId the slot ID that the ImsService should bind for.
4540 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4541 * ImsService is the device default ImsService.
4542 * @param packageName The package name of the application that contains the ImsService to bind
4543 * to.
4544 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4545 * @hide
4546 */
4547 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004548 int[] subIds = SubscriptionManager.getSubId(slotId);
4549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4550 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4551 "setImsService");
4552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004555 ImsResolver resolver = PhoneFactory.getImsResolver();
4556 if (resolver == null) {
4557 // may happen if the device does not support IMS.
4558 return false;
4559 }
4560 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4561 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 } finally {
4563 Binder.restoreCallingIdentity(identity);
4564 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004565 }
4566
4567 /**
4568 * Return the ImsService configuration.
4569 *
4570 * @param slotId The slot that the ImsService is associated with.
4571 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4572 * the device default.
4573 * @return the package name of the ImsService configuration.
4574 */
4575 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004576 int[] subIds = SubscriptionManager.getSubId(slotId);
4577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4578 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4579 "getImsService");
4580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 final long identity = Binder.clearCallingIdentity();
4582 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004583 ImsResolver resolver = PhoneFactory.getImsResolver();
4584 if (resolver == null) {
4585 // may happen if the device does not support IMS.
4586 return "";
4587 }
4588 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004592 }
4593
Brad Ebinger77b832e2019-10-17 17:03:22 -07004594 /**
4595 * Get the MmTelFeature state associated with the requested subscription id.
4596 * @param subId The subscription that the MmTelFeature is associated with.
4597 * @param callback A callback with an integer containing the
4598 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4599 */
4600 @Override
4601 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4602 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4603 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4604 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4605 "IMS not available on device.");
4606 }
4607 final long token = Binder.clearCallingIdentity();
4608 try {
4609 int slotId = getSlotIndex(subId);
4610 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4611 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4612 + subId + "'");
4613 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4614 }
4615 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4616 try {
4617 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4618 } catch (RemoteException e) {
4619 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4620 + "Ignore");
4621 }
4622 });
4623 } finally {
4624 Binder.restoreCallingIdentity(token);
4625 }
4626 }
4627
Wink Saville36469e72014-06-11 15:17:00 -07004628 public void setImsRegistrationState(boolean registered) {
4629 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630
4631 final long identity = Binder.clearCallingIdentity();
4632 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004633 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
Wink Saville36469e72014-06-11 15:17:00 -07004637 }
4638
4639 /**
Stuart Scott54788802015-03-30 13:18:01 -07004640 * Set the network selection mode to automatic.
4641 *
4642 */
4643 @Override
4644 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4646 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004647
Pengquan Menge92a50d2018-09-21 15:54:48 -07004648 if (!isActiveSubscription(subId)) {
4649 return;
4650 }
4651
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 final long identity = Binder.clearCallingIdentity();
4653 try {
4654 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4655 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
4658 }
Stuart Scott54788802015-03-30 13:18:01 -07004659 }
4660
Pengquan Mengea84e042018-09-20 14:57:26 -07004661 /**
4662 * Ask the radio to connect to the input network and change selection mode to manual.
4663 *
4664 * @param subId the id of the subscription.
4665 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4666 * the operator to attach to.
4667 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4668 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4669 * normal network selection next time.
4670 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004671 */
4672 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004673 public boolean setNetworkSelectionModeManual(
4674 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4676 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004677
4678 if (!isActiveSubscription(subId)) {
4679 return false;
4680 }
4681
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 final long identity = Binder.clearCallingIdentity();
4683 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004684 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004686 if (DBG) {
4687 log("setNetworkSelectionModeManual: subId: " + subId
4688 + " operator: " + operatorInfo);
4689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004694 }
4695
4696 /**
4697 * Scans for available networks.
4698 */
4699 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004700 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4702 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004703 LocationAccessPolicy.LocationPermissionResult locationResult =
4704 LocationAccessPolicy.checkLocationPermission(mApp,
4705 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4706 .setCallingPackage(callingPackage)
4707 .setCallingPid(Binder.getCallingPid())
4708 .setCallingUid(Binder.getCallingUid())
4709 .setMethod("getCellNetworkScanResults")
4710 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4711 .build());
4712 switch (locationResult) {
4713 case DENIED_HARD:
4714 throw new SecurityException("Not allowed to access scan results -- location");
4715 case DENIED_SOFT:
4716 return null;
4717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718
Pengquan Menga1bb6272018-09-06 09:59:22 -07004719 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 try {
4721 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004722 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
4726 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004727 }
4728
4729 /**
yinxub1bed742017-04-17 11:45:04 -07004730 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004731 *
yinxub1bed742017-04-17 11:45:04 -07004732 * @param subId id of the subscription
4733 * @param request contains the radio access networks with bands/channels to scan
4734 * @param messenger callback messenger for scan results or errors
4735 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004736 * @return the id of the requested scan which can be used to stop the scan.
4737 */
4738 @Override
4739 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004740 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4742 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004743 LocationAccessPolicy.LocationPermissionResult locationResult =
4744 LocationAccessPolicy.checkLocationPermission(mApp,
4745 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4746 .setCallingPackage(callingPackage)
4747 .setCallingPid(Binder.getCallingPid())
4748 .setCallingUid(Binder.getCallingUid())
4749 .setMethod("requestNetworkScan")
4750 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4751 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004752 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004753 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004754 if (e != null) {
4755 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4756 throw e;
4757 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004758 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004759 return TelephonyScanManager.INVALID_SCAN_ID;
4760 }
4761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004762 }
Hall Liu912dfd32019-04-25 14:02:26 -07004763 int callingUid = Binder.getCallingUid();
4764 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 return mNetworkScanRequestTracker.startNetworkScan(
4768 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004769 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004770 } finally {
4771 Binder.restoreCallingIdentity(identity);
4772 }
yinxu504e1392017-04-12 16:03:22 -07004773 }
4774
Hall Liub2ac8ef2019-02-28 15:56:23 -08004775 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004776 NetworkScanRequest request, int subId) {
4777 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4778 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4779 boolean hasNetworkScanPermission =
4780 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4781 == PERMISSION_GRANTED;
4782
4783 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4784 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4785 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004786 }
4787
4788 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4789 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004790 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4791 return new SecurityException("Specific channels must not be"
4792 + " scanned without location access.");
4793 }
4794 }
4795 }
4796
Hall Liub2ac8ef2019-02-28 15:56:23 -08004797 return null;
4798 }
4799
yinxu504e1392017-04-12 16:03:22 -07004800 /**
4801 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004802 *
4803 * @param subId id of the subscription
4804 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004805 */
4806 @Override
4807 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004808 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4809 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810
Hall Liu912dfd32019-04-25 14:02:26 -07004811 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 final long identity = Binder.clearCallingIdentity();
4813 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004814 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
yinxu504e1392017-04-12 16:03:22 -07004818 }
4819
4820 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004821 * Get the calculated preferred network type.
4822 * Used for debugging incorrect network type.
4823 *
4824 * @return the preferred network type, defined in RILConstants.java.
4825 */
4826 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004827 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004828 final Phone defaultPhone = getDefaultPhone();
4829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4830 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004831 return RILConstants.PREFERRED_NETWORK_MODE;
4832 }
4833
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004837 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Junda Liu84d15a22014-07-02 11:21:04 -07004841 }
4842
4843 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004844 * Get the preferred network type.
4845 * Used for device configuration by some CDMA operators.
4846 *
4847 * @return the preferred network type, defined in RILConstants.java.
4848 */
4849 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004850 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004851 TelephonyPermissions
4852 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4853 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 if (DBG) log("getPreferredNetworkType");
4858 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4859 int networkType = (result != null ? result[0] : -1);
4860 if (DBG) log("getPreferredNetworkType: " + networkType);
4861 return networkType;
4862 } finally {
4863 Binder.restoreCallingIdentity(identity);
4864 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004865 }
4866
4867 /**
4868 * Set the preferred network type.
4869 * Used for device configuration by some CDMA operators.
4870 *
4871 * @param networkType the preferred network type, defined in RILConstants.java.
4872 * @return true on success; false on any failure.
4873 */
4874 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004875 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4877 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878
4879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4882 Boolean success = (Boolean) sendRequest(
4883 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4884 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4885 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004886 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004887 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4888 }
4889 return success;
4890 } finally {
4891 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004892 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004893 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004894
4895 /**
Miaoa84611c2019-03-15 09:21:10 +08004896 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004897 *
Miaoa84611c2019-03-15 09:21:10 +08004898 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004899 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004900 * @hide
4901 */
4902 @Override
SongFerngWangd381c3a2019-11-07 17:27:26 +08004903 public boolean isTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004904 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004905 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907 try {
Miaoa84611c2019-03-15 09:21:10 +08004908 if (phone != null) {
4909 return phone.hasMatchedTetherApnSetting();
4910 } else {
4911 return false;
4912 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 } finally {
4914 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004915 }
Junda Liu475951f2014-11-07 16:45:03 -08004916 }
4917
4918 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004919 * Set mobile data enabled
4920 * Used by the user through settings etc to turn on/off mobile data
4921 *
4922 * @param enable {@code true} turn turn data on, else {@code false}
4923 */
4924 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004925 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4927 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928
4929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 int phoneId = mSubscriptionController.getPhoneId(subId);
4932 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4933 Phone phone = PhoneFactory.getPhone(phoneId);
4934 if (phone != null) {
4935 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004936 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004938 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 }
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004942 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004943 }
4944
4945 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004946 * Get the user enabled state of Mobile Data.
4947 *
4948 * TODO: remove and use isUserDataEnabled.
4949 * This can't be removed now because some vendor codes
4950 * calls through ITelephony directly while they should
4951 * use TelephonyManager.
4952 *
4953 * @return true on enabled
4954 */
4955 @Override
4956 public boolean getDataEnabled(int subId) {
4957 return isUserDataEnabled(subId);
4958 }
4959
4960 /**
4961 * Get whether mobile data is enabled per user setting.
4962 *
4963 * There are other factors deciding whether mobile data is actually enabled, but they are
4964 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004965 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004966 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004967 *
4968 * @return {@code true} if data is enabled else {@code false}
4969 */
4970 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004971 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004972 try {
4973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4974 null);
4975 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004976 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4977 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979
4980 final long identity = Binder.clearCallingIdentity();
4981 try {
4982 int phoneId = mSubscriptionController.getPhoneId(subId);
4983 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4984 Phone phone = PhoneFactory.getPhone(phoneId);
4985 if (phone != null) {
4986 boolean retVal = phone.isUserDataEnabled();
4987 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4988 return retVal;
4989 } else {
4990 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4991 return false;
4992 }
4993 } finally {
4994 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004995 }
4996 }
4997
4998 /**
4999 * Get whether mobile data is enabled.
5000 *
5001 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5002 * whether mobile data is actually enabled.
5003 *
5004 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5005 *
5006 * @return {@code true} if data is enabled else {@code false}
5007 */
5008 @Override
5009 public boolean isDataEnabled(int subId) {
5010 try {
5011 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5012 null);
5013 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005014 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5015 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005016 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
5020 int phoneId = mSubscriptionController.getPhoneId(subId);
5021 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5022 Phone phone = PhoneFactory.getPhone(phoneId);
5023 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005024 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5026 return retVal;
5027 } else {
5028 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5029 return false;
5030 }
5031 } finally {
5032 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005033 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005034 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005035
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005036 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5037 Phone phone) {
5038 //load access rules from carrier configs, and check those as well: b/139133814
5039 SubscriptionController subController = SubscriptionController.getInstance();
5040 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5041 || subController == null) return privilegeFromSim;
5042
5043 int uid = Binder.getCallingUid();
5044 PackageManager pkgMgr = phone.getContext().getPackageManager();
5045 String[] packages = pkgMgr.getPackagesForUid(uid);
5046
5047 final long identity = Binder.clearCallingIdentity();
5048 try {
5049 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5050 SubscriptionManager subManager = (SubscriptionManager)
5051 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5052 for (String pkg : packages) {
5053 if (subManager.canManageSubscription(subInfo, pkg)) {
5054 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5055 }
5056 }
5057 return privilegeFromSim;
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
5061 }
5062
5063 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5064 String pkgName) {
5065 //load access rules from carrier configs, and check those as well: b/139133814
5066 SubscriptionController subController = SubscriptionController.getInstance();
5067 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5068 || subController == null) return privilegeFromSim;
5069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
5072 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5073 SubscriptionManager subManager = (SubscriptionManager)
5074 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5075 return subManager.canManageSubscription(subInfo, pkgName)
5076 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
5080 }
5081
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005082 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005083 public int getCarrierPrivilegeStatus(int subId) {
5084 final Phone phone = getPhone(subId);
5085 if (phone == null) {
5086 loge("getCarrierPrivilegeStatus: Invalid subId");
5087 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5088 }
5089 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005090 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005091 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005092 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5093 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005094
5095 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5096 card.getCarrierPrivilegeStatusForCurrentTransaction(
5097 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005098 }
Junda Liu29340342014-07-10 15:23:27 -07005099
5100 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5102 final Phone phone = getPhone(subId);
5103 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005104 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005105 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5106 }
5107 UiccProfile profile =
5108 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5109 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005110 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005111 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5112 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005113 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5114 profile.getCarrierPrivilegeStatusForUid(
5115 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005116 }
5117
5118 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005119 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5120 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005121 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005122 }
5123
5124 int phoneId = SubscriptionManager.getPhoneId(subId);
5125 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005126 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005127 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5129 }
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005130 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5131 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5132 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005133 }
5134
5135 @Override
5136 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005137 if (TextUtils.isEmpty(pkgName))
5138 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005139 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5140 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5141 UiccCard card = UiccController.getInstance().getUiccCard(i);
5142 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005143 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005144 continue;
5145 }
5146
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005147 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5148 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5149 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005150 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5151 break;
5152 }
5153 }
5154
5155 return result;
Junda Liu29340342014-07-10 15:23:27 -07005156 }
Derek Tan89e89d42014-07-08 17:00:10 -07005157
5158 @Override
Junda Liue64de782015-04-16 17:19:16 -07005159 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5160 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5161 loge("phoneId " + phoneId + " is not valid.");
5162 return null;
5163 }
5164 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005165 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005166 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005167 return null ;
5168 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005169 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005170 }
5171
Amith Yamasani6e118872016-02-19 12:53:51 -08005172 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005173 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005174 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005175 List<String> privilegedPackages = new ArrayList<>();
5176 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005177 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5178 // has UICC in that slot.
5179 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005180 if (card.hasCarrierPrivilegeRules()) {
5181 if (packages == null) {
5182 // Only check packages in user 0 for now
5183 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi63d0a362019-08-19 16:29:37 -07005184 PackageManager.MATCH_DISABLED_COMPONENTS
5185 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
5186 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005187 }
5188 for (int p = packages.size() - 1; p >= 0; p--) {
5189 PackageInfo pkgInfo = packages.get(p);
5190 if (pkgInfo != null && pkgInfo.packageName != null
5191 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005192 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005193 privilegedPackages.add(pkgInfo.packageName);
5194 }
5195 }
5196 }
5197 }
5198 return privilegedPackages;
5199 }
5200
chen xuf7e9fe82019-05-09 19:31:02 -07005201 @Override
5202 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5203 List<String> privilegedPackages = new ArrayList<>();
5204 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5205 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5206 }
5207 return privilegedPackages;
5208 }
5209
Wink Savilleb564aae2014-10-23 10:18:09 -07005210 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005211 final Phone phone = getPhone(subId);
5212 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005213 if (card == null) {
5214 loge("getIccId: No UICC");
5215 return null;
5216 }
5217 String iccId = card.getIccId();
5218 if (TextUtils.isEmpty(iccId)) {
5219 loge("getIccId: ICC ID is null or empty.");
5220 return null;
5221 }
5222 return iccId;
5223 }
5224
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005225 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005226 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5227 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5229 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 final long identity = Binder.clearCallingIdentity();
5232 try {
5233 final String iccId = getIccId(subId);
5234 final Phone phone = getPhone(subId);
5235 if (phone == null) {
5236 return false;
5237 }
5238 final String subscriberId = phone.getSubscriberId();
5239
5240 if (DBG_MERGE) {
5241 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5242 + subscriberId + " to " + number);
5243 }
5244
5245 if (TextUtils.isEmpty(iccId)) {
5246 return false;
5247 }
5248
5249 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5250
5251 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5252 if (alphaTag == null) {
5253 editor.remove(alphaTagPrefKey);
5254 } else {
5255 editor.putString(alphaTagPrefKey, alphaTag);
5256 }
5257
5258 // Record both the line number and IMSI for this ICCID, since we need to
5259 // track all merged IMSIs based on line number
5260 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5261 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5262 if (number == null) {
5263 editor.remove(numberPrefKey);
5264 editor.remove(subscriberPrefKey);
5265 } else {
5266 editor.putString(numberPrefKey, number);
5267 editor.putString(subscriberPrefKey, subscriberId);
5268 }
5269
5270 editor.commit();
5271 return true;
5272 } finally {
5273 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005274 }
Derek Tan7226c842014-07-02 17:42:23 -07005275 }
5276
5277 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005278 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005279 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005280 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005281 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005282 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005283 return null;
5284 }
Derek Tan97ebb422014-09-05 16:55:38 -07005285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 final long identity = Binder.clearCallingIdentity();
5287 try {
5288 String iccId = getIccId(subId);
5289 if (iccId != null) {
5290 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5291 if (DBG_MERGE) {
5292 log("getLine1NumberForDisplay returning "
5293 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5294 }
5295 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5298 return null;
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005301 }
Derek Tan7226c842014-07-02 17:42:23 -07005302 }
5303
5304 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005305 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005307 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005308 return null;
5309 }
Derek Tan97ebb422014-09-05 16:55:38 -07005310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 final long identity = Binder.clearCallingIdentity();
5312 try {
5313 String iccId = getIccId(subId);
5314 if (iccId != null) {
5315 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5316 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5317 }
5318 return null;
5319 } finally {
5320 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005321 }
Derek Tan7226c842014-07-02 17:42:23 -07005322 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005323
5324 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005325 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005326 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5327 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005329 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5330 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005331 return null;
5332 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005333
Jordan Liub49b04b2019-05-06 14:45:15 -07005334 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5335 // the process, where TelephonyManager was instantiated.
5336 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005337 final long identity = Binder.clearCallingIdentity();
5338 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005339 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final TelephonyManager tele = TelephonyManager.from(context);
5341 final SubscriptionManager sub = SubscriptionManager.from(context);
5342
5343 // Figure out what subscribers are currently active
5344 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345
Jordan Liub49b04b2019-05-06 14:45:15 -07005346 // Only consider subs which match the current subId
5347 // This logic can be simplified. See b/131189269 for progress.
5348 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005349 activeSubscriberIds.add(tele.getSubscriberId(subId));
5350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 // First pass, find a number override for an active subscriber
5353 String mergeNumber = null;
5354 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5355 for (String key : prefs.keySet()) {
5356 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5357 final String subscriberId = (String) prefs.get(key);
5358 if (activeSubscriberIds.contains(subscriberId)) {
5359 final String iccId = key.substring(
5360 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5361 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5362 mergeNumber = (String) prefs.get(numberKey);
5363 if (DBG_MERGE) {
5364 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5365 + " for active subscriber " + subscriberId);
5366 }
5367 if (!TextUtils.isEmpty(mergeNumber)) {
5368 break;
5369 }
5370 }
5371 }
5372 }
5373
5374 // Shortcut when no active merged subscribers
5375 if (TextUtils.isEmpty(mergeNumber)) {
5376 return null;
5377 }
5378
5379 // Second pass, find all subscribers under that line override
5380 final ArraySet<String> result = new ArraySet<>();
5381 for (String key : prefs.keySet()) {
5382 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5383 final String number = (String) prefs.get(key);
5384 if (mergeNumber.equals(number)) {
5385 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5386 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5387 final String subscriberId = (String) prefs.get(subscriberKey);
5388 if (!TextUtils.isEmpty(subscriberId)) {
5389 result.add(subscriberId);
5390 }
5391 }
5392 }
5393 }
5394
5395 final String[] resultArray = result.toArray(new String[result.size()]);
5396 Arrays.sort(resultArray);
5397 if (DBG_MERGE) {
5398 Slog.d(LOG_TAG,
5399 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5400 }
5401 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005404 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005405 }
5406
5407 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005408 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5409 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 final TelephonyManager telephonyManager = mApp.getSystemService(
5414 TelephonyManager.class);
5415 String subscriberId = telephonyManager.getSubscriberId(subId);
5416 if (subscriberId == null) {
5417 if (DBG) {
5418 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5419 + subId);
5420 }
5421 return null;
5422 }
5423
5424 final SubscriptionInfo info = SubscriptionController.getInstance()
5425 .getSubscriptionInfo(subId);
5426 final ParcelUuid groupUuid = info.getGroupUuid();
5427 // If it doesn't belong to any group, return just subscriberId of itself.
5428 if (groupUuid == null) {
5429 return new String[]{subscriberId};
5430 }
5431
5432 // Get all subscriberIds from the group.
5433 final List<String> mergedSubscriberIds = new ArrayList<>();
5434 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5435 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5436 for (SubscriptionInfo subInfo : groupInfos) {
5437 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5438 if (subscriberId != null) {
5439 mergedSubscriberIds.add(subscriberId);
5440 }
5441 }
5442
5443 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446
5447 }
5448 }
5449
5450 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005451 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005452 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5453 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
5455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 final Phone phone = getPhone(subId);
5458 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5459 } finally {
5460 Binder.restoreCallingIdentity(identity);
5461 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005462 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005463
5464 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005465 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005466 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5467 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005468 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
5470 final long identity = Binder.clearCallingIdentity();
5471 try {
5472 final Phone phone = getPhone(subId);
5473 if (phone == null) {
5474 return false;
5475 }
5476 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5477 cdmaNonRoamingList);
5478 } finally {
5479 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005480 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005481 }
5482
5483 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005484 @Deprecated
5485 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5486 enforceModifyPermission();
5487
5488 int returnValue = 0;
5489 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005490 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005491 if(result.exception == null) {
5492 if (result.result != null) {
5493 byte[] responseData = (byte[])(result.result);
5494 if(responseData.length > oemResp.length) {
5495 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5496 responseData.length + "bytes. Buffer Size is " +
5497 oemResp.length + "bytes.");
5498 }
5499 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5500 returnValue = responseData.length;
5501 }
5502 } else {
5503 CommandException ex = (CommandException) result.exception;
5504 returnValue = ex.getCommandError().ordinal();
5505 if(returnValue > 0) returnValue *= -1;
5506 }
5507 } catch (RuntimeException e) {
5508 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5509 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5510 if(returnValue > 0) returnValue *= -1;
5511 }
5512
5513 return returnValue;
5514 }
5515
5516 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005517 public void setRadioCapability(RadioAccessFamily[] rafs) {
5518 try {
5519 ProxyController.getInstance().setRadioCapability(rafs);
5520 } catch (RuntimeException e) {
5521 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5522 }
5523 }
5524
5525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005526 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005527 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005528 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005529 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005530 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005531 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 final long identity = Binder.clearCallingIdentity();
5533 try {
chen xub97461a2018-10-26 14:17:57 -07005534 TelephonyPermissions
5535 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5536 mApp, phone.getSubId(), "getRadioAccessFamily");
5537 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
chen xub97461a2018-10-26 14:17:57 -07005541 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005542 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005543
5544 @Override
5545 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005546 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
5550 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005551 ImsManager.getInstance(defaultPhone.getContext(),
5552 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
5555 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005556 }
5557
5558 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005559 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005560 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005561 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005562 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005563 return false;
5564 }
Svet Ganovb320e182015-04-16 12:30:10 -07005565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 final long identity = Binder.clearCallingIdentity();
5567 try {
5568 // Check the user preference and the system-level IMS setting. Even if the user has
5569 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5570 // In the long run, we may instead need to check if there exists a connection service
5571 // which can support video calling.
5572 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005573 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 return imsManager.isVtEnabledByPlatform()
5575 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5576 && imsManager.isVtEnabledByUser();
5577 } finally {
5578 Binder.restoreCallingIdentity(identity);
5579 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005580 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005581
Andrew Leea1239f22015-03-02 17:44:07 -08005582 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5585 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5586 return false;
5587 }
5588
5589 final long identity = Binder.clearCallingIdentity();
5590 try {
5591 CarrierConfigManager configManager =
5592 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005593 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005594 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
Andrew Leea1239f22015-03-02 17:44:07 -08005598 }
5599
5600 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 public boolean isWorldPhone(int subId, String callingPackage) {
5602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5603 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5604 return false;
5605 }
5606
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 CarrierConfigManager configManager =
5610 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005611 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5613 } finally {
5614 Binder.restoreCallingIdentity(identity);
5615 }
Andrew Leea1239f22015-03-02 17:44:07 -08005616 }
5617
Andrew Lee9431b832015-03-09 18:46:45 -07005618 @Override
5619 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005620 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005621 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005622 }
5623
5624 @Override
5625 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 final long identity = Binder.clearCallingIdentity();
5627 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005628 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
Andrew Lee9431b832015-03-09 18:46:45 -07005632 }
5633
Hall Liuf6668912018-10-31 17:05:23 -07005634 /**
5635 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5636 * support for the feature and device firmware support.
5637 *
5638 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5639 */
5640 @Override
5641 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 final Phone phone = getPhone(subscriptionId);
5644 if (phone == null) {
5645 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5646 return false;
5647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005649 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5651 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005652 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 return isCarrierSupported && isDeviceSupported;
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
Hall Liu98187582018-01-22 19:15:32 -08005657 }
5658
Hall Liuf6668912018-10-31 17:05:23 -07005659 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005660 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5661 * RTT setting, will return true if the device and carrier both support RTT.
5662 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005663 */
5664 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 final long identity = Binder.clearCallingIdentity();
5666 try {
Hall Liu6a06be62019-07-23 18:39:00 -07005667 boolean isRttSupported = isRttSupported(subscriptionId);
5668 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005669 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liu6a06be62019-07-23 18:39:00 -07005670 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5671 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5672 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 } finally {
5674 Binder.restoreCallingIdentity(identity);
5675 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005676 }
5677
Sanket Padawe7310cc72015-01-14 09:53:20 -08005678 /**
5679 * Returns the unique device ID of phone, for example, the IMEI for
5680 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5681 *
5682 * <p>Requires Permission:
5683 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5684 */
5685 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005686 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005687 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005688 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005689 return null;
5690 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005691 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005692 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5693 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005694 return null;
5695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696
5697 final long identity = Binder.clearCallingIdentity();
5698 try {
5699 return phone.getDeviceId();
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
5702 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005703 }
5704
Ping Sunc67b7c22016-03-02 19:16:45 +08005705 /**
5706 * {@hide}
5707 * Returns the IMS Registration Status on a particular subid
5708 *
5709 * @param subId
5710 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005711 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005712 Phone phone = getPhone(subId);
5713 if (phone != null) {
5714 return phone.isImsRegistered();
5715 } else {
5716 return false;
5717 }
5718 }
5719
Santos Cordon7a1885b2015-02-03 11:15:19 -08005720 @Override
5721 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005722 final long identity = Binder.clearCallingIdentity();
5723 try {
5724 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005728 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005729
Tyler Gunnf70ed162019-04-03 15:28:53 -07005730 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005731 public int getSubIdForPhoneAccountHandle(
5732 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5734 callingPackage, "getSubIdForPhoneAccountHandle")) {
5735 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5736 }
5737 final long identity = Binder.clearCallingIdentity();
5738 try {
5739 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
5743 }
5744
5745 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005746 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5747 final long identity = Binder.clearCallingIdentity();
5748 try {
5749 Phone phone = getPhone(subscriptionId);
5750 if (phone == null) {
5751 return null;
5752 }
5753 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5754 } finally {
5755 Binder.restoreCallingIdentity(identity);
5756 }
5757 }
5758
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005759 /**
5760 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005761 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005762 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 final long identity = Binder.clearCallingIdentity();
5764 try {
5765 Phone phone = getPhone(subId);
5766 if (phone != null) {
5767 return phone.isWifiCallingEnabled();
5768 } else {
5769 return false;
5770 }
5771 } finally {
5772 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005773 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005774 }
5775
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005776 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005777 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005778 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005779 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 Phone phone = getPhone(subId);
5783 if (phone != null) {
5784 return phone.isVideoEnabled();
5785 } else {
5786 return false;
5787 }
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005790 }
5791 }
5792
5793 /**
5794 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5795 * defined in {@link ImsRegistrationImplBase}.
5796 */
5797 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 final long identity = Binder.clearCallingIdentity();
5799 try {
5800 Phone phone = getPhone(subId);
5801 if (phone != null) {
5802 return phone.getImsRegistrationTech();
5803 } else {
5804 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5805 }
5806 } finally {
5807 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005808 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005809 }
5810
Stuart Scott8eef64f2015-04-08 15:13:54 -07005811 @Override
5812 public void factoryReset(int subId) {
5813 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005814 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5815 return;
5816 }
5817
Svet Ganovcc087f82015-05-12 20:35:54 -07005818 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819
Svet Ganovcc087f82015-05-12 20:35:54 -07005820 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005821 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5822 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005823 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005824 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005825 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5827 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005828 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005829 // There has been issues when Sms raw table somehow stores orphan
5830 // fragments. They lead to garbled message when new fragments come
5831 // in and combined with those stale ones. In case this happens again,
5832 // user can reset all network settings which will clean up this table.
5833 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005834 // Clean up IMS settings as well here.
5835 int slotId = getSlotIndex(subId);
5836 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5837 ImsManager.getInstance(mApp, slotId).factoryReset();
5838 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005839 } finally {
5840 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005841 }
5842 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005843
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005844 private void cleanUpSmsRawTable(Context context) {
5845 ContentResolver resolver = context.getContentResolver();
5846 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5847 resolver.delete(uri, null, null);
5848 }
5849
Narayan Kamath1c496c22015-04-16 14:40:19 +01005850 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005851 public String getSimLocaleForSubscriber(int subId) {
5852 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5853 final Phone phone = getPhone(subId);
5854 if (phone == null) {
5855 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005856 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 final long identity = Binder.clearCallingIdentity();
5859 try {
chen xu5d3637b2019-01-21 23:31:38 -08005860 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5861 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005862 if (info == null) {
5863 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5864 return null;
5865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 // Try and fetch the locale from the carrier properties or from the SIM language
5867 // preferences (EF-PL and EF-LI)...
5868 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005869 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005870 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5871 if (localeFromDefaultSim != null) {
5872 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5873 if (DBG) log("Using locale from subId: " + subId + " locale: "
5874 + localeFromDefaultSim);
5875 return localeFromDefaultSim.toLanguageTag();
5876 } else {
5877 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 }
5879 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 // The SIM language preferences only store a language (e.g. fr = French), not an
5882 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5883 // the SIM and carrier preferences does not include a country we add the country
5884 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005887 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 return mccLocale.toLanguageTag();
5889 }
5890
5891 if (DBG) log("No locale found - returning null");
5892 return null;
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
5895 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005896 }
5897
5898 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005899 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005900 }
5901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005902 /**
5903 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5904 */
5905 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005906 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005907 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005908
Chenjie Yu1ba97252018-01-11 18:16:20 -08005909 private final ModemActivityInfo mLastModemActivityInfo =
5910 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5911
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005912 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005913 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5914 * representing the state of the modem.
5915 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005916 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5917 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005918 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005919 */
5920 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005921 public void requestModemActivityInfo(ResultReceiver result) {
5922 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924
5925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 ModemActivityInfo ret = null;
5928 synchronized (mLastModemActivityInfo) {
5929 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5930 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005931 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005932 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5934 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005935 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5936 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005937 }
5938 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005939 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5940 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 mLastModemActivityInfo.setIdleTimeMillis(
5942 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5943 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5944 mLastModemActivityInfo.setRxTimeMillis(
5945 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5946 mLastModemActivityInfo.setEnergyUsed(
5947 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5950 mLastModemActivityInfo.getSleepTimeMillis(),
5951 mLastModemActivityInfo.getIdleTimeMillis(),
5952 mLastModemActivityInfo.getTxTimeMillis(),
5953 mLastModemActivityInfo.getRxTimeMillis(),
5954 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005955 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 Bundle bundle = new Bundle();
5957 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5958 result.send(0, bundle);
5959 } finally {
5960 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005961 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005962 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005963
Siddharth Rayb8114062018-06-17 15:02:38 -07005964 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5965 // less than total activity duration.
5966 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5967 if (info == null) {
5968 return false;
5969 }
5970 int activityDurationMs =
5971 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5972 int totalTxTimeMs = 0;
5973 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5974 totalTxTimeMs += info.getTxTimeMillis()[i];
5975 }
5976 return (info.isValid()
5977 && (info.getSleepTimeMillis() <= activityDurationMs)
5978 && (info.getIdleTimeMillis() <= activityDurationMs)
5979 && (info.getRxTimeMillis() <= activityDurationMs)
5980 && (totalTxTimeMs <= activityDurationMs));
5981 }
5982
Jack Yu85bd38a2015-11-09 11:34:32 -08005983 /**
5984 * {@hide}
5985 * Returns the service state information on specified subscription.
5986 */
5987 @Override
5988 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005989 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005990 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005991 return null;
5992 }
5993
Hall Liuf19c44f2018-11-27 14:38:17 -08005994 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5995 LocationAccessPolicy.checkLocationPermission(mApp,
5996 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5997 .setCallingPackage(callingPackage)
5998 .setCallingPid(Binder.getCallingPid())
5999 .setCallingUid(Binder.getCallingUid())
6000 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006001 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006002 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6003 .build());
6004
6005 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6006 LocationAccessPolicy.checkLocationPermission(mApp,
6007 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6008 .setCallingPackage(callingPackage)
6009 .setCallingPid(Binder.getCallingPid())
6010 .setCallingUid(Binder.getCallingUid())
6011 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006012 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006013 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6014 .build());
6015 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6016 boolean hasFinePermission =
6017 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6018 boolean hasCoarsePermission =
6019 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 final Phone phone = getPhone(subId);
6024 if (phone == null) {
6025 return null;
6026 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006027
Hall Liuf19c44f2018-11-27 14:38:17 -08006028 ServiceState ss = phone.getServiceState();
6029
6030 // Scrub out the location info in ServiceState depending on what level of access
6031 // the caller has.
6032 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006033 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6034 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006038 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006039
6040 /**
6041 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6042 *
6043 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6044 * voicemail ringtone.
6045 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6046 * PhoneAccount.
6047 */
6048 @Override
6049 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6053 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006054 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006056
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006061 }
6062
6063 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006064 * Sets the per-account voicemail ringtone.
6065 *
6066 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6067 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6068 *
6069 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6070 * voicemail ringtone.
6071 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6072 * PhoneAccount.
6073 */
6074 @Override
6075 public void setVoicemailRingtoneUri(String callingPackage,
6076 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006077 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006078 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006079 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6080 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6082 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6083 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6089 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006090 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091 }
6092 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006095 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006096 }
6097
6098 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006099 * Returns whether vibration is set for voicemail notification in Phone settings.
6100 *
6101 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6102 * voicemail vibration setting.
6103 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6104 */
6105 @Override
6106 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6110 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006111 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006113
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6115 } finally {
6116 Binder.restoreCallingIdentity(identity);
6117 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006118 }
6119
Youhan Wange64578a2016-05-02 15:32:42 -07006120 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006121 * Sets the per-account voicemail vibration.
6122 *
6123 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6124 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6125 *
6126 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6127 * voicemail vibration setting.
6128 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6129 * specific PhoneAccount.
6130 */
6131 @Override
6132 public void setVoicemailVibrationEnabled(String callingPackage,
6133 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006134 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006135 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006136 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6137 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6139 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6140 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006141 }
6142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 final long identity = Binder.clearCallingIdentity();
6144 try {
6145 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6146 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006147 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 }
6149 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6150 } finally {
6151 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006152 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006153 }
6154
6155 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006156 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6157 *
6158 * @throws SecurityException if the caller does not have the required permission
6159 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006160 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006161 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006162 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006163 }
6164
6165 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006166 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6167 * permission.
6168 *
6169 * @throws SecurityException if the caller does not have the required permission
6170 */
6171 private void enforceSendSmsPermission() {
6172 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6173 }
6174
6175 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006176 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006177 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006178 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006179 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006180 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006184 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006185 if (componentName == null) {
6186 throw new SecurityException(
6187 "Caller not current active visual voicemail package[null]");
6188 }
6189 String vvmPackage = componentName.getPackageName();
6190 if (!callingPackage.equals(vvmPackage)) {
6191 throw new SecurityException("Caller not current active visual voicemail package["
6192 + vvmPackage + "]");
6193 }
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006196 }
6197 }
6198
6199 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006200 * Return the application ID for the app type.
6201 *
6202 * @param subId the subscription ID that this request applies to.
6203 * @param appType the uicc app type.
6204 * @return Application ID for specificied app type, or null if no uicc.
6205 */
6206 @Override
6207 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006208 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006209 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006210
6211 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006212 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 if (phone == null) {
6214 return null;
6215 }
6216 String aid = null;
6217 try {
6218 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6219 .getApplicationByType(appType).getAid();
6220 } catch (Exception e) {
6221 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6222 }
6223 return aid;
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006226 }
Youhan Wange64578a2016-05-02 15:32:42 -07006227 }
6228
Youhan Wang4001d252016-05-11 10:29:41 -07006229 /**
6230 * Return the Electronic Serial Number.
6231 *
6232 * @param subId the subscription ID that this request applies to.
6233 * @return ESN or null if error.
6234 */
6235 @Override
6236 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006237 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006238 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239
6240 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006241 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 if (phone == null) {
6243 return null;
6244 }
6245 String esn = null;
6246 try {
6247 esn = phone.getEsn();
6248 } catch (Exception e) {
6249 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6250 }
6251 return esn;
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006254 }
Youhan Wang4001d252016-05-11 10:29:41 -07006255 }
6256
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006257 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006258 * Return the Preferred Roaming List Version.
6259 *
6260 * @param subId the subscription ID that this request applies to.
6261 * @return PRLVersion or null if error.
6262 */
6263 @Override
6264 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006265 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006266 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006269 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 if (phone == null) {
6271 return null;
6272 }
6273 String cdmaPrlVersion = null;
6274 try {
6275 cdmaPrlVersion = phone.getCdmaPrlVersion();
6276 } catch (Exception e) {
6277 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6278 }
6279 return cdmaPrlVersion;
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006282 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006283 }
6284
6285 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006286 * Get snapshot of Telephony histograms
6287 * @return List of Telephony histograms
6288 * @hide
6289 */
6290 @Override
6291 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6293 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 return RIL.getTelephonyRILTimingHistograms();
6298 } finally {
6299 Binder.restoreCallingIdentity(identity);
6300 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006301 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006302
6303 /**
6304 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006305 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6306 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006307 * Require system privileges. In the future we may add this to carrier APIs.
6308 *
Michele Berionne482f8202018-11-27 18:57:59 -08006309 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006310 */
6311 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006312 @TelephonyManager.SetCarrierRestrictionResult
6313 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006314 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006316
Michele Berionne482f8202018-11-27 18:57:59 -08006317 if (carrierRestrictionRules == null) {
6318 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006319 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006323 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006324 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 } finally {
6326 Binder.restoreCallingIdentity(identity);
6327 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006328 }
6329
6330 /**
6331 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006332 * Get the allowed carrier list and the excluded carrier list, including the priority between
6333 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006334 * Require system privileges. In the future we may add this to carrier APIs.
6335 *
Michele Berionne482f8202018-11-27 18:57:59 -08006336 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006337 */
6338 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006339 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006340 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006341 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342
6343 final long identity = Binder.clearCallingIdentity();
6344 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006345 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6346 if (response instanceof CarrierRestrictionRules) {
6347 return (CarrierRestrictionRules) response;
6348 }
6349 // Response is an Exception of some kind,
6350 // which is signalled to the user as a NULL retval
6351 return null;
6352 } catch (Exception e) {
6353 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6354 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006358 }
6359
fionaxu59545b42016-05-25 15:53:37 -07006360 /**
6361 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6362 * @param subId the subscription ID that this action applies to.
6363 * @param enabled control enable or disable metered apns.
6364 * {@hide}
6365 */
6366 @Override
6367 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6368 enforceModifyPermission();
6369 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370
6371 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006372 if (phone == null) {
6373 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6374 return;
6375 }
6376 try {
6377 phone.carrierActionSetMeteredApnsEnabled(enabled);
6378 } catch (Exception e) {
6379 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 } finally {
6381 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006382 }
6383 }
6384
6385 /**
6386 * Action set from carrier signalling broadcast receivers to enable/disable radio
6387 * @param subId the subscription ID that this action applies to.
6388 * @param enabled control enable or disable radio.
6389 * {@hide}
6390 */
6391 @Override
6392 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6393 enforceModifyPermission();
6394 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395
6396 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006397 if (phone == null) {
6398 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6399 return;
6400 }
6401 try {
6402 phone.carrierActionSetRadioEnabled(enabled);
6403 } catch (Exception e) {
6404 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 } finally {
6406 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006407 }
6408 }
6409
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006410 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006411 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6412 * network status based on which carrier apps could apply actions accordingly,
6413 * enable/disable default url handler for example.
6414 *
6415 * @param subId the subscription ID that this action applies to.
6416 * @param report control start/stop reporting the default network status.
6417 * {@hide}
6418 */
6419 @Override
6420 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6421 enforceModifyPermission();
6422 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423
6424 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006425 if (phone == null) {
6426 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6427 return;
6428 }
6429 try {
6430 phone.carrierActionReportDefaultNetworkStatus(report);
6431 } catch (Exception e) {
6432 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 } finally {
6434 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006435 }
6436 }
6437
6438 /**
fionaxud9622282017-07-17 17:51:30 -07006439 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6440 * @param subId the subscription ID that this action applies to.
6441 * {@hide}
6442 */
6443 @Override
6444 public void carrierActionResetAll(int subId) {
6445 enforceModifyPermission();
6446 final Phone phone = getPhone(subId);
6447 if (phone == null) {
6448 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6449 return;
6450 }
6451 try {
6452 phone.carrierActionResetAll();
6453 } catch (Exception e) {
6454 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6455 }
6456 }
6457
6458 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006459 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6460 * bug report is being generated.
6461 */
6462 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006463 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006464 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6465 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006466 writer.println("Permission Denial: can't dump Phone from pid="
6467 + Binder.getCallingPid()
6468 + ", uid=" + Binder.getCallingUid()
6469 + "without permission "
6470 + android.Manifest.permission.DUMP);
6471 return;
6472 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006473 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006474 }
Jack Yueb89b242016-06-22 13:27:47 -07006475
Brad Ebingerdac2f002018-04-03 15:17:52 -07006476 @Override
6477 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6478 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6479 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006480 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6481 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006482 }
6483
Jack Yueb89b242016-06-22 13:27:47 -07006484 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006485 * Get aggregated video call data usage since boot.
6486 *
6487 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6488 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006489 * {@hide}
6490 */
6491 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006492 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006493 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6494 null);
6495
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 final long identity = Binder.clearCallingIdentity();
6497 try {
6498 // NetworkStatsService keeps tracking the active network interface and identity. It
6499 // records the delta with the corresponding network identity.
6500 // We just return the total video call data usage snapshot since boot.
6501 Phone phone = getPhone(subId);
6502 if (phone != null) {
6503 return phone.getVtDataUsage(perUidStats);
6504 }
6505 return null;
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006508 }
Jack Yueb89b242016-06-22 13:27:47 -07006509 }
Jack Yu75ab2952016-07-08 14:29:33 -07006510
6511 /**
6512 * Policy control of data connection. Usually used when data limit is passed.
6513 * @param enabled True if enabling the data, otherwise disabling.
6514 * @param subId Subscription index
6515 * {@hide}
6516 */
6517 @Override
6518 public void setPolicyDataEnabled(boolean enabled, int subId) {
6519 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520
6521 final long identity = Binder.clearCallingIdentity();
6522 try {
6523 Phone phone = getPhone(subId);
6524 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006525 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006526 }
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006529 }
6530 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006531
6532 /**
6533 * Get Client request stats
6534 * @return List of Client Request Stats
6535 * @hide
6536 */
6537 @Override
6538 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006540 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006541 return null;
6542 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006543 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 if (phone != null) {
6548 return phone.getClientRequestStats();
6549 }
6550
6551 return null;
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006555 }
6556
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006557 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006558 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006559 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006560 }
Jack Yueb4124c2017-02-16 15:32:43 -08006561
6562 /**
Grace Chen70990072017-03-24 17:21:30 -07006563 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006564 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006565 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006566 * @param state State of SIM (power down, power up, pass through)
6567 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6568 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6569 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006570 *
6571 **/
6572 @Override
Grace Chen70990072017-03-24 17:21:30 -07006573 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006574 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006575 Phone phone = PhoneFactory.getPhone(slotIndex);
6576
vagdeviaf9a5b92018-08-15 16:01:53 -07006577 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006582 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006583 }
6584 } finally {
6585 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006586 }
6587 }
Shuo Qiandd210312017-04-12 22:11:33 +00006588
Tyler Gunn65d45c22017-06-05 11:22:26 -07006589 private boolean isUssdApiAllowed(int subId) {
6590 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006591 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006592 if (configManager == null) {
6593 return false;
6594 }
6595 PersistableBundle pb = configManager.getConfigForSubId(subId);
6596 if (pb == null) {
6597 return false;
6598 }
6599 return pb.getBoolean(
6600 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6601 }
6602
Shuo Qiandd210312017-04-12 22:11:33 +00006603 /**
6604 * Check if phone is in emergency callback mode
6605 * @return true if phone is in emergency callback mode
6606 * @param subId sub id
6607 */
goneil9c5f4872017-12-05 14:07:56 -08006608 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006609 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006610 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006611 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612
6613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 if (phone != null) {
6616 return phone.isInEcm();
6617 } else {
6618 return false;
6619 }
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006622 }
6623 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006624
6625 /**
6626 * Get the current signal strength information for the given subscription.
6627 * Because this information is not updated when the device is in a low power state
6628 * it should not be relied-upon to be current.
6629 * @param subId Subscription index
6630 * @return the most recent cached signal strength info from the modem
6631 */
6632 @Override
6633 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 Phone p = getPhone(subId);
6637 if (p == null) {
6638 return null;
6639 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641 return p.getSignalStrength();
6642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006645 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006646
Pengquan Meng77b7f132018-08-22 14:49:57 -07006647 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006648 * Get the current modem radio state for the given slot.
6649 * @param slotIndex slot index.
6650 * @param callingPackage the name of the package making the call.
6651 * @return the current radio power state from the modem
6652 */
6653 @Override
6654 public int getRadioPowerState(int slotIndex, String callingPackage) {
6655 Phone phone = PhoneFactory.getPhone(slotIndex);
6656 if (phone != null) {
6657 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6658 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6659 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6660 }
6661
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
6664 return phone.getRadioPowerState();
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
6667 }
6668 }
6669 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6670 }
6671
6672 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006673 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6674 *
6675 * <p>Requires one of the following permissions:
6676 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6677 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6678 * privileges.
6679 *
6680 * @param subId subscription id
6681 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6682 * {@code false}.
6683 */
6684 @Override
6685 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006686 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6687 null /* message */);
6688
Pengquan Menga1bb6272018-09-06 09:59:22 -07006689 boolean isEnabled = false;
6690 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006691 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006692 Phone phone = getPhone(subId);
6693 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006694 } catch (Exception e) {
6695 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6696 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006697 } finally {
6698 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006699 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006700 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006701 }
6702
6703
6704 /**
6705 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6706 *
6707 * <p> Requires permission:
6708 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6709 * privileges.
6710 *
6711 * @param subId subscription id
6712 * @param isEnabled {@code true} means enable, {@code false} means disable.
6713 */
6714 @Override
6715 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6717 mApp, subId, "setDataRoamingEnabled");
6718
Pengquan Menga1bb6272018-09-06 09:59:22 -07006719 final long identity = Binder.clearCallingIdentity();
6720 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006721 Phone phone = getPhone(subId);
6722 if (phone != null) {
6723 phone.setDataRoamingEnabled(isEnabled);
6724 }
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006727 }
6728 }
6729
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006730 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006731 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006732 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6733 mApp, subId, "isManualNetworkSelectionAllowed");
6734
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006735 boolean isAllowed = true;
6736 final long identity = Binder.clearCallingIdentity();
6737 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006738 Phone phone = getPhone(subId);
6739 if (phone != null) {
6740 isAllowed = phone.isCspPlmnEnabled();
6741 }
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
6744 }
6745 return isAllowed;
6746 }
6747
6748 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006749 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006750 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006751 try {
6752 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006753 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006754 } catch (SecurityException e) {
6755 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6756 // has carrier privileges on an active UICC
6757 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6758 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006759 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006760 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006761 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006762
6763 final long identity = Binder.clearCallingIdentity();
6764 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006765 UiccController uiccController = UiccController.getInstance();
6766 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006767 if (hasReadPermission) {
6768 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006769 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006770
6771 // Remove private info if the caller doesn't have access
6772 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6773 for (UiccCardInfo cardInfo : cardInfos) {
6774 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6775 // is available
6776 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6777 if (card == null || card.getUiccProfile() == null) {
6778 // assume no access if the card or profile is unavailable
6779 filteredInfos.add(cardInfo.getUnprivileged());
6780 continue;
6781 }
6782 UiccProfile profile = card.getUiccProfile();
6783 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6784 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6785 filteredInfos.add(cardInfo);
6786 } else {
6787 filteredInfos.add(cardInfo.getUnprivileged());
6788 }
6789 }
6790 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
6796 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006797 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006798 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 final long identity = Binder.clearCallingIdentity();
6801 try {
6802 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6803 if (slots == null) {
6804 Rlog.i(LOG_TAG, "slots is null.");
6805 return null;
6806 }
6807
6808 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6809 for (int i = 0; i < slots.length; i++) {
6810 UiccSlot slot = slots[i];
6811 if (slot == null) {
6812 continue;
6813 }
6814
Jordan Liu7be7e652019-05-06 18:55:02 +00006815 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 UiccCard card = slot.getUiccCard();
6817 if (card != null) {
6818 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006819 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006820 cardId = slot.getEid();
6821 if (TextUtils.isEmpty(cardId)) {
6822 cardId = slot.getIccId();
6823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006824 }
6825
Jordan Liu857451f2019-05-09 16:35:35 -07006826 if (cardId != null) {
6827 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6828 // if cardId is an EID, it's all digits so this is fine
6829 cardId = IccUtils.stripTrailingFs(cardId);
6830 }
6831
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 int cardState = 0;
6833 switch (slot.getCardState()) {
6834 case CARDSTATE_ABSENT:
6835 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6836 break;
6837 case CARDSTATE_PRESENT:
6838 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6839 break;
6840 case CARDSTATE_ERROR:
6841 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6842 break;
6843 case CARDSTATE_RESTRICTED:
6844 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6845 break;
6846 default:
6847 break;
6848
6849 }
6850
6851 infos[i] = new UiccSlotInfo(
6852 slot.isActive(),
6853 slot.isEuicc(),
6854 cardId,
6855 cardState,
6856 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006857 slot.isExtendedApduSupported(),
6858 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006859 }
6860 return infos;
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006863 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006864 }
6865
6866 @Override
6867 public boolean switchSlots(int[] physicalSlots) {
6868 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
6872 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
6875 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006876 }
Jack Yu4c988042018-02-27 15:30:01 -08006877
6878 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006879 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006880 final long identity = Binder.clearCallingIdentity();
6881 try {
6882 return UiccController.getInstance().getCardIdForDefaultEuicc();
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
6887
6888 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006889 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6890 enforceModifyPermission();
6891 final Phone phone = getPhone(subId);
6892 if (phone == null) {
6893 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6894 return;
6895 }
6896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 phone.setRadioIndicationUpdateMode(filters, mode);
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
6902 }
Jack Yu4c988042018-02-27 15:30:01 -08006903 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006904
6905 /**
goneil47ffb6e2018-04-06 15:40:58 -07006906 * A test API to reload the UICC profile.
6907 *
6908 * <p>Requires that the calling app has permission
6909 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6910 * @hide
6911 */
6912 @Override
6913 public void refreshUiccProfile(int subId) {
6914 enforceModifyPermission();
6915
6916 final long identity = Binder.clearCallingIdentity();
6917 try {
6918 Phone phone = getPhone(subId);
6919 if (phone == null) {
6920 return;
6921 }
6922 UiccCard uiccCard = phone.getUiccCard();
6923 if (uiccCard == null) {
6924 return;
6925 }
6926 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6927 if (uiccProfile == null) {
6928 return;
6929 }
6930 uiccProfile.refresh();
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
6934 }
6935
6936 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006937 * Returns false if the mobile data is disabled by default, otherwise return true.
6938 */
6939 private boolean getDefaultDataEnabled() {
6940 return "true".equalsIgnoreCase(
6941 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6942 }
6943
6944 /**
6945 * Returns true if the data roaming is enabled by default, i.e the system property
6946 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6947 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6948 */
6949 private boolean getDefaultDataRoamingEnabled(int subId) {
6950 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006951 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006952 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6953 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6954 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6955 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6956 return isDataRoamingEnabled;
6957 }
6958
6959 /**
6960 * Returns the default network type for the given {@code subId}, if the default network type is
6961 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6962 */
6963 private int getDefaultNetworkType(int subId) {
6964 return Integer.parseInt(
6965 TelephonyManager.getTelephonyProperty(
6966 mSubscriptionController.getPhoneId(subId),
6967 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6968 String.valueOf(Phone.PREFERRED_NT_MODE)));
6969 }
fionaxua13278b2018-03-21 00:08:13 -07006970
6971 @Override
6972 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006973 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006975
6976 final long identity = Binder.clearCallingIdentity();
6977 try {
6978 final Phone phone = getPhone(subId);
6979 if (phone == null) {
6980 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6981 return;
6982 }
chen xueaba88a2019-03-15 13:15:10 -07006983 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6984 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006987 }
fionaxua13278b2018-03-21 00:08:13 -07006988 }
6989
6990 @Override
6991 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006992 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 final Phone phone = getPhone(subId);
6997 if (phone == null) {
6998 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6999 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7000 }
7001 return phone.getCarrierIdListVersion();
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007004 }
fionaxua13278b2018-03-21 00:08:13 -07007005 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007006
7007 @Override
7008 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7010 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7011 return -1;
7012 }
7013
7014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007021
7022 @Override
7023 public int getCdmaRoamingMode(int subId) {
7024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7025 mApp, subId, "getCdmaRoamingMode");
7026
7027 final long identity = Binder.clearCallingIdentity();
7028 try {
7029 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
7032 }
7033 }
7034
7035 @Override
7036 public boolean setCdmaRoamingMode(int subId, int mode) {
7037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7038 mApp, subId, "setCdmaRoamingMode");
7039
7040 final long identity = Binder.clearCallingIdentity();
7041 try {
7042 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7043 } finally {
7044 Binder.restoreCallingIdentity(identity);
7045 }
7046 }
7047
7048 @Override
7049 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7051 mApp, subId, "setCdmaSubscriptionMode");
7052
7053 final long identity = Binder.clearCallingIdentity();
7054 try {
7055 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007060
sqianc5eccab2018-10-19 18:46:41 -07007061 @Override
sqian8c685422019-02-22 15:55:18 -08007062 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007063 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007065 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007066 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7067 }
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
sqian854d44b2018-12-12 16:48:18 -08007070 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7071 for (Phone phone: PhoneFactory.getPhones()) {
7072 if (phone.getEmergencyNumberTracker() != null
7073 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7074 emergencyNumberListInternal.put(
7075 phone.getSubId(),
7076 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7077 }
sqian11b7a0e2018-12-05 18:48:28 -08007078 }
sqian854d44b2018-12-12 16:48:18 -08007079 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007080 } finally {
7081 Binder.restoreCallingIdentity(identity);
7082 }
sqianc5eccab2018-10-19 18:46:41 -07007083 }
7084
7085 @Override
sqian8c685422019-02-22 15:55:18 -08007086 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007087 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007088 if (!exactMatch) {
7089 TelephonyPermissions
7090 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007091 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007092 }
7093 final long identity = Binder.clearCallingIdentity();
7094 try {
sqian854d44b2018-12-12 16:48:18 -08007095 for (Phone phone: PhoneFactory.getPhones()) {
7096 if (phone.getEmergencyNumberTracker() != null
7097 && phone.getEmergencyNumberTracker() != null) {
7098 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7099 number, exactMatch)) {
7100 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007101 }
7102 }
sqian11b7a0e2018-12-05 18:48:28 -08007103 }
7104 return false;
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
7108 }
7109
sqianf4ca7ed2019-01-15 18:32:07 -08007110 /**
7111 * Update emergency number list for test mode.
7112 */
7113 @Override
7114 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7115 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7116 "updateEmergencyNumberListTestMode");
7117
7118 final long identity = Binder.clearCallingIdentity();
7119 try {
7120 for (Phone phone: PhoneFactory.getPhones()) {
7121 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7122 if (tracker != null) {
7123 tracker.executeEmergencyNumberTestModeCommand(action, num);
7124 }
7125 }
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
7129 }
7130
7131 /**
7132 * Get the full emergency number list for test mode.
7133 */
7134 @Override
7135 public List<String> getEmergencyNumberListTestMode() {
7136 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7137 "getEmergencyNumberListTestMode");
7138
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 Set<String> emergencyNumbers = new HashSet<>();
7142 for (Phone phone: PhoneFactory.getPhones()) {
7143 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7144 if (tracker != null) {
7145 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7146 emergencyNumbers.add(num.getNumber());
7147 }
7148 }
7149 }
7150 return new ArrayList<>(emergencyNumbers);
7151 } finally {
7152 Binder.restoreCallingIdentity(identity);
7153 }
7154 }
7155
chen xud6b45bd2018-10-30 22:27:10 -07007156 @Override
7157 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7158 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7159 Phone phone = getPhone(subId);
7160 if (phone == null) {
7161 return null;
7162 }
7163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 UiccProfile profile = UiccController.getInstance()
7166 .getUiccProfileForPhone(phone.getPhoneId());
7167 if (profile != null) {
7168 return profile.getCertsFromCarrierPrivilegeAccessRules();
7169 }
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
7173 return null;
7174 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007175
7176 /**
7177 * Enable or disable a modem stack.
7178 */
7179 @Override
7180 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7181 enforceModifyPermission();
7182
7183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 Phone phone = PhoneFactory.getPhone(slotIndex);
7186 if (phone == null) {
7187 return false;
7188 } else {
7189 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7190 }
7191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
7194 }
Michelecea4cf22018-12-21 15:00:11 -08007195
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007196 /**
7197 * Whether a modem stack is enabled or not.
7198 */
7199 @Override
7200 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7201 Phone phone = PhoneFactory.getPhone(slotIndex);
7202 if (phone == null) return false;
7203
7204 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7205 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7206 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7207 }
7208
7209 final long identity = Binder.clearCallingIdentity();
7210 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007211 try {
7212 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7213 } catch (NoSuchElementException ex) {
7214 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7215 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
7219 }
7220
Michelecea4cf22018-12-21 15:00:11 -08007221 @Override
Michele0ea7d782019-03-19 14:58:42 -07007222 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007223 enforceModifyPermission();
7224
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007228 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007229 .commit();
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
7235 @Override
Michele0ea7d782019-03-19 14:58:42 -07007236 @TelephonyManager.IsMultiSimSupportedResult
7237 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007239 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7240 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007241 }
Michelecea4cf22018-12-21 15:00:11 -08007242
7243 final long identity = Binder.clearCallingIdentity();
7244 try {
Michele0ea7d782019-03-19 14:58:42 -07007245 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
7249 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007250
Michele0ea7d782019-03-19 14:58:42 -07007251 @TelephonyManager.IsMultiSimSupportedResult
7252 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007253 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7254 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7255 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007256 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7257 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007258 }
7259 // Check if the hardware supports multisim functionality. If usage of multisim is not
7260 // supported by the modem, indicate that it is restricted.
7261 PhoneCapability staticCapability =
7262 mPhoneConfigurationManager.getStaticPhoneCapability();
7263 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007264 loge("isMultiSimSupportedInternal: no static configuration available");
7265 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007266 }
7267 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007268 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7269 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007270 }
7271 // Check if support of multiple SIMs is restricted by carrier
7272 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007273 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007274 }
7275
Michele0ea7d782019-03-19 14:58:42 -07007276 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007277 }
7278
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007279 /**
7280 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007281 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7282 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7283 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007284 * @param numOfSims number of active sims we want to switch to
7285 */
7286 @Override
7287 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007288 if (numOfSims == 1) {
7289 enforceModifyPermission();
7290 } else {
7291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7292 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7293 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007294 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007295
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007296 try {
Michele30b57b22019-03-01 12:01:14 -08007297 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007298 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007299 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7300 return;
7301 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007302 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007308 @Override
7309 public boolean isApplicationOnUicc(int subId, int appType) {
7310 enforceReadPrivilegedPermission("isApplicationOnUicc");
7311 Phone phone = getPhone(subId);
7312 if (phone == null) {
7313 return false;
7314 }
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 UiccCard uiccCard = phone.getUiccCard();
7318 if (uiccCard == null) {
7319 return false;
7320 }
7321 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7322 if (uiccProfile == null) {
7323 return false;
7324 }
7325 if (TelephonyManager.APPTYPE_SIM <= appType
7326 && appType <= TelephonyManager.APPTYPE_ISIM) {
7327 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7328 }
7329 return false;
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007335 /**
chen xub4baa772019-04-03 10:23:41 -07007336 * Get whether making changes to modem configurations will trigger reboot.
7337 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007338 */
7339 @Override
chen xub4baa772019-04-03 10:23:41 -07007340 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7342 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7343 return false;
7344 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7348 } finally {
7349 Binder.restoreCallingIdentity(identity);
7350 }
7351 }
7352
Nathan Harold29f5f052019-02-15 13:41:57 -08007353 private void updateModemStateMetrics() {
7354 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7355 // TODO: check the state for each modem if the api is ready.
7356 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7357 }
7358
Pengquan Meng3889a572019-01-23 11:16:29 -08007359 @Override
7360 public int[] getSlotsMapping() {
7361 enforceReadPrivilegedPermission("getSlotsMapping");
7362
7363 final long identity = Binder.clearCallingIdentity();
7364 try {
7365 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7366 // All logical slots should have a mapping to a physical slot.
7367 int[] logicalSlotsMapping = new int[phoneCount];
7368 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7369 for (int i = 0; i < slotInfos.length; i++) {
7370 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7371 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7372 }
7373 }
7374 return logicalSlotsMapping;
7375 } finally {
7376 Binder.restoreCallingIdentity(identity);
7377 }
7378 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007379
7380 /**
7381 * Get the IRadio HAL Version
7382 */
7383 @Override
7384 public int getRadioHalVersion() {
7385 Phone phone = getDefaultPhone();
7386 if (phone == null) return -1;
7387 HalVersion hv = phone.getHalVersion();
7388 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7389 return hv.major * 100 + hv.minor;
7390 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007391
7392 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007393 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7394 * corresponding network requests on a subId.
7395 *
7396 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007397 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007398 * 2) APN is un-metered for this subscription, or
7399 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7400 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7401 *
7402 * @return whether data is allowed for a apn type.
7403 *
7404 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007405 */
7406 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007407 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007408 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7409 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007410
7411 // Now that all security checks passes, perform the operation as ourselves.
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
7414 Phone phone = getPhone(subId);
7415 if (phone == null) return false;
7416
Jack Yu41407ee2019-05-13 16:54:09 -07007417 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007418 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
7422 }
7423
7424 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007425 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007426 enforceReadPrivilegedPermission("isApnMetered");
7427
7428 // Now that all security checks passes, perform the operation as ourselves.
7429 final long identity = Binder.clearCallingIdentity();
7430 try {
7431 Phone phone = getPhone(subId);
7432 if (phone == null) return true; // By default return true.
7433
Jack Yu41407ee2019-05-13 16:54:09 -07007434 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007435 } finally {
7436 Binder.restoreCallingIdentity(identity);
7437 }
7438 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007439
7440 @Override
7441 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7442 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7443 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7444 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7445 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7446 }
7447 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7448 Intent intent = new Intent();
7449 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7450 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7451 // Bring up choose default SMS subscription dialog right now
7452 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7453 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7454 mApp.startActivity(intent);
7455 }
chen xud5ca2d52019-05-28 15:20:57 -07007456
7457 @Override
7458 public String getMmsUAProfUrl(int subId) {
7459 //TODO investigate if this API should require proper permission check in R b/133791609
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7463 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
7467 }
7468
7469 @Override
7470 public String getMmsUserAgent(int subId) {
7471 //TODO investigate if this API should require proper permission check in R b/133791609
7472 final long identity = Binder.clearCallingIdentity();
7473 try {
7474 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7475 .getString(com.android.internal.R.string.config_mms_user_agent);
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
7479 }
Jack Yub07d4972019-05-28 16:12:25 -07007480
7481 @Override
7482 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7483 enforceModifyPermission();
7484
7485 // Now that all security checks passes, perform the operation as ourselves.
7486 final long identity = Binder.clearCallingIdentity();
7487 try {
7488 Phone phone = getPhone(subId);
7489 if (phone == null) return false;
7490
7491 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7492 } finally {
7493 Binder.restoreCallingIdentity(identity);
7494 }
7495 }
7496
7497 @Override
7498 public boolean isDataAllowedInVoiceCall(int subId) {
7499 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7500
7501 // Now that all security checks passes, perform the operation as ourselves.
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 Phone phone = getPhone(subId);
7505 if (phone == null) return false;
7506
7507 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
7510 }
7511 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007512
7513 /**
7514 * Updates whether conference event pacakge handling is enabled.
7515 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7516 * otherwise.
7517 */
7518 @Override
7519 public void setCepEnabled(boolean isCepEnabled) {
7520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7521
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7525 for (Phone phone : PhoneFactory.getPhones()) {
7526 Phone defaultPhone = phone.getImsPhone();
7527 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7528 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7529 ImsPhoneCallTracker imsPhoneCallTracker =
7530 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7531 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7532 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7533 + imsPhone.getMsisdn());
7534 }
7535 }
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
7539 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007540}