blob: 23911938b22cea739272031ed3a213d6bf924d94 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
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 Ebingera34a6c22019-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 Ebingerbc7dd582019-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;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import 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 zhao2737e882019-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;
Naina Nallurid63128d2019-09-17 14:10:30 -0700265 private static final int CMD_ERASE_MODEM_CONFIG = 74;
266 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800268 // Parameters of select command.
269 private static final int SELECT_COMMAND = 0xA4;
270 private static final int SELECT_P1 = 0x04;
271 private static final int SELECT_P2 = 0;
272 private static final int SELECT_P3 = 0x10;
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /** The singleton instance. */
275 private static PhoneInterfaceManager sInstance;
276
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800279 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800880 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001104 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001114 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001392 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001397 mTelephonySharedPreferences =
1398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 publish();
1403 }
1404
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001405 private Phone getDefaultPhone() {
1406 Phone thePhone = getPhone(getDefaultSubscription());
1407 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1408 }
1409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 private void publish() {
1411 if (DBG) log("publish: " + this);
1412
1413 ServiceManager.addService("phone", this);
1414 }
1415
Stuart Scott584921c2015-01-15 17:10:34 -08001416 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001417 if (request.phone != null) {
1418 return request.phone;
1419 } else {
1420 return getPhoneFromSubId(request.subId);
1421 }
1422 }
1423
1424 private Phone getPhoneFromSubId(int subId) {
1425 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1426 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001427 }
1428
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001429 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1430 Phone phone = getPhoneFromRequest(request);
1431 return phone == null ? null :
1432 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1433 }
1434
Wink Saville36469e72014-06-11 15:17:00 -07001435 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001436 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001437 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
Naina Nallurid63128d2019-09-17 14:10:30 -07001440 private void sendEraseModemConfig(Phone phone) {
1441 if (phone != null) {
1442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1443 mApp, phone.getSubId(), "eraseModemConfig");
1444 final long identity = Binder.clearCallingIdentity();
1445 try {
1446 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1447 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
1451 }
1452 }
1453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("dial: " + number);
1460 // No permission check needed here: This is just a wrapper around the
1461 // ACTION_DIAL intent, which is available to any app since it puts up
1462 // the UI before it does anything.
1463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001464 final long identity = Binder.clearCallingIdentity();
1465 try {
1466 String url = createTelUrl(number);
1467 if (url == null) {
1468 return;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 // PENDING: should we just silently fail if phone is offhook or ringing?
1472 PhoneConstants.State state = mCM.getState(subId);
1473 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1474 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1476 mApp.startActivity(intent);
1477 }
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 }
1482
1483 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 if (DBG) log("call: " + number);
1489
1490 // This is just a wrapper around the ACTION_CALL intent, but we still
1491 // need to do a permission check since we're calling startActivity()
1492 // from the context of the phone app.
1493 enforceCallPermission();
1494
Jordan Liu1617b712019-07-10 15:06:26 -07001495 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 != AppOpsManager.MODE_ALLOWED) {
1497 return;
1498 }
1499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 String url = createTelUrl(number);
1503 if (url == null) {
1504 return;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001507 boolean isValid = false;
1508 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1509 if (slist != null) {
1510 for (SubscriptionInfo subInfoRecord : slist) {
1511 if (subInfoRecord.getSubscriptionId() == subId) {
1512 isValid = true;
1513 break;
1514 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001515 }
Wink Saville08874612014-08-31 19:19:58 -07001516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001517 if (!isValid) {
1518 return;
1519 }
Wink Saville08874612014-08-31 19:19:58 -07001520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1522 intent.putExtra(SUBSCRIPTION_KEY, subId);
1523 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1524 mApp.startActivity(intent);
1525 } finally {
1526 Binder.restoreCallingIdentity(identity);
1527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001532 }
1533
Wink Savilleb564aae2014-10-23 10:18:09 -07001534 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001536 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1537 }
1538
1539 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001545 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1546 }
1547
1548 /** {@hide} */
1549 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001550 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPin.start();
1560 return checkSimPin.unlockSim(null, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville9de0f752013-10-22 19:04:03 -07001566 /** {@hide} */
1567 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1577 checkSimPuk.start();
1578 return checkSimPuk.unlockSim(puk, pin);
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
1584 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001585 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 * a synchronous one.
1587 */
1588 private static class UnlockSim extends Thread {
1589
1590 private final IccCard mSimCard;
1591
1592 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001593 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595
1596 // For replies from SimCard interface
1597 private Handler mHandler;
1598
1599 // For async handler to identify request type
1600 private static final int SUPPLY_PIN_COMPLETE = 100;
1601
1602 public UnlockSim(IccCard simCard) {
1603 mSimCard = simCard;
1604 }
1605
1606 @Override
1607 public void run() {
1608 Looper.prepare();
1609 synchronized (UnlockSim.this) {
1610 mHandler = new Handler() {
1611 @Override
1612 public void handleMessage(Message msg) {
1613 AsyncResult ar = (AsyncResult) msg.obj;
1614 switch (msg.what) {
1615 case SUPPLY_PIN_COMPLETE:
1616 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1617 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001618 mRetryCount = msg.arg1;
1619 if (ar.exception != null) {
1620 if (ar.exception instanceof CommandException &&
1621 ((CommandException)(ar.exception)).getCommandError()
1622 == CommandException.Error.PASSWORD_INCORRECT) {
1623 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1624 } else {
1625 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1626 }
1627 } else {
1628 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 mDone = true;
1631 UnlockSim.this.notifyAll();
1632 }
1633 break;
1634 }
1635 }
1636 };
1637 UnlockSim.this.notifyAll();
1638 }
1639 Looper.loop();
1640 }
1641
1642 /*
1643 * Use PIN or PUK to unlock SIM card
1644 *
1645 * If PUK is null, unlock SIM card with PIN
1646 *
1647 * If PUK is not null, unlock SIM card with PUK and set PIN code
1648 */
Wink Saville9de0f752013-10-22 19:04:03 -07001649 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650
1651 while (mHandler == null) {
1652 try {
1653 wait();
1654 } catch (InterruptedException e) {
1655 Thread.currentThread().interrupt();
1656 }
1657 }
1658 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1659
1660 if (puk == null) {
1661 mSimCard.supplyPin(pin, callback);
1662 } else {
1663 mSimCard.supplyPuk(puk, pin, callback);
1664 }
1665
1666 while (!mDone) {
1667 try {
1668 Log.d(LOG_TAG, "wait for done");
1669 wait();
1670 } catch (InterruptedException e) {
1671 // Restore the interrupted status
1672 Thread.currentThread().interrupt();
1673 }
1674 }
1675 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001676 int[] resultArray = new int[2];
1677 resultArray[0] = mResult;
1678 resultArray[1] = mRetryCount;
1679 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681 }
1682
1683 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001684 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001685
1686 }
1687
Wink Savilleb564aae2014-10-23 10:18:09 -07001688 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 // No permission check needed here: this call is harmless, and it's
1690 // needed for the ServiceState.requestStateUpdate() call (which is
1691 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.updateServiceLocation();
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001703 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
1705 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001706 return isRadioOnWithFeature(callingPackage, null);
1707 }
1708
1709
1710 @Override
1711 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1712 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1713 callingFeatureId);
1714 }
1715
1716 @Deprecated
1717 @Override
1718 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1719 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001720 }
1721
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001723 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1724 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001726 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001727 return false;
1728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 return isRadioOnForSubscriber(subId);
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
1735 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001736 }
1737
1738 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
1743 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1744 } else {
1745 return false;
1746 }
1747 } finally {
1748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001753 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 final Phone phone = getPhone(subId);
1762 if (phone != null) {
1763 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Wink Saville36469e72014-06-11 15:17:00 -07001768 }
1769
1770 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001771 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Wink Savilleb564aae2014-10-23 10:18:09 -07001774 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 final Phone phone = getPhone(subId);
1780 if (phone == null) {
1781 return false;
1782 }
1783 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1784 toggleRadioOnOffForSubscriber(subId);
1785 }
1786 return true;
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
Wink Saville36469e72014-06-11 15:17:00 -07001791
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001793 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 /*
1795 * If any of the Radios are available, it will need to be
1796 * shutdown. So return true if any Radio is available.
1797 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1801 Phone phone = PhoneFactory.getPhone(i);
1802 if (phone != null && phone.isRadioAvailable()) return true;
1803 }
1804 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1805 return false;
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001812 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 enforceModifyPermission();
1814
1815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1818 logv("Shutting down Phone " + i);
1819 shutdownRadioUsingPhoneId(i);
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001823 }
1824 }
1825
1826 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001827 Phone phone = PhoneFactory.getPhone(phoneId);
1828 if (phone != null && phone.isRadioAvailable()) {
1829 phone.shutdownRadio();
1830 }
1831 }
1832
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1839 if (defaultPhone != null) {
1840 defaultPhone.setRadioPower(turnOn);
1841 return true;
1842 } else {
1843 loge("There's no default phone.");
1844 return false;
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001848 }
Wink Saville36469e72014-06-11 15:17:00 -07001849 }
1850
Wink Savilleb564aae2014-10-23 10:18:09 -07001851 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 final Phone phone = getPhone(subId);
1857 if (phone != null) {
1858 phone.setRadioPower(turnOn);
1859 return true;
1860 } else {
1861 return false;
1862 }
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
1867
Wink Saville36469e72014-06-11 15:17:00 -07001868 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 public boolean enableDataConnectivity() {
1871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872
1873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 int subId = mSubscriptionController.getDefaultDataSubId();
1876 final Phone phone = getPhone(subId);
1877 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001878 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879 return true;
1880 } else {
1881 return false;
1882 }
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
Wink Saville36469e72014-06-11 15:17:00 -07001888 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public boolean disableDataConnectivity() {
1891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892
1893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 int subId = mSubscriptionController.getDefaultDataSubId();
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001898 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 return true;
1900 } else {
1901 return false;
1902 }
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001909 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910 final long identity = Binder.clearCallingIdentity();
1911 try {
1912 final Phone phone = getPhone(subId);
1913 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001914 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 } else {
1916 return false;
1917 }
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
1923 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001924 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
pkanwarae03a6b2016-11-06 20:37:09 -08001927 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 enforceCallPermission();
1929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1933 return;
1934 }
1935 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1936 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
1939 }
pkanwar32d516d2016-10-14 19:37:38 -07001940 };
1941
Wink Savilleb564aae2014-10-23 10:18:09 -07001942 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944
1945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1948 return false;
1949 }
1950 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1951 } finally {
1952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001957 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001958 }
1959
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001960 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 Phone phone = PhoneFactory.getPhone(slotIndex);
1964 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1965 PhoneConstantConversions.convertCallState(phone.getState());
1966 } finally {
1967 Binder.restoreCallingIdentity(identity);
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001972 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001973 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1974 }
1975
1976 @Override
1977 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978 final long identity = Binder.clearCallingIdentity();
1979 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 if (phone != null) {
1982 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1983 } else {
1984 return PhoneConstantConversions.convertDataState(
1985 PhoneConstants.DataState.DISCONNECTED);
1986 }
1987 } finally {
1988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001993 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001994 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1995 }
1996
1997 @Override
1998 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 final long identity = Binder.clearCallingIdentity();
2000 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002 if (phone != null) {
2003 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2004 } else {
2005 return TelephonyManager.DATA_ACTIVITY_NONE;
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002013 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002014 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002015 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002016
2017 LocationAccessPolicy.LocationPermissionResult locationResult =
2018 LocationAccessPolicy.checkLocationPermission(mApp,
2019 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2020 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002021 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002022 .setCallingPid(Binder.getCallingPid())
2023 .setCallingUid(Binder.getCallingUid())
2024 .setMethod("getCellLocation")
2025 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2026 .build());
2027 switch (locationResult) {
2028 case DENIED_HARD:
2029 throw new SecurityException("Not allowed to access cell location");
2030 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002031 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2032 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002035 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002039 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002040 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 } finally {
2042 Binder.restoreCallingIdentity(identity);
2043 }
Svetoslav64fad262015-04-14 14:35:21 -07002044 }
2045
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002047 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2048 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002049 if (!TextUtils.isEmpty(callingPackage)) {
2050 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2052 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002053 return "";
2054 }
2055 }
2056
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002057 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2058 // registered cell info, so return a NULL country instead.
2059 final long identity = Binder.clearCallingIdentity();
2060 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002061 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2062 // Get default phone in this case.
2063 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2064 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002065 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002066 // Todo: fix this when we can get the actual cellular network info when the device
2067 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002068 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002069 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2070 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002071 return "";
2072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073 Phone phone = PhoneFactory.getPhone(phoneId);
2074 if (phone != null) {
2075 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002076 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002077 if (sst != null) {
2078 LocaleTracker lt = sst.getLocaleTracker();
2079 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002080 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2081 return lt.getCurrentCountry();
2082 } else if (emergencyNumberTracker != null) {
2083 return emergencyNumberTracker.getEmergencyCountryIso();
2084 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002085 }
2086 }
2087 }
2088 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002089 } finally {
2090 Binder.restoreCallingIdentity(identity);
2091 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002092 }
2093
2094 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002096 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002097 }
2098
Sanket Padawe356d7632015-06-22 14:03:32 -07002099 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002100 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002101 mApp.enforceCallingOrSelfPermission(
2102 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002103
2104 final long identity = Binder.clearCallingIdentity();
2105 try {
2106 final Phone phone = getPhone(subId);
2107 if (phone != null) {
2108 phone.enableLocationUpdates();
2109 }
2110 } finally {
2111 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002112 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002113 }
2114
2115 @Override
2116 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002117 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002118 }
2119
Sanket Padawe356d7632015-06-22 14:03:32 -07002120 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002121 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002122 mApp.enforceCallingOrSelfPermission(
2123 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124
2125 final long identity = Binder.clearCallingIdentity();
2126 try {
2127 final Phone phone = getPhone(subId);
2128 if (phone != null) {
2129 phone.disableLocationUpdates();
2130 }
2131 } finally {
2132 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Nathan Harold31d7ff32018-10-15 20:20:30 -07002136 /**
2137 * Returns the target SDK version number for a given package name.
2138 *
Nathan Haroldec184742019-07-10 17:04:16 -07002139 * This call MUST be invoked before clearing the calling UID.
2140 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002141 * @return target SDK if the package is found or INT_MAX.
2142 */
2143 private int getTargetSdk(String packageName) {
2144 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002145 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002146 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002147 if (ai != null) return ai.targetSdkVersion;
2148 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002149 loge("Failed to get package info for pkg="
2150 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002151 }
2152 return Integer.MAX_VALUE;
2153 }
2154
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155 @Override
2156 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002157 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2158 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002159 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002160 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2161 throw new SecurityException(
2162 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2163 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002164
Jordan Liu1617b712019-07-10 15:06:26 -07002165 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2167 return null;
2168 }
Svetoslav64fad262015-04-14 14:35:21 -07002169
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002170 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002171
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002172 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002173 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174
Nathan Haroldf180aac2018-06-01 18:43:55 -07002175 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2176 for (CellInfo ci : info) {
2177 if (ci instanceof CellInfoGsm) {
2178 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2179 } else if (ci instanceof CellInfoWcdma) {
2180 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002183 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002186 private List<CellInfo> getCachedCellInfo() {
2187 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2188 for (Phone phone : PhoneFactory.getPhones()) {
2189 List<CellInfo> info = phone.getAllCellInfo();
2190 if (info != null) cellInfos.addAll(info);
2191 }
2192 return cellInfos;
2193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194
2195 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002196 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002197 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002198 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002199
2200 LocationAccessPolicy.LocationPermissionResult locationResult =
2201 LocationAccessPolicy.checkLocationPermission(mApp,
2202 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2203 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002204 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002205 .setCallingPid(Binder.getCallingPid())
2206 .setCallingUid(Binder.getCallingUid())
2207 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002208 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002209 .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:
2215 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216 }
2217
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002218 final int targetSdk = getTargetSdk(callingPackage);
2219 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2220 return getCachedCellInfo();
2221 }
2222
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002223 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002224 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2228 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002229 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002230 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231 if (info != null) cellInfos.addAll(info);
2232 }
2233 return cellInfos;
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237 }
2238
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002239 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002240 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2241 String callingFeatureId) {
2242 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2243 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002244 }
2245
2246 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002247 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2248 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002249 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002250 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 }
2252
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002253 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2254 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002255 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002256 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002257
2258 LocationAccessPolicy.LocationPermissionResult locationResult =
2259 LocationAccessPolicy.checkLocationPermission(mApp,
2260 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2261 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002262 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002263 .setCallingPid(Binder.getCallingPid())
2264 .setCallingUid(Binder.getCallingUid())
2265 .setMethod("requestCellInfoUpdate")
2266 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2267 .build());
2268 switch (locationResult) {
2269 case DENIED_HARD:
2270 throw new SecurityException("Not allowed to access cell info");
2271 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002272 try {
2273 cb.onCellInfo(new ArrayList<CellInfo>());
2274 } catch (RemoteException re) {
2275 // Drop without consequences
2276 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002277 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002278 }
2279
Nathan Harolda939a962019-05-09 10:13:47 -07002280
2281 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002282 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2283
2284 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2285 }
2286
2287 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002289 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002290 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002291
2292 final long identity = Binder.clearCallingIdentity();
2293 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 } finally {
2296 Binder.restoreCallingIdentity(identity);
2297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Shishir Agrawala9f32182016-04-12 12:00:16 -07002300 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002301 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002302 Phone phone = PhoneFactory.getPhone(slotIndex);
2303 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002304 return null;
2305 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002306 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002307 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002308 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002309 return null;
2310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 return phone.getImei();
2315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002318 }
2319
2320 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002321 public String getTypeAllocationCodeForSlot(int slotIndex) {
2322 Phone phone = PhoneFactory.getPhone(slotIndex);
2323 String tac = null;
2324 if (phone != null) {
2325 String imei = phone.getImei();
2326 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2327 }
2328 return tac;
2329 }
2330
2331 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002332 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002333 Phone phone = PhoneFactory.getPhone(slotIndex);
2334 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002335 return null;
2336 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002337
Jeff Davidson913390f2018-02-23 17:11:49 -08002338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002340 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 return null;
2342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343
2344 final long identity = Binder.clearCallingIdentity();
2345 try {
2346 return phone.getMeid();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
Jack Yu2af8d712017-03-15 17:14:14 -07002350 }
2351
2352 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002353 public String getManufacturerCodeForSlot(int slotIndex) {
2354 Phone phone = PhoneFactory.getPhone(slotIndex);
2355 String manufacturerCode = null;
2356 if (phone != null) {
2357 String meid = phone.getMeid();
2358 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2359 }
2360 return manufacturerCode;
2361 }
2362
2363 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002364 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2365 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002366 Phone phone = PhoneFactory.getPhone(slotIndex);
2367 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002368 return null;
2369 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002370 int subId = phone.getSubId();
2371 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002372 mApp, subId, callingPackage, callingFeatureId,
2373 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002374 return null;
2375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 return phone.getDeviceSvn();
2380 } finally {
2381 Binder.restoreCallingIdentity(identity);
2382 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002383 }
2384
fionaxu43304da2017-11-27 22:51:16 -08002385 @Override
2386 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 final long identity = Binder.clearCallingIdentity();
2388 try {
2389 final Phone phone = getPhone(subId);
2390 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
fionaxu43304da2017-11-27 22:51:16 -08002394 }
2395
2396 @Override
2397 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002398 final long identity = Binder.clearCallingIdentity();
2399 try {
2400 final Phone phone = getPhone(subId);
2401 return phone == null ? null : phone.getCarrierName();
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
2404 }
fionaxu43304da2017-11-27 22:51:16 -08002405 }
2406
calvinpanffe225e2018-11-01 19:43:06 +08002407 @Override
chen xu0026ca62019-03-06 15:28:50 -08002408 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 final Phone phone = getPhone(subId);
2412 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002413 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002414 } finally {
2415 Binder.restoreCallingIdentity(identity);
2416 }
2417 }
2418
2419 @Override
chen xu0026ca62019-03-06 15:28:50 -08002420 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002424 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002425 } finally {
2426 Binder.restoreCallingIdentity(identity);
2427 }
2428 }
2429
chen xu651eec72018-11-11 19:03:44 -08002430 @Override
chen xu864e11c2018-12-06 22:10:03 -08002431 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2432 if (!isSubscriptionMccMnc) {
2433 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2434 }
chen xu651eec72018-11-11 19:03:44 -08002435 final Phone phone = PhoneFactory.getPhone(slotIndex);
2436 if (phone == null) {
2437 return TelephonyManager.UNKNOWN_CARRIER_ID;
2438 }
2439 final long identity = Binder.clearCallingIdentity();
2440 try {
2441 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
2444 }
2445 }
2446
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002447 //
2448 // Internal helper methods.
2449 //
2450
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002451 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2453 *
2454 * @throws SecurityException if the caller does not have the required permission
2455 */
2456 private void enforceModifyPermission() {
2457 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2458 }
2459
Shuo Qian3b6ee772019-11-13 17:43:31 -08002460 private void enforceActiveEmergencySessionPermission() {
2461 mApp.enforceCallingOrSelfPermission(
2462 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2463 }
2464
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002465 /**
2466 * Make sure the caller has the CALL_PHONE permission.
2467 *
2468 * @throws SecurityException if the caller does not have the required permission
2469 */
2470 private void enforceCallPermission() {
2471 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2472 }
2473
paulhu5a773602019-08-23 19:17:33 +08002474 private void enforceSettingsPermission() {
2475 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002476 }
2477
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002478 private String createTelUrl(String number) {
2479 if (TextUtils.isEmpty(number)) {
2480 return null;
2481 }
2482
Jake Hambye994d462014-02-03 13:10:13 -08002483 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Ihab Awadf9e92732013-12-05 18:02:52 -08002486 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002487 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2488 }
2489
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002490 private static void logv(String msg) {
2491 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2492 }
2493
Ihab Awadf9e92732013-12-05 18:02:52 -08002494 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2496 }
2497
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002499 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002500 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002501 }
2502
Sanket Padawe356d7632015-06-22 14:03:32 -07002503 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002504 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 final Phone phone = PhoneFactory.getPhone(slotIndex);
2508 if (phone == null) {
2509 return PhoneConstants.PHONE_TYPE_NONE;
2510 } else {
2511 return phone.getPhoneType();
2512 }
2513 } finally {
2514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002516 }
2517
2518 /**
2519 * Returns the CDMA ERI icon index to display
2520 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002521 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002522 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2523 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2524 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
Sanket Padawe356d7632015-06-22 14:03:32 -07002527 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002528 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2529 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002530 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002531 mApp, subId, callingPackage, callingFeatureId,
2532 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 return -1;
2534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 final Phone phone = getPhone(subId);
2539 if (phone != null) {
2540 return phone.getCdmaEriIconIndex();
2541 } else {
2542 return -1;
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
2549 /**
2550 * Returns the CDMA ERI icon mode,
2551 * 0 - ON
2552 * 1 - FLASHING
2553 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002554 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002555 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2556 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2557 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2562 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002563 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002564 mApp, subId, callingPackage, callingFeatureId,
2565 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002566 return -1;
2567 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 final Phone phone = getPhone(subId);
2572 if (phone != null) {
2573 return phone.getCdmaEriIconMode();
2574 } else {
2575 return -1;
2576 }
2577 } finally {
2578 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002579 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002580 }
2581
2582 /**
2583 * Returns the CDMA ERI text,
2584 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002585 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002586 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2587 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2588 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002592 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2593 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002594 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002595 mApp, subId, callingPackage, callingFeatureId,
2596 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002597 return null;
2598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 final Phone phone = getPhone(subId);
2603 if (phone != null) {
2604 return phone.getCdmaEriText();
2605 } else {
2606 return null;
2607 }
2608 } finally {
2609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002611 }
2612
2613 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002614 * Returns the CDMA MDN.
2615 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002616 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002617 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 return phone.getLine1Number();
2626 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628 return null;
2629 }
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002632 }
2633 }
2634
2635 /**
2636 * Returns the CDMA MIN.
2637 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002638 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002639 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2641 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2647 return phone.getCdmaMin();
2648 } else {
2649 return null;
2650 }
2651 } finally {
2652 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002653 }
2654 }
2655
Hall Liud892bec2018-11-30 14:51:45 -08002656 @Override
2657 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2658 INumberVerificationCallback callback, String callingPackage) {
2659 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2660 != PERMISSION_GRANTED) {
2661 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2662 }
2663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2664
2665 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2666 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2667 throw new SecurityException("Calling package must be configured in the device config");
2668 }
2669
2670 if (range == null) {
2671 throw new NullPointerException("Range must be non-null");
2672 }
2673
2674 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002675 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002676
2677 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2678 }
2679
Junda Liuca05d5d2014-08-14 22:36:34 -07002680 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002681 * Returns true if CDMA provisioning needs to run.
2682 */
2683 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002684 final long identity = Binder.clearCallingIdentity();
2685 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002686 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687 } finally {
2688 Binder.restoreCallingIdentity(identity);
2689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
2692 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002693 * Sets the voice mail number of a given subId.
2694 */
2695 @Override
2696 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002697 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2698 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2703 new Pair<String, String>(alphaTag, number), new Integer(subId));
2704 return success;
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002708 }
2709
Ta-wei Yen87c49842016-05-13 21:19:52 -07002710 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002711 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002713 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2714 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002715 if (!TextUtils.equals(callingPackage, systemDialer)) {
2716 throw new SecurityException("caller must be system dialer");
2717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718
2719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2722 if (phoneAccountHandle == null) {
2723 return null;
2724 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002728 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
2730
2731 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002732 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2733 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002736 mApp, subId, callingPackage, callingFeatureId,
2737 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002738 return null;
2739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002741 final long identity = Binder.clearCallingIdentity();
2742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002743 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002747 }
2748
2749 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002750 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2751 VisualVoicemailSmsFilterSettings settings) {
2752 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002757 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002758 } finally {
2759 Binder.restoreCallingIdentity(identity);
2760 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002761 }
2762
2763 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002764 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2765 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002770 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002771 } finally {
2772 Binder.restoreCallingIdentity(identity);
2773 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002774 }
2775
2776 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002777 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2778 String callingPackage, int subId) {
2779 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780
2781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002784 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002785 } finally {
2786 Binder.restoreCallingIdentity(identity);
2787 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002788 }
2789
2790 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002791 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002792 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793
2794 final long identity = Binder.clearCallingIdentity();
2795 try {
2796 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002801 }
2802
2803 @Override
2804 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2805 String number, int port, String text, PendingIntent sentIntent) {
2806 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002807 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002808 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002809 SmsController smsController = PhoneFactory.getSmsController();
2810 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2811 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002812 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002813
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002814 /**
fionaxu0152e512016-11-14 13:36:14 -08002815 * Sets the voice activation state of a given subId.
2816 */
2817 @Override
2818 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2820 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
2824 final Phone phone = getPhone(subId);
2825 if (phone != null) {
2826 phone.setVoiceActivationState(activationState);
2827 } else {
2828 loge("setVoiceActivationState fails with invalid subId: " + subId);
2829 }
2830 } finally {
2831 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002832 }
2833 }
2834
2835 /**
2836 * Sets the data activation state of a given subId.
2837 */
2838 @Override
2839 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002840 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2841 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002842
2843 final long identity = Binder.clearCallingIdentity();
2844 try {
2845 final Phone phone = getPhone(subId);
2846 if (phone != null) {
2847 phone.setDataActivationState(activationState);
2848 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002849 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002853 }
2854 }
2855
2856 /**
2857 * Returns the voice activation state of a given subId.
2858 */
2859 @Override
2860 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
fionaxu0152e512016-11-14 13:36:14 -08002863 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864 final long identity = Binder.clearCallingIdentity();
2865 try {
2866 if (phone != null) {
2867 return phone.getVoiceActivationState();
2868 } else {
2869 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2870 }
2871 } finally {
2872 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002873 }
2874 }
2875
2876 /**
2877 * Returns the data activation state of a given subId.
2878 */
2879 @Override
2880 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002881 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
fionaxu0152e512016-11-14 13:36:14 -08002883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 final long identity = Binder.clearCallingIdentity();
2885 try {
2886 if (phone != null) {
2887 return phone.getDataActivationState();
2888 } else {
2889 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002893 }
2894 }
2895
2896 /**
Wink Saville36469e72014-06-11 15:17:00 -07002897 * Returns the unread count of voicemails for a subId
2898 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002900 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2901 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002902 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002903 mApp, subId, callingPackage, callingFeatureId,
2904 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002905 return 0;
2906 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 final Phone phone = getPhone(subId);
2910 if (phone != null) {
2911 return phone.getVoiceMessageCount();
2912 } else {
2913 return 0;
2914 }
2915 } finally {
2916 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002918 }
2919
2920 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002921 * returns true, if the device is in a state where both voice and data
2922 * are supported simultaneously. This can change based on location or network condition.
2923 */
2924 @Override
2925 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002926 final long identity = Binder.clearCallingIdentity();
2927 try {
2928 final Phone phone = getPhone(subId);
2929 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
2932 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002933 }
2934
2935 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002936 * Send the dialer code if called from the current default dialer or the caller has
2937 * carrier privilege.
2938 * @param inputCode The dialer code to send
2939 */
2940 @Override
2941 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002942 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002943 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002944 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2945 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002946 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002947 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002950
2951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
fionaxu235cc5e2017-03-06 22:25:57 -08002957 }
2958
Pengquan Menga1bb6272018-09-06 09:59:22 -07002959 @Override
2960 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002961 if (!isActiveSubscription(subId)) {
2962 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2963 }
2964
Pengquan Menga1bb6272018-09-06 09:59:22 -07002965 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2966 }
2967
Brad Ebinger35c841c2018-10-01 10:40:55 -07002968 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002969 public boolean isInEmergencySmsMode() {
2970 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 for (Phone phone : PhoneFactory.getPhones()) {
2974 if (phone.isInEmergencySmsMode()) {
2975 return true;
2976 }
2977 }
2978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 return false;
2982 }
2983
2984 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002985 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2986 throws RemoteException {
2987 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002988 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2989 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2990 "IMS not available on device.");
2991 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002992 final long token = Binder.clearCallingIdentity();
2993 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002994 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002997 } catch (ImsException e) {
2998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002999 } finally {
3000 Binder.restoreCallingIdentity(token);
3001 }
3002 }
3003
3004 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003005 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3006 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003007 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3008 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3009 }
Meng Wangafbc5852019-09-19 17:37:13 -07003010 final long token = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3013 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3014 .removeRegistrationCallbackForSubscription(c, subId);
3015 } catch (ImsException e) {
3016 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3017 + "is inactive, ignoring unregister.");
3018 // If the subscription is no longer active, just return, since the callback
3019 // will already have been removed internally.
3020 } finally {
3021 Binder.restoreCallingIdentity(token);
3022 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 }
3024
Brad Ebingera34a6c22019-10-22 17:36:18 -07003025 /**
3026 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3027 */
3028 @Override
3029 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3030 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3031 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3032 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3033 "IMS not available on device.");
3034 }
3035 final long token = Binder.clearCallingIdentity();
3036 try {
3037 Phone phone = getPhone(subId);
3038 if (phone == null) {
3039 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3040 + subId + "'");
3041 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3042 }
3043 phone.getImsRegistrationState(regState -> {
3044 try {
3045 consumer.accept((regState == null)
3046 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3047 } catch (RemoteException e) {
3048 // Ignore if the remote process is no longer available to call back.
3049 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3050 }
3051 });
3052 } finally {
3053 Binder.restoreCallingIdentity(token);
3054 }
3055 }
3056
3057 /**
3058 * Get the transport type for the IMS service registration state.
3059 */
3060 @Override
3061 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3062 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3063 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3064 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3065 "IMS not available on device.");
3066 }
3067 final long token = Binder.clearCallingIdentity();
3068 try {
3069 Phone phone = getPhone(subId);
3070 if (phone == null) {
3071 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3072 + subId + "'");
3073 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3074 }
3075 phone.getImsRegistrationTech(regTech -> {
3076 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3077 int regTechConverted = (regTech == null)
3078 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3079 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3080 regTechConverted);
3081 try {
3082 consumer.accept(regTechConverted);
3083 } catch (RemoteException e) {
3084 // Ignore if the remote process is no longer available to call back.
3085 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3086 }
3087 });
3088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
3091 }
3092
Brad Ebinger35c841c2018-10-01 10:40:55 -07003093 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003094 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3095 throws RemoteException {
3096 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003097 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3098 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3099 "IMS not available on device.");
3100 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3102 final long token = Binder.clearCallingIdentity();
3103 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003104 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003105 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003106 } catch (ImsException e) {
3107 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 } finally {
3109 Binder.restoreCallingIdentity(token);
3110 }
3111 }
3112
3113 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003114 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3115 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003116 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3117 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3118 }
Meng Wangafbc5852019-09-19 17:37:13 -07003119
3120 final long token = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3123 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003124 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003125 } catch (ImsException e) {
3126 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3127 + "is inactive, ignoring unregister.");
3128 // If the subscription is no longer active, just return, since the callback
3129 // will already have been removed internally.
3130 } finally {
3131 Binder.restoreCallingIdentity(token);
3132 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 }
3134
3135 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003136 public boolean isCapable(int subId, int capability, int regTech) {
3137 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3139 final long token = Binder.clearCallingIdentity();
3140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003143 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3145 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003147 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3148 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 } finally {
3150 Binder.restoreCallingIdentity(token);
3151 }
3152 }
3153
3154 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 public boolean isAvailable(int subId, int capability, int regTech) {
3156 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 final long token = Binder.clearCallingIdentity();
3158 try {
3159 Phone phone = getPhone(subId);
3160 if (phone == null) return false;
3161 return phone.isImsCapabilityAvailable(capability, regTech);
3162 } finally {
3163 Binder.restoreCallingIdentity(token);
3164 }
3165 }
3166
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003167 /**
3168 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3169 * subscription.
3170 * @param subId The subscription to use to check the configuration.
3171 * @param callback The callback that will be used to send the result.
3172 * @param capability The MmTelFeature capability that will be used to send the result.
3173 * @param transportType The transport type of the MmTelFeature capability.
3174 */
3175 @Override
3176 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3177 int transportType) {
3178 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3179 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3180 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3181 "IMS not available on device.");
3182 }
3183 final long token = Binder.clearCallingIdentity();
3184 try {
3185 int slotId = getSlotIndex(subId);
3186 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3187 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3188 + subId + "'");
3189 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3190 }
3191 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3192 transportType, aBoolean -> {
3193 try {
3194 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3195 } catch (RemoteException e) {
3196 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3197 + "running. Ignore");
3198 }
3199 });
3200 } finally {
3201 Binder.restoreCallingIdentity(token);
3202 }
3203 }
3204
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 @Override
3206 public boolean isAdvancedCallingSettingEnabled(int subId) {
3207 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3208 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3209 final long token = Binder.clearCallingIdentity();
3210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003211 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003213 } catch (ImsException e) {
3214 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 } finally {
3216 Binder.restoreCallingIdentity(token);
3217 }
3218 }
3219
3220 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003223 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003224 final long identity = Binder.clearCallingIdentity();
3225 try {
3226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003227 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003229 } catch (ImsException e) {
3230 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 } finally {
3232 Binder.restoreCallingIdentity(identity);
3233 }
3234 }
3235
3236 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003237 public boolean isVtSettingEnabled(int subId) {
3238 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003239 final long identity = Binder.clearCallingIdentity();
3240 try {
3241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003242 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3243 } catch (ImsException e) {
3244 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 } finally {
3246 Binder.restoreCallingIdentity(identity);
3247 }
3248 }
3249
3250 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003253 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 final long identity = Binder.clearCallingIdentity();
3255 try {
3256 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003257 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
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 boolean isVoWiFiSettingEnabled(int subId) {
3267 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
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)).isWfcEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003283 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 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, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003288 } catch (ImsException e) {
3289 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3297 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003301 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003303 } catch (ImsException e) {
3304 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 } finally {
3306 Binder.restoreCallingIdentity(identity);
3307 }
3308 }
3309
3310 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003313 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 final long identity = Binder.clearCallingIdentity();
3315 try {
3316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003317 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003318 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
3327 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3329 "setVoWiFiNonPersistent");
3330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003334 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003335 } 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 int getVoWiFiModeSetting(int subId) {
3344 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
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)).getWfcMode(false /*isRoaming*/);
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
3357 @Override
3358 public void setVoWiFiModeSetting(int subId, int mode) {
3359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3360 "setVoWiFiModeSetting");
3361 final long identity = Binder.clearCallingIdentity();
3362 try {
3363 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003364 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003366 } catch (ImsException e) {
3367 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public int getVoWiFiRoamingModeSetting(int subId) {
3375 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003381 } catch (ImsException e) {
3382 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 } finally {
3384 Binder.restoreCallingIdentity(identity);
3385 }
3386 }
3387
3388 @Override
3389 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3391 "setVoWiFiRoamingModeSetting");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003395 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003397 } catch (ImsException e) {
3398 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3407 "setRttCapabilityEnabled");
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3412 } catch (ImsException e) {
3413 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 } finally {
3415 Binder.restoreCallingIdentity(identity);
3416 }
3417 }
3418
3419 @Override
3420 public boolean isTtyOverVolteEnabled(int subId) {
3421 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003425 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003427 } catch (ImsException e) {
3428 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003429 } finally {
3430 Binder.restoreCallingIdentity(identity);
3431 }
3432 }
3433
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 @Override
3435 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3436 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3437 final long identity = Binder.clearCallingIdentity();
3438 try {
3439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003441 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (ImsException e) {
3443 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 } finally {
3445 Binder.restoreCallingIdentity(identity);
3446 }
3447 }
3448
3449 @Override
3450 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3451 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3452 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003453 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3454 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3455 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003456 try {
3457 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003458 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003460 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003461 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3462 + "is inactive, ignoring unregister.");
3463 // If the subscription is no longer active, just return, since the callback will already
3464 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
3468 }
3469
3470 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3472 boolean isProvisioned) {
3473 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3474 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3475 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3476 }
3477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3478 "setProvisioningStatusForCapability");
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3482 Phone phone = getPhone(subId);
3483 if (phone == null) {
3484 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3485 + subId);
3486 return;
3487 }
3488 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3489 return;
3490 }
3491
3492 // this capability requires provisioning, route to the correct API.
3493 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3494 switch (capability) {
3495 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3496 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3497 ims.setVolteProvisioned(isProvisioned);
3498 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3499 ims.setWfcProvisioned(isProvisioned);
3500 }
3501 break;
3502 }
3503 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3504 // There is currently no difference in VT provisioning type.
3505 ims.setVtProvisioned(isProvisioned);
3506 break;
3507 }
3508 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3509 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3510 // change the capability of the feature instead if needed.
3511 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3512 == isProvisioned) {
3513 // No change in provisioning.
3514 return;
3515 }
3516 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3517 try {
3518 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003519 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003520 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3521 + ", Exception" + e.getMessage());
3522 }
3523 break;
3524 }
3525 default: {
3526 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3527 + capability + "', which does not require provisioning.");
3528 }
3529 }
3530
3531 } finally {
3532 Binder.restoreCallingIdentity(identity);
3533 }
3534 }
3535
3536 @Override
3537 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3538 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3539 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3540 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3541 }
3542 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3546 Phone phone = getPhone(subId);
3547 if (phone == null) {
3548 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3549 + subId);
3550 // We will fail with "true" as the provisioning status because this is the default
3551 // if we do not require provisioning.
3552 return true;
3553 }
3554
3555 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3556 return true;
3557 }
3558
3559 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3560 switch (capability) {
3561 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3562 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3563 return ims.isVolteProvisionedOnDevice();
3564 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3565 return ims.isWfcProvisionedOnDevice();
3566 }
3567 // This should never happen, since we are checking tech above to make sure it
3568 // is either LTE or IWLAN.
3569 throw new IllegalArgumentException("Invalid radio technology for voice "
3570 + "capability.");
3571 }
3572 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3573 // There is currently no difference in VT provisioning type.
3574 return ims.isVtProvisionedOnDevice();
3575 }
3576 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3577 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3578 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3579 }
3580 default: {
3581 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3582 + capability + "', which does not require provisioning.");
3583 }
3584 }
3585
3586 } finally {
3587 Binder.restoreCallingIdentity(identity);
3588 }
3589 }
3590
3591 @Override
3592 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3593 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3594 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3595 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3596 }
3597 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3598 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3599 return (provisionedBits & capability) > 0;
3600 }
3601
3602 @Override
3603 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3604 boolean isProvisioned) {
3605 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3606 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3607 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3608 }
3609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3610 "setProvisioningStatusForCapability");
3611 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3612 // If the current provisioning status for capability already matches isProvisioned,
3613 // do nothing.
3614 if (((provisionedBits & capability) > 0) == isProvisioned) {
3615 return;
3616 }
3617 if (isProvisioned) {
3618 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3619 } else {
3620 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3621 }
3622 }
3623
3624 /**
3625 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3626 * technology. The bitfield should mirror the bitfield defined by
3627 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3628 */
3629 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3630 String key = getMmTelProvisioningKey(subId, tech);
3631 // Default is no capabilities are provisioned.
3632 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3633 }
3634
3635 /**
3636 * Sets the MmTel capability provisioning bitfield (defined by
3637 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3638 * technology specified.
3639 *
3640 * Note: This is a synchronous command and should not be called on UI thread.
3641 */
3642 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3643 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3644 String key = getMmTelProvisioningKey(subId, tech);
3645 editor.putInt(key, newField);
3646 editor.commit();
3647 }
3648
3649 private static String getMmTelProvisioningKey(int subId, int tech) {
3650 // resulting key is provision_ims_mmtel_{subId}_{tech}
3651 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3652 }
3653
3654 /**
3655 * Query CarrierConfig to see if the specified capability requires provisioning for the
3656 * carrier associated with the subscription id.
3657 */
3658 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3659 int capability) {
3660 CarrierConfigManager configManager = new CarrierConfigManager(context);
3661 PersistableBundle c = configManager.getConfigForSubId(subId);
3662 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003663 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003664 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3665 false);
3666 boolean requireVoiceVtProvisioning = c.getBoolean(
3667 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3668
3669 // First check to make sure that the capability requires provisioning.
3670 switch (capability) {
3671 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3672 // intentional fallthrough
3673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3674 if (requireVoiceVtProvisioning) {
3675 // Voice and Video requires provisioning
3676 return true;
3677 }
3678 break;
3679 }
3680 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3681 if (requireUtProvisioning) {
3682 // UT requires provisioning
3683 return true;
3684 }
3685 break;
3686 }
3687 }
3688 return false;
3689 }
3690
3691 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003692 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003693 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3694 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3695 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003696 enforceReadPrivilegedPermission("getImsProvisioningInt");
3697 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, "getImsProvisioningInt: called with an inactive subscription '"
3703 + subId + "' for key:" + key);
3704 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3705 }
3706 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
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, "getImsProvisioningInt: ImsService is not available for subscription '"
3709 + subId + "' for key:" + key);
3710 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003718 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3719 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3720 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003721 enforceReadPrivilegedPermission("getImsProvisioningString");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003725 int slotId = getSlotIndex(subId);
3726 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3727 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3728 + subId + "' for key:" + key);
3729 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3730 }
3731 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003732 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3734 + subId + "' for key:" + key);
3735 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
3739 }
3740
3741 @Override
3742 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003743 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3744 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3745 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3747 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003751 int slotId = getSlotIndex(subId);
3752 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3753 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3754 + subId + "' for key:" + key);
3755 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3756 }
3757 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003759 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3760 + "' for key:" + key);
3761 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
3767 @Override
3768 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003769 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3770 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3771 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3773 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003774 final long identity = Binder.clearCallingIdentity();
3775 try {
3776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003777 int slotId = getSlotIndex(subId);
3778 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3779 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3780 + subId + "' for key:" + key);
3781 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3782 }
3783 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003784 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003785 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3786 + "' for key:" + key);
3787 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003788 } finally {
3789 Binder.restoreCallingIdentity(identity);
3790 }
3791 }
3792
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003794 int slotId = SubscriptionManager.getSlotIndex(subId);
3795 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003796 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3797 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003798 }
3799 return slotId;
3800 }
3801
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003802 private int getSlotIndex(int subId) {
3803 int slotId = SubscriptionManager.getSlotIndex(subId);
3804 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3805 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3806 }
3807 return slotId;
3808 }
3809
Wink Saville36469e72014-06-11 15:17:00 -07003810 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003811 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003812 */
3813 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003814 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3815 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003816 final int targetSdk = getTargetSdk(callingPackage);
3817 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003818 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003819 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003820 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003821 mApp, subId, callingPackage, callingFeatureId,
3822 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003823 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3824 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003826 final long identity = Binder.clearCallingIdentity();
3827 try {
3828 final Phone phone = getPhone(subId);
3829 if (phone != null) {
3830 return phone.getServiceState().getDataNetworkType();
3831 } else {
3832 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3833 }
3834 } finally {
3835 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003836 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003837 }
3838
3839 /**
3840 * Returns the data network type
3841 */
3842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003843 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3844 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3845 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003846 }
3847
3848 /**
3849 * Returns the data network type for a subId
3850 */
3851 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003852 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3853 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003854 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003855 mApp, subId, callingPackage, callingFeatureId,
3856 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003857 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3858 }
3859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 final Phone phone = getPhone(subId);
3863 if (phone != null) {
3864 return phone.getServiceState().getDataNetworkType();
3865 } else {
3866 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3867 }
3868 } finally {
3869 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003870 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003871 }
3872
3873 /**
Wink Saville36469e72014-06-11 15:17:00 -07003874 * Returns the Voice network type for a subId
3875 */
3876 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003877 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3878 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003879 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003880 mApp, subId, callingPackage, callingFeatureId,
3881 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003882 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3883 }
3884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 final Phone phone = getPhone(subId);
3888 if (phone != null) {
3889 return phone.getServiceState().getVoiceNetworkType();
3890 } else {
3891 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3892 }
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003895 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003896 }
3897
3898 /**
3899 * @return true if a ICC card is present
3900 */
3901 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003902 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003903 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3904 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003905 }
3906
3907 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003908 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003909 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003910 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003911 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 final Phone phone = PhoneFactory.getPhone(slotIndex);
3915 if (phone != null) {
3916 return phone.getIccCard().hasIccCard();
3917 } else {
3918 return false;
3919 }
3920 } finally {
3921 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003923 }
3924
3925 /**
3926 * Return if the current radio is LTE on CDMA. This
3927 * is a tri-state return value as for a period of time
3928 * the mode may be unknown.
3929 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003930 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003932 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003933 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003934 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003935 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3936 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3937 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003938 }
3939
Sanket Padawe356d7632015-06-22 14:03:32 -07003940 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003941 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3942 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003944 mApp, subId, callingPackage, callingFeatureId,
3945 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003946 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3947 }
3948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 final Phone phone = getPhone(subId);
3952 if (phone == null) {
3953 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3954 } else {
3955 return phone.getLteOnCdmaMode();
3956 }
3957 } finally {
3958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003959 }
Wink Saville36469e72014-06-11 15:17:00 -07003960 }
3961
Wink Saville36469e72014-06-11 15:17:00 -07003962 /**
3963 * {@hide}
3964 * Returns Default subId, 0 in the case of single standby.
3965 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003966 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003967 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003968 }
3969
Shishir Agrawala9f32182016-04-12 12:00:16 -07003970 private int getSlotForDefaultSubscription() {
3971 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3972 }
3973
Wink Savilleb564aae2014-10-23 10:18:09 -07003974 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003975 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003976 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003977
Pengquan Menge92a50d2018-09-21 15:54:48 -07003978 private boolean isActiveSubscription(int subId) {
3979 return mSubscriptionController.isActiveSubId(subId);
3980 }
3981
Ihab Awadf2177b72013-11-25 13:33:23 -08003982 /**
3983 * @see android.telephony.TelephonyManager.WifiCallingChoices
3984 */
3985 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 final long identity = Binder.clearCallingIdentity();
3987 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3990 getWhenToMakeWifiCallsDefaultPreference());
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003994 }
3995
3996 /**
3997 * @see android.telephony.TelephonyManager.WifiCallingChoices
3998 */
3999 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000 final long identity = Binder.clearCallingIdentity();
4001 try {
4002 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004003 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004004 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004008 }
4009
Sailesh Nepald1e68152013-12-12 19:08:02 -08004010 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004011 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004012 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004013 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004014
Jordan Liu4c733742019-02-28 12:03:40 -08004015 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4016 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4017 if (phoneId == -1) {
4018 throw new IllegalArgumentException("Given slot index: " + slotIndex
4019 + " does not correspond to an active phone");
4020 }
4021 return PhoneFactory.getPhone(phoneId);
4022 }
4023
Shishir Agrawal566b7612013-10-28 14:41:00 -07004024 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004025 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4026 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4028 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004030 if (DBG) {
4031 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4032 }
4033 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4034 p2);
4035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004036
Jordan Liu4c733742019-02-28 12:03:40 -08004037
4038 @Override
4039 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4040 int slotIndex, String callingPackage, String aid, int p2) {
4041 enforceModifyPermission();
4042 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4043 if (DBG) {
4044 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4045 }
4046 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4047 callingPackage, aid, p2);
4048 }
4049
4050 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4051 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (TextUtils.equals(ISDR_AID, aid)) {
4055 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004056 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4057 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 if (bestComponent == null
4059 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4060 loge("The calling package is not allowed to access ISD-R.");
4061 throw new SecurityException(
4062 "The calling package is not allowed to access ISD-R.");
4063 }
Derek Tan740e1672017-06-27 14:56:27 -07004064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004066 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004067 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4068 null /* workSource */);
4069 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 return response;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004074 }
4075
4076 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004077 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4079 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004080 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4081 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4082 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004083
Jordan Liu4c733742019-02-28 12:03:40 -08004084 @Override
4085 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4086 enforceModifyPermission();
4087 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4088 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4089 channel);
4090 }
4091
4092 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 final long identity = Binder.clearCallingIdentity();
4094 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004095 if (channel < 0) {
4096 return false;
4097 }
Jordan Liu4c733742019-02-28 12:03:40 -08004098 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4099 null /* workSource */);
4100 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101 return success;
4102 } finally {
4103 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004104 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
4106
4107 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004108 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004109 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4111 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004112 if (DBG) {
4113 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4114 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4115 + p3 + " data=" + data);
4116 }
4117 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4118 command, p1, p2, p3, data);
4119 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004120
Jordan Liu4c733742019-02-28 12:03:40 -08004121 @Override
4122 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4123 int command, int p1, int p2, int p3, String data) {
4124 enforceModifyPermission();
4125 if (DBG) {
4126 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4127 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4128 + p3 + " data=" + data);
4129 }
4130 return iccTransmitApduLogicalChannelWithPermission(
4131 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4132 data);
4133 }
4134
4135 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4136 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004137 final long identity = Binder.clearCallingIdentity();
4138 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004139 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004140 return "";
4141 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004144 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4145 null /* workSource */);
4146 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004147
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004148 // Append the returned status code to the end of the response payload.
4149 String s = Integer.toHexString(
4150 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4151 if (response.payload != null) {
4152 s = IccUtils.bytesToHexString(response.payload) + s;
4153 }
4154 return s;
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004157 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004158 }
Jake Hambye994d462014-02-03 13:10:13 -08004159
Evan Charltonc66da362014-05-16 14:06:40 -07004160 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004161 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4162 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4164 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004165 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004166 if (DBG) {
4167 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4168 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4169 }
4170 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4171 cla, command, p1, p2, p3, data);
4172 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004173
Jordan Liu4c733742019-02-28 12:03:40 -08004174 @Override
4175 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4176 int command, int p1, int p2, int p3, String data) {
4177 enforceModifyPermission();
4178 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4179 if (DBG) {
4180 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4181 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4182 + " data=" + data);
4183 }
4184
4185 return iccTransmitApduBasicChannelWithPermission(
4186 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4187 p2, p3, data);
4188 }
4189
4190 // open APDU basic channel assuming the caller has sufficient permissions
4191 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4192 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4196 && TextUtils.equals(ISDR_AID, data)) {
4197 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004198 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4199 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 if (bestComponent == null
4201 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4202 loge("The calling package is not allowed to select ISD-R.");
4203 throw new SecurityException(
4204 "The calling package is not allowed to select ISD-R.");
4205 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004209 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4210 null /* workSource */);
4211 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213 // Append the returned status code to the end of the response payload.
4214 String s = Integer.toHexString(
4215 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4216 if (response.payload != null) {
4217 s = IccUtils.bytesToHexString(response.payload) + s;
4218 }
4219 return s;
4220 } finally {
4221 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004222 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004223 }
4224
4225 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004226 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004227 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004228 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4229 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004230
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
4233 if (DBG) {
4234 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4235 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4236 }
4237
4238 IccIoResult response =
4239 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4240 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4241 subId);
4242
4243 if (DBG) {
4244 log("Exchange SIM_IO [R]" + response);
4245 }
4246
4247 byte[] result = null;
4248 int length = 2;
4249 if (response.payload != null) {
4250 length = 2 + response.payload.length;
4251 result = new byte[length];
4252 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4253 } else {
4254 result = new byte[length];
4255 }
4256
4257 result[length - 1] = (byte) response.sw2;
4258 result[length - 2] = (byte) response.sw1;
4259 return result;
4260 } finally {
4261 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004262 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
4264
Nathan Haroldb3014052017-01-25 15:57:32 -08004265 /**
4266 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4267 * on a particular subscription
4268 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004269 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4270 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004272 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004273 return null;
4274 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 if (appType != TelephonyManager.APPTYPE_USIM
4279 && appType != TelephonyManager.APPTYPE_SIM) {
4280 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4281 return null;
4282 }
4283 Object response = sendRequest(
4284 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4285 if (response instanceof String[]) {
4286 return (String[]) response;
4287 }
yincheng zhao2737e882019-09-06 17:06:54 -07004288 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004290 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 } finally {
4292 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004293 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
4295
yincheng zhao2737e882019-09-06 17:06:54 -07004296 /**
4297 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4298 * subscription.
4299 *
4300 * @param subId the id of the subscription.
4301 * @param appType the uicc app type, must be USIM or SIM.
4302 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4303 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004305 * @return number of fplmns that is successfully written to the SIM.
4306 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4308 String callingFeatureId) {
4309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4310 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004311 if (DBG) logv("no permissions for setForbiddenplmns");
4312 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4313 }
4314 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4315 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4316 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4317 }
4318 if (fplmns == null) {
4319 throw new IllegalArgumentException("Fplmn List provided is null");
4320 }
4321 for (String fplmn : fplmns) {
4322 if (!CellIdentity.isValidPlmn(fplmn)) {
4323 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4324 }
4325 }
4326 final long identity = Binder.clearCallingIdentity();
4327 try {
4328 Object response = sendRequest(
4329 CMD_SET_FORBIDDEN_PLMNS,
4330 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4331 subId);
4332 return (int) response;
4333 } finally {
4334 Binder.restoreCallingIdentity(identity);
4335 }
4336 }
4337
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004338 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004339 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4341 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004342
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4346 if (response.payload == null) {
4347 return "";
4348 }
Evan Charltonc66da362014-05-16 14:06:40 -07004349
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004350 // Append the returned status code to the end of the response payload.
4351 String s = Integer.toHexString(
4352 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4353 s = IccUtils.bytesToHexString(response.payload) + s;
4354 return s;
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Evan Charltonc66da362014-05-16 14:06:40 -07004358 }
4359
Jake Hambye994d462014-02-03 13:10:13 -08004360 /**
4361 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4362 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4363 *
4364 * @param itemID the ID of the item to read
4365 * @return the NV item as a String, or null on error.
4366 */
4367 @Override
4368 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4371 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372
4373 final long identity = Binder.clearCallingIdentity();
4374 try {
4375 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004376 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004377 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4378 return value;
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
4381 }
Jake Hambye994d462014-02-03 13:10:13 -08004382 }
4383
4384 /**
4385 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4386 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4387 *
4388 * @param itemID the ID of the item to read
4389 * @param itemValue the value to write, as a String
4390 * @return true on success; false on any failure
4391 */
4392 @Override
4393 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004394 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004395 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4396 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
4398 final long identity = Binder.clearCallingIdentity();
4399 try {
4400 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4401 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004402 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4404 return success;
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
4407 }
Jake Hambye994d462014-02-03 13:10:13 -08004408 }
4409
4410 /**
4411 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4412 * Used for device configuration by some CDMA operators.
4413 *
4414 * @param preferredRoamingList byte array containing the new PRL
4415 * @return true on success; false on any failure
4416 */
4417 @Override
4418 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4425 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4426 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4427 return success;
4428 } finally {
4429 Binder.restoreCallingIdentity(identity);
4430 }
Jake Hambye994d462014-02-03 13:10:13 -08004431 }
4432
4433 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004434 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004435 * Used for device configuration by some CDMA operators.
4436 *
chen xu6dac5ab2018-10-26 17:39:23 -07004437 * @param slotIndex - device slot.
4438 *
Jake Hambye994d462014-02-03 13:10:13 -08004439 * @return true on success; false on any failure
4440 */
4441 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004442 public boolean resetModemConfig(int slotIndex) {
4443 Phone phone = PhoneFactory.getPhone(slotIndex);
4444 if (phone != null) {
4445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4446 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447
chen xu6dac5ab2018-10-26 17:39:23 -07004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4451 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4452 return success;
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 }
chen xu6dac5ab2018-10-26 17:39:23 -07004457 return false;
4458 }
4459
4460 /**
4461 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4462 *
4463 * @param slotIndex - device slot.
4464 *
4465 * @return true on success; false on any failure
4466 */
4467 @Override
4468 public boolean rebootModem(int slotIndex) {
4469 Phone phone = PhoneFactory.getPhone(slotIndex);
4470 if (phone != null) {
4471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4472 mApp, phone.getSubId(), "rebootModem");
4473
4474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4477 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4478 return success;
4479 } finally {
4480 Binder.restoreCallingIdentity(identity);
4481 }
4482 }
4483 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004484 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004485
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004486 public String[] getPcscfAddress(String apnType, String callingPackage,
4487 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004488 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4490 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004491 return new String[0];
4492 }
4493
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 final long identity = Binder.clearCallingIdentity();
4495 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004496 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 } finally {
4498 Binder.restoreCallingIdentity(identity);
4499 }
Wink Saville36469e72014-06-11 15:17:00 -07004500 }
4501
Brad Ebinger51f743a2017-01-23 13:50:20 -08004502 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004503 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4504 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004505 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004506 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004507 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508
4509 final long identity = Binder.clearCallingIdentity();
4510 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004511 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004512 // may happen if the device does not support IMS.
4513 return;
4514 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004515 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 } finally {
4517 Binder.restoreCallingIdentity(identity);
4518 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004519 }
4520
4521 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004522 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4523 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004524 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004525 public void disableIms(int slotId) {
4526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527
4528 final long identity = Binder.clearCallingIdentity();
4529 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004530 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004531 // may happen if the device does not support IMS.
4532 return;
4533 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004534 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535 } finally {
4536 Binder.restoreCallingIdentity(identity);
4537 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004538 }
4539
4540 /**
4541 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4542 * feature or {@link null} if the service is not available. If the feature is available, the
4543 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4544 */
4545 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004546 IImsServiceFeatureCallback callback) {
4547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004548
4549 final long identity = Binder.clearCallingIdentity();
4550 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004551 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004552 // may happen if the device does not support IMS.
4553 return null;
4554 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004555 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 } finally {
4557 Binder.restoreCallingIdentity(identity);
4558 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004559 }
4560
4561 /**
4562 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4563 * feature during emergency calling or {@link null} if the service is not available. If the
4564 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4565 * listener for feature updates.
4566 */
4567 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569
4570 final long identity = Binder.clearCallingIdentity();
4571 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004572 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004573 // may happen if the device does not support IMS.
4574 return null;
4575 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004576 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577 } finally {
4578 Binder.restoreCallingIdentity(identity);
4579 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004580 }
4581
Brad Ebinger5f64b052017-12-14 14:26:15 -08004582 /**
4583 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004584 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004585 */
4586 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588
4589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004591 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004592 // may happen if the device does not support IMS.
4593 return null;
4594 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004595 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004599 }
4600
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004601 /**
4602 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004603 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004604 */
4605 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004607
4608 final long identity = Binder.clearCallingIdentity();
4609 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004610 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004611 // may happen if the device does not support IMS.
4612 return null;
4613 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004614 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 } finally {
4616 Binder.restoreCallingIdentity(identity);
4617 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004618 }
4619
Brad Ebinger884c07b2018-02-15 16:17:40 -08004620 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004621 * Sets the ImsService Package Name that Telephony will bind to.
4622 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004623 * @param slotIndex the slot ID that the ImsService should bind for.
4624 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004625 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004626 * @param featureTypes An integer array of feature types associated with a packageName.
4627 * @param packageName The name of the package that the current configuration will be replaced
4628 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004629 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004630 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004631 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4632 int[] featureTypes, String packageName) {
4633 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4634 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4636 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004637 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
4640 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004641 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004642 // may happen if the device does not support IMS.
4643 return false;
4644 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004645 Map<Integer, String> featureConfig = new HashMap<>();
4646 for (int featureType : featureTypes) {
4647 featureConfig.put(featureType, packageName);
4648 }
4649 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4650 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
4653 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004654 }
4655
4656 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004657 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004658 *
4659 * @param slotId The slot that the ImsService is associated with.
4660 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4661 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004662 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004663 * @return the package name of the ImsService configuration.
4664 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004665 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4666 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004667 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004668 TelephonyPermissions
4669 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4670 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4671 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 final long identity = Binder.clearCallingIdentity();
4674 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004675 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004676 // may happen if the device does not support IMS.
4677 return "";
4678 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004679 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004680 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4681 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004682 } finally {
4683 Binder.restoreCallingIdentity(identity);
4684 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004685 }
4686
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004687 /**
4688 * Get the MmTelFeature state associated with the requested subscription id.
4689 * @param subId The subscription that the MmTelFeature is associated with.
4690 * @param callback A callback with an integer containing the
4691 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4692 */
4693 @Override
4694 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4695 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4696 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4698 "IMS not available on device.");
4699 }
4700 final long token = Binder.clearCallingIdentity();
4701 try {
4702 int slotId = getSlotIndex(subId);
4703 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4704 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4705 + subId + "'");
4706 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4707 }
4708 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4709 try {
4710 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4711 } catch (RemoteException e) {
4712 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4713 + "Ignore");
4714 }
4715 });
4716 } finally {
4717 Binder.restoreCallingIdentity(token);
4718 }
4719 }
4720
Wink Saville36469e72014-06-11 15:17:00 -07004721 public void setImsRegistrationState(boolean registered) {
4722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004726 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Wink Saville36469e72014-06-11 15:17:00 -07004730 }
4731
4732 /**
Stuart Scott54788802015-03-30 13:18:01 -07004733 * Set the network selection mode to automatic.
4734 *
4735 */
4736 @Override
4737 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4739 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
Pengquan Menge92a50d2018-09-21 15:54:48 -07004741 if (!isActiveSubscription(subId)) {
4742 return;
4743 }
4744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4748 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
4751 }
Stuart Scott54788802015-03-30 13:18:01 -07004752 }
4753
Pengquan Mengea84e042018-09-20 14:57:26 -07004754 /**
4755 * Ask the radio to connect to the input network and change selection mode to manual.
4756 *
4757 * @param subId the id of the subscription.
4758 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4759 * the operator to attach to.
4760 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4761 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4762 * normal network selection next time.
4763 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004764 */
4765 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004766 public boolean setNetworkSelectionModeManual(
4767 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4769 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004770
4771 if (!isActiveSubscription(subId)) {
4772 return false;
4773 }
4774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 final long identity = Binder.clearCallingIdentity();
4776 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004777 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004779 if (DBG) {
4780 log("setNetworkSelectionModeManual: subId: " + subId
4781 + " operator: " + operatorInfo);
4782 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4784 } finally {
4785 Binder.restoreCallingIdentity(identity);
4786 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004787 }
4788
4789 /**
4790 * Scans for available networks.
4791 */
4792 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004793 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004795 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4796 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004797 LocationAccessPolicy.LocationPermissionResult locationResult =
4798 LocationAccessPolicy.checkLocationPermission(mApp,
4799 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4800 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004801 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004802 .setCallingPid(Binder.getCallingPid())
4803 .setCallingUid(Binder.getCallingUid())
4804 .setMethod("getCellNetworkScanResults")
4805 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4806 .build());
4807 switch (locationResult) {
4808 case DENIED_HARD:
4809 throw new SecurityException("Not allowed to access scan results -- location");
4810 case DENIED_SOFT:
4811 return null;
4812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
Pengquan Menga1bb6272018-09-06 09:59:22 -07004814 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 try {
4816 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004817 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004822 }
4823
4824 /**
yinxub1bed742017-04-17 11:45:04 -07004825 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004826 *
yinxub1bed742017-04-17 11:45:04 -07004827 * @param subId id of the subscription
4828 * @param request contains the radio access networks with bands/channels to scan
4829 * @param messenger callback messenger for scan results or errors
4830 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004831 * @return the id of the requested scan which can be used to stop the scan.
4832 */
4833 @Override
4834 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004835 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4837 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004838 LocationAccessPolicy.LocationPermissionResult locationResult =
4839 LocationAccessPolicy.checkLocationPermission(mApp,
4840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4841 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004842 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004843 .setCallingPid(Binder.getCallingPid())
4844 .setCallingUid(Binder.getCallingUid())
4845 .setMethod("requestNetworkScan")
4846 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4847 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004848 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004849 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004850 if (e != null) {
4851 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4852 throw e;
4853 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004854 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004855 return TelephonyScanManager.INVALID_SCAN_ID;
4856 }
4857 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004858 }
Hall Liu912dfd32019-04-25 14:02:26 -07004859 int callingUid = Binder.getCallingUid();
4860 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 return mNetworkScanRequestTracker.startNetworkScan(
4864 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004865 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
yinxu504e1392017-04-12 16:03:22 -07004869 }
4870
Hall Liub2ac8ef2019-02-28 15:56:23 -08004871 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004872 NetworkScanRequest request, int subId) {
4873 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4874 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4875 boolean hasNetworkScanPermission =
4876 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4877 == PERMISSION_GRANTED;
4878
4879 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4880 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4881 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004882 }
4883
4884 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4885 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004886 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4887 return new SecurityException("Specific channels must not be"
4888 + " scanned without location access.");
4889 }
4890 }
4891 }
4892
Hall Liub2ac8ef2019-02-28 15:56:23 -08004893 return null;
4894 }
4895
yinxu504e1392017-04-12 16:03:22 -07004896 /**
4897 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004898 *
4899 * @param subId id of the subscription
4900 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004901 */
4902 @Override
4903 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906
Hall Liu912dfd32019-04-25 14:02:26 -07004907 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 final long identity = Binder.clearCallingIdentity();
4909 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004910 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
yinxu504e1392017-04-12 16:03:22 -07004914 }
4915
4916 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004917 * Get the calculated preferred network type.
4918 * Used for debugging incorrect network type.
4919 *
4920 * @return the preferred network type, defined in RILConstants.java.
4921 */
4922 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004923 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004924 final Phone defaultPhone = getDefaultPhone();
4925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004926 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004927 return RILConstants.PREFERRED_NETWORK_MODE;
4928 }
4929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 final long identity = Binder.clearCallingIdentity();
4931 try {
4932 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004933 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934 } finally {
4935 Binder.restoreCallingIdentity(identity);
4936 }
Junda Liu84d15a22014-07-02 11:21:04 -07004937 }
4938
4939 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004940 * Get the preferred network type.
4941 * Used for device configuration by some CDMA operators.
4942 *
4943 * @return the preferred network type, defined in RILConstants.java.
4944 */
4945 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004946 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004947 TelephonyPermissions
4948 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4949 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950
4951 final long identity = Binder.clearCallingIdentity();
4952 try {
4953 if (DBG) log("getPreferredNetworkType");
4954 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4955 int networkType = (result != null ? result[0] : -1);
4956 if (DBG) log("getPreferredNetworkType: " + networkType);
4957 return networkType;
4958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004961 }
4962
4963 /**
4964 * Set the preferred network type.
4965 * Used for device configuration by some CDMA operators.
4966 *
4967 * @param networkType the preferred network type, defined in RILConstants.java.
4968 * @return true on success; false on any failure.
4969 */
4970 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004971 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4973 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974
4975 final long identity = Binder.clearCallingIdentity();
4976 try {
4977 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4978 Boolean success = (Boolean) sendRequest(
4979 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4980 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4981 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004982 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4984 }
4985 return success;
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004988 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004989 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004990
4991 /**
Miaoa84611c2019-03-15 09:21:10 +08004992 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004993 *
Miaoa84611c2019-03-15 09:21:10 +08004994 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004995 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004996 * @hide
4997 */
4998 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004999 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003 try {
Miaoa84611c2019-03-15 09:21:10 +08005004 if (phone != null) {
5005 return phone.hasMatchedTetherApnSetting();
5006 } else {
5007 return false;
5008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005011 }
Junda Liu475951f2014-11-07 16:45:03 -08005012 }
5013
5014 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005015 * Set mobile data enabled
5016 * Used by the user through settings etc to turn on/off mobile data
5017 *
5018 * @param enable {@code true} turn turn data on, else {@code false}
5019 */
5020 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005021 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5023 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 int phoneId = mSubscriptionController.getPhoneId(subId);
5028 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5029 Phone phone = PhoneFactory.getPhone(phoneId);
5030 if (phone != null) {
5031 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005032 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005034 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005035 }
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005038 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005039 }
5040
5041 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005042 * Get the user enabled state of Mobile Data.
5043 *
5044 * TODO: remove and use isUserDataEnabled.
5045 * This can't be removed now because some vendor codes
5046 * calls through ITelephony directly while they should
5047 * use TelephonyManager.
5048 *
5049 * @return true on enabled
5050 */
5051 @Override
5052 public boolean getDataEnabled(int subId) {
5053 return isUserDataEnabled(subId);
5054 }
5055
5056 /**
5057 * Get whether mobile data is enabled per user setting.
5058 *
5059 * There are other factors deciding whether mobile data is actually enabled, but they are
5060 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005061 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005062 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005063 *
5064 * @return {@code true} if data is enabled else {@code false}
5065 */
5066 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005067 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005068 try {
5069 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5070 null);
5071 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5073 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075
5076 final long identity = Binder.clearCallingIdentity();
5077 try {
5078 int phoneId = mSubscriptionController.getPhoneId(subId);
5079 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5080 Phone phone = PhoneFactory.getPhone(phoneId);
5081 if (phone != null) {
5082 boolean retVal = phone.isUserDataEnabled();
5083 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5084 return retVal;
5085 } else {
5086 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5087 return false;
5088 }
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005091 }
5092 }
5093
5094 /**
5095 * Get whether mobile data is enabled.
5096 *
5097 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5098 * whether mobile data is actually enabled.
5099 *
5100 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5101 *
5102 * @return {@code true} if data is enabled else {@code false}
5103 */
5104 @Override
5105 public boolean isDataEnabled(int subId) {
5106 try {
5107 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5108 null);
5109 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5111 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113
5114 final long identity = Binder.clearCallingIdentity();
5115 try {
5116 int phoneId = mSubscriptionController.getPhoneId(subId);
5117 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5118 Phone phone = PhoneFactory.getPhone(phoneId);
5119 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005120 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5122 return retVal;
5123 } else {
5124 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5125 return false;
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005129 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005130 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005131
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005132 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5133 Phone phone) {
5134 //load access rules from carrier configs, and check those as well: b/139133814
5135 SubscriptionController subController = SubscriptionController.getInstance();
5136 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5137 || subController == null) return privilegeFromSim;
5138
5139 int uid = Binder.getCallingUid();
5140 PackageManager pkgMgr = phone.getContext().getPackageManager();
5141 String[] packages = pkgMgr.getPackagesForUid(uid);
5142
5143 final long identity = Binder.clearCallingIdentity();
5144 try {
5145 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5146 SubscriptionManager subManager = (SubscriptionManager)
5147 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5148 for (String pkg : packages) {
5149 if (subManager.canManageSubscription(subInfo, pkg)) {
5150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5151 }
5152 }
5153 return privilegeFromSim;
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
5157 }
5158
5159 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5160 String pkgName) {
5161 //load access rules from carrier configs, and check those as well: b/139133814
5162 SubscriptionController subController = SubscriptionController.getInstance();
5163 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5164 || subController == null) return privilegeFromSim;
5165
5166 final long identity = Binder.clearCallingIdentity();
5167 try {
5168 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5169 SubscriptionManager subManager = (SubscriptionManager)
5170 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5171 return subManager.canManageSubscription(subInfo, pkgName)
5172 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5173 } finally {
5174 Binder.restoreCallingIdentity(identity);
5175 }
5176 }
5177
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005178 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005179 public int getCarrierPrivilegeStatus(int subId) {
5180 final Phone phone = getPhone(subId);
5181 if (phone == null) {
5182 loge("getCarrierPrivilegeStatus: Invalid subId");
5183 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5184 }
5185 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005186 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005187 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005188 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5189 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005190
5191 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5192 card.getCarrierPrivilegeStatusForCurrentTransaction(
5193 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005194 }
Junda Liu29340342014-07-10 15:23:27 -07005195
5196 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005198 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005199 final Phone phone = getPhone(subId);
5200 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005201 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5203 }
5204 UiccProfile profile =
5205 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5206 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005207 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5209 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005210 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005211 profile.getCarrierPrivilegeStatusForUid(
5212 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 }
5214
5215 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005216 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5217 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005218 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005219 }
5220
5221 int phoneId = SubscriptionManager.getPhoneId(subId);
5222 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005223 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005224 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005225 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5226 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005227 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5228 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5229 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005230 }
5231
5232 @Override
5233 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005234 if (TextUtils.isEmpty(pkgName))
5235 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005236 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5237 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5238 UiccCard card = UiccController.getInstance().getUiccCard(i);
5239 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005240 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005241 continue;
5242 }
5243
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005244 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5245 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5246 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005247 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5248 break;
5249 }
5250 }
5251
5252 return result;
Junda Liu29340342014-07-10 15:23:27 -07005253 }
Derek Tan89e89d42014-07-08 17:00:10 -07005254
5255 @Override
Junda Liue64de782015-04-16 17:19:16 -07005256 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5257 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5258 loge("phoneId " + phoneId + " is not valid.");
5259 return null;
5260 }
5261 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005262 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005263 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005264 return null ;
5265 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005267 }
5268
Amith Yamasani6e118872016-02-19 12:53:51 -08005269 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005270 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005272 List<String> privilegedPackages = new ArrayList<>();
5273 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005274 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5275 // has UICC in that slot.
5276 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005277 if (card.hasCarrierPrivilegeRules()) {
5278 if (packages == null) {
5279 // Only check packages in user 0 for now
5280 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005281 PackageManager.MATCH_DISABLED_COMPONENTS
5282 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005283 | PackageManager.GET_SIGNING_CERTIFICATES,
5284 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005285 }
5286 for (int p = packages.size() - 1; p >= 0; p--) {
5287 PackageInfo pkgInfo = packages.get(p);
5288 if (pkgInfo != null && pkgInfo.packageName != null
5289 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005290 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005291 privilegedPackages.add(pkgInfo.packageName);
5292 }
5293 }
5294 }
5295 }
5296 return privilegedPackages;
5297 }
5298
chen xuf7e9fe82019-05-09 19:31:02 -07005299 @Override
5300 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005301 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5302
5303 final long identity = Binder.clearCallingIdentity();
5304
chen xuf7e9fe82019-05-09 19:31:02 -07005305 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005306 try {
5307 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5308 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5309 }
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005312 }
5313 return privilegedPackages;
5314 }
5315
Wink Savilleb564aae2014-10-23 10:18:09 -07005316 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005317 final Phone phone = getPhone(subId);
5318 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005319 if (card == null) {
5320 loge("getIccId: No UICC");
5321 return null;
5322 }
5323 String iccId = card.getIccId();
5324 if (TextUtils.isEmpty(iccId)) {
5325 loge("getIccId: ICC ID is null or empty.");
5326 return null;
5327 }
5328 return iccId;
5329 }
5330
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005331 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005332 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5333 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005334 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005335 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 final String iccId = getIccId(subId);
5340 final Phone phone = getPhone(subId);
5341 if (phone == null) {
5342 return false;
5343 }
5344 final String subscriberId = phone.getSubscriberId();
5345
5346 if (DBG_MERGE) {
5347 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5348 + subscriberId + " to " + number);
5349 }
5350
5351 if (TextUtils.isEmpty(iccId)) {
5352 return false;
5353 }
5354
5355 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5356
5357 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5358 if (alphaTag == null) {
5359 editor.remove(alphaTagPrefKey);
5360 } else {
5361 editor.putString(alphaTagPrefKey, alphaTag);
5362 }
5363
5364 // Record both the line number and IMSI for this ICCID, since we need to
5365 // track all merged IMSIs based on line number
5366 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5367 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5368 if (number == null) {
5369 editor.remove(numberPrefKey);
5370 editor.remove(subscriberPrefKey);
5371 } else {
5372 editor.putString(numberPrefKey, number);
5373 editor.putString(subscriberPrefKey, subscriberId);
5374 }
5375
5376 editor.commit();
5377 return true;
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005380 }
Derek Tan7226c842014-07-02 17:42:23 -07005381 }
5382
5383 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005384 public String getLine1NumberForDisplay(int subId, String callingPackage,
5385 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005386 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005388 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005389 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005390 return null;
5391 }
Derek Tan97ebb422014-09-05 16:55:38 -07005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 String iccId = getIccId(subId);
5396 if (iccId != null) {
5397 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5398 if (DBG_MERGE) {
5399 log("getLine1NumberForDisplay returning "
5400 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5401 }
5402 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5405 return null;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005408 }
Derek Tan7226c842014-07-02 17:42:23 -07005409 }
5410
5411 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005412 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5413 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005415 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005416 return null;
5417 }
Derek Tan97ebb422014-09-05 16:55:38 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 String iccId = getIccId(subId);
5422 if (iccId != null) {
5423 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5424 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5425 }
5426 return null;
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005429 }
Derek Tan7226c842014-07-02 17:42:23 -07005430 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005431
5432 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005433 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5434 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005435 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5436 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005438 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005439 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005440 return null;
5441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005442
Jordan Liub49b04b2019-05-06 14:45:15 -07005443 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5444 // the process, where TelephonyManager was instantiated.
5445 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005446 final long identity = Binder.clearCallingIdentity();
5447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005448 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final TelephonyManager tele = TelephonyManager.from(context);
5450 final SubscriptionManager sub = SubscriptionManager.from(context);
5451
5452 // Figure out what subscribers are currently active
5453 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
Jordan Liub49b04b2019-05-06 14:45:15 -07005455 // Only consider subs which match the current subId
5456 // This logic can be simplified. See b/131189269 for progress.
5457 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005458 activeSubscriberIds.add(tele.getSubscriberId(subId));
5459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 // First pass, find a number override for an active subscriber
5462 String mergeNumber = null;
5463 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5464 for (String key : prefs.keySet()) {
5465 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5466 final String subscriberId = (String) prefs.get(key);
5467 if (activeSubscriberIds.contains(subscriberId)) {
5468 final String iccId = key.substring(
5469 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5470 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5471 mergeNumber = (String) prefs.get(numberKey);
5472 if (DBG_MERGE) {
5473 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5474 + " for active subscriber " + subscriberId);
5475 }
5476 if (!TextUtils.isEmpty(mergeNumber)) {
5477 break;
5478 }
5479 }
5480 }
5481 }
5482
5483 // Shortcut when no active merged subscribers
5484 if (TextUtils.isEmpty(mergeNumber)) {
5485 return null;
5486 }
5487
5488 // Second pass, find all subscribers under that line override
5489 final ArraySet<String> result = new ArraySet<>();
5490 for (String key : prefs.keySet()) {
5491 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5492 final String number = (String) prefs.get(key);
5493 if (mergeNumber.equals(number)) {
5494 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5495 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5496 final String subscriberId = (String) prefs.get(subscriberKey);
5497 if (!TextUtils.isEmpty(subscriberId)) {
5498 result.add(subscriberId);
5499 }
5500 }
5501 }
5502 }
5503
5504 final String[] resultArray = result.toArray(new String[result.size()]);
5505 Arrays.sort(resultArray);
5506 if (DBG_MERGE) {
5507 Slog.d(LOG_TAG,
5508 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5509 }
5510 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005511 } finally {
5512 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005513 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005514 }
5515
5516 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005517 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5518 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 final TelephonyManager telephonyManager = mApp.getSystemService(
5523 TelephonyManager.class);
5524 String subscriberId = telephonyManager.getSubscriberId(subId);
5525 if (subscriberId == null) {
5526 if (DBG) {
5527 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5528 + subId);
5529 }
5530 return null;
5531 }
5532
5533 final SubscriptionInfo info = SubscriptionController.getInstance()
5534 .getSubscriptionInfo(subId);
5535 final ParcelUuid groupUuid = info.getGroupUuid();
5536 // If it doesn't belong to any group, return just subscriberId of itself.
5537 if (groupUuid == null) {
5538 return new String[]{subscriberId};
5539 }
5540
5541 // Get all subscriberIds from the group.
5542 final List<String> mergedSubscriberIds = new ArrayList<>();
5543 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5545 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005546 for (SubscriptionInfo subInfo : groupInfos) {
5547 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5548 if (subscriberId != null) {
5549 mergedSubscriberIds.add(subscriberId);
5550 }
5551 }
5552
5553 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556
5557 }
5558 }
5559
5560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005561 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005563 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 final Phone phone = getPhone(subId);
5568 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005572 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005573
5574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005575 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005576 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5577 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005578 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5579 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 final Phone phone = getPhone(subId);
5584 if (phone == null) {
5585 return false;
5586 }
5587 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5588 cdmaNonRoamingList);
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005591 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005592 }
5593
5594 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005595 @Deprecated
5596 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5597 enforceModifyPermission();
5598
5599 int returnValue = 0;
5600 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005601 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005602 if(result.exception == null) {
5603 if (result.result != null) {
5604 byte[] responseData = (byte[])(result.result);
5605 if(responseData.length > oemResp.length) {
5606 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5607 responseData.length + "bytes. Buffer Size is " +
5608 oemResp.length + "bytes.");
5609 }
5610 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5611 returnValue = responseData.length;
5612 }
5613 } else {
5614 CommandException ex = (CommandException) result.exception;
5615 returnValue = ex.getCommandError().ordinal();
5616 if(returnValue > 0) returnValue *= -1;
5617 }
5618 } catch (RuntimeException e) {
5619 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5620 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5621 if(returnValue > 0) returnValue *= -1;
5622 }
5623
5624 return returnValue;
5625 }
5626
5627 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005628 public void setRadioCapability(RadioAccessFamily[] rafs) {
5629 try {
5630 ProxyController.getInstance().setRadioCapability(rafs);
5631 } catch (RuntimeException e) {
5632 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5633 }
5634 }
5635
5636 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005637 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005638 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005639 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005640 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005641 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005642 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643 final long identity = Binder.clearCallingIdentity();
5644 try {
chen xub97461a2018-10-26 14:17:57 -07005645 TelephonyPermissions
5646 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5647 mApp, phone.getSubId(), "getRadioAccessFamily");
5648 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 } finally {
5650 Binder.restoreCallingIdentity(identity);
5651 }
chen xub97461a2018-10-26 14:17:57 -07005652 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005653 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005654
5655 @Override
5656 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 ImsManager.getInstance(defaultPhone.getContext(),
5663 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005667 }
5668
5669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005670 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005671 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5673 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005674 return false;
5675 }
Svet Ganovb320e182015-04-16 12:30:10 -07005676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 // Check the user preference and the system-level IMS setting. Even if the user has
5680 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5681 // In the long run, we may instead need to check if there exists a connection service
5682 // which can support video calling.
5683 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005684 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 return imsManager.isVtEnabledByPlatform()
5686 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5687 && imsManager.isVtEnabledByUser();
5688 } finally {
5689 Binder.restoreCallingIdentity(identity);
5690 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005691 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005692
Andrew Leea1239f22015-03-02 17:44:07 -08005693 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005694 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5695 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005697 mApp, subId, callingPackage, callingFeatureId,
5698 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699 return false;
5700 }
5701
5702 final long identity = Binder.clearCallingIdentity();
5703 try {
5704 CarrierConfigManager configManager =
5705 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005706 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005707 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Andrew Leea1239f22015-03-02 17:44:07 -08005711 }
5712
5713 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005716 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717 return false;
5718 }
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 try {
5722 CarrierConfigManager configManager =
5723 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005724 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005725 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
5728 }
Andrew Leea1239f22015-03-02 17:44:07 -08005729 }
5730
Andrew Lee9431b832015-03-09 18:46:45 -07005731 @Override
5732 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005733 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005734 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005735 }
5736
5737 @Override
5738 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005739 final long identity = Binder.clearCallingIdentity();
5740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005741 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742 } finally {
5743 Binder.restoreCallingIdentity(identity);
5744 }
Andrew Lee9431b832015-03-09 18:46:45 -07005745 }
5746
Hall Liuf6668912018-10-31 17:05:23 -07005747 /**
5748 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5749 * support for the feature and device firmware support.
5750 *
5751 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5752 */
5753 @Override
5754 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005755 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005756 final Phone phone = getPhone(subscriptionId);
5757 if (phone == null) {
5758 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5759 return false;
5760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005762 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5764 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005765 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 return isCarrierSupported && isDeviceSupported;
5767 } finally {
5768 Binder.restoreCallingIdentity(identity);
5769 }
Hall Liu98187582018-01-22 19:15:32 -08005770 }
5771
Hall Liuf6668912018-10-31 17:05:23 -07005772 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005773 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5774 * RTT setting, will return true if the device and carrier both support RTT.
5775 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005776 */
5777 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 final long identity = Binder.clearCallingIdentity();
5779 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005780 boolean isRttSupported = isRttSupported(subscriptionId);
5781 boolean isUserRttSettingOn = Settings.Secure.getInt(
5782 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5783 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5784 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5785 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
5788 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005789 }
5790
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005791 @Deprecated
5792 @Override
5793 public String getDeviceId(String callingPackage) {
5794 return getDeviceIdWithFeature(callingPackage, null);
5795 }
5796
Sanket Padawe7310cc72015-01-14 09:53:20 -08005797 /**
5798 * Returns the unique device ID of phone, for example, the IMEI for
5799 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5800 *
5801 * <p>Requires Permission:
5802 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5803 */
5804 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005805 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005806 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005807 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005808 return null;
5809 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005810 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005811 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005812 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005813 return null;
5814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005815
5816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 return phone.getDeviceId();
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
5821 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005822 }
5823
Ping Sunc67b7c22016-03-02 19:16:45 +08005824 /**
5825 * {@hide}
5826 * Returns the IMS Registration Status on a particular subid
5827 *
5828 * @param subId
5829 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005830 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005831 Phone phone = getPhone(subId);
5832 if (phone != null) {
5833 return phone.isImsRegistered();
5834 } else {
5835 return false;
5836 }
5837 }
5838
Santos Cordon7a1885b2015-02-03 11:15:19 -08005839 @Override
5840 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005841 final long identity = Binder.clearCallingIdentity();
5842 try {
5843 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005847 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005848
Tyler Gunnf70ed162019-04-03 15:28:53 -07005849 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005850 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005851 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005853 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005854 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5855 }
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
5862 }
5863
5864 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005865 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5866 final long identity = Binder.clearCallingIdentity();
5867 try {
5868 Phone phone = getPhone(subscriptionId);
5869 if (phone == null) {
5870 return null;
5871 }
5872 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
5875 }
5876 }
5877
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005878 /**
5879 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005880 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005881 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 Phone phone = getPhone(subId);
5885 if (phone != null) {
5886 return phone.isWifiCallingEnabled();
5887 } else {
5888 return false;
5889 }
5890 } finally {
5891 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005892 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005893 }
5894
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005895 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005896 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005897 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005898 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 Phone phone = getPhone(subId);
5902 if (phone != null) {
5903 return phone.isVideoEnabled();
5904 } else {
5905 return false;
5906 }
5907 } finally {
5908 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005909 }
5910 }
5911
5912 /**
5913 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5914 * defined in {@link ImsRegistrationImplBase}.
5915 */
5916 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 Phone phone = getPhone(subId);
5920 if (phone != null) {
5921 return phone.getImsRegistrationTech();
5922 } else {
5923 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5924 }
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005927 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005928 }
5929
Stuart Scott8eef64f2015-04-08 15:13:54 -07005930 @Override
5931 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08005932 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005933 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5934 return;
5935 }
5936
Svet Ganovcc087f82015-05-12 20:35:54 -07005937 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005938
Svet Ganovcc087f82015-05-12 20:35:54 -07005939 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005940 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5941 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005942 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005943 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005944 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005945 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5946 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005947 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005948 // There has been issues when Sms raw table somehow stores orphan
5949 // fragments. They lead to garbled message when new fragments come
5950 // in and combined with those stale ones. In case this happens again,
5951 // user can reset all network settings which will clean up this table.
5952 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005953 // Clean up IMS settings as well here.
5954 int slotId = getSlotIndex(subId);
5955 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5956 ImsManager.getInstance(mApp, slotId).factoryReset();
5957 }
Naina Nallurid63128d2019-09-17 14:10:30 -07005958
5959 // Erase modem config if erase modem on network setting is enabled.
5960 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5961 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5962 if (configValue != null && Boolean.parseBoolean(configValue)) {
5963 sendEraseModemConfig(getDefaultPhone());
5964 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005967 }
5968 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005969
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005970 private void cleanUpSmsRawTable(Context context) {
5971 ContentResolver resolver = context.getContentResolver();
5972 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5973 resolver.delete(uri, null, null);
5974 }
5975
Narayan Kamath1c496c22015-04-16 14:40:19 +01005976 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005977 public String getSimLocaleForSubscriber(int subId) {
5978 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5979 final Phone phone = getPhone(subId);
5980 if (phone == null) {
5981 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005982 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005983 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
chen xu5d3637b2019-01-21 23:31:38 -08005986 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005987 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08005988 if (info == null) {
5989 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5990 return null;
5991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 // Try and fetch the locale from the carrier properties or from the SIM language
5993 // preferences (EF-PL and EF-LI)...
5994 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005996 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5997 if (localeFromDefaultSim != null) {
5998 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5999 if (DBG) log("Using locale from subId: " + subId + " locale: "
6000 + localeFromDefaultSim);
6001 return localeFromDefaultSim.toLanguageTag();
6002 } else {
6003 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006004 }
6005 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006006
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 // The SIM language preferences only store a language (e.g. fr = French), not an
6008 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6009 // the SIM and carrier preferences does not include a country we add the country
6010 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006011 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006013 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 return mccLocale.toLanguageTag();
6015 }
6016
6017 if (DBG) log("No locale found - returning null");
6018 return null;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
6021 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006022 }
6023
6024 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006025 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6026 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006027 }
6028
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 /**
6030 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6031 */
6032 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006033 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6034 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006035 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006036
Chenjie Yu1ba97252018-01-11 18:16:20 -08006037 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006038 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006039
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006040 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006041 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6042 * representing the state of the modem.
6043 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006044 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6045 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006046 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006047 */
6048 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006049 public void requestModemActivityInfo(ResultReceiver result) {
6050 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006051 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 ModemActivityInfo ret = null;
6056 synchronized (mLastModemActivityInfo) {
6057 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6058 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006059 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006060 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006062 int[] txTimeMs = info.getTransmitTimeMillis();
6063 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006065 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 }
6067 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006068 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6069 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 mLastModemActivityInfo.setIdleTimeMillis(
6071 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006072 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6073 mLastModemActivityInfo.setReceiveTimeMillis(
6074 info.getReceiveTimeMillis() + mLastModemActivityInfo
6075 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006076 }
Chen Xud78231e2019-09-10 18:49:52 -07006077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6079 mLastModemActivityInfo.getSleepTimeMillis(),
6080 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006081 mLastModemActivityInfo.getTransmitTimeMillis(),
6082 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006084 Bundle bundle = new Bundle();
6085 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6086 result.send(0, bundle);
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006089 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006090 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006091
Siddharth Rayb8114062018-06-17 15:02:38 -07006092 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6093 // less than total activity duration.
6094 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6095 if (info == null) {
6096 return false;
6097 }
6098 int activityDurationMs =
6099 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6100 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006101 int[] txTimeMs = info.getTransmitTimeMillis();
6102 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6103 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006104 }
6105 return (info.isValid()
6106 && (info.getSleepTimeMillis() <= activityDurationMs)
6107 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006108 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006109 && (totalTxTimeMs <= activityDurationMs));
6110 }
6111
Jack Yu85bd38a2015-11-09 11:34:32 -08006112 /**
6113 * {@hide}
6114 * Returns the service state information on specified subscription.
6115 */
6116 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006117 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6118 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006120 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006121 return null;
6122 }
6123
Hall Liuf19c44f2018-11-27 14:38:17 -08006124 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6125 LocationAccessPolicy.checkLocationPermission(mApp,
6126 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6127 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006128 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006129 .setCallingPid(Binder.getCallingPid())
6130 .setCallingUid(Binder.getCallingUid())
6131 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006132 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006133 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6134 .build());
6135
6136 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6137 LocationAccessPolicy.checkLocationPermission(mApp,
6138 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6139 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006140 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006141 .setCallingPid(Binder.getCallingPid())
6142 .setCallingUid(Binder.getCallingUid())
6143 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006144 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006145 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6146 .build());
6147 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6148 boolean hasFinePermission =
6149 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6150 boolean hasCoarsePermission =
6151 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 final Phone phone = getPhone(subId);
6156 if (phone == null) {
6157 return null;
6158 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006159
Hall Liuf19c44f2018-11-27 14:38:17 -08006160 ServiceState ss = phone.getServiceState();
6161
6162 // Scrub out the location info in ServiceState depending on what level of access
6163 // the caller has.
6164 if (hasFinePermission) return ss;
6165 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6166 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006170 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006171
6172 /**
6173 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6174 *
6175 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6176 * voicemail ringtone.
6177 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6178 * PhoneAccount.
6179 */
6180 @Override
6181 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6185 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006186 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6190 } finally {
6191 Binder.restoreCallingIdentity(identity);
6192 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006193 }
6194
6195 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006196 * Sets the per-account voicemail ringtone.
6197 *
6198 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6199 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6200 *
6201 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6202 * voicemail ringtone.
6203 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6204 * PhoneAccount.
6205 */
6206 @Override
6207 public void setVoicemailRingtoneUri(String callingPackage,
6208 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006209 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006211 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6212 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6214 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6215 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217
6218 final long identity = Binder.clearCallingIdentity();
6219 try {
6220 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6221 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006222 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006223 }
6224 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6225 } finally {
6226 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006227 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006228 }
6229
6230 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006231 * Returns whether vibration is set for voicemail notification in Phone settings.
6232 *
6233 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6234 * voicemail vibration setting.
6235 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6236 */
6237 @Override
6238 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6242 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006243 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006246 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
6249 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006250 }
6251
Youhan Wange64578a2016-05-02 15:32:42 -07006252 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006253 * Sets the per-account voicemail vibration.
6254 *
6255 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6256 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6257 *
6258 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6259 * voicemail vibration setting.
6260 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6261 * specific PhoneAccount.
6262 */
6263 @Override
6264 public void setVoicemailVibrationEnabled(String callingPackage,
6265 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006266 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006267 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006268 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6269 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6271 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6272 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006273 }
6274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6278 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006279 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006280 }
6281 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006284 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006285 }
6286
6287 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006288 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6289 *
6290 * @throws SecurityException if the caller does not have the required permission
6291 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006292 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006293 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006294 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006295 }
6296
6297 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006298 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6299 * permission.
6300 *
6301 * @throws SecurityException if the caller does not have the required permission
6302 */
6303 private void enforceSendSmsPermission() {
6304 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6305 }
6306
6307 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006308 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006309 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006310 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006311 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006312 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006316 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 if (componentName == null) {
6318 throw new SecurityException(
6319 "Caller not current active visual voicemail package[null]");
6320 }
6321 String vvmPackage = componentName.getPackageName();
6322 if (!callingPackage.equals(vvmPackage)) {
6323 throw new SecurityException("Caller not current active visual voicemail package["
6324 + vvmPackage + "]");
6325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006328 }
6329 }
6330
6331 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006332 * Return the application ID for the app type.
6333 *
6334 * @param subId the subscription ID that this request applies to.
6335 * @param appType the uicc app type.
6336 * @return Application ID for specificied app type, or null if no uicc.
6337 */
6338 @Override
6339 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006340 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006341 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006342
6343 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006344 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 if (phone == null) {
6346 return null;
6347 }
6348 String aid = null;
6349 try {
6350 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6351 .getApplicationByType(appType).getAid();
6352 } catch (Exception e) {
6353 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6354 }
6355 return aid;
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006358 }
Youhan Wange64578a2016-05-02 15:32:42 -07006359 }
6360
Youhan Wang4001d252016-05-11 10:29:41 -07006361 /**
6362 * Return the Electronic Serial Number.
6363 *
6364 * @param subId the subscription ID that this request applies to.
6365 * @return ESN or null if error.
6366 */
6367 @Override
6368 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006369 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006370 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371
6372 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006373 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 if (phone == null) {
6375 return null;
6376 }
6377 String esn = null;
6378 try {
6379 esn = phone.getEsn();
6380 } catch (Exception e) {
6381 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6382 }
6383 return esn;
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006386 }
Youhan Wang4001d252016-05-11 10:29:41 -07006387 }
6388
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006389 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006390 * Return the Preferred Roaming List Version.
6391 *
6392 * @param subId the subscription ID that this request applies to.
6393 * @return PRLVersion or null if error.
6394 */
6395 @Override
6396 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006397 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006398 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399
6400 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006401 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 if (phone == null) {
6403 return null;
6404 }
6405 String cdmaPrlVersion = null;
6406 try {
6407 cdmaPrlVersion = phone.getCdmaPrlVersion();
6408 } catch (Exception e) {
6409 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6410 }
6411 return cdmaPrlVersion;
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006414 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006415 }
6416
6417 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006418 * Get snapshot of Telephony histograms
6419 * @return List of Telephony histograms
6420 * @hide
6421 */
6422 @Override
6423 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6425 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426
6427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 return RIL.getTelephonyRILTimingHistograms();
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006433 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006434
6435 /**
6436 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006437 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6438 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006439 * Require system privileges. In the future we may add this to carrier APIs.
6440 *
Michele Berionne482f8202018-11-27 18:57:59 -08006441 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006442 */
6443 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006444 @TelephonyManager.SetCarrierRestrictionResult
6445 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006446 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006447 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006448
Michele Berionne482f8202018-11-27 18:57:59 -08006449 if (carrierRestrictionRules == null) {
6450 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006451 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006452
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006455 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006456 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 } finally {
6458 Binder.restoreCallingIdentity(identity);
6459 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006460 }
6461
6462 /**
6463 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006464 * Get the allowed carrier list and the excluded carrier list, including the priority between
6465 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006466 * Require system privileges. In the future we may add this to carrier APIs.
6467 *
Michele Berionne482f8202018-11-27 18:57:59 -08006468 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006469 */
6470 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006471 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006472 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006473 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474
6475 final long identity = Binder.clearCallingIdentity();
6476 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006477 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6478 if (response instanceof CarrierRestrictionRules) {
6479 return (CarrierRestrictionRules) response;
6480 }
6481 // Response is an Exception of some kind,
6482 // which is signalled to the user as a NULL retval
6483 return null;
6484 } catch (Exception e) {
6485 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6486 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006490 }
6491
fionaxu59545b42016-05-25 15:53:37 -07006492 /**
6493 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6494 * @param subId the subscription ID that this action applies to.
6495 * @param enabled control enable or disable metered apns.
6496 * {@hide}
6497 */
6498 @Override
6499 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6500 enforceModifyPermission();
6501 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006502
6503 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006504 if (phone == null) {
6505 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6506 return;
6507 }
6508 try {
6509 phone.carrierActionSetMeteredApnsEnabled(enabled);
6510 } catch (Exception e) {
6511 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 } finally {
6513 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006514 }
6515 }
6516
6517 /**
6518 * Action set from carrier signalling broadcast receivers to enable/disable radio
6519 * @param subId the subscription ID that this action applies to.
6520 * @param enabled control enable or disable radio.
6521 * {@hide}
6522 */
6523 @Override
6524 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6525 enforceModifyPermission();
6526 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006527
6528 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006529 if (phone == null) {
6530 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6531 return;
6532 }
6533 try {
6534 phone.carrierActionSetRadioEnabled(enabled);
6535 } catch (Exception e) {
6536 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006537 } finally {
6538 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006539 }
6540 }
6541
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006542 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006543 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6544 * network status based on which carrier apps could apply actions accordingly,
6545 * enable/disable default url handler for example.
6546 *
6547 * @param subId the subscription ID that this action applies to.
6548 * @param report control start/stop reporting the default network status.
6549 * {@hide}
6550 */
6551 @Override
6552 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6553 enforceModifyPermission();
6554 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006557 if (phone == null) {
6558 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6559 return;
6560 }
6561 try {
6562 phone.carrierActionReportDefaultNetworkStatus(report);
6563 } catch (Exception e) {
6564 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006565 } finally {
6566 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006567 }
6568 }
6569
6570 /**
fionaxud9622282017-07-17 17:51:30 -07006571 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6572 * @param subId the subscription ID that this action applies to.
6573 * {@hide}
6574 */
6575 @Override
6576 public void carrierActionResetAll(int subId) {
6577 enforceModifyPermission();
6578 final Phone phone = getPhone(subId);
6579 if (phone == null) {
6580 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6581 return;
6582 }
6583 try {
6584 phone.carrierActionResetAll();
6585 } catch (Exception e) {
6586 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6587 }
6588 }
6589
6590 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006591 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6592 * bug report is being generated.
6593 */
6594 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006595 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6597 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006598 writer.println("Permission Denial: can't dump Phone from pid="
6599 + Binder.getCallingPid()
6600 + ", uid=" + Binder.getCallingUid()
6601 + "without permission "
6602 + android.Manifest.permission.DUMP);
6603 return;
6604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006605 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006606 }
Jack Yueb89b242016-06-22 13:27:47 -07006607
Brad Ebingerdac2f002018-04-03 15:17:52 -07006608 @Override
6609 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6610 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6611 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006612 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6613 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006614 }
6615
Jack Yueb89b242016-06-22 13:27:47 -07006616 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006617 * Get aggregated video call data usage since boot.
6618 *
6619 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6620 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006621 * {@hide}
6622 */
6623 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006624 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006625 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6626 null);
6627
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 // NetworkStatsService keeps tracking the active network interface and identity. It
6631 // records the delta with the corresponding network identity.
6632 // We just return the total video call data usage snapshot since boot.
6633 Phone phone = getPhone(subId);
6634 if (phone != null) {
6635 return phone.getVtDataUsage(perUidStats);
6636 }
6637 return null;
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006640 }
Jack Yueb89b242016-06-22 13:27:47 -07006641 }
Jack Yu75ab2952016-07-08 14:29:33 -07006642
6643 /**
6644 * Policy control of data connection. Usually used when data limit is passed.
6645 * @param enabled True if enabling the data, otherwise disabling.
6646 * @param subId Subscription index
6647 * {@hide}
6648 */
6649 @Override
6650 public void setPolicyDataEnabled(boolean enabled, int subId) {
6651 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652
6653 final long identity = Binder.clearCallingIdentity();
6654 try {
6655 Phone phone = getPhone(subId);
6656 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006657 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006658 }
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006661 }
6662 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006663
6664 /**
6665 * Get Client request stats
6666 * @return List of Client Request Stats
6667 * @hide
6668 */
6669 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006670 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6671 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006672 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006673 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006674 return null;
6675 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006676 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006677
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 if (phone != null) {
6681 return phone.getClientRequestStats();
6682 }
6683
6684 return null;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006688 }
6689
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006690 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006691 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006692 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006693 }
Jack Yueb4124c2017-02-16 15:32:43 -08006694
6695 /**
Grace Chen70990072017-03-24 17:21:30 -07006696 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006697 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006698 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006699 * @param state State of SIM (power down, power up, pass through)
6700 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6701 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6702 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006703 *
6704 **/
6705 @Override
Grace Chen70990072017-03-24 17:21:30 -07006706 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006707 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006708 Phone phone = PhoneFactory.getPhone(slotIndex);
6709
vagdeviaf9a5b92018-08-15 16:01:53 -07006710 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 final long identity = Binder.clearCallingIdentity();
6713 try {
6714 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006715 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 }
6717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006719 }
6720 }
Shuo Qiandd210312017-04-12 22:11:33 +00006721
Tyler Gunn65d45c22017-06-05 11:22:26 -07006722 private boolean isUssdApiAllowed(int subId) {
6723 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006724 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006725 if (configManager == null) {
6726 return false;
6727 }
6728 PersistableBundle pb = configManager.getConfigForSubId(subId);
6729 if (pb == null) {
6730 return false;
6731 }
6732 return pb.getBoolean(
6733 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6734 }
6735
Shuo Qiandd210312017-04-12 22:11:33 +00006736 /**
6737 * Check if phone is in emergency callback mode
6738 * @return true if phone is in emergency callback mode
6739 * @param subId sub id
6740 */
goneil9c5f4872017-12-05 14:07:56 -08006741 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006742 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006743 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745
6746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 if (phone != null) {
6749 return phone.isInEcm();
6750 } else {
6751 return false;
6752 }
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006755 }
6756 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006757
6758 /**
6759 * Get the current signal strength information for the given subscription.
6760 * Because this information is not updated when the device is in a low power state
6761 * it should not be relied-upon to be current.
6762 * @param subId Subscription index
6763 * @return the most recent cached signal strength info from the modem
6764 */
6765 @Override
6766 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 Phone p = getPhone(subId);
6770 if (p == null) {
6771 return null;
6772 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 return p.getSignalStrength();
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006778 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006779
Pengquan Meng77b7f132018-08-22 14:49:57 -07006780 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006781 * Get the current modem radio state for the given slot.
6782 * @param slotIndex slot index.
6783 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006784 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006785 * @return the current radio power state from the modem
6786 */
6787 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006788 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006789 Phone phone = PhoneFactory.getPhone(slotIndex);
6790 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6792 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006793 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6794 }
6795
6796 final long identity = Binder.clearCallingIdentity();
6797 try {
6798 return phone.getRadioPowerState();
6799 } finally {
6800 Binder.restoreCallingIdentity(identity);
6801 }
6802 }
6803 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6804 }
6805
6806 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006807 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6808 *
6809 * <p>Requires one of the following permissions:
6810 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6811 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6812 * privileges.
6813 *
6814 * @param subId subscription id
6815 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6816 * {@code false}.
6817 */
6818 @Override
6819 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006820 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6821 null /* message */);
6822
Pengquan Menga1bb6272018-09-06 09:59:22 -07006823 boolean isEnabled = false;
6824 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006825 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006826 Phone phone = getPhone(subId);
6827 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006828 } catch (Exception e) {
6829 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6830 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006831 } finally {
6832 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006833 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006834 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006835 }
6836
6837
6838 /**
6839 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6840 *
6841 * <p> Requires permission:
6842 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6843 * privileges.
6844 *
6845 * @param subId subscription id
6846 * @param isEnabled {@code true} means enable, {@code false} means disable.
6847 */
6848 @Override
6849 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006850 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6851 mApp, subId, "setDataRoamingEnabled");
6852
Pengquan Menga1bb6272018-09-06 09:59:22 -07006853 final long identity = Binder.clearCallingIdentity();
6854 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006855 Phone phone = getPhone(subId);
6856 if (phone != null) {
6857 phone.setDataRoamingEnabled(isEnabled);
6858 }
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006861 }
6862 }
6863
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006864 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006865 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006866 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6867 mApp, subId, "isManualNetworkSelectionAllowed");
6868
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006869 boolean isAllowed = true;
6870 final long identity = Binder.clearCallingIdentity();
6871 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006872 Phone phone = getPhone(subId);
6873 if (phone != null) {
6874 isAllowed = phone.isCspPlmnEnabled();
6875 }
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 return isAllowed;
6880 }
6881
6882 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006883 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006884 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006885 try {
6886 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006887 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006888 } catch (SecurityException e) {
6889 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6890 // has carrier privileges on an active UICC
6891 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6892 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006893 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006894 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006895 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006896
6897 final long identity = Binder.clearCallingIdentity();
6898 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006899 UiccController uiccController = UiccController.getInstance();
6900 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006901 if (hasReadPermission) {
6902 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006903 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006904
6905 // Remove private info if the caller doesn't have access
6906 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6907 for (UiccCardInfo cardInfo : cardInfos) {
6908 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6909 // is available
6910 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6911 if (card == null || card.getUiccProfile() == null) {
6912 // assume no access if the card or profile is unavailable
6913 filteredInfos.add(cardInfo.getUnprivileged());
6914 continue;
6915 }
6916 UiccProfile profile = card.getUiccProfile();
6917 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6918 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6919 filteredInfos.add(cardInfo);
6920 } else {
6921 filteredInfos.add(cardInfo.getUnprivileged());
6922 }
6923 }
6924 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006925 } finally {
6926 Binder.restoreCallingIdentity(identity);
6927 }
6928 }
6929
6930 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006931 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006932 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006933
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 final long identity = Binder.clearCallingIdentity();
6935 try {
6936 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6937 if (slots == null) {
6938 Rlog.i(LOG_TAG, "slots is null.");
6939 return null;
6940 }
6941
6942 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6943 for (int i = 0; i < slots.length; i++) {
6944 UiccSlot slot = slots[i];
6945 if (slot == null) {
6946 continue;
6947 }
6948
Jordan Liu7be7e652019-05-06 18:55:02 +00006949 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 UiccCard card = slot.getUiccCard();
6951 if (card != null) {
6952 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006953 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006954 cardId = slot.getEid();
6955 if (TextUtils.isEmpty(cardId)) {
6956 cardId = slot.getIccId();
6957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 }
6959
Jordan Liu857451f2019-05-09 16:35:35 -07006960 if (cardId != null) {
6961 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6962 // if cardId is an EID, it's all digits so this is fine
6963 cardId = IccUtils.stripTrailingFs(cardId);
6964 }
6965
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006966 int cardState = 0;
6967 switch (slot.getCardState()) {
6968 case CARDSTATE_ABSENT:
6969 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6970 break;
6971 case CARDSTATE_PRESENT:
6972 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6973 break;
6974 case CARDSTATE_ERROR:
6975 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6976 break;
6977 case CARDSTATE_RESTRICTED:
6978 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6979 break;
6980 default:
6981 break;
6982
6983 }
6984
6985 infos[i] = new UiccSlotInfo(
6986 slot.isActive(),
6987 slot.isEuicc(),
6988 cardId,
6989 cardState,
6990 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006991 slot.isExtendedApduSupported(),
6992 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 }
6994 return infos;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006997 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006998 }
6999
7000 @Override
7001 public boolean switchSlots(int[] physicalSlots) {
7002 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003
7004 final long identity = Binder.clearCallingIdentity();
7005 try {
7006 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007010 }
Jack Yu4c988042018-02-27 15:30:01 -08007011
7012 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007013 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007014 final long identity = Binder.clearCallingIdentity();
7015 try {
7016 return UiccController.getInstance().getCardIdForDefaultEuicc();
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
7020 }
7021
7022 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007023 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7024 enforceModifyPermission();
7025 final Phone phone = getPhone(subId);
7026 if (phone == null) {
7027 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7028 return;
7029 }
7030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 final long identity = Binder.clearCallingIdentity();
7032 try {
7033 phone.setRadioIndicationUpdateMode(filters, mode);
7034 } finally {
7035 Binder.restoreCallingIdentity(identity);
7036 }
Jack Yu4c988042018-02-27 15:30:01 -08007037 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007038
7039 /**
goneil47ffb6e2018-04-06 15:40:58 -07007040 * A test API to reload the UICC profile.
7041 *
7042 * <p>Requires that the calling app has permission
7043 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7044 * @hide
7045 */
7046 @Override
7047 public void refreshUiccProfile(int subId) {
7048 enforceModifyPermission();
7049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
7052 Phone phone = getPhone(subId);
7053 if (phone == null) {
7054 return;
7055 }
7056 UiccCard uiccCard = phone.getUiccCard();
7057 if (uiccCard == null) {
7058 return;
7059 }
7060 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7061 if (uiccProfile == null) {
7062 return;
7063 }
7064 uiccProfile.refresh();
7065 } finally {
7066 Binder.restoreCallingIdentity(identity);
7067 }
7068 }
7069
7070 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007071 * Returns false if the mobile data is disabled by default, otherwise return true.
7072 */
7073 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007074 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007075 }
7076
7077 /**
7078 * Returns true if the data roaming is enabled by default, i.e the system property
7079 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7080 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7081 */
7082 private boolean getDefaultDataRoamingEnabled(int subId) {
7083 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007084 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007085 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007086 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7087 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7088 return isDataRoamingEnabled;
7089 }
7090
7091 /**
7092 * Returns the default network type for the given {@code subId}, if the default network type is
7093 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7094 */
7095 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007096 List<Integer> list = TelephonyProperties.default_network();
7097 int phoneId = mSubscriptionController.getPhoneId(subId);
7098 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7099 return list.get(phoneId);
7100 }
7101 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007102 }
fionaxua13278b2018-03-21 00:08:13 -07007103
7104 @Override
7105 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007106 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007107 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
7111 final Phone phone = getPhone(subId);
7112 if (phone == null) {
7113 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7114 return;
7115 }
chen xueaba88a2019-03-15 13:15:10 -07007116 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7117 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 } finally {
7119 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007120 }
fionaxua13278b2018-03-21 00:08:13 -07007121 }
7122
7123 @Override
7124 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007125 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126
7127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 final Phone phone = getPhone(subId);
7130 if (phone == null) {
7131 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7132 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7133 }
7134 return phone.getCarrierIdListVersion();
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007137 }
fionaxua13278b2018-03-21 00:08:13 -07007138 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007139
7140 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007141 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7142 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007144 mApp, subId, callingPackage, callingFeatureId,
7145 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007146 return -1;
7147 }
7148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
7151 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
7155 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007156
7157 @Override
7158 public int getCdmaRoamingMode(int subId) {
7159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7160 mApp, subId, "getCdmaRoamingMode");
7161
7162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
7170 @Override
7171 public boolean setCdmaRoamingMode(int subId, int mode) {
7172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7173 mApp, subId, "setCdmaRoamingMode");
7174
7175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7178 } finally {
7179 Binder.restoreCallingIdentity(identity);
7180 }
7181 }
7182
7183 @Override
7184 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7185 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7186 mApp, subId, "setCdmaSubscriptionMode");
7187
7188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
7194 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007195
sqianc5eccab2018-10-19 18:46:41 -07007196 @Override
sqian8c685422019-02-22 15:55:18 -08007197 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007198 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007200 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7201 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007202 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7203 }
7204 final long identity = Binder.clearCallingIdentity();
7205 try {
sqian854d44b2018-12-12 16:48:18 -08007206 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7207 for (Phone phone: PhoneFactory.getPhones()) {
7208 if (phone.getEmergencyNumberTracker() != null
7209 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7210 emergencyNumberListInternal.put(
7211 phone.getSubId(),
7212 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7213 }
sqian11b7a0e2018-12-05 18:48:28 -08007214 }
sqian854d44b2018-12-12 16:48:18 -08007215 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
7218 }
sqianc5eccab2018-10-19 18:46:41 -07007219 }
7220
7221 @Override
sqian8c685422019-02-22 15:55:18 -08007222 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007223 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007224 if (!exactMatch) {
7225 TelephonyPermissions
7226 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007227 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007228 }
7229 final long identity = Binder.clearCallingIdentity();
7230 try {
sqian854d44b2018-12-12 16:48:18 -08007231 for (Phone phone: PhoneFactory.getPhones()) {
7232 if (phone.getEmergencyNumberTracker() != null
7233 && phone.getEmergencyNumberTracker() != null) {
7234 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7235 number, exactMatch)) {
7236 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007237 }
7238 }
sqian11b7a0e2018-12-05 18:48:28 -08007239 }
7240 return false;
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
sqianf4ca7ed2019-01-15 18:32:07 -08007246 /**
7247 * Update emergency number list for test mode.
7248 */
7249 @Override
7250 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7251 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7252 "updateEmergencyNumberListTestMode");
7253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
7256 for (Phone phone: PhoneFactory.getPhones()) {
7257 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7258 if (tracker != null) {
7259 tracker.executeEmergencyNumberTestModeCommand(action, num);
7260 }
7261 }
7262 } finally {
7263 Binder.restoreCallingIdentity(identity);
7264 }
7265 }
7266
7267 /**
7268 * Get the full emergency number list for test mode.
7269 */
7270 @Override
7271 public List<String> getEmergencyNumberListTestMode() {
7272 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7273 "getEmergencyNumberListTestMode");
7274
7275 final long identity = Binder.clearCallingIdentity();
7276 try {
7277 Set<String> emergencyNumbers = new HashSet<>();
7278 for (Phone phone: PhoneFactory.getPhones()) {
7279 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7280 if (tracker != null) {
7281 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7282 emergencyNumbers.add(num.getNumber());
7283 }
7284 }
7285 }
7286 return new ArrayList<>(emergencyNumbers);
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 }
7291
chen xud6b45bd2018-10-30 22:27:10 -07007292 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007293 public int getEmergencyNumberDbVersion(int subId) {
7294 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7295
7296 final long identity = Binder.clearCallingIdentity();
7297 try {
7298 final Phone phone = getPhone(subId);
7299 if (phone == null) {
7300 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7301 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7302 }
7303 return phone.getEmergencyNumberDbVersion();
7304 } finally {
7305 Binder.restoreCallingIdentity(identity);
7306 }
7307 }
7308
7309 @Override
7310 public void notifyOtaEmergencyNumberDbInstalled() {
7311 enforceModifyPermission();
7312
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 for (Phone phone: PhoneFactory.getPhones()) {
7316 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7317 if (tracker != null) {
7318 tracker.updateOtaEmergencyNumberDatabase();
7319 }
7320 }
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
7325
7326 @Override
7327 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7328 enforceActiveEmergencySessionPermission();
7329
7330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 for (Phone phone: PhoneFactory.getPhones()) {
7333 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7334 if (tracker != null) {
7335 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7336 }
7337 }
7338 } finally {
7339 Binder.restoreCallingIdentity(identity);
7340 }
7341 }
7342
7343 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007344 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7345 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7346 Phone phone = getPhone(subId);
7347 if (phone == null) {
7348 return null;
7349 }
7350 final long identity = Binder.clearCallingIdentity();
7351 try {
7352 UiccProfile profile = UiccController.getInstance()
7353 .getUiccProfileForPhone(phone.getPhoneId());
7354 if (profile != null) {
7355 return profile.getCertsFromCarrierPrivilegeAccessRules();
7356 }
7357 } finally {
7358 Binder.restoreCallingIdentity(identity);
7359 }
7360 return null;
7361 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007362
7363 /**
7364 * Enable or disable a modem stack.
7365 */
7366 @Override
7367 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7368 enforceModifyPermission();
7369
7370 final long identity = Binder.clearCallingIdentity();
7371 try {
7372 Phone phone = PhoneFactory.getPhone(slotIndex);
7373 if (phone == null) {
7374 return false;
7375 } else {
7376 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7377 }
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
7381 }
Michelecea4cf22018-12-21 15:00:11 -08007382
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007383 /**
7384 * Whether a modem stack is enabled or not.
7385 */
7386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7388 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007389 Phone phone = PhoneFactory.getPhone(slotIndex);
7390 if (phone == null) return false;
7391
7392 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007393 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7394 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007395 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7396 }
7397
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007400 try {
7401 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7402 } catch (NoSuchElementException ex) {
7403 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7404 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007405 } finally {
7406 Binder.restoreCallingIdentity(identity);
7407 }
7408 }
7409
Michelecea4cf22018-12-21 15:00:11 -08007410 @Override
Michele0ea7d782019-03-19 14:58:42 -07007411 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007412 enforceModifyPermission();
7413
7414 final long identity = Binder.clearCallingIdentity();
7415 try {
7416 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007417 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007418 .commit();
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
7422 }
7423
7424 @Override
Michele0ea7d782019-03-19 14:58:42 -07007425 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007426 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007427 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007428 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7429 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007430 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007431 }
Michelecea4cf22018-12-21 15:00:11 -08007432
7433 final long identity = Binder.clearCallingIdentity();
7434 try {
Michele0ea7d782019-03-19 14:58:42 -07007435 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
7439 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007440
Michele0ea7d782019-03-19 14:58:42 -07007441 @TelephonyManager.IsMultiSimSupportedResult
7442 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007443 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7444 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7445 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007446 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7447 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007448 }
7449 // Check if the hardware supports multisim functionality. If usage of multisim is not
7450 // supported by the modem, indicate that it is restricted.
7451 PhoneCapability staticCapability =
7452 mPhoneConfigurationManager.getStaticPhoneCapability();
7453 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007454 loge("isMultiSimSupportedInternal: no static configuration available");
7455 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007456 }
7457 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007458 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7459 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007460 }
7461 // Check if support of multiple SIMs is restricted by carrier
7462 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007463 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007464 }
7465
Michele0ea7d782019-03-19 14:58:42 -07007466 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007467 }
7468
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007469 /**
7470 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007471 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7472 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7473 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007474 * @param numOfSims number of active sims we want to switch to
7475 */
7476 @Override
7477 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007478 if (numOfSims == 1) {
7479 enforceModifyPermission();
7480 } else {
7481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7482 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7483 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007484 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007485
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007486 try {
Michele30b57b22019-03-01 12:01:14 -08007487 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007488 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007489 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7490 return;
7491 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007492 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7493 } finally {
7494 Binder.restoreCallingIdentity(identity);
7495 }
7496 }
7497
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007498 @Override
7499 public boolean isApplicationOnUicc(int subId, int appType) {
7500 enforceReadPrivilegedPermission("isApplicationOnUicc");
7501 Phone phone = getPhone(subId);
7502 if (phone == null) {
7503 return false;
7504 }
7505 final long identity = Binder.clearCallingIdentity();
7506 try {
7507 UiccCard uiccCard = phone.getUiccCard();
7508 if (uiccCard == null) {
7509 return false;
7510 }
7511 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7512 if (uiccProfile == null) {
7513 return false;
7514 }
7515 if (TelephonyManager.APPTYPE_SIM <= appType
7516 && appType <= TelephonyManager.APPTYPE_ISIM) {
7517 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7518 }
7519 return false;
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
7522 }
7523 }
7524
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007525 /**
chen xub4baa772019-04-03 10:23:41 -07007526 * Get whether making changes to modem configurations will trigger reboot.
7527 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007528 */
7529 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007530 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7531 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007533 mApp, subId, callingPackage, callingFeatureId,
7534 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007535 return false;
7536 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
7543 }
7544
Nathan Harold29f5f052019-02-15 13:41:57 -08007545 private void updateModemStateMetrics() {
7546 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7547 // TODO: check the state for each modem if the api is ready.
7548 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7549 }
7550
Pengquan Meng3889a572019-01-23 11:16:29 -08007551 @Override
7552 public int[] getSlotsMapping() {
7553 enforceReadPrivilegedPermission("getSlotsMapping");
7554
7555 final long identity = Binder.clearCallingIdentity();
7556 try {
7557 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7558 // All logical slots should have a mapping to a physical slot.
7559 int[] logicalSlotsMapping = new int[phoneCount];
7560 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7561 for (int i = 0; i < slotInfos.length; i++) {
7562 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7563 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7564 }
7565 }
7566 return logicalSlotsMapping;
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
7570 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007571
7572 /**
7573 * Get the IRadio HAL Version
7574 */
7575 @Override
7576 public int getRadioHalVersion() {
7577 Phone phone = getDefaultPhone();
7578 if (phone == null) return -1;
7579 HalVersion hv = phone.getHalVersion();
7580 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7581 return hv.major * 100 + hv.minor;
7582 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007583
7584 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007585 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7586 * corresponding network requests on a subId.
7587 *
7588 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007589 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007590 * 2) APN is un-metered for this subscription, or
7591 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7592 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7593 *
7594 * @return whether data is allowed for a apn type.
7595 *
7596 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007597 */
7598 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007599 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007600 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7601 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007602
7603 // Now that all security checks passes, perform the operation as ourselves.
7604 final long identity = Binder.clearCallingIdentity();
7605 try {
7606 Phone phone = getPhone(subId);
7607 if (phone == null) return false;
7608
Jack Yu41407ee2019-05-13 16:54:09 -07007609 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007610 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
7614 }
7615
7616 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007617 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007618 enforceReadPrivilegedPermission("isApnMetered");
7619
7620 // Now that all security checks passes, perform the operation as ourselves.
7621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 Phone phone = getPhone(subId);
7624 if (phone == null) return true; // By default return true.
7625
Jack Yu41407ee2019-05-13 16:54:09 -07007626 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007627 } finally {
7628 Binder.restoreCallingIdentity(identity);
7629 }
7630 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007631
7632 @Override
7633 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7634 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7635 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7636 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7637 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7638 }
7639 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7640 Intent intent = new Intent();
7641 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7642 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7643 // Bring up choose default SMS subscription dialog right now
7644 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7645 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7646 mApp.startActivity(intent);
7647 }
chen xud5ca2d52019-05-28 15:20:57 -07007648
7649 @Override
7650 public String getMmsUAProfUrl(int subId) {
7651 //TODO investigate if this API should require proper permission check in R b/133791609
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7655 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
7660
7661 @Override
7662 public String getMmsUserAgent(int subId) {
7663 //TODO investigate if this API should require proper permission check in R b/133791609
7664 final long identity = Binder.clearCallingIdentity();
7665 try {
7666 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7667 .getString(com.android.internal.R.string.config_mms_user_agent);
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
7671 }
Jack Yub07d4972019-05-28 16:12:25 -07007672
7673 @Override
7674 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7675 enforceModifyPermission();
7676
7677 // Now that all security checks passes, perform the operation as ourselves.
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 Phone phone = getPhone(subId);
7681 if (phone == null) return false;
7682
7683 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
7687 }
7688
7689 @Override
7690 public boolean isDataAllowedInVoiceCall(int subId) {
7691 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7692
7693 // Now that all security checks passes, perform the operation as ourselves.
7694 final long identity = Binder.clearCallingIdentity();
7695 try {
7696 Phone phone = getPhone(subId);
7697 if (phone == null) return false;
7698
7699 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7700 } finally {
7701 Binder.restoreCallingIdentity(identity);
7702 }
7703 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007704
7705 /**
7706 * Updates whether conference event pacakge handling is enabled.
7707 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7708 * otherwise.
7709 */
7710 @Override
7711 public void setCepEnabled(boolean isCepEnabled) {
7712 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7713
7714 final long identity = Binder.clearCallingIdentity();
7715 try {
7716 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7717 for (Phone phone : PhoneFactory.getPhones()) {
7718 Phone defaultPhone = phone.getImsPhone();
7719 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7720 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7721 ImsPhoneCallTracker imsPhoneCallTracker =
7722 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7723 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7724 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7725 + imsPhone.getMsisdn());
7726 }
7727 }
7728 } finally {
7729 Binder.restoreCallingIdentity(identity);
7730 }
7731 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007732}