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