blob: 8c60f8452cdf98a53d6274df41bbd6b05ec38a79 [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;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad 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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /** The singleton instance. */
273 private static PhoneInterfaceManager sInstance;
274
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700277 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private AppOpsManager mAppOps;
279 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800280 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700282 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
Derek Tan97ebb422014-09-05 16:55:38 -0700284 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
285 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800286 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800287 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700288
Michelecea4cf22018-12-21 15:00:11 -0800289 // String to store multi SIM allowed
290 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
291
Derek Tan740e1672017-06-27 14:56:27 -0700292 // The AID of ISD-R.
293 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
294
yinxub1bed742017-04-17 11:45:04 -0700295 private NetworkScanRequestTracker mNetworkScanRequestTracker;
296
David Kelly5e06a7f2018-03-12 14:10:59 +0000297 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
298 private static final int MANUFACTURER_CODE_LENGTH = 8;
299
Derek Tan89e89d42014-07-08 17:00:10 -0700300 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 * A request object to use for transmitting data to an ICC.
302 */
303 private static final class IccAPDUArgument {
304 public int channel, cla, command, p1, p2, p3;
305 public String data;
306
307 public IccAPDUArgument(int channel, int cla, int command,
308 int p1, int p2, int p3, String data) {
309 this.channel = channel;
310 this.cla = cla;
311 this.command = command;
312 this.p1 = p1;
313 this.p2 = p2;
314 this.p3 = p3;
315 this.data = data;
316 }
317 }
318
319 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700320 * A request object to use for transmitting data to an ICC.
321 */
322 private static final class ManualNetworkSelectionArgument {
323 public OperatorInfo operatorInfo;
324 public boolean persistSelection;
325
326 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
327 this.operatorInfo = operatorInfo;
328 this.persistSelection = persistSelection;
329 }
330 }
331
332 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
334 * request after sending. The main thread will notify the request when it is complete.
335 */
336 private static final class MainThreadRequest {
337 /** The argument to use for the request */
338 public Object argument;
339 /** The result of the request that is run on the main thread */
340 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800341 // The subscriber id that this request applies to. Defaults to
342 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
343 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Nathan Harold92bed182018-10-12 18:16:49 -0700345 // In cases where subId is unavailable, the caller needs to specify the phone.
346 public Phone phone;
347
vagdeviaf9a5b92018-08-15 16:01:53 -0700348 public WorkSource workSource;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 public MainThreadRequest(Object argument) {
351 this.argument = argument;
352 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
355 this.argument = argument;
356 if (phone != null) {
357 this.phone = phone;
358 }
359 this.workSource = workSource;
360 }
361
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800364 if (subId != null) {
365 this.subId = subId;
366 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700367 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800371 private static final class IncomingThirdPartyCallArgs {
372 public final ComponentName component;
373 public final String callId;
374 public final String callerDisplayName;
375
376 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
377 String callerDisplayName) {
378 this.component = component;
379 this.callId = callId;
380 this.callerDisplayName = callerDisplayName;
381 }
382 }
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 /**
385 * A handler that processes messages on the main thread in the phone process. Since many
386 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
387 * inbound binder threads to the main thread in the phone process. The Binder thread
388 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
389 * on, which will be notified when the operation completes and will contain the result of the
390 * request.
391 *
392 * <p>If a MainThreadRequest object is provided in the msg.obj field,
393 * note that request.result must be set to something non-null for the calling thread to
394 * unblock.
395 */
396 private final class MainThreadHandler extends Handler {
397 @Override
398 public void handleMessage(Message msg) {
399 MainThreadRequest request;
400 Message onCompleted;
401 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800404 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
406 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 case CMD_HANDLE_USSD_REQUEST: {
408 request = (MainThreadRequest) msg.obj;
409 final Phone phone = getPhoneFromRequest(request);
410 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
411 String ussdRequest = ussdObject.first;
412 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700413
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 if (!isUssdApiAllowed(request.subId)) {
415 // Carrier does not support use of this API, return failure.
416 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
417 UssdResponse response = new UssdResponse(ussdRequest, null);
418 Bundle returnData = new Bundle();
419 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
420 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700421
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 request.result = true;
423 notifyRequester(request);
424 return;
425 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 try {
428 request.result = phone != null
429 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
430 } catch (CallStateException cse) {
431 request.result = false;
432 }
433 // Wake up the requesting thread
434 notifyRequester(request);
435 break;
pkanwar32d516d2016-10-14 19:37:38 -0700436 }
437
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 final Phone phone = getPhoneFromRequest(request);
441 request.result = phone != null ?
442 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
443 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800452 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 if (uiccCard == null) {
454 loge("iccTransmitApduLogicalChannel: No UICC");
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
459 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument.channel, iccArgument.cla, iccArgument.command,
462 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 ar = (AsyncResult) msg.obj;
469 request = (MainThreadRequest) ar.userObj;
470 if (ar.exception == null && ar.result != null) {
471 request.result = ar.result;
472 } else {
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 if (ar.result == null) {
475 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800476 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800478 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 } else {
480 loge("iccTransmitApduLogicalChannel: Unknown exception");
481 }
482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 break;
485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduBasicChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
496 request);
497 uiccCard.iccTransmitApduBasicChannel(
498 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
499 iccArgument.p3, iccArgument.data, onCompleted);
500 }
501 break;
502
503 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("iccTransmitApduBasicChannel: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("iccTransmitApduBasicChannel: CommandException: " +
514 ar.exception);
515 } else {
516 loge("iccTransmitApduBasicChannel: Unknown exception");
517 }
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 break;
521
522 case CMD_EXCHANGE_SIM_IO:
523 request = (MainThreadRequest) msg.obj;
524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 if (uiccCard == null) {
527 loge("iccExchangeSimIO: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
532 request);
533 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
534 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
535 iccArgument.data, onCompleted);
536 }
537 break;
538
539 case EVENT_EXCHANGE_SIM_IO_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6f, 0, (byte[])null);
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 break;
549
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 case CMD_SEND_ENVELOPE:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("sendEnvelopeWithStatus: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
559 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 break;
562
563 case EVENT_SEND_ENVELOPE_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("sendEnvelopeWithStatus: Empty response");
572 } else if (ar.exception instanceof CommandException) {
573 loge("sendEnvelopeWithStatus: CommandException: " +
574 ar.exception);
575 } else {
576 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
577 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 break;
581
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 case CMD_OPEN_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 if (uiccCard == null) {
587 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800588 request.result = new IccOpenLogicalChannelResponse(-1,
589 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case CMD_CLOSE_CHANNEL:
640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800641 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 if (uiccCard == null) {
643 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900644 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800659 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
660 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
663 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 request.result = "";
670 if (ar.result == null) {
671 loge("nvReadItem: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("nvReadItem: CommandException: " +
674 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800676 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 }
678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700687 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
chen xu6dac5ab2018-10-26 17:39:23 -0700704 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800705 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700706 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
chen xu6dac5ab2018-10-26 17:39:23 -0700710 case EVENT_RESET_MODEM_CONFIG_DONE:
711 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case CMD_SET_PREFERRED_NETWORK_TYPE:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
742 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
747 handleNullReturnEvent(msg, "setPreferredNetworkType");
748 break;
749
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
751 request = (MainThreadRequest)msg.obj;
752 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
756 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
757 ar = (AsyncResult)msg.obj;
758 request = (MainThreadRequest)ar.userObj;
759 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 break;
762
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 case CMD_SET_VOICEMAIL_NUMBER:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
766 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800767 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
768 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 break;
770
771 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
772 handleNullReturnEvent(msg, "setVoicemailNumber");
773 break;
774
Stuart Scott54788802015-03-30 13:18:01 -0700775 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
778 request);
779 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
780 break;
781
782 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
783 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
784 break;
785
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 case CMD_PERFORM_NETWORK_SCAN:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
789 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
790 break;
791
792 case EVENT_PERFORM_NETWORK_SCAN_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 CellNetworkScanResult cellScanResult;
796 if (ar.exception == null && ar.result != null) {
797 cellScanResult = new CellNetworkScanResult(
798 CellNetworkScanResult.STATUS_SUCCESS,
799 (List<OperatorInfo>) ar.result);
800 } else {
801 if (ar.result == null) {
802 loge("getCellNetworkScanResults: Empty response");
803 }
804 if (ar.exception != null) {
805 loge("getCellNetworkScanResults: Exception: " + ar.exception);
806 }
807 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
810 ((CommandException) (ar.exception)).getCommandError();
811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
813 } else if (error == CommandException.Error.GENERIC_FAILURE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
815 }
816 }
817 cellScanResult = new CellNetworkScanResult(errorCode, null);
818 }
819 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 break;
822
823 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
824 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 ManualNetworkSelectionArgument selArg =
826 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
828 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
830 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null) {
837 request.result = true;
838 } else {
839 request.result = false;
840 loge("setNetworkSelectionModeManual " + ar.exception);
841 }
842 notifyRequester(request);
843 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 case CMD_GET_MODEM_ACTIVITY_INFO:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700849 if (defaultPhone != null) {
850 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 break;
853
854 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("queryModemActivityInfo: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("queryModemActivityInfo: CommandException: " +
864 ar.exception);
865 } else {
866 loge("queryModemActivityInfo: Unknown exception");
867 }
868 }
Amit Mahajand4766222016-01-28 15:28:28 -0800869 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
870 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700871 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700874 break;
875
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 case CMD_SET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800878 CarrierRestrictionRules argument =
879 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800881 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
884 case EVENT_SET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800890 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
891 if (ar.exception instanceof CommandException) {
892 loge("setAllowedCarriers: CommandException: " + ar.exception);
893 CommandException.Error error =
894 ((CommandException) (ar.exception)).getCommandError();
895 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
896 request.result =
897 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
898 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
906 case CMD_GET_ALLOWED_CARRIERS:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
912 case EVENT_GET_ALLOWED_CARRIERS_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800918 request.result = new IllegalStateException(
919 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 if (ar.result == null) {
921 loge("getAllowedCarriers: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("getAllowedCarriers: CommandException: " +
924 ar.exception);
925 } else {
926 loge("getAllowedCarriers: Unknown exception");
927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948
949 case CMD_GET_FORBIDDEN_PLMNS:
950 request = (MainThreadRequest) msg.obj;
951 uiccCard = getUiccCardFromRequest(request);
952 if (uiccCard == null) {
953 loge("getForbiddenPlmns() UiccCard is null");
954 request.result = new IllegalArgumentException(
955 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958 }
959 Integer appType = (Integer) request.argument;
960 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
961 if (uiccApp == null) {
962 loge("getForbiddenPlmns() no app with specified type -- "
963 + appType);
964 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 } else {
968 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
969 + " specified type -- " + appType);
970 }
971 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
972 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
973 onCompleted);
974 break;
975
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 case CMD_SWITCH_SLOTS:
977 request = (MainThreadRequest) msg.obj;
978 int[] physicalSlots = (int[]) request.argument;
979 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
980 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
981 break;
982
983 case EVENT_SWITCH_SLOTS_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700987 notifyRequester(request);
988 break;
989 case CMD_GET_NETWORK_SELECTION_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
992 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
993 break;
994
995 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception != null) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1000 } else {
1001 int mode = ((int[]) ar.result)[0];
1002 if (mode == 0) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1004 } else {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001008 notifyRequester(request);
1009 break;
1010 case CMD_GET_CDMA_ROAMING_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1013 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1014 break;
1015 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception != null) {
1019 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1020 } else {
1021 request.result = ((int[]) ar.result)[0];
1022 }
1023 notifyRequester(request);
1024 break;
1025 case CMD_SET_CDMA_ROAMING_MODE:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1028 int mode = (int) request.argument;
1029 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1030 break;
1031 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 request.result = ar.exception == null;
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1040 int subscriptionMode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001048 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 case CMD_GET_ALL_CELL_INFO:
1050 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001052 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 case EVENT_GET_ALL_CELL_INFO_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001057 // If a timeout occurs, the response will be null
1058 request.result = (ar.exception == null && ar.result != null)
1059 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 synchronized (request) {
1061 request.notifyAll();
1062 }
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case CMD_REQUEST_CELL_INFO_UPDATE:
1065 request = (MainThreadRequest) msg.obj;
1066 request.phone.requestCellInfoUpdate(request.workSource,
1067 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1068 break;
1069 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
1072 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1073 try {
1074 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001076 cb.onError(
1077 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1078 ar.exception.getClass().getName(),
1079 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001082 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else {
1084 // use the result as returned
1085 cb.onCellInfo((List<CellInfo>) ar.result);
1086 }
1087 } catch (RemoteException re) {
1088 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1089 }
1090 break;
1091 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 request = (MainThreadRequest) msg.obj;
1093 WorkSource ws = (WorkSource) request.argument;
1094 Phone phone = getPhoneFromRequest(request);
1095 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1096 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = ar.result;
1102 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001103 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1105 ? new CdmaCellLocation() : new GsmCellLocation();
1106 }
1107
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case CMD_MODEM_REBOOT:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001116 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001117 case EVENT_CMD_MODEM_REBOOT_DONE:
1118 handleNullReturnEvent(msg, "rebootModem");
1119 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 case CMD_REQUEST_ENABLE_MODEM:
1121 request = (MainThreadRequest) msg.obj;
1122 boolean enable = (boolean) request.argument;
1123 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001125 PhoneConfigurationManager.getInstance()
1126 .enablePhone(request.phone, enable, onCompleted);
1127 break;
1128 case EVENT_ENABLE_MODEM_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001132 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 if ((boolean) request.result) {
1135 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1136 updateModemStateMetrics();
1137 } else {
1138 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1139 + ar.exception);
1140 }
1141 notifyRequester(request);
1142 break;
1143 case CMD_GET_MODEM_STATUS:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1146 PhoneConfigurationManager.getInstance()
1147 .getPhoneStatusFromModem(request.phone, onCompleted);
1148 break;
1149 case EVENT_GET_MODEM_STATUS_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 int id = request.phone.getPhoneId();
1153 if (ar.exception == null && ar.result != null) {
1154 request.result = ar.result;
1155 //update the cache as modem status has changed
1156 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1157 (boolean) request.result);
1158 } else {
1159 // Return true if modem status cannot be retrieved. For most cases,
1160 // modem status is on. And for older version modems, GET_MODEM_STATUS
1161 // and disable modem are not supported. Modem is always on.
1162 // TODO: this should be fixed in R to support a third
1163 // status UNKNOWN b/131631629
1164 request.result = true;
1165 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1166 + ar.exception);
1167 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001168 notifyRequester(request);
1169 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001170 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null && ar.result != null) {
1174 request.result = ar.result;
1175 } else {
1176 request.result = -1;
1177 loge("Failed to set Forbidden Plmns");
1178 if (ar.result == null) {
1179 loge("setForbidenPlmns: Empty response");
1180 } else if (ar.exception != null) {
1181 loge("setForbiddenPlmns: Exception: " + ar.exception);
1182 request.result = -1;
1183 } else {
1184 loge("setForbiddenPlmns: Unknown exception");
1185 }
1186 }
1187 notifyRequester(request);
1188 break;
1189 case CMD_SET_FORBIDDEN_PLMNS:
1190 request = (MainThreadRequest) msg.obj;
1191 uiccCard = getUiccCardFromRequest(request);
1192 if (uiccCard == null) {
1193 loge("setForbiddenPlmns: UiccCard is null");
1194 request.result = -1;
1195 notifyRequester(request);
1196 break;
1197 }
1198 Pair<Integer, List<String>> setFplmnsArgs =
1199 (Pair<Integer, List<String>>) request.argument;
1200 appType = setFplmnsArgs.first;
1201 List<String> fplmns = setFplmnsArgs.second;
1202 uiccApp = uiccCard.getApplicationByType(appType);
1203 if (uiccApp == null) {
1204 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1205 request.result = -1;
1206 loge("Failed to get UICC App");
1207 notifyRequester(request);
1208 } else {
1209 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1210 ((SIMRecords) uiccApp.getIccRecords())
1211 .setForbiddenPlmns(onCompleted, fplmns);
1212 }
1213 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 default:
1215 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1216 break;
1217 }
1218 }
Jake Hambye994d462014-02-03 13:10:13 -08001219
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 private void notifyRequester(MainThreadRequest request) {
1221 synchronized (request) {
1222 request.notifyAll();
1223 }
1224 }
1225
Jake Hambye994d462014-02-03 13:10:13 -08001226 private void handleNullReturnEvent(Message msg, String command) {
1227 AsyncResult ar = (AsyncResult) msg.obj;
1228 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception == null) {
1230 request.result = true;
1231 } else {
1232 request.result = false;
1233 if (ar.exception instanceof CommandException) {
1234 loge(command + ": CommandException: " + ar.exception);
1235 } else {
1236 loge(command + ": Unknown exception");
1237 }
1238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001249 return sendRequest(
1250 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001251 }
1252
1253 /**
1254 * Posts the specified command to be executed on the main thread,
1255 * waits for the request to complete, and returns the result.
1256 * @see #sendRequestAsync
1257 */
1258 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1259 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001260 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001268 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
Nathan Harold92bed182018-10-12 18:16:49 -07001277 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1278 return sendRequest(command, argument, subId, null, workSource);
1279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
1286 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1287 return sendRequest(
1288 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
1296 private Object sendRequest(
1297 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1299 throw new RuntimeException("This method will deadlock if called from the main thread.");
1300 }
1301
Nathan Harold92bed182018-10-12 18:16:49 -07001302 MainThreadRequest request = null;
1303 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1304 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1305 } else if (phone != null) {
1306 request = new MainThreadRequest(argument, phone, workSource);
1307 } else {
1308 request = new MainThreadRequest(argument, subId, workSource);
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 Message msg = mMainThreadHandler.obtainMessage(command, request);
1312 msg.sendToTarget();
1313
1314 // Wait for the request to complete
1315 synchronized (request) {
1316 while (request.result == null) {
1317 try {
1318 request.wait();
1319 } catch (InterruptedException e) {
1320 // Do nothing, go back and wait until the request is complete
1321 }
1322 }
1323 }
1324 return request.result;
1325 }
1326
1327 /**
1328 * Asynchronous ("fire and forget") version of sendRequest():
1329 * Posts the specified command to be executed on the main thread, and
1330 * returns immediately.
1331 * @see #sendRequest
1332 */
1333 private void sendRequestAsync(int command) {
1334 mMainThreadHandler.sendEmptyMessage(command);
1335 }
1336
1337 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001338 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001339 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 */
1341 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 sendRequestAsync(command, argument, null, null);
1343 }
1344
1345 /**
1346 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1347 * @see {@link #sendRequest(int,Object)}
1348 */
1349 private void sendRequestAsync(
1350 int command, Object argument, Phone phone, WorkSource workSource) {
1351 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001352 Message msg = mMainThreadHandler.obtainMessage(command, request);
1353 msg.sendToTarget();
1354 }
1355
1356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 * Initialize the singleton PhoneInterfaceManager instance.
1358 * This is only done once, at startup, from PhoneApp.onCreate().
1359 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001360 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 synchronized (PhoneInterfaceManager.class) {
1362 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 } else {
1365 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1366 }
1367 return sInstance;
1368 }
1369 }
1370
1371 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001372 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001375 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1377 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001378 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 mTelephonySharedPreferences =
1380 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001381 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001382 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 publish();
1385 }
1386
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001387 private Phone getDefaultPhone() {
1388 Phone thePhone = getPhone(getDefaultSubscription());
1389 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1390 }
1391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 private void publish() {
1393 if (DBG) log("publish: " + this);
1394
1395 ServiceManager.addService("phone", this);
1396 }
1397
Stuart Scott584921c2015-01-15 17:10:34 -08001398 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001399 if (request.phone != null) {
1400 return request.phone;
1401 } else {
1402 return getPhoneFromSubId(request.subId);
1403 }
1404 }
1405
1406 private Phone getPhoneFromSubId(int subId) {
1407 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1408 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001409 }
1410
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001411 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1412 Phone phone = getPhoneFromRequest(request);
1413 return phone == null ? null :
1414 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1415 }
1416
Wink Saville36469e72014-06-11 15:17:00 -07001417 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001419 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
1422 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 if (DBG) log("dial: " + number);
1428 // No permission check needed here: This is just a wrapper around the
1429 // ACTION_DIAL intent, which is available to any app since it puts up
1430 // the UI before it does anything.
1431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 String url = createTelUrl(number);
1435 if (url == null) {
1436 return;
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 // PENDING: should we just silently fail if phone is offhook or ringing?
1440 PhoneConstants.State state = mCM.getState(subId);
1441 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1442 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 }
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449 }
1450
1451 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Wink Savilleb564aae2014-10-23 10:18:09 -07001455 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 if (DBG) log("call: " + number);
1457
1458 // This is just a wrapper around the ACTION_CALL intent, but we still
1459 // need to do a permission check since we're calling startActivity()
1460 // from the context of the phone app.
1461 enforceCallPermission();
1462
Jordan Liu1617b712019-07-10 15:06:26 -07001463 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 != AppOpsManager.MODE_ALLOWED) {
1465 return;
1466 }
1467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 String url = createTelUrl(number);
1471 if (url == null) {
1472 return;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475 boolean isValid = false;
1476 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1477 if (slist != null) {
1478 for (SubscriptionInfo subInfoRecord : slist) {
1479 if (subInfoRecord.getSubscriptionId() == subId) {
1480 isValid = true;
1481 break;
1482 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001483 }
Wink Saville08874612014-08-31 19:19:58 -07001484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001485 if (!isValid) {
1486 return;
1487 }
Wink Saville08874612014-08-31 19:19:58 -07001488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1490 intent.putExtra(SUBSCRIPTION_KEY, subId);
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 } finally {
1494 Binder.restoreCallingIdentity(identity);
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001504 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1505 }
1506
1507 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
Wink Savilleb564aae2014-10-23 10:18:09 -07001511 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001513 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1514 }
1515
1516 /** {@hide} */
1517 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523
1524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1527 checkSimPin.start();
1528 return checkSimPin.unlockSim(null, pin);
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Wink Saville9de0f752013-10-22 19:04:03 -07001534 /** {@hide} */
1535 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001541
1542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1545 checkSimPuk.start();
1546 return checkSimPuk.unlockSim(puk, pin);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
1552 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001553 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 * a synchronous one.
1555 */
1556 private static class UnlockSim extends Thread {
1557
1558 private final IccCard mSimCard;
1559
1560 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001561 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1562 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563
1564 // For replies from SimCard interface
1565 private Handler mHandler;
1566
1567 // For async handler to identify request type
1568 private static final int SUPPLY_PIN_COMPLETE = 100;
1569
1570 public UnlockSim(IccCard simCard) {
1571 mSimCard = simCard;
1572 }
1573
1574 @Override
1575 public void run() {
1576 Looper.prepare();
1577 synchronized (UnlockSim.this) {
1578 mHandler = new Handler() {
1579 @Override
1580 public void handleMessage(Message msg) {
1581 AsyncResult ar = (AsyncResult) msg.obj;
1582 switch (msg.what) {
1583 case SUPPLY_PIN_COMPLETE:
1584 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1585 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001586 mRetryCount = msg.arg1;
1587 if (ar.exception != null) {
1588 if (ar.exception instanceof CommandException &&
1589 ((CommandException)(ar.exception)).getCommandError()
1590 == CommandException.Error.PASSWORD_INCORRECT) {
1591 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1592 } else {
1593 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 }
1595 } else {
1596 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 mDone = true;
1599 UnlockSim.this.notifyAll();
1600 }
1601 break;
1602 }
1603 }
1604 };
1605 UnlockSim.this.notifyAll();
1606 }
1607 Looper.loop();
1608 }
1609
1610 /*
1611 * Use PIN or PUK to unlock SIM card
1612 *
1613 * If PUK is null, unlock SIM card with PIN
1614 *
1615 * If PUK is not null, unlock SIM card with PUK and set PIN code
1616 */
Wink Saville9de0f752013-10-22 19:04:03 -07001617 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618
1619 while (mHandler == null) {
1620 try {
1621 wait();
1622 } catch (InterruptedException e) {
1623 Thread.currentThread().interrupt();
1624 }
1625 }
1626 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1627
1628 if (puk == null) {
1629 mSimCard.supplyPin(pin, callback);
1630 } else {
1631 mSimCard.supplyPuk(puk, pin, callback);
1632 }
1633
1634 while (!mDone) {
1635 try {
1636 Log.d(LOG_TAG, "wait for done");
1637 wait();
1638 } catch (InterruptedException e) {
1639 // Restore the interrupted status
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001644 int[] resultArray = new int[2];
1645 resultArray[0] = mResult;
1646 resultArray[1] = mRetryCount;
1647 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649 }
1650
1651 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001652 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001653
1654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 // No permission check needed here: this call is harmless, and it's
1658 // needed for the ServiceState.requestStateUpdate() call (which is
1659 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone phone = getPhone(subId);
1663 if (phone != null) {
1664 phone.updateServiceLocation();
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001671 @Override
1672 public boolean isRadioOn(String callingPackage) {
1673 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
1675
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001676 @Override
1677 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001679 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 return false;
1681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001682
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 return isRadioOnForSubscriber(subId);
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
1688 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 }
1690
1691 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1697 } else {
1698 return false;
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001706 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
Wink Saville36469e72014-06-11 15:17:00 -07001708
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
1723 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001724 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
Wink Savilleb564aae2014-10-23 10:18:09 -07001727 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 final Phone phone = getPhone(subId);
1733 if (phone == null) {
1734 return false;
1735 }
1736 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1737 toggleRadioOnOffForSubscriber(subId);
1738 }
1739 return true;
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
Wink Saville36469e72014-06-11 15:17:00 -07001744
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001745 public boolean needMobileRadioShutdown() {
1746 /*
1747 * If any of the Radios are available, it will need to be
1748 * shutdown. So return true if any Radio is available.
1749 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1753 Phone phone = PhoneFactory.getPhone(i);
1754 if (phone != null && phone.isRadioAvailable()) return true;
1755 }
1756 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1757 return false;
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001760 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001761 }
1762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 enforceModifyPermission();
1766
1767 final long identity = Binder.clearCallingIdentity();
1768 try {
1769 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1770 logv("Shutting down Phone " + i);
1771 shutdownRadioUsingPhoneId(i);
1772 }
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001775 }
1776 }
1777
1778 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 Phone phone = PhoneFactory.getPhone(phoneId);
1780 if (phone != null && phone.isRadioAvailable()) {
1781 phone.shutdownRadio();
1782 }
1783 }
1784
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1791 if (defaultPhone != null) {
1792 defaultPhone.setRadioPower(turnOn);
1793 return true;
1794 } else {
1795 loge("There's no default phone.");
1796 return false;
1797 }
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001800 }
Wink Saville36469e72014-06-11 15:17:00 -07001801 }
1802
Wink Savilleb564aae2014-10-23 10:18:09 -07001803 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 final Phone phone = getPhone(subId);
1809 if (phone != null) {
1810 phone.setRadioPower(turnOn);
1811 return true;
1812 } else {
1813 return false;
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Wink Saville36469e72014-06-11 15:17:00 -07001820 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 public boolean enableDataConnectivity() {
1823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824
1825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 int subId = mSubscriptionController.getDefaultDataSubId();
1828 final Phone phone = getPhone(subId);
1829 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001830 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 return true;
1832 } else {
1833 return false;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
Wink Saville36469e72014-06-11 15:17:00 -07001840 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 public boolean disableDataConnectivity() {
1843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001844
1845 final long identity = Binder.clearCallingIdentity();
1846 try {
1847 int subId = mSubscriptionController.getDefaultDataSubId();
1848 final Phone phone = getPhone(subId);
1849 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001850 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851 return true;
1852 } else {
1853 return false;
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001861 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001866 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
1875 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001876 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
pkanwarae03a6b2016-11-06 20:37:09 -08001879 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 enforceCallPermission();
1881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1885 return;
1886 }
1887 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1888 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
1891 }
pkanwar32d516d2016-10-14 19:37:38 -07001892 };
1893
Wink Savilleb564aae2014-10-23 10:18:09 -07001894 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1900 return false;
1901 }
1902 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001909 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001912 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 Phone phone = PhoneFactory.getPhone(slotIndex);
1916 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1917 PhoneConstantConversions.convertCallState(phone.getState());
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
1920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001924 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001925 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1926 }
1927
1928 @Override
1929 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001932 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 if (phone != null) {
1934 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1935 } else {
1936 return PhoneConstantConversions.convertDataState(
1937 PhoneConstants.DataState.DISCONNECTED);
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001945 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001946 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1947 }
1948
1949 @Override
1950 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 if (phone != null) {
1955 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1956 } else {
1957 return TelephonyManager.DATA_ACTIVITY_NONE;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
1964 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001965 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001966 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001967 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001968
1969 LocationAccessPolicy.LocationPermissionResult locationResult =
1970 LocationAccessPolicy.checkLocationPermission(mApp,
1971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1972 .setCallingPackage(callingPackage)
1973 .setCallingPid(Binder.getCallingPid())
1974 .setCallingUid(Binder.getCallingUid())
1975 .setMethod("getCellLocation")
1976 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1977 .build());
1978 switch (locationResult) {
1979 case DENIED_HARD:
1980 throw new SecurityException("Not allowed to access cell location");
1981 case DENIED_SOFT:
1982 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001986 final long identity = Binder.clearCallingIdentity();
1987 try {
1988 if (DBG_LOC) log("getCellLocation: is active user");
1989 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001990 int subId = mSubscriptionController.getDefaultDataSubId();
1991 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1992 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993 return data;
1994 } finally {
1995 Binder.restoreCallingIdentity(identity);
1996 }
Svetoslav64fad262015-04-14 14:35:21 -07001997 }
1998
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002000 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2001 if (!TextUtils.isEmpty(callingPackage)) {
2002 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2004 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2005 return "";
2006 }
2007 }
2008
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002009 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2010 // registered cell info, so return a NULL country instead.
2011 final long identity = Binder.clearCallingIdentity();
2012 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002013 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2014 // Get default phone in this case.
2015 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2016 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002017 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002018 // Todo: fix this when we can get the actual cellular network info when the device
2019 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002020 if (TelephonyManager.NETWORK_TYPE_IWLAN
2021 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2022 return "";
2023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002024 Phone phone = PhoneFactory.getPhone(phoneId);
2025 if (phone != null) {
2026 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002027 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 if (sst != null) {
2029 LocaleTracker lt = sst.getLocaleTracker();
2030 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002031 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2032 return lt.getCurrentCountry();
2033 } else if (emergencyNumberTracker != null) {
2034 return emergencyNumberTracker.getEmergencyCountryIso();
2035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 }
2037 }
2038 }
2039 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002043 }
2044
2045 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002047 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002048 }
2049
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002051 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 mApp.enforceCallingOrSelfPermission(
2053 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002054
2055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 final Phone phone = getPhone(subId);
2058 if (phone != null) {
2059 phone.enableLocationUpdates();
2060 }
2061 } finally {
2062 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002063 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 }
2065
2066 @Override
2067 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002068 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
2070
Sanket Padawe356d7632015-06-22 14:03:32 -07002071 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002072 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 mApp.enforceCallingOrSelfPermission(
2074 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 final Phone phone = getPhone(subId);
2079 if (phone != null) {
2080 phone.disableLocationUpdates();
2081 }
2082 } finally {
2083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
2086
Nathan Harold31d7ff32018-10-15 20:20:30 -07002087 /**
2088 * Returns the target SDK version number for a given package name.
2089 *
Nathan Haroldec184742019-07-10 17:04:16 -07002090 * This call MUST be invoked before clearing the calling UID.
2091 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002092 * @return target SDK if the package is found or INT_MAX.
2093 */
2094 private int getTargetSdk(String packageName) {
2095 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002096 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002097 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002098 if (ai != null) return ai.targetSdkVersion;
2099 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002100 loge("Failed to get package info for pkg="
2101 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002102 }
2103 return Integer.MAX_VALUE;
2104 }
2105
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 @Override
2107 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002108 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2109 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002110 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2111 throw new SecurityException(
2112 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2113 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002114
Jordan Liu1617b712019-07-10 15:06:26 -07002115 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2117 return null;
2118 }
Svetoslav64fad262015-04-14 14:35:21 -07002119
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002120 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121
Nathan Haroldf180aac2018-06-01 18:43:55 -07002122 List<CellInfo> info = getAllCellInfo(callingPackage);
2123 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124
Nathan Haroldf180aac2018-06-01 18:43:55 -07002125 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2126 for (CellInfo ci : info) {
2127 if (ci instanceof CellInfoGsm) {
2128 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2129 } else if (ci instanceof CellInfoWcdma) {
2130 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2131 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002133 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
2135
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002136 private List<CellInfo> getCachedCellInfo() {
2137 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2138 for (Phone phone : PhoneFactory.getPhones()) {
2139 List<CellInfo> info = phone.getAllCellInfo();
2140 if (info != null) cellInfos.addAll(info);
2141 }
2142 return cellInfos;
2143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002144
2145 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002146 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002147 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002148 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002149
2150 LocationAccessPolicy.LocationPermissionResult locationResult =
2151 LocationAccessPolicy.checkLocationPermission(mApp,
2152 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2153 .setCallingPackage(callingPackage)
2154 .setCallingPid(Binder.getCallingPid())
2155 .setCallingUid(Binder.getCallingUid())
2156 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002157 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002158 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2159 .build());
2160 switch (locationResult) {
2161 case DENIED_HARD:
2162 throw new SecurityException("Not allowed to access cell info");
2163 case DENIED_SOFT:
2164 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002167 final int targetSdk = getTargetSdk(callingPackage);
2168 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2169 return getCachedCellInfo();
2170 }
2171
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002172 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174 final long identity = Binder.clearCallingIdentity();
2175 try {
2176 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2177 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002178 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002179 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002180 if (info != null) cellInfos.addAll(info);
2181 }
2182 return cellInfos;
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186 }
2187
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002188 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002189 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2190 requestCellInfoUpdateInternal(
2191 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2192 }
2193
2194 @Override
2195 public void requestCellInfoUpdateWithWorkSource(
2196 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2197 enforceModifyPermission();
2198 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2199 }
2200
2201 private void requestCellInfoUpdateInternal(
2202 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002203 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002204 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002205
2206 LocationAccessPolicy.LocationPermissionResult locationResult =
2207 LocationAccessPolicy.checkLocationPermission(mApp,
2208 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2209 .setCallingPackage(callingPackage)
2210 .setCallingPid(Binder.getCallingPid())
2211 .setCallingUid(Binder.getCallingUid())
2212 .setMethod("requestCellInfoUpdate")
2213 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2214 .build());
2215 switch (locationResult) {
2216 case DENIED_HARD:
2217 throw new SecurityException("Not allowed to access cell info");
2218 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002219 try {
2220 cb.onCellInfo(new ArrayList<CellInfo>());
2221 } catch (RemoteException re) {
2222 // Drop without consequences
2223 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002224 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 }
2226
Nathan Harolda939a962019-05-09 10:13:47 -07002227
2228 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002229 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2230
2231 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2232 }
2233
2234 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002236 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002237 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002238
2239 final long identity = Binder.clearCallingIdentity();
2240 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002241 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242 } finally {
2243 Binder.restoreCallingIdentity(identity);
2244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246
Shishir Agrawala9f32182016-04-12 12:00:16 -07002247 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002248 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002249 Phone phone = PhoneFactory.getPhone(slotIndex);
2250 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002251 return null;
2252 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002253 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002254 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2255 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002256 return null;
2257 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return phone.getImei();
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002265 }
2266
2267 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002268 public String getTypeAllocationCodeForSlot(int slotIndex) {
2269 Phone phone = PhoneFactory.getPhone(slotIndex);
2270 String tac = null;
2271 if (phone != null) {
2272 String imei = phone.getImei();
2273 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2274 }
2275 return tac;
2276 }
2277
2278 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002279 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002280 Phone phone = PhoneFactory.getPhone(slotIndex);
2281 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002282 return null;
2283 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002284
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002286 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2287 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002288 return null;
2289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 return phone.getMeid();
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Jack Yu2af8d712017-03-15 17:14:14 -07002297 }
2298
2299 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002300 public String getManufacturerCodeForSlot(int slotIndex) {
2301 Phone phone = PhoneFactory.getPhone(slotIndex);
2302 String manufacturerCode = null;
2303 if (phone != null) {
2304 String meid = phone.getMeid();
2305 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2306 }
2307 return manufacturerCode;
2308 }
2309
2310 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002311 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002312 Phone phone = PhoneFactory.getPhone(slotIndex);
2313 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002314 return null;
2315 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 int subId = phone.getSubId();
2317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2318 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2319 return null;
2320 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321
2322 final long identity = Binder.clearCallingIdentity();
2323 try {
2324 return phone.getDeviceSvn();
2325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002328 }
2329
fionaxu43304da2017-11-27 22:51:16 -08002330 @Override
2331 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
fionaxu43304da2017-11-27 22:51:16 -08002339 }
2340
2341 @Override
2342 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 final Phone phone = getPhone(subId);
2346 return phone == null ? null : phone.getCarrierName();
2347 } finally {
2348 Binder.restoreCallingIdentity(identity);
2349 }
fionaxu43304da2017-11-27 22:51:16 -08002350 }
2351
calvinpanffe225e2018-11-01 19:43:06 +08002352 @Override
chen xu0026ca62019-03-06 15:28:50 -08002353 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002354 final long identity = Binder.clearCallingIdentity();
2355 try {
2356 final Phone phone = getPhone(subId);
2357 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002358 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002359 } finally {
2360 Binder.restoreCallingIdentity(identity);
2361 }
2362 }
2363
2364 @Override
chen xu0026ca62019-03-06 15:28:50 -08002365 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002369 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002370 } finally {
2371 Binder.restoreCallingIdentity(identity);
2372 }
2373 }
2374
chen xu651eec72018-11-11 19:03:44 -08002375 @Override
chen xu864e11c2018-12-06 22:10:03 -08002376 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2377 if (!isSubscriptionMccMnc) {
2378 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2379 }
chen xu651eec72018-11-11 19:03:44 -08002380 final Phone phone = PhoneFactory.getPhone(slotIndex);
2381 if (phone == null) {
2382 return TelephonyManager.UNKNOWN_CARRIER_ID;
2383 }
2384 final long identity = Binder.clearCallingIdentity();
2385 try {
2386 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
2389 }
2390 }
2391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002392 //
2393 // Internal helper methods.
2394 //
2395
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002396 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2398 *
2399 * @throws SecurityException if the caller does not have the required permission
2400 */
2401 private void enforceModifyPermission() {
2402 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2403 }
2404
2405 /**
2406 * Make sure the caller has the CALL_PHONE permission.
2407 *
2408 * @throws SecurityException if the caller does not have the required permission
2409 */
2410 private void enforceCallPermission() {
2411 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2412 }
2413
Stuart Scott8eef64f2015-04-08 15:13:54 -07002414 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002415 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002416 "ConnectivityService");
2417 }
2418
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 private String createTelUrl(String number) {
2420 if (TextUtils.isEmpty(number)) {
2421 return null;
2422 }
2423
Jake Hambye994d462014-02-03 13:10:13 -08002424 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Ihab Awadf9e92732013-12-05 18:02:52 -08002427 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2429 }
2430
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002431 private static void logv(String msg) {
2432 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Ihab Awadf9e92732013-12-05 18:02:52 -08002435 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2437 }
2438
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002441 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002445 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446 final long identity = Binder.clearCallingIdentity();
2447 try {
2448 final Phone phone = PhoneFactory.getPhone(slotIndex);
2449 if (phone == null) {
2450 return PhoneConstants.PHONE_TYPE_NONE;
2451 } else {
2452 return phone.getPhoneType();
2453 }
2454 } finally {
2455 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
2459 /**
2460 * Returns the CDMA ERI icon index to display
2461 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 @Override
2463 public int getCdmaEriIconIndex(String callingPackage) {
2464 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002465 }
2466
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002470 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 return -1;
2472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473
2474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 return phone.getCdmaEriIconIndex();
2479 } else {
2480 return -1;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 /**
2488 * Returns the CDMA ERI icon mode,
2489 * 0 - ON
2490 * 1 - FLASHING
2491 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002492 @Override
2493 public int getCdmaEriIconMode(String callingPackage) {
2494 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002495 }
2496
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002498 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002499 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002500 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002501 return -1;
2502 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 final Phone phone = getPhone(subId);
2507 if (phone != null) {
2508 return phone.getCdmaEriIconMode();
2509 } else {
2510 return -1;
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
2518 * Returns the CDMA ERI text,
2519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
2521 public String getCdmaEriText(String callingPackage) {
2522 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002523 }
2524
Sanket Padawe356d7632015-06-22 14:03:32 -07002525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002526 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002529 return null;
2530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002531
2532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 final Phone phone = getPhone(subId);
2535 if (phone != null) {
2536 return phone.getCdmaEriText();
2537 } else {
2538 return null;
2539 }
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 }
2544
2545 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002546 * Returns the CDMA MDN.
2547 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002549 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002550 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2551 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002556 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557 return phone.getLine1Number();
2558 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002559 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 return null;
2561 }
2562 } finally {
2563 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002564 }
2565 }
2566
2567 /**
2568 * Returns the CDMA MIN.
2569 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002571 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2573 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2579 return phone.getCdmaMin();
2580 } else {
2581 return null;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002585 }
2586 }
2587
Hall Liud892bec2018-11-30 14:51:45 -08002588 @Override
2589 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2590 INumberVerificationCallback callback, String callingPackage) {
2591 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2592 != PERMISSION_GRANTED) {
2593 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2594 }
2595 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2596
2597 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2598 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2599 throw new SecurityException("Calling package must be configured in the device config");
2600 }
2601
2602 if (range == null) {
2603 throw new NullPointerException("Range must be non-null");
2604 }
2605
2606 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002607 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002608
2609 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2610 }
2611
Junda Liuca05d5d2014-08-14 22:36:34 -07002612 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 * Returns true if CDMA provisioning needs to run.
2614 */
2615 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
2624 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002625 * Sets the voice mail number of a given subId.
2626 */
2627 @Override
2628 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002629 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2634 new Pair<String, String>(alphaTag, number), new Integer(subId));
2635 return success;
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002639 }
2640
Ta-wei Yen87c49842016-05-13 21:19:52 -07002641 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002642 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2643 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002644 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002645 if (!TextUtils.equals(callingPackage, systemDialer)) {
2646 throw new SecurityException("caller must be system dialer");
2647 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648
2649 final long identity = Binder.clearCallingIdentity();
2650 try {
2651 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2652 if (phoneAccountHandle == null) {
2653 return null;
2654 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002655 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 } finally {
2657 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002658 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002659 }
2660
2661 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002662 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002663 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002665 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002666 return null;
2667 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002669 final long identity = Binder.clearCallingIdentity();
2670 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002671 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002675 }
2676
2677 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002678 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2679 VisualVoicemailSmsFilterSettings settings) {
2680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002685 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002689 }
2690
2691 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002692 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2693 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002698 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 } finally {
2700 Binder.restoreCallingIdentity(identity);
2701 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002702 }
2703
2704 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002705 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2706 String callingPackage, int subId) {
2707 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002708
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002712 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713 } finally {
2714 Binder.restoreCallingIdentity(identity);
2715 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002716 }
2717
2718 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002719 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002720 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002721
2722 final long identity = Binder.clearCallingIdentity();
2723 try {
2724 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002729 }
2730
2731 @Override
2732 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2733 String number, int port, String text, PendingIntent sentIntent) {
2734 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002735 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002736 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002737 SmsController smsController = PhoneFactory.getSmsController();
2738 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2739 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002740 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002741
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002742 /**
fionaxu0152e512016-11-14 13:36:14 -08002743 * Sets the voice activation state of a given subId.
2744 */
2745 @Override
2746 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2748 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
2752 final Phone phone = getPhone(subId);
2753 if (phone != null) {
2754 phone.setVoiceActivationState(activationState);
2755 } else {
2756 loge("setVoiceActivationState fails with invalid subId: " + subId);
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002760 }
2761 }
2762
2763 /**
2764 * Sets the data activation state of a given subId.
2765 */
2766 @Override
2767 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2769 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770
2771 final long identity = Binder.clearCallingIdentity();
2772 try {
2773 final Phone phone = getPhone(subId);
2774 if (phone != null) {
2775 phone.setDataActivationState(activationState);
2776 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002777 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 }
2779 } finally {
2780 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002781 }
2782 }
2783
2784 /**
2785 * Returns the voice activation state of a given subId.
2786 */
2787 @Override
2788 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002789 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
fionaxu0152e512016-11-14 13:36:14 -08002791 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 if (phone != null) {
2795 return phone.getVoiceActivationState();
2796 } else {
2797 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002801 }
2802 }
2803
2804 /**
2805 * Returns the data activation state of a given subId.
2806 */
2807 @Override
2808 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002809 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
fionaxu0152e512016-11-14 13:36:14 -08002811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002812 final long identity = Binder.clearCallingIdentity();
2813 try {
2814 if (phone != null) {
2815 return phone.getDataActivationState();
2816 } else {
2817 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2818 }
2819 } finally {
2820 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002821 }
2822 }
2823
2824 /**
Wink Saville36469e72014-06-11 15:17:00 -07002825 * Returns the unread count of voicemails for a subId
2826 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002828 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2830 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2831 return 0;
2832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 final Phone phone = getPhone(subId);
2836 if (phone != null) {
2837 return phone.getVoiceMessageCount();
2838 } else {
2839 return 0;
2840 }
2841 } finally {
2842 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 }
2845
2846 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002847 * returns true, if the device is in a state where both voice and data
2848 * are supported simultaneously. This can change based on location or network condition.
2849 */
2850 @Override
2851 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002852 final long identity = Binder.clearCallingIdentity();
2853 try {
2854 final Phone phone = getPhone(subId);
2855 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
2858 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002859 }
2860
2861 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002862 * Send the dialer code if called from the current default dialer or the caller has
2863 * carrier privilege.
2864 * @param inputCode The dialer code to send
2865 */
2866 @Override
2867 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002868 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002869 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2871 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002872 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2874 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002875 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002876
2877 final long identity = Binder.clearCallingIdentity();
2878 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 } finally {
2881 Binder.restoreCallingIdentity(identity);
2882 }
fionaxu235cc5e2017-03-06 22:25:57 -08002883 }
2884
Pengquan Menga1bb6272018-09-06 09:59:22 -07002885 @Override
2886 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002887 if (!isActiveSubscription(subId)) {
2888 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2889 }
2890
Pengquan Menga1bb6272018-09-06 09:59:22 -07002891 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2892 }
2893
Brad Ebinger35c841c2018-10-01 10:40:55 -07002894 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002895 public boolean isInEmergencySmsMode() {
2896 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 for (Phone phone : PhoneFactory.getPhones()) {
2900 if (phone.isInEmergencySmsMode()) {
2901 return true;
2902 }
2903 }
2904 } finally {
2905 Binder.restoreCallingIdentity(identity);
2906 }
2907 return false;
2908 }
2909
2910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002911 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2912 throws RemoteException {
2913 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002914 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2915 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2916 "IMS not available on device.");
2917 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002918 final long token = Binder.clearCallingIdentity();
2919 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002920 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002921 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002922 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002923 } catch (ImsException e) {
2924 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 } finally {
2926 Binder.restoreCallingIdentity(token);
2927 }
2928 }
2929
2930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002931 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2932 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002933 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2934 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2935 }
Meng Wangafbc5852019-09-19 17:37:13 -07002936 final long token = Binder.clearCallingIdentity();
2937 try {
2938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2939 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2940 .removeRegistrationCallbackForSubscription(c, subId);
2941 } catch (ImsException e) {
2942 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2943 + "is inactive, ignoring unregister.");
2944 // If the subscription is no longer active, just return, since the callback
2945 // will already have been removed internally.
2946 } finally {
2947 Binder.restoreCallingIdentity(token);
2948 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 }
2950
Brad Ebingera34a6c22019-10-22 17:36:18 -07002951 /**
2952 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2953 */
2954 @Override
2955 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2956 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2957 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2958 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2959 "IMS not available on device.");
2960 }
2961 final long token = Binder.clearCallingIdentity();
2962 try {
2963 Phone phone = getPhone(subId);
2964 if (phone == null) {
2965 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2966 + subId + "'");
2967 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2968 }
2969 phone.getImsRegistrationState(regState -> {
2970 try {
2971 consumer.accept((regState == null)
2972 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2973 } catch (RemoteException e) {
2974 // Ignore if the remote process is no longer available to call back.
2975 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2976 }
2977 });
2978 } finally {
2979 Binder.restoreCallingIdentity(token);
2980 }
2981 }
2982
2983 /**
2984 * Get the transport type for the IMS service registration state.
2985 */
2986 @Override
2987 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2988 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2991 "IMS not available on device.");
2992 }
2993 final long token = Binder.clearCallingIdentity();
2994 try {
2995 Phone phone = getPhone(subId);
2996 if (phone == null) {
2997 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2998 + subId + "'");
2999 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3000 }
3001 phone.getImsRegistrationTech(regTech -> {
3002 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3003 int regTechConverted = (regTech == null)
3004 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3005 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3006 regTechConverted);
3007 try {
3008 consumer.accept(regTechConverted);
3009 } catch (RemoteException e) {
3010 // Ignore if the remote process is no longer available to call back.
3011 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3012 }
3013 });
3014 } finally {
3015 Binder.restoreCallingIdentity(token);
3016 }
3017 }
3018
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003020 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3021 throws RemoteException {
3022 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003023 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3024 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3025 "IMS not available on device.");
3026 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3028 final long token = Binder.clearCallingIdentity();
3029 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003032 } catch (ImsException e) {
3033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003034 } finally {
3035 Binder.restoreCallingIdentity(token);
3036 }
3037 }
3038
3039 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003040 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3041 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003042 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3043 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3044 }
Meng Wangafbc5852019-09-19 17:37:13 -07003045
3046 final long token = Binder.clearCallingIdentity();
3047 try {
3048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3049 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003050 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003051 } catch (ImsException e) {
3052 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3053 + "is inactive, ignoring unregister.");
3054 // If the subscription is no longer active, just return, since the callback
3055 // will already have been removed internally.
3056 } finally {
3057 Binder.restoreCallingIdentity(token);
3058 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 }
3060
3061 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003062 public boolean isCapable(int subId, int capability, int regTech) {
3063 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3065 final long token = Binder.clearCallingIdentity();
3066 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003067 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003069 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3071 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003072 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003073 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3074 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 } finally {
3076 Binder.restoreCallingIdentity(token);
3077 }
3078 }
3079
3080 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003081 public boolean isAvailable(int subId, int capability, int regTech) {
3082 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003083 final long token = Binder.clearCallingIdentity();
3084 try {
3085 Phone phone = getPhone(subId);
3086 if (phone == null) return false;
3087 return phone.isImsCapabilityAvailable(capability, regTech);
3088 } finally {
3089 Binder.restoreCallingIdentity(token);
3090 }
3091 }
3092
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003093 /**
3094 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3095 * subscription.
3096 * @param subId The subscription to use to check the configuration.
3097 * @param callback The callback that will be used to send the result.
3098 * @param capability The MmTelFeature capability that will be used to send the result.
3099 * @param transportType The transport type of the MmTelFeature capability.
3100 */
3101 @Override
3102 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3103 int transportType) {
3104 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3105 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3106 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3107 "IMS not available on device.");
3108 }
3109 final long token = Binder.clearCallingIdentity();
3110 try {
3111 int slotId = getSlotIndex(subId);
3112 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3113 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3114 + subId + "'");
3115 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3116 }
3117 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3118 transportType, aBoolean -> {
3119 try {
3120 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3121 } catch (RemoteException e) {
3122 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3123 + "running. Ignore");
3124 }
3125 });
3126 } finally {
3127 Binder.restoreCallingIdentity(token);
3128 }
3129 }
3130
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 @Override
3132 public boolean isAdvancedCallingSettingEnabled(int subId) {
3133 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3135 final long token = Binder.clearCallingIdentity();
3136 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003137 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003139 } catch (ImsException e) {
3140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 } finally {
3142 Binder.restoreCallingIdentity(token);
3143 }
3144 }
3145
3146 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003147 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003149 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003153 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003155 } catch (ImsException e) {
3156 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003157 } finally {
3158 Binder.restoreCallingIdentity(identity);
3159 }
3160 }
3161
3162 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003163 public boolean isVtSettingEnabled(int subId) {
3164 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003168 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3169 } catch (ImsException e) {
3170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
3174 }
3175
3176 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003177 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003178 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003179 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003180 final long identity = Binder.clearCallingIdentity();
3181 try {
3182 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003183 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003184 } catch (ImsException e) {
3185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
3191 @Override
3192 public boolean isVoWiFiSettingEnabled(int subId) {
3193 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003199 } catch (ImsException e) {
3200 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
3204 }
3205
3206 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003207 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003209 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003213 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003214 } catch (ImsException e) {
3215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3223 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3224 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003228 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
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 Ebinger1c162042019-02-21 14:49:10 -08003237 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003238 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003239 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003243 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003245 } catch (ImsException e) {
3246 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 }
3251
3252 @Override
3253 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3255 "setVoWiFiNonPersistent");
3256 final long identity = Binder.clearCallingIdentity();
3257 try {
3258 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003259 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003260 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003261 } catch (ImsException e) {
3262 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 } finally {
3264 Binder.restoreCallingIdentity(identity);
3265 }
3266 }
3267
3268 @Override
3269 public int getVoWiFiModeSetting(int subId) {
3270 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3271 final long identity = Binder.clearCallingIdentity();
3272 try {
3273 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003274 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (ImsException e) {
3277 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 } finally {
3279 Binder.restoreCallingIdentity(identity);
3280 }
3281 }
3282
3283 @Override
3284 public void setVoWiFiModeSetting(int subId, int mode) {
3285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3286 "setVoWiFiModeSetting");
3287 final long identity = Binder.clearCallingIdentity();
3288 try {
3289 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003290 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003292 } catch (ImsException e) {
3293 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003294 } finally {
3295 Binder.restoreCallingIdentity(identity);
3296 }
3297 }
3298
3299 @Override
3300 public int getVoWiFiRoamingModeSetting(int subId) {
3301 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003305 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003307 } catch (ImsException e) {
3308 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003309 } finally {
3310 Binder.restoreCallingIdentity(identity);
3311 }
3312 }
3313
3314 @Override
3315 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3317 "setVoWiFiRoamingModeSetting");
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003323 } catch (ImsException e) {
3324 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 } finally {
3326 Binder.restoreCallingIdentity(identity);
3327 }
3328 }
3329
3330 @Override
3331 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3332 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3333 "setRttCapabilityEnabled");
3334 final long identity = Binder.clearCallingIdentity();
3335 try {
3336 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003337 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3338 } catch (ImsException e) {
3339 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
3343 }
3344
3345 @Override
3346 public boolean isTtyOverVolteEnabled(int subId) {
3347 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003351 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003352 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003353 } catch (ImsException e) {
3354 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003355 } finally {
3356 Binder.restoreCallingIdentity(identity);
3357 }
3358 }
3359
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003360 @Override
3361 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3362 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003367 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003368 } catch (ImsException e) {
3369 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003370 } finally {
3371 Binder.restoreCallingIdentity(identity);
3372 }
3373 }
3374
3375 @Override
3376 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3377 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3378 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3380 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3381 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003382 try {
3383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003384 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003385 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003386 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003387 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3388 + "is inactive, ignoring unregister.");
3389 // If the subscription is no longer active, just return, since the callback will already
3390 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003397 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3398 boolean isProvisioned) {
3399 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3400 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3401 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3402 }
3403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3404 "setProvisioningStatusForCapability");
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3408 Phone phone = getPhone(subId);
3409 if (phone == null) {
3410 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3411 + subId);
3412 return;
3413 }
3414 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3415 return;
3416 }
3417
3418 // this capability requires provisioning, route to the correct API.
3419 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3420 switch (capability) {
3421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3422 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3423 ims.setVolteProvisioned(isProvisioned);
3424 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3425 ims.setWfcProvisioned(isProvisioned);
3426 }
3427 break;
3428 }
3429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3430 // There is currently no difference in VT provisioning type.
3431 ims.setVtProvisioned(isProvisioned);
3432 break;
3433 }
3434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3435 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3436 // change the capability of the feature instead if needed.
3437 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3438 == isProvisioned) {
3439 // No change in provisioning.
3440 return;
3441 }
3442 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3443 try {
3444 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003445 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3447 + ", Exception" + e.getMessage());
3448 }
3449 break;
3450 }
3451 default: {
3452 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3453 + capability + "', which does not require provisioning.");
3454 }
3455 }
3456
3457 } finally {
3458 Binder.restoreCallingIdentity(identity);
3459 }
3460 }
3461
3462 @Override
3463 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3464 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3465 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3466 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3467 }
3468 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3469 final long identity = Binder.clearCallingIdentity();
3470 try {
3471 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3472 Phone phone = getPhone(subId);
3473 if (phone == null) {
3474 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3475 + subId);
3476 // We will fail with "true" as the provisioning status because this is the default
3477 // if we do not require provisioning.
3478 return true;
3479 }
3480
3481 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3482 return true;
3483 }
3484
3485 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3486 switch (capability) {
3487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3488 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3489 return ims.isVolteProvisionedOnDevice();
3490 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3491 return ims.isWfcProvisionedOnDevice();
3492 }
3493 // This should never happen, since we are checking tech above to make sure it
3494 // is either LTE or IWLAN.
3495 throw new IllegalArgumentException("Invalid radio technology for voice "
3496 + "capability.");
3497 }
3498 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3499 // There is currently no difference in VT provisioning type.
3500 return ims.isVtProvisionedOnDevice();
3501 }
3502 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3503 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3504 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3505 }
3506 default: {
3507 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3508 + capability + "', which does not require provisioning.");
3509 }
3510 }
3511
3512 } finally {
3513 Binder.restoreCallingIdentity(identity);
3514 }
3515 }
3516
3517 @Override
3518 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3519 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3520 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3521 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3522 }
3523 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3524 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3525 return (provisionedBits & capability) > 0;
3526 }
3527
3528 @Override
3529 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3530 boolean isProvisioned) {
3531 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3532 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3533 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3534 }
3535 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3536 "setProvisioningStatusForCapability");
3537 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3538 // If the current provisioning status for capability already matches isProvisioned,
3539 // do nothing.
3540 if (((provisionedBits & capability) > 0) == isProvisioned) {
3541 return;
3542 }
3543 if (isProvisioned) {
3544 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3545 } else {
3546 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3547 }
3548 }
3549
3550 /**
3551 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3552 * technology. The bitfield should mirror the bitfield defined by
3553 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3554 */
3555 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3556 String key = getMmTelProvisioningKey(subId, tech);
3557 // Default is no capabilities are provisioned.
3558 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3559 }
3560
3561 /**
3562 * Sets the MmTel capability provisioning bitfield (defined by
3563 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3564 * technology specified.
3565 *
3566 * Note: This is a synchronous command and should not be called on UI thread.
3567 */
3568 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3569 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3570 String key = getMmTelProvisioningKey(subId, tech);
3571 editor.putInt(key, newField);
3572 editor.commit();
3573 }
3574
3575 private static String getMmTelProvisioningKey(int subId, int tech) {
3576 // resulting key is provision_ims_mmtel_{subId}_{tech}
3577 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3578 }
3579
3580 /**
3581 * Query CarrierConfig to see if the specified capability requires provisioning for the
3582 * carrier associated with the subscription id.
3583 */
3584 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3585 int capability) {
3586 CarrierConfigManager configManager = new CarrierConfigManager(context);
3587 PersistableBundle c = configManager.getConfigForSubId(subId);
3588 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003589 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003590 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3591 false);
3592 boolean requireVoiceVtProvisioning = c.getBoolean(
3593 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3594
3595 // First check to make sure that the capability requires provisioning.
3596 switch (capability) {
3597 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3598 // intentional fallthrough
3599 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3600 if (requireVoiceVtProvisioning) {
3601 // Voice and Video requires provisioning
3602 return true;
3603 }
3604 break;
3605 }
3606 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3607 if (requireUtProvisioning) {
3608 // UT requires provisioning
3609 return true;
3610 }
3611 break;
3612 }
3613 }
3614 return false;
3615 }
3616
3617 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003618 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003619 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3620 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3621 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003622 enforceReadPrivilegedPermission("getImsProvisioningInt");
3623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003626 int slotId = getSlotIndex(subId);
3627 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3628 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3629 + subId + "' for key:" + key);
3630 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3631 }
3632 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003633 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003634 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3635 + subId + "' for key:" + key);
3636 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
3640 }
3641
3642 @Override
3643 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3645 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3646 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003647 enforceReadPrivilegedPermission("getImsProvisioningString");
3648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 int slotId = getSlotIndex(subId);
3652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3653 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3654 + subId + "' for key:" + key);
3655 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3656 }
3657 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003658 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003659 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3660 + subId + "' for key:" + key);
3661 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
3665 }
3666
3667 @Override
3668 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3670 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3671 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003672 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3673 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003674 final long identity = Binder.clearCallingIdentity();
3675 try {
3676 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003677 int slotId = getSlotIndex(subId);
3678 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3679 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3680 + subId + "' for key:" + key);
3681 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3682 }
3683 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003684 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003685 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3686 + "' for key:" + key);
3687 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
3691 }
3692
3693 @Override
3694 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003695 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3696 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3697 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3699 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003703 int slotId = getSlotIndex(subId);
3704 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3705 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3706 + subId + "' for key:" + key);
3707 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3708 }
3709 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003711 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3712 + "' for key:" + key);
3713 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003714 } finally {
3715 Binder.restoreCallingIdentity(identity);
3716 }
3717 }
3718
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 int slotId = SubscriptionManager.getSlotIndex(subId);
3721 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003722 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3723 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 }
3725 return slotId;
3726 }
3727
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003728 private int getSlotIndex(int subId) {
3729 int slotId = SubscriptionManager.getSlotIndex(subId);
3730 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3731 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3732 }
3733 return slotId;
3734 }
3735
Wink Saville36469e72014-06-11 15:17:00 -07003736 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003737 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003738 */
3739 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003740 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003741 final int targetSdk = getTargetSdk(callingPackage);
3742 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3743 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3744 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003745 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3746 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003747 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3748 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003749
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 final Phone phone = getPhone(subId);
3753 if (phone != null) {
3754 return phone.getServiceState().getDataNetworkType();
3755 } else {
3756 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3757 }
3758 } finally {
3759 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003760 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003761 }
3762
3763 /**
3764 * Returns the data network type
3765 */
3766 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003767 public int getDataNetworkType(String callingPackage) {
3768 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003769 }
3770
3771 /**
3772 * Returns the data network type for a subId
3773 */
3774 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003775 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003777 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003778 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3779 }
3780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003781 final long identity = Binder.clearCallingIdentity();
3782 try {
3783 final Phone phone = getPhone(subId);
3784 if (phone != null) {
3785 return phone.getServiceState().getDataNetworkType();
3786 } else {
3787 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3788 }
3789 } finally {
3790 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003792 }
3793
3794 /**
Wink Saville36469e72014-06-11 15:17:00 -07003795 * Returns the Voice network type for a subId
3796 */
3797 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003798 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003799 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003800 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003801 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3802 }
3803
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003804 final long identity = Binder.clearCallingIdentity();
3805 try {
3806 final Phone phone = getPhone(subId);
3807 if (phone != null) {
3808 return phone.getServiceState().getVoiceNetworkType();
3809 } else {
3810 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3811 }
3812 } finally {
3813 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003815 }
3816
3817 /**
3818 * @return true if a ICC card is present
3819 */
3820 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003821 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003822 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3823 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003824 }
3825
3826 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003827 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003828 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003829 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003830 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 final Phone phone = PhoneFactory.getPhone(slotIndex);
3834 if (phone != null) {
3835 return phone.getIccCard().hasIccCard();
3836 } else {
3837 return false;
3838 }
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003842 }
3843
3844 /**
3845 * Return if the current radio is LTE on CDMA. This
3846 * is a tri-state return value as for a period of time
3847 * the mode may be unknown.
3848 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003849 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003850 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003851 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003852 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 @Override
3854 public int getLteOnCdmaMode(String callingPackage) {
3855 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003856 }
3857
Sanket Padawe356d7632015-06-22 14:03:32 -07003858 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003859 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003861 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003862 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3863 }
3864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 final Phone phone = getPhone(subId);
3868 if (phone == null) {
3869 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3870 } else {
3871 return phone.getLteOnCdmaMode();
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003875 }
Wink Saville36469e72014-06-11 15:17:00 -07003876 }
3877
Wink Saville36469e72014-06-11 15:17:00 -07003878 /**
3879 * {@hide}
3880 * Returns Default subId, 0 in the case of single standby.
3881 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003882 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003883 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003884 }
3885
Shishir Agrawala9f32182016-04-12 12:00:16 -07003886 private int getSlotForDefaultSubscription() {
3887 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3888 }
3889
Wink Savilleb564aae2014-10-23 10:18:09 -07003890 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003891 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003892 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003893
Pengquan Menge92a50d2018-09-21 15:54:48 -07003894 private boolean isActiveSubscription(int subId) {
3895 return mSubscriptionController.isActiveSubId(subId);
3896 }
3897
Ihab Awadf2177b72013-11-25 13:33:23 -08003898 /**
3899 * @see android.telephony.TelephonyManager.WifiCallingChoices
3900 */
3901 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003905 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3906 getWhenToMakeWifiCallsDefaultPreference());
3907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003910 }
3911
3912 /**
3913 * @see android.telephony.TelephonyManager.WifiCallingChoices
3914 */
3915 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003919 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003924 }
3925
Sailesh Nepald1e68152013-12-12 19:08:02 -08003926 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003927 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003928 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003929 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003930
Jordan Liu4c733742019-02-28 12:03:40 -08003931 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3932 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3933 if (phoneId == -1) {
3934 throw new IllegalArgumentException("Given slot index: " + slotIndex
3935 + " does not correspond to an active phone");
3936 }
3937 return PhoneFactory.getPhone(phoneId);
3938 }
3939
Shishir Agrawal566b7612013-10-28 14:41:00 -07003940 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003941 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3942 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003943 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3944 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003946 if (DBG) {
3947 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3948 }
3949 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3950 p2);
3951 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003952
Jordan Liu4c733742019-02-28 12:03:40 -08003953
3954 @Override
3955 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3956 int slotIndex, String callingPackage, String aid, int p2) {
3957 enforceModifyPermission();
3958 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3959 if (DBG) {
3960 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3961 }
3962 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3963 callingPackage, aid, p2);
3964 }
3965
3966 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3967 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 if (TextUtils.equals(ISDR_AID, aid)) {
3971 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003972 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3973 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 if (bestComponent == null
3975 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3976 loge("The calling package is not allowed to access ISD-R.");
3977 throw new SecurityException(
3978 "The calling package is not allowed to access ISD-R.");
3979 }
Derek Tan740e1672017-06-27 14:56:27 -07003980 }
Derek Tan740e1672017-06-27 14:56:27 -07003981
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003982 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003983 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3984 null /* workSource */);
3985 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 return response;
3987 } finally {
3988 Binder.restoreCallingIdentity(identity);
3989 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003990 }
3991
3992 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003993 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3995 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003996 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3997 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3998 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003999
Jordan Liu4c733742019-02-28 12:03:40 -08004000 @Override
4001 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4002 enforceModifyPermission();
4003 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4004 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4005 channel);
4006 }
4007
4008 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004011 if (channel < 0) {
4012 return false;
4013 }
Jordan Liu4c733742019-02-28 12:03:40 -08004014 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4015 null /* workSource */);
4016 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 return success;
4018 } finally {
4019 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004021 }
4022
4023 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004024 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004028 if (DBG) {
4029 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4030 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4031 + p3 + " data=" + data);
4032 }
4033 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4034 command, p1, p2, p3, data);
4035 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004036
Jordan Liu4c733742019-02-28 12:03:40 -08004037 @Override
4038 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4039 int command, int p1, int p2, int p3, String data) {
4040 enforceModifyPermission();
4041 if (DBG) {
4042 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4043 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4044 + p3 + " data=" + data);
4045 }
4046 return iccTransmitApduLogicalChannelWithPermission(
4047 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4048 data);
4049 }
4050
4051 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4052 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004055 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 return "";
4057 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004058
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004060 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4061 null /* workSource */);
4062 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 // Append the returned status code to the end of the response payload.
4065 String s = Integer.toHexString(
4066 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4067 if (response.payload != null) {
4068 s = IccUtils.bytesToHexString(response.payload) + s;
4069 }
4070 return s;
4071 } finally {
4072 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004073 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004074 }
Jake Hambye994d462014-02-03 13:10:13 -08004075
Evan Charltonc66da362014-05-16 14:06:40 -07004076 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004077 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4078 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004082 if (DBG) {
4083 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4084 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4085 }
4086 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4087 cla, command, p1, p2, p3, data);
4088 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004089
Jordan Liu4c733742019-02-28 12:03:40 -08004090 @Override
4091 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4092 int command, int p1, int p2, int p3, String data) {
4093 enforceModifyPermission();
4094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4095 if (DBG) {
4096 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4097 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4098 + " data=" + data);
4099 }
4100
4101 return iccTransmitApduBasicChannelWithPermission(
4102 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4103 p2, p3, data);
4104 }
4105
4106 // open APDU basic channel assuming the caller has sufficient permissions
4107 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4108 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 final long identity = Binder.clearCallingIdentity();
4110 try {
4111 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4112 && TextUtils.equals(ISDR_AID, data)) {
4113 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004114 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4115 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004116 if (bestComponent == null
4117 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4118 loge("The calling package is not allowed to select ISD-R.");
4119 throw new SecurityException(
4120 "The calling package is not allowed to select ISD-R.");
4121 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004122 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004125 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4126 null /* workSource */);
4127 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 // Append the returned status code to the end of the response payload.
4130 String s = Integer.toHexString(
4131 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4132 if (response.payload != null) {
4133 s = IccUtils.bytesToHexString(response.payload) + s;
4134 }
4135 return s;
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004138 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004139 }
4140
4141 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004142 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004143 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4145 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004147 final long identity = Binder.clearCallingIdentity();
4148 try {
4149 if (DBG) {
4150 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4151 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4152 }
4153
4154 IccIoResult response =
4155 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4156 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4157 subId);
4158
4159 if (DBG) {
4160 log("Exchange SIM_IO [R]" + response);
4161 }
4162
4163 byte[] result = null;
4164 int length = 2;
4165 if (response.payload != null) {
4166 length = 2 + response.payload.length;
4167 result = new byte[length];
4168 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4169 } else {
4170 result = new byte[length];
4171 }
4172
4173 result[length - 1] = (byte) response.sw2;
4174 result[length - 2] = (byte) response.sw1;
4175 return result;
4176 } finally {
4177 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004178 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004179 }
4180
Nathan Haroldb3014052017-01-25 15:57:32 -08004181 /**
4182 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4183 * on a particular subscription
4184 */
sqianb6e41952018-03-12 14:54:01 -07004185 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4186 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4187 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4188 return null;
4189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190
4191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 if (appType != TelephonyManager.APPTYPE_USIM
4194 && appType != TelephonyManager.APPTYPE_SIM) {
4195 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4196 return null;
4197 }
4198 Object response = sendRequest(
4199 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4200 if (response instanceof String[]) {
4201 return (String[]) response;
4202 }
yincheng zhao2737e882019-09-06 17:06:54 -07004203 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004205 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 } finally {
4207 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004208 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004209 }
4210
yincheng zhao2737e882019-09-06 17:06:54 -07004211 /**
4212 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4213 * subscription.
4214 *
4215 * @param subId the id of the subscription.
4216 * @param appType the uicc app type, must be USIM or SIM.
4217 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4218 * @param callingPackage the op Package name.
4219 * @return number of fplmns that is successfully written to the SIM.
4220 */
4221 public int setForbiddenPlmns(
4222 int subId, int appType, List<String> fplmns, String callingPackage) {
4223 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4224 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4225 if (DBG) logv("no permissions for setForbiddenplmns");
4226 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4227 }
4228 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4229 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4230 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4231 }
4232 if (fplmns == null) {
4233 throw new IllegalArgumentException("Fplmn List provided is null");
4234 }
4235 for (String fplmn : fplmns) {
4236 if (!CellIdentity.isValidPlmn(fplmn)) {
4237 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4238 }
4239 }
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
4242 Object response = sendRequest(
4243 CMD_SET_FORBIDDEN_PLMNS,
4244 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4245 subId);
4246 return (int) response;
4247 } finally {
4248 Binder.restoreCallingIdentity(identity);
4249 }
4250 }
4251
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004252 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004253 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4255 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4260 if (response.payload == null) {
4261 return "";
4262 }
Evan Charltonc66da362014-05-16 14:06:40 -07004263
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 // Append the returned status code to the end of the response payload.
4265 String s = Integer.toHexString(
4266 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4267 s = IccUtils.bytesToHexString(response.payload) + s;
4268 return s;
4269 } finally {
4270 Binder.restoreCallingIdentity(identity);
4271 }
Evan Charltonc66da362014-05-16 14:06:40 -07004272 }
4273
Jake Hambye994d462014-02-03 13:10:13 -08004274 /**
4275 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4276 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4277 *
4278 * @param itemID the ID of the item to read
4279 * @return the NV item as a String, or null on error.
4280 */
4281 @Override
4282 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004283 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4285 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286
4287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004290 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4292 return value;
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
Jake Hambye994d462014-02-03 13:10:13 -08004296 }
4297
4298 /**
4299 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4300 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4301 *
4302 * @param itemID the ID of the item to read
4303 * @param itemValue the value to write, as a String
4304 * @return true on success; false on any failure
4305 */
4306 @Override
4307 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004308 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4310 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4315 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004316 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4318 return success;
4319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Jake Hambye994d462014-02-03 13:10:13 -08004322 }
4323
4324 /**
4325 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4326 * Used for device configuration by some CDMA operators.
4327 *
4328 * @param preferredRoamingList byte array containing the new PRL
4329 * @return true on success; false on any failure
4330 */
4331 @Override
4332 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004333 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4334 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335
4336 final long identity = Binder.clearCallingIdentity();
4337 try {
4338 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4339 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4340 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4341 return success;
4342 } finally {
4343 Binder.restoreCallingIdentity(identity);
4344 }
Jake Hambye994d462014-02-03 13:10:13 -08004345 }
4346
4347 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004348 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004349 * Used for device configuration by some CDMA operators.
4350 *
chen xu6dac5ab2018-10-26 17:39:23 -07004351 * @param slotIndex - device slot.
4352 *
Jake Hambye994d462014-02-03 13:10:13 -08004353 * @return true on success; false on any failure
4354 */
4355 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004356 public boolean resetModemConfig(int slotIndex) {
4357 Phone phone = PhoneFactory.getPhone(slotIndex);
4358 if (phone != null) {
4359 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4360 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004361
chen xu6dac5ab2018-10-26 17:39:23 -07004362 final long identity = Binder.clearCallingIdentity();
4363 try {
4364 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4365 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4366 return success;
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 }
chen xu6dac5ab2018-10-26 17:39:23 -07004371 return false;
4372 }
4373
4374 /**
4375 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4376 *
4377 * @param slotIndex - device slot.
4378 *
4379 * @return true on success; false on any failure
4380 */
4381 @Override
4382 public boolean rebootModem(int slotIndex) {
4383 Phone phone = PhoneFactory.getPhone(slotIndex);
4384 if (phone != null) {
4385 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4386 mApp, phone.getSubId(), "rebootModem");
4387
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
4390 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4391 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4392 return success;
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
4396 }
4397 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004398 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004399
Svet Ganovb320e182015-04-16 12:30:10 -07004400 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004401 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004403 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004404 return new String[0];
4405 }
4406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 final long identity = Binder.clearCallingIdentity();
4408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004409 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004410 } finally {
4411 Binder.restoreCallingIdentity(identity);
4412 }
Wink Saville36469e72014-06-11 15:17:00 -07004413 }
4414
Brad Ebinger51f743a2017-01-23 13:50:20 -08004415 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004416 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4417 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004418 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004419 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004424 ImsResolver resolver = PhoneFactory.getImsResolver();
4425 if (resolver == null) {
4426 // may happen if the device does not support IMS.
4427 return;
4428 }
4429 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 } finally {
4431 Binder.restoreCallingIdentity(identity);
4432 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004433 }
4434
4435 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004436 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4437 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004438 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004439 public void disableIms(int slotId) {
4440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441
4442 final long identity = Binder.clearCallingIdentity();
4443 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004444 ImsResolver resolver = PhoneFactory.getImsResolver();
4445 if (resolver == null) {
4446 // may happen if the device does not support IMS.
4447 return;
4448 }
4449 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004453 }
4454
4455 /**
4456 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4457 * feature or {@link null} if the service is not available. If the feature is available, the
4458 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4459 */
4460 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004461 IImsServiceFeatureCallback callback) {
4462 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004463
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004466 ImsResolver resolver = PhoneFactory.getImsResolver();
4467 if (resolver == null) {
4468 // may happen if the device does not support IMS.
4469 return null;
4470 }
4471 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004472 } finally {
4473 Binder.restoreCallingIdentity(identity);
4474 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004475 }
4476
4477 /**
4478 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4479 * feature during emergency calling or {@link null} if the service is not available. If the
4480 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4481 * listener for feature updates.
4482 */
4483 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4484 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004488 ImsResolver resolver = PhoneFactory.getImsResolver();
4489 if (resolver == null) {
4490 // may happen if the device does not support IMS.
4491 return null;
4492 }
4493 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004494 } finally {
4495 Binder.restoreCallingIdentity(identity);
4496 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004497 }
4498
Brad Ebinger5f64b052017-12-14 14:26:15 -08004499 /**
4500 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004501 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004502 */
4503 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004505
4506 final long identity = Binder.clearCallingIdentity();
4507 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004508 ImsResolver resolver = PhoneFactory.getImsResolver();
4509 if (resolver == null) {
4510 // may happen if the device does not support IMS.
4511 return null;
4512 }
4513 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004517 }
4518
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004519 /**
4520 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004521 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004522 */
4523 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004528 ImsResolver resolver = PhoneFactory.getImsResolver();
4529 if (resolver == null) {
4530 // may happen if the device does not support IMS.
4531 return null;
4532 }
4533 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 } finally {
4535 Binder.restoreCallingIdentity(identity);
4536 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004537 }
4538
Brad Ebinger884c07b2018-02-15 16:17:40 -08004539 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004540 * Sets the ImsService Package Name that Telephony will bind to.
4541 *
4542 * @param slotId the slot ID that the ImsService should bind for.
4543 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4544 * ImsService is the device default ImsService.
4545 * @param packageName The package name of the application that contains the ImsService to bind
4546 * to.
4547 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4548 * @hide
4549 */
4550 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004551 int[] subIds = SubscriptionManager.getSubId(slotId);
4552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4553 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4554 "setImsService");
4555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 final long identity = Binder.clearCallingIdentity();
4557 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004558 ImsResolver resolver = PhoneFactory.getImsResolver();
4559 if (resolver == null) {
4560 // may happen if the device does not support IMS.
4561 return false;
4562 }
4563 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4564 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 } finally {
4566 Binder.restoreCallingIdentity(identity);
4567 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004568 }
4569
4570 /**
4571 * Return the ImsService configuration.
4572 *
4573 * @param slotId The slot that the ImsService is associated with.
4574 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4575 * the device default.
4576 * @return the package name of the ImsService configuration.
4577 */
4578 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004579 int[] subIds = SubscriptionManager.getSubId(slotId);
4580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4581 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4582 "getImsService");
4583
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004584 final long identity = Binder.clearCallingIdentity();
4585 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004586 ImsResolver resolver = PhoneFactory.getImsResolver();
4587 if (resolver == null) {
4588 // may happen if the device does not support IMS.
4589 return "";
4590 }
4591 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004595 }
4596
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004597 /**
4598 * Get the MmTelFeature state associated with the requested subscription id.
4599 * @param subId The subscription that the MmTelFeature is associated with.
4600 * @param callback A callback with an integer containing the
4601 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4602 */
4603 @Override
4604 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4605 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4606 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4607 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4608 "IMS not available on device.");
4609 }
4610 final long token = Binder.clearCallingIdentity();
4611 try {
4612 int slotId = getSlotIndex(subId);
4613 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4614 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4615 + subId + "'");
4616 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4617 }
4618 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4619 try {
4620 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4621 } catch (RemoteException e) {
4622 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4623 + "Ignore");
4624 }
4625 });
4626 } finally {
4627 Binder.restoreCallingIdentity(token);
4628 }
4629 }
4630
Wink Saville36469e72014-06-11 15:17:00 -07004631 public void setImsRegistrationState(boolean registered) {
4632 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633
4634 final long identity = Binder.clearCallingIdentity();
4635 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004636 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 } finally {
4638 Binder.restoreCallingIdentity(identity);
4639 }
Wink Saville36469e72014-06-11 15:17:00 -07004640 }
4641
4642 /**
Stuart Scott54788802015-03-30 13:18:01 -07004643 * Set the network selection mode to automatic.
4644 *
4645 */
4646 @Override
4647 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4649 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650
Pengquan Menge92a50d2018-09-21 15:54:48 -07004651 if (!isActiveSubscription(subId)) {
4652 return;
4653 }
4654
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655 final long identity = Binder.clearCallingIdentity();
4656 try {
4657 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4658 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4659 } finally {
4660 Binder.restoreCallingIdentity(identity);
4661 }
Stuart Scott54788802015-03-30 13:18:01 -07004662 }
4663
Pengquan Mengea84e042018-09-20 14:57:26 -07004664 /**
4665 * Ask the radio to connect to the input network and change selection mode to manual.
4666 *
4667 * @param subId the id of the subscription.
4668 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4669 * the operator to attach to.
4670 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4671 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4672 * normal network selection next time.
4673 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004674 */
4675 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004676 public boolean setNetworkSelectionModeManual(
4677 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4679 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004680
4681 if (!isActiveSubscription(subId)) {
4682 return false;
4683 }
4684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685 final long identity = Binder.clearCallingIdentity();
4686 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004687 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004689 if (DBG) {
4690 log("setNetworkSelectionModeManual: subId: " + subId
4691 + " operator: " + operatorInfo);
4692 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004697 }
4698
4699 /**
4700 * Scans for available networks.
4701 */
4702 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004703 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4705 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004706 LocationAccessPolicy.LocationPermissionResult locationResult =
4707 LocationAccessPolicy.checkLocationPermission(mApp,
4708 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4709 .setCallingPackage(callingPackage)
4710 .setCallingPid(Binder.getCallingPid())
4711 .setCallingUid(Binder.getCallingUid())
4712 .setMethod("getCellNetworkScanResults")
4713 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4714 .build());
4715 switch (locationResult) {
4716 case DENIED_HARD:
4717 throw new SecurityException("Not allowed to access scan results -- location");
4718 case DENIED_SOFT:
4719 return null;
4720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721
Pengquan Menga1bb6272018-09-06 09:59:22 -07004722 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 try {
4724 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004725 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 } finally {
4728 Binder.restoreCallingIdentity(identity);
4729 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004730 }
4731
4732 /**
yinxub1bed742017-04-17 11:45:04 -07004733 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004734 *
yinxub1bed742017-04-17 11:45:04 -07004735 * @param subId id of the subscription
4736 * @param request contains the radio access networks with bands/channels to scan
4737 * @param messenger callback messenger for scan results or errors
4738 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004739 * @return the id of the requested scan which can be used to stop the scan.
4740 */
4741 @Override
4742 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004743 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4745 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004746 LocationAccessPolicy.LocationPermissionResult locationResult =
4747 LocationAccessPolicy.checkLocationPermission(mApp,
4748 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4749 .setCallingPackage(callingPackage)
4750 .setCallingPid(Binder.getCallingPid())
4751 .setCallingUid(Binder.getCallingUid())
4752 .setMethod("requestNetworkScan")
4753 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4754 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004755 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004756 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004757 if (e != null) {
4758 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4759 throw e;
4760 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004761 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004762 return TelephonyScanManager.INVALID_SCAN_ID;
4763 }
4764 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 }
Hall Liu912dfd32019-04-25 14:02:26 -07004766 int callingUid = Binder.getCallingUid();
4767 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004768 final long identity = Binder.clearCallingIdentity();
4769 try {
4770 return mNetworkScanRequestTracker.startNetworkScan(
4771 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004772 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004773 } finally {
4774 Binder.restoreCallingIdentity(identity);
4775 }
yinxu504e1392017-04-12 16:03:22 -07004776 }
4777
Hall Liub2ac8ef2019-02-28 15:56:23 -08004778 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004779 NetworkScanRequest request, int subId) {
4780 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4781 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4782 boolean hasNetworkScanPermission =
4783 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4784 == PERMISSION_GRANTED;
4785
4786 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4787 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4788 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004789 }
4790
4791 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4792 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004793 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4794 return new SecurityException("Specific channels must not be"
4795 + " scanned without location access.");
4796 }
4797 }
4798 }
4799
Hall Liub2ac8ef2019-02-28 15:56:23 -08004800 return null;
4801 }
4802
yinxu504e1392017-04-12 16:03:22 -07004803 /**
4804 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004805 *
4806 * @param subId id of the subscription
4807 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004808 */
4809 @Override
4810 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4812 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813
Hall Liu912dfd32019-04-25 14:02:26 -07004814 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 final long identity = Binder.clearCallingIdentity();
4816 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004817 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 } finally {
4819 Binder.restoreCallingIdentity(identity);
4820 }
yinxu504e1392017-04-12 16:03:22 -07004821 }
4822
4823 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004824 * Get the calculated preferred network type.
4825 * Used for debugging incorrect network type.
4826 *
4827 * @return the preferred network type, defined in RILConstants.java.
4828 */
4829 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004830 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004831 final Phone defaultPhone = getDefaultPhone();
4832 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4833 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004834 return RILConstants.PREFERRED_NETWORK_MODE;
4835 }
4836
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004840 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 } finally {
4842 Binder.restoreCallingIdentity(identity);
4843 }
Junda Liu84d15a22014-07-02 11:21:04 -07004844 }
4845
4846 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004847 * Get the preferred network type.
4848 * Used for device configuration by some CDMA operators.
4849 *
4850 * @return the preferred network type, defined in RILConstants.java.
4851 */
4852 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004853 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004854 TelephonyPermissions
4855 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4856 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 if (DBG) log("getPreferredNetworkType");
4861 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4862 int networkType = (result != null ? result[0] : -1);
4863 if (DBG) log("getPreferredNetworkType: " + networkType);
4864 return networkType;
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004868 }
4869
4870 /**
4871 * Set the preferred network type.
4872 * Used for device configuration by some CDMA operators.
4873 *
4874 * @param networkType the preferred network type, defined in RILConstants.java.
4875 * @return true on success; false on any failure.
4876 */
4877 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004878 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4880 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004881
4882 final long identity = Binder.clearCallingIdentity();
4883 try {
4884 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4885 Boolean success = (Boolean) sendRequest(
4886 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4887 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4888 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004889 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4891 }
4892 return success;
4893 } finally {
4894 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004895 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004896 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004897
4898 /**
Miaoa84611c2019-03-15 09:21:10 +08004899 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004900 *
Miaoa84611c2019-03-15 09:21:10 +08004901 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004902 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004903 * @hide
4904 */
4905 @Override
Miaoa84611c2019-03-15 09:21:10 +08004906 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004909 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004910 try {
Miaoa84611c2019-03-15 09:21:10 +08004911 if (phone != null) {
4912 return phone.hasMatchedTetherApnSetting();
4913 } else {
4914 return false;
4915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004918 }
Junda Liu475951f2014-11-07 16:45:03 -08004919 }
4920
4921 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004922 * Set mobile data enabled
4923 * Used by the user through settings etc to turn on/off mobile data
4924 *
4925 * @param enable {@code true} turn turn data on, else {@code false}
4926 */
4927 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004928 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4930 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 int phoneId = mSubscriptionController.getPhoneId(subId);
4935 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4936 Phone phone = PhoneFactory.getPhone(phoneId);
4937 if (phone != null) {
4938 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004939 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004941 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 }
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004945 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004946 }
4947
4948 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004949 * Get the user enabled state of Mobile Data.
4950 *
4951 * TODO: remove and use isUserDataEnabled.
4952 * This can't be removed now because some vendor codes
4953 * calls through ITelephony directly while they should
4954 * use TelephonyManager.
4955 *
4956 * @return true on enabled
4957 */
4958 @Override
4959 public boolean getDataEnabled(int subId) {
4960 return isUserDataEnabled(subId);
4961 }
4962
4963 /**
4964 * Get whether mobile data is enabled per user setting.
4965 *
4966 * There are other factors deciding whether mobile data is actually enabled, but they are
4967 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004968 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004969 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004970 *
4971 * @return {@code true} if data is enabled else {@code false}
4972 */
4973 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004974 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004975 try {
4976 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4977 null);
4978 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4980 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004981 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982
4983 final long identity = Binder.clearCallingIdentity();
4984 try {
4985 int phoneId = mSubscriptionController.getPhoneId(subId);
4986 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4987 Phone phone = PhoneFactory.getPhone(phoneId);
4988 if (phone != null) {
4989 boolean retVal = phone.isUserDataEnabled();
4990 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4991 return retVal;
4992 } else {
4993 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4994 return false;
4995 }
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004998 }
4999 }
5000
5001 /**
5002 * Get whether mobile data is enabled.
5003 *
5004 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5005 * whether mobile data is actually enabled.
5006 *
5007 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5008 *
5009 * @return {@code true} if data is enabled else {@code false}
5010 */
5011 @Override
5012 public boolean isDataEnabled(int subId) {
5013 try {
5014 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5015 null);
5016 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5018 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005019 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020
5021 final long identity = Binder.clearCallingIdentity();
5022 try {
5023 int phoneId = mSubscriptionController.getPhoneId(subId);
5024 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5025 Phone phone = PhoneFactory.getPhone(phoneId);
5026 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005027 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5029 return retVal;
5030 } else {
5031 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5032 return false;
5033 }
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005036 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005037 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005038
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005039 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5040 Phone phone) {
5041 //load access rules from carrier configs, and check those as well: b/139133814
5042 SubscriptionController subController = SubscriptionController.getInstance();
5043 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5044 || subController == null) return privilegeFromSim;
5045
5046 int uid = Binder.getCallingUid();
5047 PackageManager pkgMgr = phone.getContext().getPackageManager();
5048 String[] packages = pkgMgr.getPackagesForUid(uid);
5049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5053 SubscriptionManager subManager = (SubscriptionManager)
5054 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5055 for (String pkg : packages) {
5056 if (subManager.canManageSubscription(subInfo, pkg)) {
5057 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5058 }
5059 }
5060 return privilegeFromSim;
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
5064 }
5065
5066 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5067 String pkgName) {
5068 //load access rules from carrier configs, and check those as well: b/139133814
5069 SubscriptionController subController = SubscriptionController.getInstance();
5070 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5071 || subController == null) return privilegeFromSim;
5072
5073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5076 SubscriptionManager subManager = (SubscriptionManager)
5077 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5078 return subManager.canManageSubscription(subInfo, pkgName)
5079 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
5083 }
5084
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005085 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005086 public int getCarrierPrivilegeStatus(int subId) {
5087 final Phone phone = getPhone(subId);
5088 if (phone == null) {
5089 loge("getCarrierPrivilegeStatus: Invalid subId");
5090 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5091 }
5092 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005093 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005094 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005095 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5096 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005097
5098 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5099 card.getCarrierPrivilegeStatusForCurrentTransaction(
5100 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005101 }
Junda Liu29340342014-07-10 15:23:27 -07005102
5103 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005104 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5105 final Phone phone = getPhone(subId);
5106 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005107 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5109 }
5110 UiccProfile profile =
5111 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5112 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005113 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005114 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5115 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005116 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5117 profile.getCarrierPrivilegeStatusForUid(
5118 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005119 }
5120
5121 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005122 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5123 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005124 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005125 }
5126
5127 int phoneId = SubscriptionManager.getPhoneId(subId);
5128 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005129 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005130 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005131 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5132 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005133 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5134 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5135 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005136 }
5137
5138 @Override
5139 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005140 if (TextUtils.isEmpty(pkgName))
5141 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005142 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5143 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5144 UiccCard card = UiccController.getInstance().getUiccCard(i);
5145 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005146 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005147 continue;
5148 }
5149
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005150 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5151 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5152 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005153 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5154 break;
5155 }
5156 }
5157
5158 return result;
Junda Liu29340342014-07-10 15:23:27 -07005159 }
Derek Tan89e89d42014-07-08 17:00:10 -07005160
5161 @Override
Junda Liue64de782015-04-16 17:19:16 -07005162 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5163 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5164 loge("phoneId " + phoneId + " is not valid.");
5165 return null;
5166 }
5167 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005168 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005169 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005170 return null ;
5171 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005173 }
5174
Amith Yamasani6e118872016-02-19 12:53:51 -08005175 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005176 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005177 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005178 List<String> privilegedPackages = new ArrayList<>();
5179 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005180 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5181 // has UICC in that slot.
5182 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005183 if (card.hasCarrierPrivilegeRules()) {
5184 if (packages == null) {
5185 // Only check packages in user 0 for now
5186 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005187 PackageManager.MATCH_DISABLED_COMPONENTS
5188 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005189 | PackageManager.GET_SIGNING_CERTIFICATES,
5190 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005191 }
5192 for (int p = packages.size() - 1; p >= 0; p--) {
5193 PackageInfo pkgInfo = packages.get(p);
5194 if (pkgInfo != null && pkgInfo.packageName != null
5195 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005196 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005197 privilegedPackages.add(pkgInfo.packageName);
5198 }
5199 }
5200 }
5201 }
5202 return privilegedPackages;
5203 }
5204
chen xuf7e9fe82019-05-09 19:31:02 -07005205 @Override
5206 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5207 List<String> privilegedPackages = new ArrayList<>();
5208 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5209 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5210 }
5211 return privilegedPackages;
5212 }
5213
Wink Savilleb564aae2014-10-23 10:18:09 -07005214 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005215 final Phone phone = getPhone(subId);
5216 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005217 if (card == null) {
5218 loge("getIccId: No UICC");
5219 return null;
5220 }
5221 String iccId = card.getIccId();
5222 if (TextUtils.isEmpty(iccId)) {
5223 loge("getIccId: ICC ID is null or empty.");
5224 return null;
5225 }
5226 return iccId;
5227 }
5228
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005229 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005230 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5231 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005232 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5233 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005234
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 final long identity = Binder.clearCallingIdentity();
5236 try {
5237 final String iccId = getIccId(subId);
5238 final Phone phone = getPhone(subId);
5239 if (phone == null) {
5240 return false;
5241 }
5242 final String subscriberId = phone.getSubscriberId();
5243
5244 if (DBG_MERGE) {
5245 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5246 + subscriberId + " to " + number);
5247 }
5248
5249 if (TextUtils.isEmpty(iccId)) {
5250 return false;
5251 }
5252
5253 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5254
5255 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5256 if (alphaTag == null) {
5257 editor.remove(alphaTagPrefKey);
5258 } else {
5259 editor.putString(alphaTagPrefKey, alphaTag);
5260 }
5261
5262 // Record both the line number and IMSI for this ICCID, since we need to
5263 // track all merged IMSIs based on line number
5264 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5265 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5266 if (number == null) {
5267 editor.remove(numberPrefKey);
5268 editor.remove(subscriberPrefKey);
5269 } else {
5270 editor.putString(numberPrefKey, number);
5271 editor.putString(subscriberPrefKey, subscriberId);
5272 }
5273
5274 editor.commit();
5275 return true;
5276 } finally {
5277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005278 }
Derek Tan7226c842014-07-02 17:42:23 -07005279 }
5280
5281 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005282 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005283 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005285 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005286 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005287 return null;
5288 }
Derek Tan97ebb422014-09-05 16:55:38 -07005289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
5292 String iccId = getIccId(subId);
5293 if (iccId != null) {
5294 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5295 if (DBG_MERGE) {
5296 log("getLine1NumberForDisplay returning "
5297 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5298 }
5299 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5302 return null;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005305 }
Derek Tan7226c842014-07-02 17:42:23 -07005306 }
5307
5308 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005309 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005311 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005312 return null;
5313 }
Derek Tan97ebb422014-09-05 16:55:38 -07005314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 final long identity = Binder.clearCallingIdentity();
5316 try {
5317 String iccId = getIccId(subId);
5318 if (iccId != null) {
5319 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5320 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5321 }
5322 return null;
5323 } finally {
5324 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005325 }
Derek Tan7226c842014-07-02 17:42:23 -07005326 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005327
5328 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005329 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005330 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5331 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005333 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5334 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005335 return null;
5336 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005337
Jordan Liub49b04b2019-05-06 14:45:15 -07005338 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5339 // the process, where TelephonyManager was instantiated.
5340 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005341 final long identity = Binder.clearCallingIdentity();
5342 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005343 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005344 final TelephonyManager tele = TelephonyManager.from(context);
5345 final SubscriptionManager sub = SubscriptionManager.from(context);
5346
5347 // Figure out what subscribers are currently active
5348 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
Jordan Liub49b04b2019-05-06 14:45:15 -07005350 // Only consider subs which match the current subId
5351 // This logic can be simplified. See b/131189269 for progress.
5352 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005353 activeSubscriberIds.add(tele.getSubscriberId(subId));
5354 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355
5356 // First pass, find a number override for an active subscriber
5357 String mergeNumber = null;
5358 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5359 for (String key : prefs.keySet()) {
5360 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5361 final String subscriberId = (String) prefs.get(key);
5362 if (activeSubscriberIds.contains(subscriberId)) {
5363 final String iccId = key.substring(
5364 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5365 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5366 mergeNumber = (String) prefs.get(numberKey);
5367 if (DBG_MERGE) {
5368 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5369 + " for active subscriber " + subscriberId);
5370 }
5371 if (!TextUtils.isEmpty(mergeNumber)) {
5372 break;
5373 }
5374 }
5375 }
5376 }
5377
5378 // Shortcut when no active merged subscribers
5379 if (TextUtils.isEmpty(mergeNumber)) {
5380 return null;
5381 }
5382
5383 // Second pass, find all subscribers under that line override
5384 final ArraySet<String> result = new ArraySet<>();
5385 for (String key : prefs.keySet()) {
5386 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5387 final String number = (String) prefs.get(key);
5388 if (mergeNumber.equals(number)) {
5389 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5390 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5391 final String subscriberId = (String) prefs.get(subscriberKey);
5392 if (!TextUtils.isEmpty(subscriberId)) {
5393 result.add(subscriberId);
5394 }
5395 }
5396 }
5397 }
5398
5399 final String[] resultArray = result.toArray(new String[result.size()]);
5400 Arrays.sort(resultArray);
5401 if (DBG_MERGE) {
5402 Slog.d(LOG_TAG,
5403 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5404 }
5405 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005408 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005409 }
5410
5411 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005412 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5413 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5414
5415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 final TelephonyManager telephonyManager = mApp.getSystemService(
5418 TelephonyManager.class);
5419 String subscriberId = telephonyManager.getSubscriberId(subId);
5420 if (subscriberId == null) {
5421 if (DBG) {
5422 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5423 + subId);
5424 }
5425 return null;
5426 }
5427
5428 final SubscriptionInfo info = SubscriptionController.getInstance()
5429 .getSubscriptionInfo(subId);
5430 final ParcelUuid groupUuid = info.getGroupUuid();
5431 // If it doesn't belong to any group, return just subscriberId of itself.
5432 if (groupUuid == null) {
5433 return new String[]{subscriberId};
5434 }
5435
5436 // Get all subscriberIds from the group.
5437 final List<String> mergedSubscriberIds = new ArrayList<>();
5438 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5439 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5440 for (SubscriptionInfo subInfo : groupInfos) {
5441 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5442 if (subscriberId != null) {
5443 mergedSubscriberIds.add(subscriberId);
5444 }
5445 }
5446
5447 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450
5451 }
5452 }
5453
5454 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005455 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005456 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5457 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 final Phone phone = getPhone(subId);
5462 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5463 } finally {
5464 Binder.restoreCallingIdentity(identity);
5465 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005466 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005467
5468 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005469 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005470 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5471 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005472 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005473
5474 final long identity = Binder.clearCallingIdentity();
5475 try {
5476 final Phone phone = getPhone(subId);
5477 if (phone == null) {
5478 return false;
5479 }
5480 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5481 cdmaNonRoamingList);
5482 } finally {
5483 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005484 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005485 }
5486
5487 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005488 @Deprecated
5489 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5490 enforceModifyPermission();
5491
5492 int returnValue = 0;
5493 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005494 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005495 if(result.exception == null) {
5496 if (result.result != null) {
5497 byte[] responseData = (byte[])(result.result);
5498 if(responseData.length > oemResp.length) {
5499 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5500 responseData.length + "bytes. Buffer Size is " +
5501 oemResp.length + "bytes.");
5502 }
5503 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5504 returnValue = responseData.length;
5505 }
5506 } else {
5507 CommandException ex = (CommandException) result.exception;
5508 returnValue = ex.getCommandError().ordinal();
5509 if(returnValue > 0) returnValue *= -1;
5510 }
5511 } catch (RuntimeException e) {
5512 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5513 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5514 if(returnValue > 0) returnValue *= -1;
5515 }
5516
5517 return returnValue;
5518 }
5519
5520 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005521 public void setRadioCapability(RadioAccessFamily[] rafs) {
5522 try {
5523 ProxyController.getInstance().setRadioCapability(rafs);
5524 } catch (RuntimeException e) {
5525 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5526 }
5527 }
5528
5529 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005530 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005531 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005532 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005533 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005534 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536 final long identity = Binder.clearCallingIdentity();
5537 try {
chen xub97461a2018-10-26 14:17:57 -07005538 TelephonyPermissions
5539 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5540 mApp, phone.getSubId(), "getRadioAccessFamily");
5541 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 } finally {
5543 Binder.restoreCallingIdentity(identity);
5544 }
chen xub97461a2018-10-26 14:17:57 -07005545 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005546 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005547
5548 @Override
5549 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005550 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005551 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552
5553 final long identity = Binder.clearCallingIdentity();
5554 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005555 ImsManager.getInstance(defaultPhone.getContext(),
5556 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005560 }
5561
5562 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005563 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005566 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005567 return false;
5568 }
Svet Ganovb320e182015-04-16 12:30:10 -07005569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 // Check the user preference and the system-level IMS setting. Even if the user has
5573 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5574 // In the long run, we may instead need to check if there exists a connection service
5575 // which can support video calling.
5576 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 return imsManager.isVtEnabledByPlatform()
5579 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5580 && imsManager.isVtEnabledByUser();
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005584 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005585
Andrew Leea1239f22015-03-02 17:44:07 -08005586 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5589 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5590 return false;
5591 }
5592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 CarrierConfigManager configManager =
5596 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005597 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Andrew Leea1239f22015-03-02 17:44:07 -08005602 }
5603
5604 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 public boolean isWorldPhone(int subId, String callingPackage) {
5606 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5607 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5608 return false;
5609 }
5610
5611 final long identity = Binder.clearCallingIdentity();
5612 try {
5613 CarrierConfigManager configManager =
5614 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005615 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
Andrew Leea1239f22015-03-02 17:44:07 -08005620 }
5621
Andrew Lee9431b832015-03-09 18:46:45 -07005622 @Override
5623 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005624 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005625 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005626 }
5627
5628 @Override
5629 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 final long identity = Binder.clearCallingIdentity();
5631 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005632 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Andrew Lee9431b832015-03-09 18:46:45 -07005636 }
5637
Hall Liuf6668912018-10-31 17:05:23 -07005638 /**
5639 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5640 * support for the feature and device firmware support.
5641 *
5642 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5643 */
5644 @Override
5645 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005647 final Phone phone = getPhone(subscriptionId);
5648 if (phone == null) {
5649 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5650 return false;
5651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005653 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5655 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005656 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005657 return isCarrierSupported && isDeviceSupported;
5658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Hall Liu98187582018-01-22 19:15:32 -08005661 }
5662
Hall Liuf6668912018-10-31 17:05:23 -07005663 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005664 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5665 * RTT setting, will return true if the device and carrier both support RTT.
5666 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005667 */
5668 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 final long identity = Binder.clearCallingIdentity();
5670 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005671 boolean isRttSupported = isRttSupported(subscriptionId);
5672 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005673 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005674 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5675 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5676 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005680 }
5681
Sanket Padawe7310cc72015-01-14 09:53:20 -08005682 /**
5683 * Returns the unique device ID of phone, for example, the IMEI for
5684 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5685 *
5686 * <p>Requires Permission:
5687 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5688 */
5689 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005690 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005691 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005692 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005693 return null;
5694 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005695 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005696 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5697 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005698 return null;
5699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 return phone.getDeviceId();
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005707 }
5708
Ping Sunc67b7c22016-03-02 19:16:45 +08005709 /**
5710 * {@hide}
5711 * Returns the IMS Registration Status on a particular subid
5712 *
5713 * @param subId
5714 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005715 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005716 Phone phone = getPhone(subId);
5717 if (phone != null) {
5718 return phone.isImsRegistered();
5719 } else {
5720 return false;
5721 }
5722 }
5723
Santos Cordon7a1885b2015-02-03 11:15:19 -08005724 @Override
5725 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005732 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005733
Tyler Gunnf70ed162019-04-03 15:28:53 -07005734 @Override
5735 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5736 final long identity = Binder.clearCallingIdentity();
5737 try {
5738 Phone phone = getPhone(subscriptionId);
5739 if (phone == null) {
5740 return null;
5741 }
5742 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5743 } finally {
5744 Binder.restoreCallingIdentity(identity);
5745 }
5746 }
5747
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005748 /**
5749 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005750 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005751 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 Phone phone = getPhone(subId);
5755 if (phone != null) {
5756 return phone.isWifiCallingEnabled();
5757 } else {
5758 return false;
5759 }
5760 } finally {
5761 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005762 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005763 }
5764
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005765 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005766 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005767 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005768 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769 final long identity = Binder.clearCallingIdentity();
5770 try {
5771 Phone phone = getPhone(subId);
5772 if (phone != null) {
5773 return phone.isVideoEnabled();
5774 } else {
5775 return false;
5776 }
5777 } finally {
5778 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005779 }
5780 }
5781
5782 /**
5783 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5784 * defined in {@link ImsRegistrationImplBase}.
5785 */
5786 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 final long identity = Binder.clearCallingIdentity();
5788 try {
5789 Phone phone = getPhone(subId);
5790 if (phone != null) {
5791 return phone.getImsRegistrationTech();
5792 } else {
5793 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5794 }
5795 } finally {
5796 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005797 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005798 }
5799
Stuart Scott8eef64f2015-04-08 15:13:54 -07005800 @Override
5801 public void factoryReset(int subId) {
5802 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005803 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5804 return;
5805 }
5806
Svet Ganovcc087f82015-05-12 20:35:54 -07005807 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005808
Svet Ganovcc087f82015-05-12 20:35:54 -07005809 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005810 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5811 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005812 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005813 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005814 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005815 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5816 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005817 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005818 // There has been issues when Sms raw table somehow stores orphan
5819 // fragments. They lead to garbled message when new fragments come
5820 // in and combined with those stale ones. In case this happens again,
5821 // user can reset all network settings which will clean up this table.
5822 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005823 // Clean up IMS settings as well here.
5824 int slotId = getSlotIndex(subId);
5825 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5826 ImsManager.getInstance(mApp, slotId).factoryReset();
5827 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005830 }
5831 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005832
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005833 private void cleanUpSmsRawTable(Context context) {
5834 ContentResolver resolver = context.getContentResolver();
5835 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5836 resolver.delete(uri, null, null);
5837 }
5838
Narayan Kamath1c496c22015-04-16 14:40:19 +01005839 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005840 public String getSimLocaleForSubscriber(int subId) {
5841 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5842 final Phone phone = getPhone(subId);
5843 if (phone == null) {
5844 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005845 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005847 final long identity = Binder.clearCallingIdentity();
5848 try {
chen xu5d3637b2019-01-21 23:31:38 -08005849 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5850 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005851 if (info == null) {
5852 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5853 return null;
5854 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 // Try and fetch the locale from the carrier properties or from the SIM language
5856 // preferences (EF-PL and EF-LI)...
5857 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005859 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5860 if (localeFromDefaultSim != null) {
5861 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5862 if (DBG) log("Using locale from subId: " + subId + " locale: "
5863 + localeFromDefaultSim);
5864 return localeFromDefaultSim.toLanguageTag();
5865 } else {
5866 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005867 }
5868 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 // The SIM language preferences only store a language (e.g. fr = French), not an
5871 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5872 // the SIM and carrier preferences does not include a country we add the country
5873 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005874 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005876 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 return mccLocale.toLanguageTag();
5878 }
5879
5880 if (DBG) log("No locale found - returning null");
5881 return null;
5882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005885 }
5886
5887 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005888 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005889 }
5890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 /**
5892 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5893 */
5894 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005895 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005896 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005897
Chenjie Yu1ba97252018-01-11 18:16:20 -08005898 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005899 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005900
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005901 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005902 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5903 * representing the state of the modem.
5904 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005905 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5906 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005907 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005908 */
5909 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005910 public void requestModemActivityInfo(ResultReceiver result) {
5911 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005912 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005913
5914 final long identity = Binder.clearCallingIdentity();
5915 try {
5916 ModemActivityInfo ret = null;
5917 synchronized (mLastModemActivityInfo) {
5918 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5919 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005920 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005921 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005923 int[] txTimeMs = info.getTransmitTimeMillis();
5924 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005926 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927 }
5928 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5930 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 mLastModemActivityInfo.setIdleTimeMillis(
5932 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005933 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5934 mLastModemActivityInfo.setReceiveTimeMillis(
5935 info.getReceiveTimeMillis() + mLastModemActivityInfo
5936 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005937 }
Chen Xud78231e2019-09-10 18:49:52 -07005938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5940 mLastModemActivityInfo.getSleepTimeMillis(),
5941 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005942 mLastModemActivityInfo.getTransmitTimeMillis(),
5943 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 Bundle bundle = new Bundle();
5946 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5947 result.send(0, bundle);
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005950 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005951 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005952
Siddharth Rayb8114062018-06-17 15:02:38 -07005953 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5954 // less than total activity duration.
5955 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5956 if (info == null) {
5957 return false;
5958 }
5959 int activityDurationMs =
5960 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5961 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005962 int[] txTimeMs = info.getTransmitTimeMillis();
5963 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5964 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005965 }
5966 return (info.isValid()
5967 && (info.getSleepTimeMillis() <= activityDurationMs)
5968 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005969 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005970 && (totalTxTimeMs <= activityDurationMs));
5971 }
5972
Jack Yu85bd38a2015-11-09 11:34:32 -08005973 /**
5974 * {@hide}
5975 * Returns the service state information on specified subscription.
5976 */
5977 @Override
5978 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005980 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005981 return null;
5982 }
5983
Hall Liuf19c44f2018-11-27 14:38:17 -08005984 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5985 LocationAccessPolicy.checkLocationPermission(mApp,
5986 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5987 .setCallingPackage(callingPackage)
5988 .setCallingPid(Binder.getCallingPid())
5989 .setCallingUid(Binder.getCallingUid())
5990 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005991 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005992 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5993 .build());
5994
5995 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5996 LocationAccessPolicy.checkLocationPermission(mApp,
5997 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5998 .setCallingPackage(callingPackage)
5999 .setCallingPid(Binder.getCallingPid())
6000 .setCallingUid(Binder.getCallingUid())
6001 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006002 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006003 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6004 .build());
6005 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6006 boolean hasFinePermission =
6007 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6008 boolean hasCoarsePermission =
6009 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6010
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 final Phone phone = getPhone(subId);
6014 if (phone == null) {
6015 return null;
6016 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006017
Hall Liuf19c44f2018-11-27 14:38:17 -08006018 ServiceState ss = phone.getServiceState();
6019
6020 // Scrub out the location info in ServiceState depending on what level of access
6021 // the caller has.
6022 if (hasFinePermission) return ss;
6023 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6024 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025 } finally {
6026 Binder.restoreCallingIdentity(identity);
6027 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006028 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006029
6030 /**
6031 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6032 *
6033 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6034 * voicemail ringtone.
6035 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6036 * PhoneAccount.
6037 */
6038 @Override
6039 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6043 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006044 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006045 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6048 } finally {
6049 Binder.restoreCallingIdentity(identity);
6050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006051 }
6052
6053 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006054 * Sets the per-account voicemail ringtone.
6055 *
6056 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6057 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6058 *
6059 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6060 * voicemail ringtone.
6061 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6062 * PhoneAccount.
6063 */
6064 @Override
6065 public void setVoicemailRingtoneUri(String callingPackage,
6066 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006067 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6069 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006070 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6072 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6073 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075
6076 final long identity = Binder.clearCallingIdentity();
6077 try {
6078 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6079 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006080 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081 }
6082 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6083 } finally {
6084 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006085 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006086 }
6087
6088 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006089 * Returns whether vibration is set for voicemail notification in Phone settings.
6090 *
6091 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6092 * voicemail vibration setting.
6093 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6094 */
6095 @Override
6096 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6100 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006101 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006102 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
6107 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006108 }
6109
Youhan Wange64578a2016-05-02 15:32:42 -07006110 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006111 * Sets the per-account voicemail vibration.
6112 *
6113 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6114 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6115 *
6116 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6117 * voicemail vibration setting.
6118 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6119 * specific PhoneAccount.
6120 */
6121 @Override
6122 public void setVoicemailVibrationEnabled(String callingPackage,
6123 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006124 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006125 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6126 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006127 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6129 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6130 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006131 }
6132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6136 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138 }
6139 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6140 } finally {
6141 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006142 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006143 }
6144
6145 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006146 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6147 *
6148 * @throws SecurityException if the caller does not have the required permission
6149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006150 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006152 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006153 }
6154
6155 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006156 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6157 * permission.
6158 *
6159 * @throws SecurityException if the caller does not have the required permission
6160 */
6161 private void enforceSendSmsPermission() {
6162 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6163 }
6164
6165 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006166 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006167 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006168 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006169 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006170 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006174 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 if (componentName == null) {
6176 throw new SecurityException(
6177 "Caller not current active visual voicemail package[null]");
6178 }
6179 String vvmPackage = componentName.getPackageName();
6180 if (!callingPackage.equals(vvmPackage)) {
6181 throw new SecurityException("Caller not current active visual voicemail package["
6182 + vvmPackage + "]");
6183 }
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006186 }
6187 }
6188
6189 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006190 * Return the application ID for the app type.
6191 *
6192 * @param subId the subscription ID that this request applies to.
6193 * @param appType the uicc app type.
6194 * @return Application ID for specificied app type, or null if no uicc.
6195 */
6196 @Override
6197 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006198 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006199 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006200
6201 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006202 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 if (phone == null) {
6204 return null;
6205 }
6206 String aid = null;
6207 try {
6208 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6209 .getApplicationByType(appType).getAid();
6210 } catch (Exception e) {
6211 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6212 }
6213 return aid;
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006216 }
Youhan Wange64578a2016-05-02 15:32:42 -07006217 }
6218
Youhan Wang4001d252016-05-11 10:29:41 -07006219 /**
6220 * Return the Electronic Serial Number.
6221 *
6222 * @param subId the subscription ID that this request applies to.
6223 * @return ESN or null if error.
6224 */
6225 @Override
6226 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006227 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006228 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229
6230 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006231 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232 if (phone == null) {
6233 return null;
6234 }
6235 String esn = null;
6236 try {
6237 esn = phone.getEsn();
6238 } catch (Exception e) {
6239 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6240 }
6241 return esn;
6242 } finally {
6243 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006244 }
Youhan Wang4001d252016-05-11 10:29:41 -07006245 }
6246
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006247 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006248 * Return the Preferred Roaming List Version.
6249 *
6250 * @param subId the subscription ID that this request applies to.
6251 * @return PRLVersion or null if error.
6252 */
6253 @Override
6254 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006255 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006256 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257
6258 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006259 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260 if (phone == null) {
6261 return null;
6262 }
6263 String cdmaPrlVersion = null;
6264 try {
6265 cdmaPrlVersion = phone.getCdmaPrlVersion();
6266 } catch (Exception e) {
6267 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6268 }
6269 return cdmaPrlVersion;
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006272 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006273 }
6274
6275 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006276 * Get snapshot of Telephony histograms
6277 * @return List of Telephony histograms
6278 * @hide
6279 */
6280 @Override
6281 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006282 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6283 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 return RIL.getTelephonyRILTimingHistograms();
6288 } finally {
6289 Binder.restoreCallingIdentity(identity);
6290 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006291 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006292
6293 /**
6294 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006295 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6296 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006297 * Require system privileges. In the future we may add this to carrier APIs.
6298 *
Michele Berionne482f8202018-11-27 18:57:59 -08006299 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006300 */
6301 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006302 @TelephonyManager.SetCarrierRestrictionResult
6303 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006304 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006306
Michele Berionne482f8202018-11-27 18:57:59 -08006307 if (carrierRestrictionRules == null) {
6308 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006309 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006313 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006314 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 } finally {
6316 Binder.restoreCallingIdentity(identity);
6317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006318 }
6319
6320 /**
6321 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006322 * Get the allowed carrier list and the excluded carrier list, including the priority between
6323 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006324 * Require system privileges. In the future we may add this to carrier APIs.
6325 *
Michele Berionne482f8202018-11-27 18:57:59 -08006326 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006327 */
6328 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006329 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006330 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006335 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6336 if (response instanceof CarrierRestrictionRules) {
6337 return (CarrierRestrictionRules) response;
6338 }
6339 // Response is an Exception of some kind,
6340 // which is signalled to the user as a NULL retval
6341 return null;
6342 } catch (Exception e) {
6343 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6344 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 } finally {
6346 Binder.restoreCallingIdentity(identity);
6347 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006348 }
6349
fionaxu59545b42016-05-25 15:53:37 -07006350 /**
6351 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6352 * @param subId the subscription ID that this action applies to.
6353 * @param enabled control enable or disable metered apns.
6354 * {@hide}
6355 */
6356 @Override
6357 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6358 enforceModifyPermission();
6359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006362 if (phone == null) {
6363 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6364 return;
6365 }
6366 try {
6367 phone.carrierActionSetMeteredApnsEnabled(enabled);
6368 } catch (Exception e) {
6369 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006370 } finally {
6371 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006372 }
6373 }
6374
6375 /**
6376 * Action set from carrier signalling broadcast receivers to enable/disable radio
6377 * @param subId the subscription ID that this action applies to.
6378 * @param enabled control enable or disable radio.
6379 * {@hide}
6380 */
6381 @Override
6382 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6383 enforceModifyPermission();
6384 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385
6386 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006387 if (phone == null) {
6388 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6389 return;
6390 }
6391 try {
6392 phone.carrierActionSetRadioEnabled(enabled);
6393 } catch (Exception e) {
6394 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006395 } finally {
6396 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006397 }
6398 }
6399
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006400 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006401 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6402 * network status based on which carrier apps could apply actions accordingly,
6403 * enable/disable default url handler for example.
6404 *
6405 * @param subId the subscription ID that this action applies to.
6406 * @param report control start/stop reporting the default network status.
6407 * {@hide}
6408 */
6409 @Override
6410 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6411 enforceModifyPermission();
6412 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413
6414 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006415 if (phone == null) {
6416 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6417 return;
6418 }
6419 try {
6420 phone.carrierActionReportDefaultNetworkStatus(report);
6421 } catch (Exception e) {
6422 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 } finally {
6424 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006425 }
6426 }
6427
6428 /**
fionaxud9622282017-07-17 17:51:30 -07006429 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6430 * @param subId the subscription ID that this action applies to.
6431 * {@hide}
6432 */
6433 @Override
6434 public void carrierActionResetAll(int subId) {
6435 enforceModifyPermission();
6436 final Phone phone = getPhone(subId);
6437 if (phone == null) {
6438 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6439 return;
6440 }
6441 try {
6442 phone.carrierActionResetAll();
6443 } catch (Exception e) {
6444 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6445 }
6446 }
6447
6448 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006449 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6450 * bug report is being generated.
6451 */
6452 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006453 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006454 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6455 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006456 writer.println("Permission Denial: can't dump Phone from pid="
6457 + Binder.getCallingPid()
6458 + ", uid=" + Binder.getCallingUid()
6459 + "without permission "
6460 + android.Manifest.permission.DUMP);
6461 return;
6462 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006463 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006464 }
Jack Yueb89b242016-06-22 13:27:47 -07006465
Brad Ebingerdac2f002018-04-03 15:17:52 -07006466 @Override
6467 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6468 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6469 throws RemoteException {
6470 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6471 }
6472
Jack Yueb89b242016-06-22 13:27:47 -07006473 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006474 * Get aggregated video call data usage since boot.
6475 *
6476 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6477 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006478 * {@hide}
6479 */
6480 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006481 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006482 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6483 null);
6484
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
6486 try {
6487 // NetworkStatsService keeps tracking the active network interface and identity. It
6488 // records the delta with the corresponding network identity.
6489 // We just return the total video call data usage snapshot since boot.
6490 Phone phone = getPhone(subId);
6491 if (phone != null) {
6492 return phone.getVtDataUsage(perUidStats);
6493 }
6494 return null;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006497 }
Jack Yueb89b242016-06-22 13:27:47 -07006498 }
Jack Yu75ab2952016-07-08 14:29:33 -07006499
6500 /**
6501 * Policy control of data connection. Usually used when data limit is passed.
6502 * @param enabled True if enabling the data, otherwise disabling.
6503 * @param subId Subscription index
6504 * {@hide}
6505 */
6506 @Override
6507 public void setPolicyDataEnabled(boolean enabled, int subId) {
6508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509
6510 final long identity = Binder.clearCallingIdentity();
6511 try {
6512 Phone phone = getPhone(subId);
6513 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006514 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006515 }
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006518 }
6519 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006520
6521 /**
6522 * Get Client request stats
6523 * @return List of Client Request Stats
6524 * @hide
6525 */
6526 @Override
6527 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006529 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006530 return null;
6531 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006532 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006533
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006534 final long identity = Binder.clearCallingIdentity();
6535 try {
6536 if (phone != null) {
6537 return phone.getClientRequestStats();
6538 }
6539
6540 return null;
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006544 }
6545
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006546 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006547 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006548 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006549 }
Jack Yueb4124c2017-02-16 15:32:43 -08006550
6551 /**
Grace Chen70990072017-03-24 17:21:30 -07006552 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006553 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006554 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006555 * @param state State of SIM (power down, power up, pass through)
6556 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6557 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6558 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006559 *
6560 **/
6561 @Override
Grace Chen70990072017-03-24 17:21:30 -07006562 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006563 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006564 Phone phone = PhoneFactory.getPhone(slotIndex);
6565
vagdeviaf9a5b92018-08-15 16:01:53 -07006566 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006571 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 }
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006575 }
6576 }
Shuo Qiandd210312017-04-12 22:11:33 +00006577
Tyler Gunn65d45c22017-06-05 11:22:26 -07006578 private boolean isUssdApiAllowed(int subId) {
6579 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006580 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006581 if (configManager == null) {
6582 return false;
6583 }
6584 PersistableBundle pb = configManager.getConfigForSubId(subId);
6585 if (pb == null) {
6586 return false;
6587 }
6588 return pb.getBoolean(
6589 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6590 }
6591
Shuo Qiandd210312017-04-12 22:11:33 +00006592 /**
6593 * Check if phone is in emergency callback mode
6594 * @return true if phone is in emergency callback mode
6595 * @param subId sub id
6596 */
goneil9c5f4872017-12-05 14:07:56 -08006597 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006598 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006599 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 if (phone != null) {
6605 return phone.isInEcm();
6606 } else {
6607 return false;
6608 }
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006611 }
6612 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006613
6614 /**
6615 * Get the current signal strength information for the given subscription.
6616 * Because this information is not updated when the device is in a low power state
6617 * it should not be relied-upon to be current.
6618 * @param subId Subscription index
6619 * @return the most recent cached signal strength info from the modem
6620 */
6621 @Override
6622 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 Phone p = getPhone(subId);
6626 if (p == null) {
6627 return null;
6628 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006630 return p.getSignalStrength();
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
6633 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006634 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006635
Pengquan Meng77b7f132018-08-22 14:49:57 -07006636 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006637 * Get the current modem radio state for the given slot.
6638 * @param slotIndex slot index.
6639 * @param callingPackage the name of the package making the call.
6640 * @return the current radio power state from the modem
6641 */
6642 @Override
6643 public int getRadioPowerState(int slotIndex, String callingPackage) {
6644 Phone phone = PhoneFactory.getPhone(slotIndex);
6645 if (phone != null) {
6646 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6647 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6648 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6649 }
6650
6651 final long identity = Binder.clearCallingIdentity();
6652 try {
6653 return phone.getRadioPowerState();
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
6657 }
6658 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6659 }
6660
6661 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006662 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6663 *
6664 * <p>Requires one of the following permissions:
6665 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6666 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6667 * privileges.
6668 *
6669 * @param subId subscription id
6670 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6671 * {@code false}.
6672 */
6673 @Override
6674 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006675 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6676 null /* message */);
6677
Pengquan Menga1bb6272018-09-06 09:59:22 -07006678 boolean isEnabled = false;
6679 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006680 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006681 Phone phone = getPhone(subId);
6682 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006683 } catch (Exception e) {
6684 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6685 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006686 } finally {
6687 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006689 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006690 }
6691
6692
6693 /**
6694 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6695 *
6696 * <p> Requires permission:
6697 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6698 * privileges.
6699 *
6700 * @param subId subscription id
6701 * @param isEnabled {@code true} means enable, {@code false} means disable.
6702 */
6703 @Override
6704 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006705 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6706 mApp, subId, "setDataRoamingEnabled");
6707
Pengquan Menga1bb6272018-09-06 09:59:22 -07006708 final long identity = Binder.clearCallingIdentity();
6709 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006710 Phone phone = getPhone(subId);
6711 if (phone != null) {
6712 phone.setDataRoamingEnabled(isEnabled);
6713 }
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006716 }
6717 }
6718
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006719 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006720 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006721 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6722 mApp, subId, "isManualNetworkSelectionAllowed");
6723
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006724 boolean isAllowed = true;
6725 final long identity = Binder.clearCallingIdentity();
6726 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006727 Phone phone = getPhone(subId);
6728 if (phone != null) {
6729 isAllowed = phone.isCspPlmnEnabled();
6730 }
6731 } finally {
6732 Binder.restoreCallingIdentity(identity);
6733 }
6734 return isAllowed;
6735 }
6736
6737 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006738 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006739 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006740 try {
6741 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006742 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006743 } catch (SecurityException e) {
6744 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6745 // has carrier privileges on an active UICC
6746 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6747 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006748 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006749 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006750 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006754 UiccController uiccController = UiccController.getInstance();
6755 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006756 if (hasReadPermission) {
6757 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006758 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006759
6760 // Remove private info if the caller doesn't have access
6761 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6762 for (UiccCardInfo cardInfo : cardInfos) {
6763 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6764 // is available
6765 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6766 if (card == null || card.getUiccProfile() == null) {
6767 // assume no access if the card or profile is unavailable
6768 filteredInfos.add(cardInfo.getUnprivileged());
6769 continue;
6770 }
6771 UiccProfile profile = card.getUiccProfile();
6772 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6773 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6774 filteredInfos.add(cardInfo);
6775 } else {
6776 filteredInfos.add(cardInfo.getUnprivileged());
6777 }
6778 }
6779 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006780 } finally {
6781 Binder.restoreCallingIdentity(identity);
6782 }
6783 }
6784
6785 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006786 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006787 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006789 final long identity = Binder.clearCallingIdentity();
6790 try {
6791 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6792 if (slots == null) {
6793 Rlog.i(LOG_TAG, "slots is null.");
6794 return null;
6795 }
6796
6797 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6798 for (int i = 0; i < slots.length; i++) {
6799 UiccSlot slot = slots[i];
6800 if (slot == null) {
6801 continue;
6802 }
6803
Jordan Liu7be7e652019-05-06 18:55:02 +00006804 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 UiccCard card = slot.getUiccCard();
6806 if (card != null) {
6807 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006808 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006809 cardId = slot.getEid();
6810 if (TextUtils.isEmpty(cardId)) {
6811 cardId = slot.getIccId();
6812 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006813 }
6814
Jordan Liu857451f2019-05-09 16:35:35 -07006815 if (cardId != null) {
6816 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6817 // if cardId is an EID, it's all digits so this is fine
6818 cardId = IccUtils.stripTrailingFs(cardId);
6819 }
6820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 int cardState = 0;
6822 switch (slot.getCardState()) {
6823 case CARDSTATE_ABSENT:
6824 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6825 break;
6826 case CARDSTATE_PRESENT:
6827 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6828 break;
6829 case CARDSTATE_ERROR:
6830 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6831 break;
6832 case CARDSTATE_RESTRICTED:
6833 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6834 break;
6835 default:
6836 break;
6837
6838 }
6839
6840 infos[i] = new UiccSlotInfo(
6841 slot.isActive(),
6842 slot.isEuicc(),
6843 cardId,
6844 cardState,
6845 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006846 slot.isExtendedApduSupported(),
6847 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 }
6849 return infos;
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006852 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006853 }
6854
6855 @Override
6856 public boolean switchSlots(int[] physicalSlots) {
6857 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006858
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006865 }
Jack Yu4c988042018-02-27 15:30:01 -08006866
6867 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006868 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 return UiccController.getInstance().getCardIdForDefaultEuicc();
6872 } finally {
6873 Binder.restoreCallingIdentity(identity);
6874 }
6875 }
6876
6877 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006878 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6879 enforceModifyPermission();
6880 final Phone phone = getPhone(subId);
6881 if (phone == null) {
6882 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6883 return;
6884 }
6885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 phone.setRadioIndicationUpdateMode(filters, mode);
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
Jack Yu4c988042018-02-27 15:30:01 -08006892 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006893
6894 /**
goneil47ffb6e2018-04-06 15:40:58 -07006895 * A test API to reload the UICC profile.
6896 *
6897 * <p>Requires that the calling app has permission
6898 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6899 * @hide
6900 */
6901 @Override
6902 public void refreshUiccProfile(int subId) {
6903 enforceModifyPermission();
6904
6905 final long identity = Binder.clearCallingIdentity();
6906 try {
6907 Phone phone = getPhone(subId);
6908 if (phone == null) {
6909 return;
6910 }
6911 UiccCard uiccCard = phone.getUiccCard();
6912 if (uiccCard == null) {
6913 return;
6914 }
6915 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6916 if (uiccProfile == null) {
6917 return;
6918 }
6919 uiccProfile.refresh();
6920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
6923 }
6924
6925 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006926 * Returns false if the mobile data is disabled by default, otherwise return true.
6927 */
6928 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006929 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006930 }
6931
6932 /**
6933 * Returns true if the data roaming is enabled by default, i.e the system property
6934 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6935 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6936 */
6937 private boolean getDefaultDataRoamingEnabled(int subId) {
6938 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006939 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09006940 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006941 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6942 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6943 return isDataRoamingEnabled;
6944 }
6945
6946 /**
6947 * Returns the default network type for the given {@code subId}, if the default network type is
6948 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6949 */
6950 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006951 List<Integer> list = TelephonyProperties.default_network();
6952 int phoneId = mSubscriptionController.getPhoneId(subId);
6953 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
6954 return list.get(phoneId);
6955 }
6956 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07006957 }
fionaxua13278b2018-03-21 00:08:13 -07006958
6959 @Override
6960 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006961 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006963
6964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 final Phone phone = getPhone(subId);
6967 if (phone == null) {
6968 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6969 return;
6970 }
chen xueaba88a2019-03-15 13:15:10 -07006971 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6972 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 } finally {
6974 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006975 }
fionaxua13278b2018-03-21 00:08:13 -07006976 }
6977
6978 @Override
6979 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006980 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981
6982 final long identity = Binder.clearCallingIdentity();
6983 try {
6984 final Phone phone = getPhone(subId);
6985 if (phone == null) {
6986 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6987 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6988 }
6989 return phone.getCarrierIdListVersion();
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006992 }
fionaxua13278b2018-03-21 00:08:13 -07006993 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006994
6995 @Override
6996 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6998 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6999 return -1;
7000 }
7001
7002 final long identity = Binder.clearCallingIdentity();
7003 try {
7004 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
7008 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007009
7010 @Override
7011 public int getCdmaRoamingMode(int subId) {
7012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7013 mApp, subId, "getCdmaRoamingMode");
7014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
7020 }
7021 }
7022
7023 @Override
7024 public boolean setCdmaRoamingMode(int subId, int mode) {
7025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7026 mApp, subId, "setCdmaRoamingMode");
7027
7028 final long identity = Binder.clearCallingIdentity();
7029 try {
7030 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
7033 }
7034 }
7035
7036 @Override
7037 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7039 mApp, subId, "setCdmaSubscriptionMode");
7040
7041 final long identity = Binder.clearCallingIdentity();
7042 try {
7043 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
7047 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007048
sqianc5eccab2018-10-19 18:46:41 -07007049 @Override
sqian8c685422019-02-22 15:55:18 -08007050 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007051 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007053 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007054 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7055 }
7056 final long identity = Binder.clearCallingIdentity();
7057 try {
sqian854d44b2018-12-12 16:48:18 -08007058 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7059 for (Phone phone: PhoneFactory.getPhones()) {
7060 if (phone.getEmergencyNumberTracker() != null
7061 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7062 emergencyNumberListInternal.put(
7063 phone.getSubId(),
7064 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7065 }
sqian11b7a0e2018-12-05 18:48:28 -08007066 }
sqian854d44b2018-12-12 16:48:18 -08007067 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007068 } finally {
7069 Binder.restoreCallingIdentity(identity);
7070 }
sqianc5eccab2018-10-19 18:46:41 -07007071 }
7072
7073 @Override
sqian8c685422019-02-22 15:55:18 -08007074 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007075 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007076 if (!exactMatch) {
7077 TelephonyPermissions
7078 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007079 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007080 }
7081 final long identity = Binder.clearCallingIdentity();
7082 try {
sqian854d44b2018-12-12 16:48:18 -08007083 for (Phone phone: PhoneFactory.getPhones()) {
7084 if (phone.getEmergencyNumberTracker() != null
7085 && phone.getEmergencyNumberTracker() != null) {
7086 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7087 number, exactMatch)) {
7088 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007089 }
7090 }
sqian11b7a0e2018-12-05 18:48:28 -08007091 }
7092 return false;
7093 } finally {
7094 Binder.restoreCallingIdentity(identity);
7095 }
7096 }
7097
sqianf4ca7ed2019-01-15 18:32:07 -08007098 /**
7099 * Update emergency number list for test mode.
7100 */
7101 @Override
7102 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7104 "updateEmergencyNumberListTestMode");
7105
7106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 for (Phone phone: PhoneFactory.getPhones()) {
7109 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7110 if (tracker != null) {
7111 tracker.executeEmergencyNumberTestModeCommand(action, num);
7112 }
7113 }
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
7118
7119 /**
7120 * Get the full emergency number list for test mode.
7121 */
7122 @Override
7123 public List<String> getEmergencyNumberListTestMode() {
7124 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7125 "getEmergencyNumberListTestMode");
7126
7127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 Set<String> emergencyNumbers = new HashSet<>();
7130 for (Phone phone: PhoneFactory.getPhones()) {
7131 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7132 if (tracker != null) {
7133 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7134 emergencyNumbers.add(num.getNumber());
7135 }
7136 }
7137 }
7138 return new ArrayList<>(emergencyNumbers);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
7142 }
7143
chen xud6b45bd2018-10-30 22:27:10 -07007144 @Override
7145 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7146 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7147 Phone phone = getPhone(subId);
7148 if (phone == null) {
7149 return null;
7150 }
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 UiccProfile profile = UiccController.getInstance()
7154 .getUiccProfileForPhone(phone.getPhoneId());
7155 if (profile != null) {
7156 return profile.getCertsFromCarrierPrivilegeAccessRules();
7157 }
7158 } finally {
7159 Binder.restoreCallingIdentity(identity);
7160 }
7161 return null;
7162 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007163
7164 /**
7165 * Enable or disable a modem stack.
7166 */
7167 @Override
7168 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7169 enforceModifyPermission();
7170
7171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 Phone phone = PhoneFactory.getPhone(slotIndex);
7174 if (phone == null) {
7175 return false;
7176 } else {
7177 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7178 }
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
7181 }
7182 }
Michelecea4cf22018-12-21 15:00:11 -08007183
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007184 /**
7185 * Whether a modem stack is enabled or not.
7186 */
7187 @Override
7188 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7189 Phone phone = PhoneFactory.getPhone(slotIndex);
7190 if (phone == null) return false;
7191
7192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7193 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7194 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7195 }
7196
7197 final long identity = Binder.clearCallingIdentity();
7198 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007199 try {
7200 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7201 } catch (NoSuchElementException ex) {
7202 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7203 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
7206 }
7207 }
7208
Michelecea4cf22018-12-21 15:00:11 -08007209 @Override
Michele0ea7d782019-03-19 14:58:42 -07007210 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007211 enforceModifyPermission();
7212
7213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007216 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007217 .commit();
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
7220 }
7221 }
7222
7223 @Override
Michele0ea7d782019-03-19 14:58:42 -07007224 @TelephonyManager.IsMultiSimSupportedResult
7225 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007226 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007227 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7228 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007229 }
Michelecea4cf22018-12-21 15:00:11 -08007230
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
Michele0ea7d782019-03-19 14:58:42 -07007233 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007234 } finally {
7235 Binder.restoreCallingIdentity(identity);
7236 }
7237 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007238
Michele0ea7d782019-03-19 14:58:42 -07007239 @TelephonyManager.IsMultiSimSupportedResult
7240 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007241 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7242 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7243 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007244 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7245 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007246 }
7247 // Check if the hardware supports multisim functionality. If usage of multisim is not
7248 // supported by the modem, indicate that it is restricted.
7249 PhoneCapability staticCapability =
7250 mPhoneConfigurationManager.getStaticPhoneCapability();
7251 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007252 loge("isMultiSimSupportedInternal: no static configuration available");
7253 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007254 }
7255 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007256 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7257 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007258 }
7259 // Check if support of multiple SIMs is restricted by carrier
7260 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007261 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007262 }
7263
Michele0ea7d782019-03-19 14:58:42 -07007264 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007265 }
7266
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007267 /**
7268 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007269 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7270 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7271 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007272 * @param numOfSims number of active sims we want to switch to
7273 */
7274 @Override
7275 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007276 if (numOfSims == 1) {
7277 enforceModifyPermission();
7278 } else {
7279 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7280 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7281 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007282 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007283
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007284 try {
Michele30b57b22019-03-01 12:01:14 -08007285 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007286 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007287 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7288 return;
7289 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007290 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7291 } finally {
7292 Binder.restoreCallingIdentity(identity);
7293 }
7294 }
7295
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007296 @Override
7297 public boolean isApplicationOnUicc(int subId, int appType) {
7298 enforceReadPrivilegedPermission("isApplicationOnUicc");
7299 Phone phone = getPhone(subId);
7300 if (phone == null) {
7301 return false;
7302 }
7303 final long identity = Binder.clearCallingIdentity();
7304 try {
7305 UiccCard uiccCard = phone.getUiccCard();
7306 if (uiccCard == null) {
7307 return false;
7308 }
7309 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7310 if (uiccProfile == null) {
7311 return false;
7312 }
7313 if (TelephonyManager.APPTYPE_SIM <= appType
7314 && appType <= TelephonyManager.APPTYPE_ISIM) {
7315 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7316 }
7317 return false;
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
7321 }
7322
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007323 /**
chen xub4baa772019-04-03 10:23:41 -07007324 * Get whether making changes to modem configurations will trigger reboot.
7325 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007326 */
7327 @Override
chen xub4baa772019-04-03 10:23:41 -07007328 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7330 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7331 return false;
7332 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007333 final long identity = Binder.clearCallingIdentity();
7334 try {
7335 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7336 } finally {
7337 Binder.restoreCallingIdentity(identity);
7338 }
7339 }
7340
Nathan Harold29f5f052019-02-15 13:41:57 -08007341 private void updateModemStateMetrics() {
7342 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7343 // TODO: check the state for each modem if the api is ready.
7344 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7345 }
7346
Pengquan Meng3889a572019-01-23 11:16:29 -08007347 @Override
7348 public int[] getSlotsMapping() {
7349 enforceReadPrivilegedPermission("getSlotsMapping");
7350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7354 // All logical slots should have a mapping to a physical slot.
7355 int[] logicalSlotsMapping = new int[phoneCount];
7356 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7357 for (int i = 0; i < slotInfos.length; i++) {
7358 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7359 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7360 }
7361 }
7362 return logicalSlotsMapping;
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
7366 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007367
7368 /**
7369 * Get the IRadio HAL Version
7370 */
7371 @Override
7372 public int getRadioHalVersion() {
7373 Phone phone = getDefaultPhone();
7374 if (phone == null) return -1;
7375 HalVersion hv = phone.getHalVersion();
7376 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7377 return hv.major * 100 + hv.minor;
7378 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007379
7380 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007381 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7382 * corresponding network requests on a subId.
7383 *
7384 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007385 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007386 * 2) APN is un-metered for this subscription, or
7387 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7388 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7389 *
7390 * @return whether data is allowed for a apn type.
7391 *
7392 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007393 */
7394 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007395 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007396 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7397 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007398
7399 // Now that all security checks passes, perform the operation as ourselves.
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 Phone phone = getPhone(subId);
7403 if (phone == null) return false;
7404
Jack Yu41407ee2019-05-13 16:54:09 -07007405 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007406 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
7409 }
7410 }
7411
7412 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007413 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007414 enforceReadPrivilegedPermission("isApnMetered");
7415
7416 // Now that all security checks passes, perform the operation as ourselves.
7417 final long identity = Binder.clearCallingIdentity();
7418 try {
7419 Phone phone = getPhone(subId);
7420 if (phone == null) return true; // By default return true.
7421
Jack Yu41407ee2019-05-13 16:54:09 -07007422 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
7426 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007427
7428 @Override
7429 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7430 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7431 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7432 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7433 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7434 }
7435 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7436 Intent intent = new Intent();
7437 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7438 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7439 // Bring up choose default SMS subscription dialog right now
7440 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7441 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7442 mApp.startActivity(intent);
7443 }
chen xud5ca2d52019-05-28 15:20:57 -07007444
7445 @Override
7446 public String getMmsUAProfUrl(int subId) {
7447 //TODO investigate if this API should require proper permission check in R b/133791609
7448 final long identity = Binder.clearCallingIdentity();
7449 try {
7450 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7451 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7452 } finally {
7453 Binder.restoreCallingIdentity(identity);
7454 }
7455 }
7456
7457 @Override
7458 public String getMmsUserAgent(int subId) {
7459 //TODO investigate if this API should require proper permission check in R b/133791609
7460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7463 .getString(com.android.internal.R.string.config_mms_user_agent);
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
7467 }
Jack Yub07d4972019-05-28 16:12:25 -07007468
7469 @Override
7470 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7471 enforceModifyPermission();
7472
7473 // Now that all security checks passes, perform the operation as ourselves.
7474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 Phone phone = getPhone(subId);
7477 if (phone == null) return false;
7478
7479 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7480 } finally {
7481 Binder.restoreCallingIdentity(identity);
7482 }
7483 }
7484
7485 @Override
7486 public boolean isDataAllowedInVoiceCall(int subId) {
7487 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7488
7489 // Now that all security checks passes, perform the operation as ourselves.
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 Phone phone = getPhone(subId);
7493 if (phone == null) return false;
7494
7495 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7496 } finally {
7497 Binder.restoreCallingIdentity(identity);
7498 }
7499 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007500
7501 /**
7502 * Updates whether conference event pacakge handling is enabled.
7503 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7504 * otherwise.
7505 */
7506 @Override
7507 public void setCepEnabled(boolean isCepEnabled) {
7508 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7513 for (Phone phone : PhoneFactory.getPhones()) {
7514 Phone defaultPhone = phone.getImsPhone();
7515 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7516 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7517 ImsPhoneCallTracker imsPhoneCallTracker =
7518 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7519 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7520 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7521 + imsPhone.getMsisdn());
7522 }
7523 }
7524 } finally {
7525 Binder.restoreCallingIdentity(identity);
7526 }
7527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007528}