blob: 238e853ac322b0660f1776eab50d8df16d1078d0 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100135import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700272 /** The singleton instance. */
273 private static PhoneInterfaceManager sInstance;
274
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700277 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private AppOpsManager mAppOps;
279 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800280 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700282 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700283
Derek Tan97ebb422014-09-05 16:55:38 -0700284 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
285 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800286 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800287 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700288
Michelecea4cf22018-12-21 15:00:11 -0800289 // String to store multi SIM allowed
290 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
291
Derek Tan740e1672017-06-27 14:56:27 -0700292 // The AID of ISD-R.
293 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
294
yinxub1bed742017-04-17 11:45:04 -0700295 private NetworkScanRequestTracker mNetworkScanRequestTracker;
296
David Kelly5e06a7f2018-03-12 14:10:59 +0000297 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
298 private static final int MANUFACTURER_CODE_LENGTH = 8;
299
Derek Tan89e89d42014-07-08 17:00:10 -0700300 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700301 * A request object to use for transmitting data to an ICC.
302 */
303 private static final class IccAPDUArgument {
304 public int channel, cla, command, p1, p2, p3;
305 public String data;
306
307 public IccAPDUArgument(int channel, int cla, int command,
308 int p1, int p2, int p3, String data) {
309 this.channel = channel;
310 this.cla = cla;
311 this.command = command;
312 this.p1 = p1;
313 this.p2 = p2;
314 this.p3 = p3;
315 this.data = data;
316 }
317 }
318
319 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700320 * A request object to use for transmitting data to an ICC.
321 */
322 private static final class ManualNetworkSelectionArgument {
323 public OperatorInfo operatorInfo;
324 public boolean persistSelection;
325
326 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
327 this.operatorInfo = operatorInfo;
328 this.persistSelection = persistSelection;
329 }
330 }
331
332 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
334 * request after sending. The main thread will notify the request when it is complete.
335 */
336 private static final class MainThreadRequest {
337 /** The argument to use for the request */
338 public Object argument;
339 /** The result of the request that is run on the main thread */
340 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800341 // The subscriber id that this request applies to. Defaults to
342 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
343 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Nathan Harold92bed182018-10-12 18:16:49 -0700345 // In cases where subId is unavailable, the caller needs to specify the phone.
346 public Phone phone;
347
vagdeviaf9a5b92018-08-15 16:01:53 -0700348 public WorkSource workSource;
349
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700350 public MainThreadRequest(Object argument) {
351 this.argument = argument;
352 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
355 this.argument = argument;
356 if (phone != null) {
357 this.phone = phone;
358 }
359 this.workSource = workSource;
360 }
361
vagdeviaf9a5b92018-08-15 16:01:53 -0700362 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800364 if (subId != null) {
365 this.subId = subId;
366 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700367 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 }
370
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800371 private static final class IncomingThirdPartyCallArgs {
372 public final ComponentName component;
373 public final String callId;
374 public final String callerDisplayName;
375
376 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
377 String callerDisplayName) {
378 this.component = component;
379 this.callId = callId;
380 this.callerDisplayName = callerDisplayName;
381 }
382 }
383
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384 /**
385 * A handler that processes messages on the main thread in the phone process. Since many
386 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
387 * inbound binder threads to the main thread in the phone process. The Binder thread
388 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
389 * on, which will be notified when the operation completes and will contain the result of the
390 * request.
391 *
392 * <p>If a MainThreadRequest object is provided in the msg.obj field,
393 * note that request.result must be set to something non-null for the calling thread to
394 * unblock.
395 */
396 private final class MainThreadHandler extends Handler {
397 @Override
398 public void handleMessage(Message msg) {
399 MainThreadRequest request;
400 Message onCompleted;
401 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800402 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700403 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800404 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405
406 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700407 case CMD_HANDLE_USSD_REQUEST: {
408 request = (MainThreadRequest) msg.obj;
409 final Phone phone = getPhoneFromRequest(request);
410 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
411 String ussdRequest = ussdObject.first;
412 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700413
Pengquan Menga1bb6272018-09-06 09:59:22 -0700414 if (!isUssdApiAllowed(request.subId)) {
415 // Carrier does not support use of this API, return failure.
416 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
417 UssdResponse response = new UssdResponse(ussdRequest, null);
418 Bundle returnData = new Bundle();
419 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
420 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700421
Pengquan Menga1bb6272018-09-06 09:59:22 -0700422 request.result = true;
423 notifyRequester(request);
424 return;
425 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700426
Pengquan Menga1bb6272018-09-06 09:59:22 -0700427 try {
428 request.result = phone != null
429 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
430 } catch (CallStateException cse) {
431 request.result = false;
432 }
433 // Wake up the requesting thread
434 notifyRequester(request);
435 break;
pkanwar32d516d2016-10-14 19:37:38 -0700436 }
437
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700439 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700440 final Phone phone = getPhoneFromRequest(request);
441 request.result = phone != null ?
442 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
443 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800452 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700453 if (uiccCard == null) {
454 loge("iccTransmitApduLogicalChannel: No UICC");
455 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700456 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
459 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700460 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument.channel, iccArgument.cla, iccArgument.command,
462 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 break;
466
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 ar = (AsyncResult) msg.obj;
469 request = (MainThreadRequest) ar.userObj;
470 if (ar.exception == null && ar.result != null) {
471 request.result = ar.result;
472 } else {
473 request.result = new IccIoResult(0x6F, 0, (byte[])null);
474 if (ar.result == null) {
475 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800476 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800478 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 } else {
480 loge("iccTransmitApduLogicalChannel: Unknown exception");
481 }
482 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 break;
485
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700486 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
487 request = (MainThreadRequest) msg.obj;
488 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800489 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 if (uiccCard == null) {
491 loge("iccTransmitApduBasicChannel: No UICC");
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 } else {
495 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
496 request);
497 uiccCard.iccTransmitApduBasicChannel(
498 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
499 iccArgument.p3, iccArgument.data, onCompleted);
500 }
501 break;
502
503 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("iccTransmitApduBasicChannel: Empty response");
512 } else if (ar.exception instanceof CommandException) {
513 loge("iccTransmitApduBasicChannel: CommandException: " +
514 ar.exception);
515 } else {
516 loge("iccTransmitApduBasicChannel: Unknown exception");
517 }
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 break;
521
522 case CMD_EXCHANGE_SIM_IO:
523 request = (MainThreadRequest) msg.obj;
524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 if (uiccCard == null) {
527 loge("iccExchangeSimIO: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
532 request);
533 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
534 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
535 iccArgument.data, onCompleted);
536 }
537 break;
538
539 case EVENT_EXCHANGE_SIM_IO_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6f, 0, (byte[])null);
546 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700547 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700548 break;
549
Derek Tan4d5e5c12014-02-04 11:54:58 -0800550 case CMD_SEND_ENVELOPE:
551 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800552 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700553 if (uiccCard == null) {
554 loge("sendEnvelopeWithStatus: No UICC");
555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 } else {
558 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
559 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 break;
562
563 case EVENT_SEND_ENVELOPE_DONE:
564 ar = (AsyncResult) msg.obj;
565 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 if (ar.exception == null && ar.result != null) {
567 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
570 if (ar.result == null) {
571 loge("sendEnvelopeWithStatus: Empty response");
572 } else if (ar.exception instanceof CommandException) {
573 loge("sendEnvelopeWithStatus: CommandException: " +
574 ar.exception);
575 } else {
576 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
577 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800580 break;
581
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 case CMD_OPEN_CHANNEL:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800585 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 if (uiccCard == null) {
587 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800588 request.result = new IccOpenLogicalChannelResponse(-1,
589 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700590 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 } else {
592 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800593 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
594 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700596 break;
597
598 case EVENT_OPEN_CHANNEL_DONE:
599 ar = (AsyncResult) msg.obj;
600 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 int[] result = (int[]) ar.result;
604 int channelId = result[0];
605 byte[] selectResponse = null;
606 if (result.length > 1) {
607 selectResponse = new byte[result.length - 1];
608 for (int i = 1; i < result.length; ++i) {
609 selectResponse[i - 1] = (byte) result[i];
610 }
611 }
612 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 if (ar.result == null) {
616 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 if (ar.exception != null) {
619 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
620 }
621
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700623 if (ar.exception instanceof CommandException) {
624 CommandException.Error error =
625 ((CommandException) (ar.exception)).getCommandError();
626 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700628 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700630 }
631 }
632 openChannelResp = new IccOpenLogicalChannelResponse(
633 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700635 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700636 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case CMD_CLOSE_CHANNEL:
640 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800641 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700642 if (uiccCard == null) {
643 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900644 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 } else {
647 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
648 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
649 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 break;
651
652 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800653 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
654 break;
655
656 case CMD_NV_READ_ITEM:
657 request = (MainThreadRequest) msg.obj;
658 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800659 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
660 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800661 break;
662
663 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800666 if (ar.exception == null && ar.result != null) {
667 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800669 request.result = "";
670 if (ar.result == null) {
671 loge("nvReadItem: Empty response");
672 } else if (ar.exception instanceof CommandException) {
673 loge("nvReadItem: CommandException: " +
674 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800676 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 }
678 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700679 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 break;
681
Jake Hambye994d462014-02-03 13:10:13 -0800682 case CMD_NV_WRITE_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
685 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800686 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700687 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800688 break;
689
690 case EVENT_NV_WRITE_ITEM_DONE:
691 handleNullReturnEvent(msg, "nvWriteItem");
692 break;
693
694 case CMD_NV_WRITE_CDMA_PRL:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_CDMA_PRL_DONE:
701 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
702 break;
703
chen xu6dac5ab2018-10-26 17:39:23 -0700704 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800705 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700706 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
chen xu6dac5ab2018-10-26 17:39:23 -0700710 case EVENT_RESET_MODEM_CONFIG_DONE:
711 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
Jake Hamby7c27be32014-03-03 13:25:59 -0800714 case CMD_GET_PREFERRED_NETWORK_TYPE:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700717 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 break;
719
720 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
721 ar = (AsyncResult) msg.obj;
722 request = (MainThreadRequest) ar.userObj;
723 if (ar.exception == null && ar.result != null) {
724 request.result = ar.result; // Integer
725 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800726 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 if (ar.result == null) {
728 loge("getPreferredNetworkType: Empty response");
729 } else if (ar.exception instanceof CommandException) {
730 loge("getPreferredNetworkType: CommandException: " +
731 ar.exception);
732 } else {
733 loge("getPreferredNetworkType: Unknown exception");
734 }
735 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700736 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 break;
738
739 case CMD_SET_PREFERRED_NETWORK_TYPE:
740 request = (MainThreadRequest) msg.obj;
741 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
742 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
747 handleNullReturnEvent(msg, "setPreferredNetworkType");
748 break;
749
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000750 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
751 request = (MainThreadRequest)msg.obj;
752 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800753 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 break;
755
756 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
757 ar = (AsyncResult)msg.obj;
758 request = (MainThreadRequest)ar.userObj;
759 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700760 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000761 break;
762
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800763 case CMD_SET_VOICEMAIL_NUMBER:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
766 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800767 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
768 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800769 break;
770
771 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
772 handleNullReturnEvent(msg, "setVoicemailNumber");
773 break;
774
Stuart Scott54788802015-03-30 13:18:01 -0700775 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
776 request = (MainThreadRequest) msg.obj;
777 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
778 request);
779 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
780 break;
781
782 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
783 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
784 break;
785
Shishir Agrawal302c8692015-06-19 13:49:39 -0700786 case CMD_PERFORM_NETWORK_SCAN:
787 request = (MainThreadRequest) msg.obj;
788 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
789 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
790 break;
791
792 case EVENT_PERFORM_NETWORK_SCAN_DONE:
793 ar = (AsyncResult) msg.obj;
794 request = (MainThreadRequest) ar.userObj;
795 CellNetworkScanResult cellScanResult;
796 if (ar.exception == null && ar.result != null) {
797 cellScanResult = new CellNetworkScanResult(
798 CellNetworkScanResult.STATUS_SUCCESS,
799 (List<OperatorInfo>) ar.result);
800 } else {
801 if (ar.result == null) {
802 loge("getCellNetworkScanResults: Empty response");
803 }
804 if (ar.exception != null) {
805 loge("getCellNetworkScanResults: Exception: " + ar.exception);
806 }
807 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
808 if (ar.exception instanceof CommandException) {
809 CommandException.Error error =
810 ((CommandException) (ar.exception)).getCommandError();
811 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
813 } else if (error == CommandException.Error.GENERIC_FAILURE) {
814 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
815 }
816 }
817 cellScanResult = new CellNetworkScanResult(errorCode, null);
818 }
819 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700820 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 break;
822
823 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
824 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700825 ManualNetworkSelectionArgument selArg =
826 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
828 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
830 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700834 ar = (AsyncResult) msg.obj;
835 request = (MainThreadRequest) ar.userObj;
836 if (ar.exception == null) {
837 request.result = true;
838 } else {
839 request.result = false;
840 loge("setNetworkSelectionModeManual " + ar.exception);
841 }
842 notifyRequester(request);
843 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700844 break;
845
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700846 case CMD_GET_MODEM_ACTIVITY_INFO:
847 request = (MainThreadRequest) msg.obj;
848 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700849 if (defaultPhone != null) {
850 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
851 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700852 break;
853
854 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
855 ar = (AsyncResult) msg.obj;
856 request = (MainThreadRequest) ar.userObj;
857 if (ar.exception == null && ar.result != null) {
858 request.result = ar.result;
859 } else {
860 if (ar.result == null) {
861 loge("queryModemActivityInfo: Empty response");
862 } else if (ar.exception instanceof CommandException) {
863 loge("queryModemActivityInfo: CommandException: " +
864 ar.exception);
865 } else {
866 loge("queryModemActivityInfo: Unknown exception");
867 }
868 }
Amit Mahajand4766222016-01-28 15:28:28 -0800869 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
870 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700871 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800872 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700873 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700874 break;
875
Meng Wang1a7c35a2016-05-05 20:56:15 -0700876 case CMD_SET_ALLOWED_CARRIERS:
877 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800878 CarrierRestrictionRules argument =
879 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800881 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 break;
883
884 case EVENT_SET_ALLOWED_CARRIERS_DONE:
885 ar = (AsyncResult) msg.obj;
886 request = (MainThreadRequest) ar.userObj;
887 if (ar.exception == null && ar.result != null) {
888 request.result = ar.result;
889 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800890 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
891 if (ar.exception instanceof CommandException) {
892 loge("setAllowedCarriers: CommandException: " + ar.exception);
893 CommandException.Error error =
894 ((CommandException) (ar.exception)).getCommandError();
895 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
896 request.result =
897 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
898 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700899 } else {
900 loge("setAllowedCarriers: Unknown exception");
901 }
902 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700903 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 break;
905
906 case CMD_GET_ALLOWED_CARRIERS:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800909 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700910 break;
911
912 case EVENT_GET_ALLOWED_CARRIERS_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 if (ar.exception == null && ar.result != null) {
916 request.result = ar.result;
917 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800918 request.result = new IllegalStateException(
919 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 if (ar.result == null) {
921 loge("getAllowedCarriers: Empty response");
922 } else if (ar.exception instanceof CommandException) {
923 loge("getAllowedCarriers: CommandException: " +
924 ar.exception);
925 } else {
926 loge("getAllowedCarriers: Unknown exception");
927 }
928 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 break;
931
Nathan Haroldb3014052017-01-25 15:57:32 -0800932 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
933 ar = (AsyncResult) msg.obj;
934 request = (MainThreadRequest) ar.userObj;
935 if (ar.exception == null && ar.result != null) {
936 request.result = ar.result;
937 } else {
938 request.result = new IllegalArgumentException(
939 "Failed to retrieve Forbidden Plmns");
940 if (ar.result == null) {
941 loge("getForbiddenPlmns: Empty response");
942 } else {
943 loge("getForbiddenPlmns: Unknown exception");
944 }
945 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948
949 case CMD_GET_FORBIDDEN_PLMNS:
950 request = (MainThreadRequest) msg.obj;
951 uiccCard = getUiccCardFromRequest(request);
952 if (uiccCard == null) {
953 loge("getForbiddenPlmns() UiccCard is null");
954 request.result = new IllegalArgumentException(
955 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958 }
959 Integer appType = (Integer) request.argument;
960 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
961 if (uiccApp == null) {
962 loge("getForbiddenPlmns() no app with specified type -- "
963 + appType);
964 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 } else {
968 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
969 + " specified type -- " + appType);
970 }
971 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
972 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
973 onCompleted);
974 break;
975
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000976 case CMD_SWITCH_SLOTS:
977 request = (MainThreadRequest) msg.obj;
978 int[] physicalSlots = (int[]) request.argument;
979 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
980 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
981 break;
982
983 case EVENT_SWITCH_SLOTS_DONE:
984 ar = (AsyncResult) msg.obj;
985 request = (MainThreadRequest) ar.userObj;
986 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700987 notifyRequester(request);
988 break;
989 case CMD_GET_NETWORK_SELECTION_MODE:
990 request = (MainThreadRequest) msg.obj;
991 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
992 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
993 break;
994
995 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
996 ar = (AsyncResult) msg.obj;
997 request = (MainThreadRequest) ar.userObj;
998 if (ar.exception != null) {
999 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1000 } else {
1001 int mode = ((int[]) ar.result)[0];
1002 if (mode == 0) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1004 } else {
1005 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1006 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001007 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001008 notifyRequester(request);
1009 break;
1010 case CMD_GET_CDMA_ROAMING_MODE:
1011 request = (MainThreadRequest) msg.obj;
1012 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1013 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1014 break;
1015 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception != null) {
1019 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1020 } else {
1021 request.result = ((int[]) ar.result)[0];
1022 }
1023 notifyRequester(request);
1024 break;
1025 case CMD_SET_CDMA_ROAMING_MODE:
1026 request = (MainThreadRequest) msg.obj;
1027 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1028 int mode = (int) request.argument;
1029 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1030 break;
1031 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 request.result = ar.exception == null;
1035 notifyRequester(request);
1036 break;
1037 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1038 request = (MainThreadRequest) msg.obj;
1039 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1040 int subscriptionMode = (int) request.argument;
1041 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1042 break;
1043 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
1046 request.result = ar.exception == null;
1047 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001048 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 case CMD_GET_ALL_CELL_INFO:
1050 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001052 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001054 case EVENT_GET_ALL_CELL_INFO_DONE:
1055 ar = (AsyncResult) msg.obj;
1056 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001057 // If a timeout occurs, the response will be null
1058 request.result = (ar.exception == null && ar.result != null)
1059 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 synchronized (request) {
1061 request.notifyAll();
1062 }
1063 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 case CMD_REQUEST_CELL_INFO_UPDATE:
1065 request = (MainThreadRequest) msg.obj;
1066 request.phone.requestCellInfoUpdate(request.workSource,
1067 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1068 break;
1069 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
1072 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1073 try {
1074 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001076 cb.onError(
1077 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1078 ar.exception.getClass().getName(),
1079 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001082 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 } else {
1084 // use the result as returned
1085 cb.onCellInfo((List<CellInfo>) ar.result);
1086 }
1087 } catch (RemoteException re) {
1088 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1089 }
1090 break;
1091 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001092 request = (MainThreadRequest) msg.obj;
1093 WorkSource ws = (WorkSource) request.argument;
1094 Phone phone = getPhoneFromRequest(request);
1095 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1096 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001098 ar = (AsyncResult) msg.obj;
1099 request = (MainThreadRequest) ar.userObj;
1100 if (ar.exception == null) {
1101 request.result = ar.result;
1102 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001103 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001104 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1105 ? new CdmaCellLocation() : new GsmCellLocation();
1106 }
1107
1108 synchronized (request) {
1109 request.notifyAll();
1110 }
1111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case CMD_MODEM_REBOOT:
1113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001115 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001116 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001117 case EVENT_CMD_MODEM_REBOOT_DONE:
1118 handleNullReturnEvent(msg, "rebootModem");
1119 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 case CMD_REQUEST_ENABLE_MODEM:
1121 request = (MainThreadRequest) msg.obj;
1122 boolean enable = (boolean) request.argument;
1123 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001124 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001125 PhoneConfigurationManager.getInstance()
1126 .enablePhone(request.phone, enable, onCompleted);
1127 break;
1128 case EVENT_ENABLE_MODEM_DONE:
1129 ar = (AsyncResult) msg.obj;
1130 request = (MainThreadRequest) ar.userObj;
1131 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001132 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001134 if ((boolean) request.result) {
1135 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1136 updateModemStateMetrics();
1137 } else {
1138 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1139 + ar.exception);
1140 }
1141 notifyRequester(request);
1142 break;
1143 case CMD_GET_MODEM_STATUS:
1144 request = (MainThreadRequest) msg.obj;
1145 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1146 PhoneConfigurationManager.getInstance()
1147 .getPhoneStatusFromModem(request.phone, onCompleted);
1148 break;
1149 case EVENT_GET_MODEM_STATUS_DONE:
1150 ar = (AsyncResult) msg.obj;
1151 request = (MainThreadRequest) ar.userObj;
1152 int id = request.phone.getPhoneId();
1153 if (ar.exception == null && ar.result != null) {
1154 request.result = ar.result;
1155 //update the cache as modem status has changed
1156 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1157 (boolean) request.result);
1158 } else {
1159 // Return true if modem status cannot be retrieved. For most cases,
1160 // modem status is on. And for older version modems, GET_MODEM_STATUS
1161 // and disable modem are not supported. Modem is always on.
1162 // TODO: this should be fixed in R to support a third
1163 // status UNKNOWN b/131631629
1164 request.result = true;
1165 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1166 + ar.exception);
1167 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001168 notifyRequester(request);
1169 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001170 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null && ar.result != null) {
1174 request.result = ar.result;
1175 } else {
1176 request.result = -1;
1177 loge("Failed to set Forbidden Plmns");
1178 if (ar.result == null) {
1179 loge("setForbidenPlmns: Empty response");
1180 } else if (ar.exception != null) {
1181 loge("setForbiddenPlmns: Exception: " + ar.exception);
1182 request.result = -1;
1183 } else {
1184 loge("setForbiddenPlmns: Unknown exception");
1185 }
1186 }
1187 notifyRequester(request);
1188 break;
1189 case CMD_SET_FORBIDDEN_PLMNS:
1190 request = (MainThreadRequest) msg.obj;
1191 uiccCard = getUiccCardFromRequest(request);
1192 if (uiccCard == null) {
1193 loge("setForbiddenPlmns: UiccCard is null");
1194 request.result = -1;
1195 notifyRequester(request);
1196 break;
1197 }
1198 Pair<Integer, List<String>> setFplmnsArgs =
1199 (Pair<Integer, List<String>>) request.argument;
1200 appType = setFplmnsArgs.first;
1201 List<String> fplmns = setFplmnsArgs.second;
1202 uiccApp = uiccCard.getApplicationByType(appType);
1203 if (uiccApp == null) {
1204 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1205 request.result = -1;
1206 loge("Failed to get UICC App");
1207 notifyRequester(request);
1208 } else {
1209 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1210 ((SIMRecords) uiccApp.getIccRecords())
1211 .setForbiddenPlmns(onCompleted, fplmns);
1212 }
1213 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 default:
1215 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1216 break;
1217 }
1218 }
Jake Hambye994d462014-02-03 13:10:13 -08001219
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 private void notifyRequester(MainThreadRequest request) {
1221 synchronized (request) {
1222 request.notifyAll();
1223 }
1224 }
1225
Jake Hambye994d462014-02-03 13:10:13 -08001226 private void handleNullReturnEvent(Message msg, String command) {
1227 AsyncResult ar = (AsyncResult) msg.obj;
1228 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1229 if (ar.exception == null) {
1230 request.result = true;
1231 } else {
1232 request.result = false;
1233 if (ar.exception instanceof CommandException) {
1234 loge(command + ": CommandException: " + ar.exception);
1235 } else {
1236 loge(command + ": Unknown exception");
1237 }
1238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001239 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001240 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001249 return sendRequest(
1250 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001251 }
1252
1253 /**
1254 * Posts the specified command to be executed on the main thread,
1255 * waits for the request to complete, and returns the result.
1256 * @see #sendRequestAsync
1257 */
1258 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1259 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001260 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001261 }
1262
1263 /**
1264 * Posts the specified command to be executed on the main thread,
1265 * waits for the request to complete, and returns the result.
1266 * @see #sendRequestAsync
1267 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001268 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001269 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001270 }
1271
1272 /**
1273 * Posts the specified command to be executed on the main thread,
1274 * waits for the request to complete, and returns the result.
1275 * @see #sendRequestAsync
1276 */
Nathan Harold92bed182018-10-12 18:16:49 -07001277 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1278 return sendRequest(command, argument, subId, null, workSource);
1279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
1286 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1287 return sendRequest(
1288 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1289 }
1290
1291 /**
1292 * Posts the specified command to be executed on the main thread,
1293 * waits for the request to complete, and returns the result.
1294 * @see #sendRequestAsync
1295 */
1296 private Object sendRequest(
1297 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1299 throw new RuntimeException("This method will deadlock if called from the main thread.");
1300 }
1301
Nathan Harold92bed182018-10-12 18:16:49 -07001302 MainThreadRequest request = null;
1303 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1304 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1305 } else if (phone != null) {
1306 request = new MainThreadRequest(argument, phone, workSource);
1307 } else {
1308 request = new MainThreadRequest(argument, subId, workSource);
1309 }
1310
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001311 Message msg = mMainThreadHandler.obtainMessage(command, request);
1312 msg.sendToTarget();
1313
1314 // Wait for the request to complete
1315 synchronized (request) {
1316 while (request.result == null) {
1317 try {
1318 request.wait();
1319 } catch (InterruptedException e) {
1320 // Do nothing, go back and wait until the request is complete
1321 }
1322 }
1323 }
1324 return request.result;
1325 }
1326
1327 /**
1328 * Asynchronous ("fire and forget") version of sendRequest():
1329 * Posts the specified command to be executed on the main thread, and
1330 * returns immediately.
1331 * @see #sendRequest
1332 */
1333 private void sendRequestAsync(int command) {
1334 mMainThreadHandler.sendEmptyMessage(command);
1335 }
1336
1337 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001338 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001339 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001340 */
1341 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001342 sendRequestAsync(command, argument, null, null);
1343 }
1344
1345 /**
1346 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1347 * @see {@link #sendRequest(int,Object)}
1348 */
1349 private void sendRequestAsync(
1350 int command, Object argument, Phone phone, WorkSource workSource) {
1351 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001352 Message msg = mMainThreadHandler.obtainMessage(command, request);
1353 msg.sendToTarget();
1354 }
1355
1356 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001357 * Initialize the singleton PhoneInterfaceManager instance.
1358 * This is only done once, at startup, from PhoneApp.onCreate().
1359 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001360 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 synchronized (PhoneInterfaceManager.class) {
1362 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001363 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 } else {
1365 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1366 }
1367 return sInstance;
1368 }
1369 }
1370
1371 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001372 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001375 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1377 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001378 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001379 mTelephonySharedPreferences =
1380 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001381 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001382 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001383
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001384 publish();
1385 }
1386
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001387 private Phone getDefaultPhone() {
1388 Phone thePhone = getPhone(getDefaultSubscription());
1389 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1390 }
1391
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 private void publish() {
1393 if (DBG) log("publish: " + this);
1394
1395 ServiceManager.addService("phone", this);
1396 }
1397
Stuart Scott584921c2015-01-15 17:10:34 -08001398 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001399 if (request.phone != null) {
1400 return request.phone;
1401 } else {
1402 return getPhoneFromSubId(request.subId);
1403 }
1404 }
1405
1406 private Phone getPhoneFromSubId(int subId) {
1407 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1408 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001409 }
1410
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001411 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1412 Phone phone = getPhoneFromRequest(request);
1413 return phone == null ? null :
1414 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1415 }
1416
Wink Saville36469e72014-06-11 15:17:00 -07001417 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001418 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001419 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001420 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001421
1422 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001423 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
1425
Wink Savilleb564aae2014-10-23 10:18:09 -07001426 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 if (DBG) log("dial: " + number);
1428 // No permission check needed here: This is just a wrapper around the
1429 // ACTION_DIAL intent, which is available to any app since it puts up
1430 // the UI before it does anything.
1431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 String url = createTelUrl(number);
1435 if (url == null) {
1436 return;
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001439 // PENDING: should we just silently fail if phone is offhook or ringing?
1440 PhoneConstants.State state = mCM.getState(subId);
1441 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1442 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 }
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449 }
1450
1451 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Wink Savilleb564aae2014-10-23 10:18:09 -07001455 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 if (DBG) log("call: " + number);
1457
1458 // This is just a wrapper around the ACTION_CALL intent, but we still
1459 // need to do a permission check since we're calling startActivity()
1460 // from the context of the phone app.
1461 enforceCallPermission();
1462
Jordan Liu1617b712019-07-10 15:06:26 -07001463 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001464 != AppOpsManager.MODE_ALLOWED) {
1465 return;
1466 }
1467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001468 final long identity = Binder.clearCallingIdentity();
1469 try {
1470 String url = createTelUrl(number);
1471 if (url == null) {
1472 return;
1473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475 boolean isValid = false;
1476 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1477 if (slist != null) {
1478 for (SubscriptionInfo subInfoRecord : slist) {
1479 if (subInfoRecord.getSubscriptionId() == subId) {
1480 isValid = true;
1481 break;
1482 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001483 }
Wink Saville08874612014-08-31 19:19:58 -07001484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001485 if (!isValid) {
1486 return;
1487 }
Wink Saville08874612014-08-31 19:19:58 -07001488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1490 intent.putExtra(SUBSCRIPTION_KEY, subId);
1491 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1492 mApp.startActivity(intent);
1493 } finally {
1494 Binder.restoreCallingIdentity(identity);
1495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 }
1497
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001499 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001500 }
1501
Wink Savilleb564aae2014-10-23 10:18:09 -07001502 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001504 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1505 }
1506
1507 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001508 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001509 }
1510
Wink Savilleb564aae2014-10-23 10:18:09 -07001511 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001513 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1514 }
1515
1516 /** {@hide} */
1517 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001518 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001519 }
1520
Wink Savilleb564aae2014-10-23 10:18:09 -07001521 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001523
1524 final long identity = Binder.clearCallingIdentity();
1525 try {
1526 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1527 checkSimPin.start();
1528 return checkSimPin.unlockSim(null, pin);
1529 } finally {
1530 Binder.restoreCallingIdentity(identity);
1531 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001532 }
1533
Wink Saville9de0f752013-10-22 19:04:03 -07001534 /** {@hide} */
1535 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001537 }
1538
Wink Savilleb564aae2014-10-23 10:18:09 -07001539 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001540 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001541
1542 final long identity = Binder.clearCallingIdentity();
1543 try {
1544 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1545 checkSimPuk.start();
1546 return checkSimPuk.unlockSim(puk, pin);
1547 } finally {
1548 Binder.restoreCallingIdentity(identity);
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 }
1551
1552 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001553 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 * a synchronous one.
1555 */
1556 private static class UnlockSim extends Thread {
1557
1558 private final IccCard mSimCard;
1559
1560 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001561 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1562 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563
1564 // For replies from SimCard interface
1565 private Handler mHandler;
1566
1567 // For async handler to identify request type
1568 private static final int SUPPLY_PIN_COMPLETE = 100;
1569
1570 public UnlockSim(IccCard simCard) {
1571 mSimCard = simCard;
1572 }
1573
1574 @Override
1575 public void run() {
1576 Looper.prepare();
1577 synchronized (UnlockSim.this) {
1578 mHandler = new Handler() {
1579 @Override
1580 public void handleMessage(Message msg) {
1581 AsyncResult ar = (AsyncResult) msg.obj;
1582 switch (msg.what) {
1583 case SUPPLY_PIN_COMPLETE:
1584 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1585 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001586 mRetryCount = msg.arg1;
1587 if (ar.exception != null) {
1588 if (ar.exception instanceof CommandException &&
1589 ((CommandException)(ar.exception)).getCommandError()
1590 == CommandException.Error.PASSWORD_INCORRECT) {
1591 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1592 } else {
1593 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 }
1595 } else {
1596 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 mDone = true;
1599 UnlockSim.this.notifyAll();
1600 }
1601 break;
1602 }
1603 }
1604 };
1605 UnlockSim.this.notifyAll();
1606 }
1607 Looper.loop();
1608 }
1609
1610 /*
1611 * Use PIN or PUK to unlock SIM card
1612 *
1613 * If PUK is null, unlock SIM card with PIN
1614 *
1615 * If PUK is not null, unlock SIM card with PUK and set PIN code
1616 */
Wink Saville9de0f752013-10-22 19:04:03 -07001617 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618
1619 while (mHandler == null) {
1620 try {
1621 wait();
1622 } catch (InterruptedException e) {
1623 Thread.currentThread().interrupt();
1624 }
1625 }
1626 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1627
1628 if (puk == null) {
1629 mSimCard.supplyPin(pin, callback);
1630 } else {
1631 mSimCard.supplyPuk(puk, pin, callback);
1632 }
1633
1634 while (!mDone) {
1635 try {
1636 Log.d(LOG_TAG, "wait for done");
1637 wait();
1638 } catch (InterruptedException e) {
1639 // Restore the interrupted status
1640 Thread.currentThread().interrupt();
1641 }
1642 }
1643 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001644 int[] resultArray = new int[2];
1645 resultArray[0] = mResult;
1646 resultArray[1] = mRetryCount;
1647 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 }
1649 }
1650
1651 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001652 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001653
1654 }
1655
Wink Savilleb564aae2014-10-23 10:18:09 -07001656 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 // No permission check needed here: this call is harmless, and it's
1658 // needed for the ServiceState.requestStateUpdate() call (which is
1659 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 final Phone phone = getPhone(subId);
1663 if (phone != null) {
1664 phone.updateServiceLocation();
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 }
1670
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001671 @Override
1672 public boolean isRadioOn(String callingPackage) {
1673 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
1675
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001676 @Override
1677 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001679 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 return false;
1681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001682
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 return isRadioOnForSubscriber(subId);
1686 } finally {
1687 Binder.restoreCallingIdentity(identity);
1688 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001689 }
1690
1691 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1697 } else {
1698 return false;
1699 }
1700 } finally {
1701 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001702 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001703 }
1704
1705 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001706 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
Wink Saville36469e72014-06-11 15:17:00 -07001708
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1717 }
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001720 }
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
1723 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001724 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
Wink Savilleb564aae2014-10-23 10:18:09 -07001727 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001728 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 final Phone phone = getPhone(subId);
1733 if (phone == null) {
1734 return false;
1735 }
1736 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1737 toggleRadioOnOffForSubscriber(subId);
1738 }
1739 return true;
1740 } finally {
1741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001743 }
Wink Saville36469e72014-06-11 15:17:00 -07001744
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001745 public boolean needMobileRadioShutdown() {
1746 /*
1747 * If any of the Radios are available, it will need to be
1748 * shutdown. So return true if any Radio is available.
1749 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750 final long identity = Binder.clearCallingIdentity();
1751 try {
1752 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1753 Phone phone = PhoneFactory.getPhone(i);
1754 if (phone != null && phone.isRadioAvailable()) return true;
1755 }
1756 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1757 return false;
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001760 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001761 }
1762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001763 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 enforceModifyPermission();
1766
1767 final long identity = Binder.clearCallingIdentity();
1768 try {
1769 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1770 logv("Shutting down Phone " + i);
1771 shutdownRadioUsingPhoneId(i);
1772 }
1773 } finally {
1774 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001775 }
1776 }
1777
1778 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 Phone phone = PhoneFactory.getPhone(phoneId);
1780 if (phone != null && phone.isRadioAvailable()) {
1781 phone.shutdownRadio();
1782 }
1783 }
1784
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001785 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001786 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1791 if (defaultPhone != null) {
1792 defaultPhone.setRadioPower(turnOn);
1793 return true;
1794 } else {
1795 loge("There's no default phone.");
1796 return false;
1797 }
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001800 }
Wink Saville36469e72014-06-11 15:17:00 -07001801 }
1802
Wink Savilleb564aae2014-10-23 10:18:09 -07001803 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001805
1806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 final Phone phone = getPhone(subId);
1809 if (phone != null) {
1810 phone.setRadioPower(turnOn);
1811 return true;
1812 } else {
1813 return false;
1814 }
1815 } finally {
1816 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 }
1819
Wink Saville36469e72014-06-11 15:17:00 -07001820 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 public boolean enableDataConnectivity() {
1823 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001824
1825 final long identity = Binder.clearCallingIdentity();
1826 try {
1827 int subId = mSubscriptionController.getDefaultDataSubId();
1828 final Phone phone = getPhone(subId);
1829 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001830 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 return true;
1832 } else {
1833 return false;
1834 }
1835 } finally {
1836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838 }
1839
Wink Saville36469e72014-06-11 15:17:00 -07001840 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 public boolean disableDataConnectivity() {
1843 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001844
1845 final long identity = Binder.clearCallingIdentity();
1846 try {
1847 int subId = mSubscriptionController.getDefaultDataSubId();
1848 final Phone phone = getPhone(subId);
1849 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001850 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851 return true;
1852 } else {
1853 return false;
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001861 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001862 final long identity = Binder.clearCallingIdentity();
1863 try {
1864 final Phone phone = getPhone(subId);
1865 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001866 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001867 } else {
1868 return false;
1869 }
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
1875 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001876 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001877 }
1878
pkanwarae03a6b2016-11-06 20:37:09 -08001879 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 enforceCallPermission();
1881
1882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1885 return;
1886 }
1887 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1888 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1889 } finally {
1890 Binder.restoreCallingIdentity(identity);
1891 }
pkanwar32d516d2016-10-14 19:37:38 -07001892 };
1893
Wink Savilleb564aae2014-10-23 10:18:09 -07001894 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001896
1897 final long identity = Binder.clearCallingIdentity();
1898 try {
1899 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1900 return false;
1901 }
1902 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001908 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001909 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001910 }
1911
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001912 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001913 final long identity = Binder.clearCallingIdentity();
1914 try {
1915 Phone phone = PhoneFactory.getPhone(slotIndex);
1916 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1917 PhoneConstantConversions.convertCallState(phone.getState());
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
1920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001924 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001925 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1926 }
1927
1928 @Override
1929 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001930 final long identity = Binder.clearCallingIdentity();
1931 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001932 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001933 if (phone != null) {
1934 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1935 } else {
1936 return PhoneConstantConversions.convertDataState(
1937 PhoneConstants.DataState.DISCONNECTED);
1938 }
1939 } finally {
1940 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 }
1943
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001945 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001946 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1947 }
1948
1949 @Override
1950 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001951 final long identity = Binder.clearCallingIdentity();
1952 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001953 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 if (phone != null) {
1955 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1956 } else {
1957 return TelephonyManager.DATA_ACTIVITY_NONE;
1958 }
1959 } finally {
1960 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001961 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001962 }
1963
1964 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07001965 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001966 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001967 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001968
1969 LocationAccessPolicy.LocationPermissionResult locationResult =
1970 LocationAccessPolicy.checkLocationPermission(mApp,
1971 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1972 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07001973 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08001974 .setCallingPid(Binder.getCallingPid())
1975 .setCallingUid(Binder.getCallingUid())
1976 .setMethod("getCellLocation")
1977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1978 .build());
1979 switch (locationResult) {
1980 case DENIED_HARD:
1981 throw new SecurityException("Not allowed to access cell location");
1982 case DENIED_SOFT:
1983 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001987 final long identity = Binder.clearCallingIdentity();
1988 try {
1989 if (DBG_LOC) log("getCellLocation: is active user");
1990 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001991 int subId = mSubscriptionController.getDefaultDataSubId();
1992 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1993 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 return data;
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
1997 }
Svetoslav64fad262015-04-14 14:35:21 -07001998 }
1999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002001 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2002 if (!TextUtils.isEmpty(callingPackage)) {
2003 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2005 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2006 return "";
2007 }
2008 }
2009
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002010 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2011 // registered cell info, so return a NULL country instead.
2012 final long identity = Binder.clearCallingIdentity();
2013 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002014 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2015 // Get default phone in this case.
2016 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2017 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002018 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002019 // Todo: fix this when we can get the actual cellular network info when the device
2020 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002021 if (TelephonyManager.NETWORK_TYPE_IWLAN
2022 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2023 return "";
2024 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025 Phone phone = PhoneFactory.getPhone(phoneId);
2026 if (phone != null) {
2027 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002028 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002029 if (sst != null) {
2030 LocaleTracker lt = sst.getLocaleTracker();
2031 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002032 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2033 return lt.getCurrentCountry();
2034 } else if (emergencyNumberTracker != null) {
2035 return emergencyNumberTracker.getEmergencyCountryIso();
2036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002037 }
2038 }
2039 }
2040 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002041 } finally {
2042 Binder.restoreCallingIdentity(identity);
2043 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 }
2045
2046 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002048 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002049 }
2050
Sanket Padawe356d7632015-06-22 14:03:32 -07002051 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002052 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 mApp.enforceCallingOrSelfPermission(
2054 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 final Phone phone = getPhone(subId);
2059 if (phone != null) {
2060 phone.enableLocationUpdates();
2061 }
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 }
2066
2067 @Override
2068 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002069 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002070 }
2071
Sanket Padawe356d7632015-06-22 14:03:32 -07002072 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002073 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 mApp.enforceCallingOrSelfPermission(
2075 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076
2077 final long identity = Binder.clearCallingIdentity();
2078 try {
2079 final Phone phone = getPhone(subId);
2080 if (phone != null) {
2081 phone.disableLocationUpdates();
2082 }
2083 } finally {
2084 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002085 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 }
2087
Nathan Harold31d7ff32018-10-15 20:20:30 -07002088 /**
2089 * Returns the target SDK version number for a given package name.
2090 *
Nathan Haroldec184742019-07-10 17:04:16 -07002091 * This call MUST be invoked before clearing the calling UID.
2092 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002093 * @return target SDK if the package is found or INT_MAX.
2094 */
2095 private int getTargetSdk(String packageName) {
2096 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002097 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002098 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002099 if (ai != null) return ai.targetSdkVersion;
2100 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002101 loge("Failed to get package info for pkg="
2102 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002103 }
2104 return Integer.MAX_VALUE;
2105 }
2106
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 @Override
2108 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002109 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2110 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002111 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002112 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2113 throw new SecurityException(
2114 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2115 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002116
Jordan Liu1617b712019-07-10 15:06:26 -07002117 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2119 return null;
2120 }
Svetoslav64fad262015-04-14 14:35:21 -07002121
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002122 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002123
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002124 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002125 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002126
Nathan Haroldf180aac2018-06-01 18:43:55 -07002127 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2128 for (CellInfo ci : info) {
2129 if (ci instanceof CellInfoGsm) {
2130 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2131 } else if (ci instanceof CellInfoWcdma) {
2132 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2133 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002135 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002138 private List<CellInfo> getCachedCellInfo() {
2139 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2140 for (Phone phone : PhoneFactory.getPhones()) {
2141 List<CellInfo> info = phone.getAllCellInfo();
2142 if (info != null) cellInfos.addAll(info);
2143 }
2144 return cellInfos;
2145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146
2147 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002148 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002149 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002150 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002151
2152 LocationAccessPolicy.LocationPermissionResult locationResult =
2153 LocationAccessPolicy.checkLocationPermission(mApp,
2154 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2155 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002156 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002157 .setCallingPid(Binder.getCallingPid())
2158 .setCallingUid(Binder.getCallingUid())
2159 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002160 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002161 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2162 .build());
2163 switch (locationResult) {
2164 case DENIED_HARD:
2165 throw new SecurityException("Not allowed to access cell info");
2166 case DENIED_SOFT:
2167 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 final int targetSdk = getTargetSdk(callingPackage);
2171 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2172 return getCachedCellInfo();
2173 }
2174
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002175 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177 final long identity = Binder.clearCallingIdentity();
2178 try {
2179 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2180 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002181 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002182 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 if (info != null) cellInfos.addAll(info);
2184 }
2185 return cellInfos;
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189 }
2190
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002191 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002192 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2193 String callingFeatureId) {
2194 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2195 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002196 }
2197
2198 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002199 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2200 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002201 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002202 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002203 }
2204
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002205 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2206 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002207 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002208 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002209
2210 LocationAccessPolicy.LocationPermissionResult locationResult =
2211 LocationAccessPolicy.checkLocationPermission(mApp,
2212 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2213 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002214 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002215 .setCallingPid(Binder.getCallingPid())
2216 .setCallingUid(Binder.getCallingUid())
2217 .setMethod("requestCellInfoUpdate")
2218 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2219 .build());
2220 switch (locationResult) {
2221 case DENIED_HARD:
2222 throw new SecurityException("Not allowed to access cell info");
2223 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002224 try {
2225 cb.onCellInfo(new ArrayList<CellInfo>());
2226 } catch (RemoteException re) {
2227 // Drop without consequences
2228 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002229 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002230 }
2231
Nathan Harolda939a962019-05-09 10:13:47 -07002232
2233 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002234 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2235
2236 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2237 }
2238
2239 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002241 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002246 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 } finally {
2248 Binder.restoreCallingIdentity(identity);
2249 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 }
2251
Shishir Agrawala9f32182016-04-12 12:00:16 -07002252 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002253 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002254 Phone phone = PhoneFactory.getPhone(slotIndex);
2255 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002256 return null;
2257 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002258 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002259 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2260 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 return null;
2262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 return phone.getImei();
2267 } finally {
2268 Binder.restoreCallingIdentity(identity);
2269 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002270 }
2271
2272 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002273 public String getTypeAllocationCodeForSlot(int slotIndex) {
2274 Phone phone = PhoneFactory.getPhone(slotIndex);
2275 String tac = null;
2276 if (phone != null) {
2277 String imei = phone.getImei();
2278 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2279 }
2280 return tac;
2281 }
2282
2283 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002284 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002285 Phone phone = PhoneFactory.getPhone(slotIndex);
2286 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002287 return null;
2288 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002289
Jeff Davidson913390f2018-02-23 17:11:49 -08002290 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002291 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2292 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002293 return null;
2294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295
2296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 return phone.getMeid();
2299 } finally {
2300 Binder.restoreCallingIdentity(identity);
2301 }
Jack Yu2af8d712017-03-15 17:14:14 -07002302 }
2303
2304 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002305 public String getManufacturerCodeForSlot(int slotIndex) {
2306 Phone phone = PhoneFactory.getPhone(slotIndex);
2307 String manufacturerCode = null;
2308 if (phone != null) {
2309 String meid = phone.getMeid();
2310 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2311 }
2312 return manufacturerCode;
2313 }
2314
2315 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002316 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002317 Phone phone = PhoneFactory.getPhone(slotIndex);
2318 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002319 return null;
2320 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002321 int subId = phone.getSubId();
2322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2323 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2324 return null;
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 return phone.getDeviceSvn();
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002333 }
2334
fionaxu43304da2017-11-27 22:51:16 -08002335 @Override
2336 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
fionaxu43304da2017-11-27 22:51:16 -08002344 }
2345
2346 @Override
2347 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002348 final long identity = Binder.clearCallingIdentity();
2349 try {
2350 final Phone phone = getPhone(subId);
2351 return phone == null ? null : phone.getCarrierName();
2352 } finally {
2353 Binder.restoreCallingIdentity(identity);
2354 }
fionaxu43304da2017-11-27 22:51:16 -08002355 }
2356
calvinpanffe225e2018-11-01 19:43:06 +08002357 @Override
chen xu0026ca62019-03-06 15:28:50 -08002358 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002359 final long identity = Binder.clearCallingIdentity();
2360 try {
2361 final Phone phone = getPhone(subId);
2362 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002363 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
2367 }
2368
2369 @Override
chen xu0026ca62019-03-06 15:28:50 -08002370 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002371 final long identity = Binder.clearCallingIdentity();
2372 try {
2373 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002374 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002375 } finally {
2376 Binder.restoreCallingIdentity(identity);
2377 }
2378 }
2379
chen xu651eec72018-11-11 19:03:44 -08002380 @Override
chen xu864e11c2018-12-06 22:10:03 -08002381 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2382 if (!isSubscriptionMccMnc) {
2383 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2384 }
chen xu651eec72018-11-11 19:03:44 -08002385 final Phone phone = PhoneFactory.getPhone(slotIndex);
2386 if (phone == null) {
2387 return TelephonyManager.UNKNOWN_CARRIER_ID;
2388 }
2389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2392 } finally {
2393 Binder.restoreCallingIdentity(identity);
2394 }
2395 }
2396
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002397 //
2398 // Internal helper methods.
2399 //
2400
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002401 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2403 *
2404 * @throws SecurityException if the caller does not have the required permission
2405 */
2406 private void enforceModifyPermission() {
2407 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2408 }
2409
2410 /**
2411 * Make sure the caller has the CALL_PHONE permission.
2412 *
2413 * @throws SecurityException if the caller does not have the required permission
2414 */
2415 private void enforceCallPermission() {
2416 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2417 }
2418
Stuart Scott8eef64f2015-04-08 15:13:54 -07002419 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002420 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002421 "ConnectivityService");
2422 }
2423
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 private String createTelUrl(String number) {
2425 if (TextUtils.isEmpty(number)) {
2426 return null;
2427 }
2428
Jake Hambye994d462014-02-03 13:10:13 -08002429 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
Ihab Awadf9e92732013-12-05 18:02:52 -08002432 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2434 }
2435
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002436 private static void logv(String msg) {
2437 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2438 }
2439
Ihab Awadf9e92732013-12-05 18:02:52 -08002440 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2442 }
2443
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002446 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002447 }
2448
Sanket Padawe356d7632015-06-22 14:03:32 -07002449 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002450 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = PhoneFactory.getPhone(slotIndex);
2454 if (phone == null) {
2455 return PhoneConstants.PHONE_TYPE_NONE;
2456 } else {
2457 return phone.getPhoneType();
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
2465 * Returns the CDMA ERI icon index to display
2466 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 @Override
2468 public int getCdmaEriIconIndex(String callingPackage) {
2469 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002470 }
2471
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002475 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002476 return -1;
2477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
2482 if (phone != null) {
2483 return phone.getCdmaEriIconIndex();
2484 } else {
2485 return -1;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
2492 /**
2493 * Returns the CDMA ERI icon mode,
2494 * 0 - ON
2495 * 1 - FLASHING
2496 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 @Override
2498 public int getCdmaEriIconMode(String callingPackage) {
2499 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002500 }
2501
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002503 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002505 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002506 return -1;
2507 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
2513 return phone.getCdmaEriIconMode();
2514 } else {
2515 return -1;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
2522 /**
2523 * Returns the CDMA ERI text,
2524 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002525 @Override
2526 public String getCdmaEriText(String callingPackage) {
2527 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002528 }
2529
Sanket Padawe356d7632015-06-22 14:03:32 -07002530 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002531 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002533 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002534 return null;
2535 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002536
2537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 final Phone phone = getPhone(subId);
2540 if (phone != null) {
2541 return phone.getCdmaEriText();
2542 } else {
2543 return null;
2544 }
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
2550 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002551 * Returns the CDMA MDN.
2552 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002554 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2556 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002561 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002562 return phone.getLine1Number();
2563 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 return null;
2566 }
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002569 }
2570 }
2571
2572 /**
2573 * Returns the CDMA MIN.
2574 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002575 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002576 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2578 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 final Phone phone = getPhone(subId);
2583 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2584 return phone.getCdmaMin();
2585 } else {
2586 return null;
2587 }
2588 } finally {
2589 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002590 }
2591 }
2592
Hall Liud892bec2018-11-30 14:51:45 -08002593 @Override
2594 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2595 INumberVerificationCallback callback, String callingPackage) {
2596 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2597 != PERMISSION_GRANTED) {
2598 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2599 }
2600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2601
2602 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2603 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2604 throw new SecurityException("Calling package must be configured in the device config");
2605 }
2606
2607 if (range == null) {
2608 throw new NullPointerException("Range must be non-null");
2609 }
2610
2611 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002612 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002613
2614 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2615 }
2616
Junda Liuca05d5d2014-08-14 22:36:34 -07002617 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 * Returns true if CDMA provisioning needs to run.
2619 */
2620 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621 final long identity = Binder.clearCallingIdentity();
2622 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002623 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002627 }
2628
2629 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002630 * Sets the voice mail number of a given subId.
2631 */
2632 @Override
2633 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002634 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2639 new Pair<String, String>(alphaTag, number), new Integer(subId));
2640 return success;
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002644 }
2645
Ta-wei Yen87c49842016-05-13 21:19:52 -07002646 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002647 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2648 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002649 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002650 if (!TextUtils.equals(callingPackage, systemDialer)) {
2651 throw new SecurityException("caller must be system dialer");
2652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2657 if (phoneAccountHandle == null) {
2658 return null;
2659 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002660 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661 } finally {
2662 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002663 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002664 }
2665
2666 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002667 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002670 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002671 return null;
2672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002674 final long identity = Binder.clearCallingIdentity();
2675 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002676 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002677 } finally {
2678 Binder.restoreCallingIdentity(identity);
2679 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002680 }
2681
2682 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002683 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2684 VisualVoicemailSmsFilterSettings settings) {
2685 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686
2687 final long identity = Binder.clearCallingIdentity();
2688 try {
2689 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002690 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002691 } finally {
2692 Binder.restoreCallingIdentity(identity);
2693 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002694 }
2695
2696 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002697 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2698 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699
2700 final long identity = Binder.clearCallingIdentity();
2701 try {
2702 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002703 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704 } finally {
2705 Binder.restoreCallingIdentity(identity);
2706 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002707 }
2708
2709 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002710 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2711 String callingPackage, int subId) {
2712 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002713
2714 final long identity = Binder.clearCallingIdentity();
2715 try {
2716 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002717 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 } finally {
2719 Binder.restoreCallingIdentity(identity);
2720 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002721 }
2722
2723 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002724 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002725 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726
2727 final long identity = Binder.clearCallingIdentity();
2728 try {
2729 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002730 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 } finally {
2732 Binder.restoreCallingIdentity(identity);
2733 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002734 }
2735
2736 @Override
2737 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2738 String number, int port, String text, PendingIntent sentIntent) {
2739 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002740 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002741 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002742 SmsController smsController = PhoneFactory.getSmsController();
2743 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2744 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002745 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002746
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002747 /**
fionaxu0152e512016-11-14 13:36:14 -08002748 * Sets the voice activation state of a given subId.
2749 */
2750 @Override
2751 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2753 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 final Phone phone = getPhone(subId);
2758 if (phone != null) {
2759 phone.setVoiceActivationState(activationState);
2760 } else {
2761 loge("setVoiceActivationState fails with invalid subId: " + subId);
2762 }
2763 } finally {
2764 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002765 }
2766 }
2767
2768 /**
2769 * Sets the data activation state of a given subId.
2770 */
2771 @Override
2772 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2774 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002775
2776 final long identity = Binder.clearCallingIdentity();
2777 try {
2778 final Phone phone = getPhone(subId);
2779 if (phone != null) {
2780 phone.setDataActivationState(activationState);
2781 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002782 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 }
2784 } finally {
2785 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002786 }
2787 }
2788
2789 /**
2790 * Returns the voice activation state of a given subId.
2791 */
2792 @Override
2793 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002794 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795
fionaxu0152e512016-11-14 13:36:14 -08002796 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 if (phone != null) {
2800 return phone.getVoiceActivationState();
2801 } else {
2802 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2803 }
2804 } finally {
2805 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002806 }
2807 }
2808
2809 /**
2810 * Returns the data activation state of a given subId.
2811 */
2812 @Override
2813 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002814 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
fionaxu0152e512016-11-14 13:36:14 -08002816 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 if (phone != null) {
2820 return phone.getDataActivationState();
2821 } else {
2822 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2823 }
2824 } finally {
2825 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002826 }
2827 }
2828
2829 /**
Wink Saville36469e72014-06-11 15:17:00 -07002830 * Returns the unread count of voicemails for a subId
2831 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002832 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002833 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2835 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2836 return 0;
2837 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002838 final long identity = Binder.clearCallingIdentity();
2839 try {
2840 final Phone phone = getPhone(subId);
2841 if (phone != null) {
2842 return phone.getVoiceMessageCount();
2843 } else {
2844 return 0;
2845 }
2846 } finally {
2847 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002848 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849 }
2850
2851 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002852 * returns true, if the device is in a state where both voice and data
2853 * are supported simultaneously. This can change based on location or network condition.
2854 */
2855 @Override
2856 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002857 final long identity = Binder.clearCallingIdentity();
2858 try {
2859 final Phone phone = getPhone(subId);
2860 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2861 } finally {
2862 Binder.restoreCallingIdentity(identity);
2863 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002864 }
2865
2866 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002867 * Send the dialer code if called from the current default dialer or the caller has
2868 * carrier privilege.
2869 * @param inputCode The dialer code to send
2870 */
2871 @Override
2872 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2876 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002877 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002878 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2879 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002880 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
fionaxu235cc5e2017-03-06 22:25:57 -08002888 }
2889
Pengquan Menga1bb6272018-09-06 09:59:22 -07002890 @Override
2891 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002892 if (!isActiveSubscription(subId)) {
2893 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2894 }
2895
Pengquan Menga1bb6272018-09-06 09:59:22 -07002896 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2897 }
2898
Brad Ebinger35c841c2018-10-01 10:40:55 -07002899 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002900 public boolean isInEmergencySmsMode() {
2901 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 for (Phone phone : PhoneFactory.getPhones()) {
2905 if (phone.isInEmergencySmsMode()) {
2906 return true;
2907 }
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
2912 return false;
2913 }
2914
2915 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002916 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2917 throws RemoteException {
2918 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002919 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2920 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2921 "IMS not available on device.");
2922 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 final long token = Binder.clearCallingIdentity();
2924 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002926 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002928 } catch (ImsException e) {
2929 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002930 } finally {
2931 Binder.restoreCallingIdentity(token);
2932 }
2933 }
2934
2935 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002936 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2937 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002938 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2939 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2940 }
Meng Wangafbc5852019-09-19 17:37:13 -07002941 final long token = Binder.clearCallingIdentity();
2942 try {
2943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2944 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2945 .removeRegistrationCallbackForSubscription(c, subId);
2946 } catch (ImsException e) {
2947 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2948 + "is inactive, ignoring unregister.");
2949 // If the subscription is no longer active, just return, since the callback
2950 // will already have been removed internally.
2951 } finally {
2952 Binder.restoreCallingIdentity(token);
2953 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 }
2955
Brad Ebingera34a6c22019-10-22 17:36:18 -07002956 /**
2957 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2958 */
2959 @Override
2960 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2961 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2962 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2963 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2964 "IMS not available on device.");
2965 }
2966 final long token = Binder.clearCallingIdentity();
2967 try {
2968 Phone phone = getPhone(subId);
2969 if (phone == null) {
2970 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2971 + subId + "'");
2972 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2973 }
2974 phone.getImsRegistrationState(regState -> {
2975 try {
2976 consumer.accept((regState == null)
2977 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2978 } catch (RemoteException e) {
2979 // Ignore if the remote process is no longer available to call back.
2980 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2981 }
2982 });
2983 } finally {
2984 Binder.restoreCallingIdentity(token);
2985 }
2986 }
2987
2988 /**
2989 * Get the transport type for the IMS service registration state.
2990 */
2991 @Override
2992 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2993 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2994 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2995 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2996 "IMS not available on device.");
2997 }
2998 final long token = Binder.clearCallingIdentity();
2999 try {
3000 Phone phone = getPhone(subId);
3001 if (phone == null) {
3002 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3003 + subId + "'");
3004 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3005 }
3006 phone.getImsRegistrationTech(regTech -> {
3007 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3008 int regTechConverted = (regTech == null)
3009 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3010 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3011 regTechConverted);
3012 try {
3013 consumer.accept(regTechConverted);
3014 } catch (RemoteException e) {
3015 // Ignore if the remote process is no longer available to call back.
3016 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3017 }
3018 });
3019 } finally {
3020 Binder.restoreCallingIdentity(token);
3021 }
3022 }
3023
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003025 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3026 throws RemoteException {
3027 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003028 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3029 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3030 "IMS not available on device.");
3031 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3033 final long token = Binder.clearCallingIdentity();
3034 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003036 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003037 } catch (ImsException e) {
3038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 } finally {
3040 Binder.restoreCallingIdentity(token);
3041 }
3042 }
3043
3044 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003045 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3046 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003047 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3048 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3049 }
Meng Wangafbc5852019-09-19 17:37:13 -07003050
3051 final long token = Binder.clearCallingIdentity();
3052 try {
3053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3054 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003055 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003056 } catch (ImsException e) {
3057 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3058 + "is inactive, ignoring unregister.");
3059 // If the subscription is no longer active, just return, since the callback
3060 // will already have been removed internally.
3061 } finally {
3062 Binder.restoreCallingIdentity(token);
3063 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 }
3065
3066 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003067 public boolean isCapable(int subId, int capability, int regTech) {
3068 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3070 final long token = Binder.clearCallingIdentity();
3071 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003074 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3076 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003077 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003078 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3079 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 } finally {
3081 Binder.restoreCallingIdentity(token);
3082 }
3083 }
3084
3085 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003086 public boolean isAvailable(int subId, int capability, int regTech) {
3087 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003088 final long token = Binder.clearCallingIdentity();
3089 try {
3090 Phone phone = getPhone(subId);
3091 if (phone == null) return false;
3092 return phone.isImsCapabilityAvailable(capability, regTech);
3093 } finally {
3094 Binder.restoreCallingIdentity(token);
3095 }
3096 }
3097
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003098 /**
3099 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3100 * subscription.
3101 * @param subId The subscription to use to check the configuration.
3102 * @param callback The callback that will be used to send the result.
3103 * @param capability The MmTelFeature capability that will be used to send the result.
3104 * @param transportType The transport type of the MmTelFeature capability.
3105 */
3106 @Override
3107 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3108 int transportType) {
3109 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3110 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3111 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3112 "IMS not available on device.");
3113 }
3114 final long token = Binder.clearCallingIdentity();
3115 try {
3116 int slotId = getSlotIndex(subId);
3117 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3118 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3119 + subId + "'");
3120 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3121 }
3122 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3123 transportType, aBoolean -> {
3124 try {
3125 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3126 } catch (RemoteException e) {
3127 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3128 + "running. Ignore");
3129 }
3130 });
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
3134 }
3135
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 @Override
3137 public boolean isAdvancedCallingSettingEnabled(int subId) {
3138 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3140 final long token = Binder.clearCallingIdentity();
3141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (ImsException e) {
3145 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003146 } finally {
3147 Binder.restoreCallingIdentity(token);
3148 }
3149 }
3150
3151 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003152 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003154 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 final long identity = Binder.clearCallingIdentity();
3156 try {
3157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003158 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003159 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003160 } catch (ImsException e) {
3161 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003162 } finally {
3163 Binder.restoreCallingIdentity(identity);
3164 }
3165 }
3166
3167 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003168 public boolean isVtSettingEnabled(int subId) {
3169 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003170 final long identity = Binder.clearCallingIdentity();
3171 try {
3172 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003173 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3174 } catch (ImsException e) {
3175 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003176 } finally {
3177 Binder.restoreCallingIdentity(identity);
3178 }
3179 }
3180
3181 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003182 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003184 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003189 } catch (ImsException e) {
3190 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 } finally {
3192 Binder.restoreCallingIdentity(identity);
3193 }
3194 }
3195
3196 @Override
3197 public boolean isVoWiFiSettingEnabled(int subId) {
3198 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003204 } catch (ImsException e) {
3205 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 } finally {
3207 Binder.restoreCallingIdentity(identity);
3208 }
3209 }
3210
3211 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003212 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003214 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003218 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003219 } catch (ImsException e) {
3220 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 } finally {
3222 Binder.restoreCallingIdentity(identity);
3223 }
3224 }
3225
3226 @Override
3227 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3228 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3229 final long identity = Binder.clearCallingIdentity();
3230 try {
3231 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003232 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003233 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003234 } catch (ImsException e) {
3235 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
3239 }
3240
3241 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003242 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003244 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003245 final long identity = Binder.clearCallingIdentity();
3246 try {
3247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003248 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003249 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003250 } catch (ImsException e) {
3251 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 } finally {
3253 Binder.restoreCallingIdentity(identity);
3254 }
3255 }
3256
3257 @Override
3258 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3260 "setVoWiFiNonPersistent");
3261 final long identity = Binder.clearCallingIdentity();
3262 try {
3263 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003265 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003266 } catch (ImsException e) {
3267 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 } finally {
3269 Binder.restoreCallingIdentity(identity);
3270 }
3271 }
3272
3273 @Override
3274 public int getVoWiFiModeSetting(int subId) {
3275 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3276 final long identity = Binder.clearCallingIdentity();
3277 try {
3278 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003279 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 } catch (ImsException e) {
3282 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
3286 }
3287
3288 @Override
3289 public void setVoWiFiModeSetting(int subId, int mode) {
3290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3291 "setVoWiFiModeSetting");
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003295 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003296 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
3305 public int getVoWiFiRoamingModeSetting(int subId) {
3306 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003312 } catch (ImsException e) {
3313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
3320 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3322 "setVoWiFiRoamingModeSetting");
3323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003327 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003328 } catch (ImsException e) {
3329 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 } finally {
3331 Binder.restoreCallingIdentity(identity);
3332 }
3333 }
3334
3335 @Override
3336 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3338 "setRttCapabilityEnabled");
3339 final long identity = Binder.clearCallingIdentity();
3340 try {
3341 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003342 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3343 } catch (ImsException e) {
3344 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
3350 @Override
3351 public boolean isTtyOverVolteEnabled(int subId) {
3352 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003356 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003358 } catch (ImsException e) {
3359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
3363 }
3364
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003365 @Override
3366 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3367 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3368 final long identity = Binder.clearCallingIdentity();
3369 try {
3370 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003371 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003372 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003373 } catch (ImsException e) {
3374 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003375 } finally {
3376 Binder.restoreCallingIdentity(identity);
3377 }
3378 }
3379
3380 @Override
3381 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3382 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3383 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003384 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3385 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3386 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 try {
3388 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003390 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003391 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003392 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3393 + "is inactive, ignoring unregister.");
3394 // If the subscription is no longer active, just return, since the callback will already
3395 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
3399 }
3400
3401 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003402 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3403 boolean isProvisioned) {
3404 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3405 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3406 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3407 }
3408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3409 "setProvisioningStatusForCapability");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3413 Phone phone = getPhone(subId);
3414 if (phone == null) {
3415 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3416 + subId);
3417 return;
3418 }
3419 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3420 return;
3421 }
3422
3423 // this capability requires provisioning, route to the correct API.
3424 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3425 switch (capability) {
3426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3427 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3428 ims.setVolteProvisioned(isProvisioned);
3429 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3430 ims.setWfcProvisioned(isProvisioned);
3431 }
3432 break;
3433 }
3434 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3435 // There is currently no difference in VT provisioning type.
3436 ims.setVtProvisioned(isProvisioned);
3437 break;
3438 }
3439 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3440 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3441 // change the capability of the feature instead if needed.
3442 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3443 == isProvisioned) {
3444 // No change in provisioning.
3445 return;
3446 }
3447 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3448 try {
3449 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003450 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003451 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3452 + ", Exception" + e.getMessage());
3453 }
3454 break;
3455 }
3456 default: {
3457 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3458 + capability + "', which does not require provisioning.");
3459 }
3460 }
3461
3462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
3465 }
3466
3467 @Override
3468 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3469 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3470 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3471 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3472 }
3473 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3477 Phone phone = getPhone(subId);
3478 if (phone == null) {
3479 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3480 + subId);
3481 // We will fail with "true" as the provisioning status because this is the default
3482 // if we do not require provisioning.
3483 return true;
3484 }
3485
3486 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3487 return true;
3488 }
3489
3490 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3491 switch (capability) {
3492 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3493 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3494 return ims.isVolteProvisionedOnDevice();
3495 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3496 return ims.isWfcProvisionedOnDevice();
3497 }
3498 // This should never happen, since we are checking tech above to make sure it
3499 // is either LTE or IWLAN.
3500 throw new IllegalArgumentException("Invalid radio technology for voice "
3501 + "capability.");
3502 }
3503 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3504 // There is currently no difference in VT provisioning type.
3505 return ims.isVtProvisionedOnDevice();
3506 }
3507 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3508 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3509 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3510 }
3511 default: {
3512 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3513 + capability + "', which does not require provisioning.");
3514 }
3515 }
3516
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
3520 }
3521
3522 @Override
3523 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3524 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3525 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3526 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3527 }
3528 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3529 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3530 return (provisionedBits & capability) > 0;
3531 }
3532
3533 @Override
3534 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3535 boolean isProvisioned) {
3536 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3537 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3538 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3539 }
3540 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3541 "setProvisioningStatusForCapability");
3542 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3543 // If the current provisioning status for capability already matches isProvisioned,
3544 // do nothing.
3545 if (((provisionedBits & capability) > 0) == isProvisioned) {
3546 return;
3547 }
3548 if (isProvisioned) {
3549 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3550 } else {
3551 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3552 }
3553 }
3554
3555 /**
3556 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3557 * technology. The bitfield should mirror the bitfield defined by
3558 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3559 */
3560 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3561 String key = getMmTelProvisioningKey(subId, tech);
3562 // Default is no capabilities are provisioned.
3563 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3564 }
3565
3566 /**
3567 * Sets the MmTel capability provisioning bitfield (defined by
3568 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3569 * technology specified.
3570 *
3571 * Note: This is a synchronous command and should not be called on UI thread.
3572 */
3573 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3574 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3575 String key = getMmTelProvisioningKey(subId, tech);
3576 editor.putInt(key, newField);
3577 editor.commit();
3578 }
3579
3580 private static String getMmTelProvisioningKey(int subId, int tech) {
3581 // resulting key is provision_ims_mmtel_{subId}_{tech}
3582 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3583 }
3584
3585 /**
3586 * Query CarrierConfig to see if the specified capability requires provisioning for the
3587 * carrier associated with the subscription id.
3588 */
3589 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3590 int capability) {
3591 CarrierConfigManager configManager = new CarrierConfigManager(context);
3592 PersistableBundle c = configManager.getConfigForSubId(subId);
3593 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003594 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003595 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3596 false);
3597 boolean requireVoiceVtProvisioning = c.getBoolean(
3598 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3599
3600 // First check to make sure that the capability requires provisioning.
3601 switch (capability) {
3602 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3603 // intentional fallthrough
3604 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3605 if (requireVoiceVtProvisioning) {
3606 // Voice and Video requires provisioning
3607 return true;
3608 }
3609 break;
3610 }
3611 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3612 if (requireUtProvisioning) {
3613 // UT requires provisioning
3614 return true;
3615 }
3616 break;
3617 }
3618 }
3619 return false;
3620 }
3621
3622 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003623 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003624 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3625 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3626 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003627 enforceReadPrivilegedPermission("getImsProvisioningInt");
3628 final long identity = Binder.clearCallingIdentity();
3629 try {
3630 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003631 int slotId = getSlotIndex(subId);
3632 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3633 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3634 + subId + "' for key:" + key);
3635 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3636 }
3637 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003638 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003639 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3640 + subId + "' for key:" + key);
3641 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646
3647 @Override
3648 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003649 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3650 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3651 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003652 enforceReadPrivilegedPermission("getImsProvisioningString");
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003656 int slotId = getSlotIndex(subId);
3657 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3658 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3659 + subId + "' for key:" + key);
3660 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3661 }
3662 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003663 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003664 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3665 + subId + "' for key:" + key);
3666 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
3670 }
3671
3672 @Override
3673 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003674 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3675 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3676 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3678 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003682 int slotId = getSlotIndex(subId);
3683 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3684 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3685 + subId + "' for key:" + key);
3686 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3687 }
3688 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003689 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003690 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3691 + "' for key:" + key);
3692 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 }
3697
3698 @Override
3699 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003700 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3701 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3702 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003708 int slotId = getSlotIndex(subId);
3709 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3710 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3711 + subId + "' for key:" + key);
3712 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3713 }
3714 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003715 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3717 + "' for key:" + key);
3718 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003719 } finally {
3720 Binder.restoreCallingIdentity(identity);
3721 }
3722 }
3723
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 int slotId = SubscriptionManager.getSlotIndex(subId);
3726 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3728 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 }
3730 return slotId;
3731 }
3732
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003733 private int getSlotIndex(int subId) {
3734 int slotId = SubscriptionManager.getSlotIndex(subId);
3735 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3736 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3737 }
3738 return slotId;
3739 }
3740
Wink Saville36469e72014-06-11 15:17:00 -07003741 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003742 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003743 */
3744 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003745 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003746 final int targetSdk = getTargetSdk(callingPackage);
3747 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3748 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3749 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003750 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3751 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003752 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3753 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003754
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 final Phone phone = getPhone(subId);
3758 if (phone != null) {
3759 return phone.getServiceState().getDataNetworkType();
3760 } else {
3761 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3762 }
3763 } finally {
3764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003766 }
3767
3768 /**
3769 * Returns the data network type
3770 */
3771 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003772 public int getDataNetworkType(String callingPackage) {
3773 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003774 }
3775
3776 /**
3777 * Returns the data network type for a subId
3778 */
3779 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003780 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003782 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3784 }
3785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003786 final long identity = Binder.clearCallingIdentity();
3787 try {
3788 final Phone phone = getPhone(subId);
3789 if (phone != null) {
3790 return phone.getServiceState().getDataNetworkType();
3791 } else {
3792 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3793 }
3794 } finally {
3795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003797 }
3798
3799 /**
Wink Saville36469e72014-06-11 15:17:00 -07003800 * Returns the Voice network type for a subId
3801 */
3802 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003803 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003805 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003806 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3807 }
3808
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 final long identity = Binder.clearCallingIdentity();
3810 try {
3811 final Phone phone = getPhone(subId);
3812 if (phone != null) {
3813 return phone.getServiceState().getVoiceNetworkType();
3814 } else {
3815 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3816 }
3817 } finally {
3818 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003819 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003820 }
3821
3822 /**
3823 * @return true if a ICC card is present
3824 */
3825 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003826 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003827 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3828 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003829 }
3830
3831 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003832 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003833 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003834 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003835 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 final Phone phone = PhoneFactory.getPhone(slotIndex);
3839 if (phone != null) {
3840 return phone.getIccCard().hasIccCard();
3841 } else {
3842 return false;
3843 }
3844 } finally {
3845 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003847 }
3848
3849 /**
3850 * Return if the current radio is LTE on CDMA. This
3851 * is a tri-state return value as for a period of time
3852 * the mode may be unknown.
3853 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003854 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003855 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003856 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003857 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 @Override
3859 public int getLteOnCdmaMode(String callingPackage) {
3860 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003861 }
3862
Sanket Padawe356d7632015-06-22 14:03:32 -07003863 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003864 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003866 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003867 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3868 }
3869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 final long identity = Binder.clearCallingIdentity();
3871 try {
3872 final Phone phone = getPhone(subId);
3873 if (phone == null) {
3874 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3875 } else {
3876 return phone.getLteOnCdmaMode();
3877 }
3878 } finally {
3879 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003880 }
Wink Saville36469e72014-06-11 15:17:00 -07003881 }
3882
Wink Saville36469e72014-06-11 15:17:00 -07003883 /**
3884 * {@hide}
3885 * Returns Default subId, 0 in the case of single standby.
3886 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003887 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003888 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003889 }
3890
Shishir Agrawala9f32182016-04-12 12:00:16 -07003891 private int getSlotForDefaultSubscription() {
3892 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3893 }
3894
Wink Savilleb564aae2014-10-23 10:18:09 -07003895 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003896 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003898
Pengquan Menge92a50d2018-09-21 15:54:48 -07003899 private boolean isActiveSubscription(int subId) {
3900 return mSubscriptionController.isActiveSubId(subId);
3901 }
3902
Ihab Awadf2177b72013-11-25 13:33:23 -08003903 /**
3904 * @see android.telephony.TelephonyManager.WifiCallingChoices
3905 */
3906 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907 final long identity = Binder.clearCallingIdentity();
3908 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003909 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3911 getWhenToMakeWifiCallsDefaultPreference());
3912 } finally {
3913 Binder.restoreCallingIdentity(identity);
3914 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003915 }
3916
3917 /**
3918 * @see android.telephony.TelephonyManager.WifiCallingChoices
3919 */
3920 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003921 final long identity = Binder.clearCallingIdentity();
3922 try {
3923 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003924 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003925 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
3928 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003929 }
3930
Sailesh Nepald1e68152013-12-12 19:08:02 -08003931 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003932 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003933 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003934 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003935
Jordan Liu4c733742019-02-28 12:03:40 -08003936 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3937 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3938 if (phoneId == -1) {
3939 throw new IllegalArgumentException("Given slot index: " + slotIndex
3940 + " does not correspond to an active phone");
3941 }
3942 return PhoneFactory.getPhone(phoneId);
3943 }
3944
Shishir Agrawal566b7612013-10-28 14:41:00 -07003945 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003946 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3947 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003948 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3949 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003951 if (DBG) {
3952 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3953 }
3954 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3955 p2);
3956 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003957
Jordan Liu4c733742019-02-28 12:03:40 -08003958
3959 @Override
3960 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3961 int slotIndex, String callingPackage, String aid, int p2) {
3962 enforceModifyPermission();
3963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3964 if (DBG) {
3965 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3966 }
3967 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3968 callingPackage, aid, p2);
3969 }
3970
3971 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3972 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 if (TextUtils.equals(ISDR_AID, aid)) {
3976 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3978 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003979 if (bestComponent == null
3980 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3981 loge("The calling package is not allowed to access ISD-R.");
3982 throw new SecurityException(
3983 "The calling package is not allowed to access ISD-R.");
3984 }
Derek Tan740e1672017-06-27 14:56:27 -07003985 }
Derek Tan740e1672017-06-27 14:56:27 -07003986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003988 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3989 null /* workSource */);
3990 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003991 return response;
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003995 }
3996
3997 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003998 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4000 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004001 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4002 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4003 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004004
Jordan Liu4c733742019-02-28 12:03:40 -08004005 @Override
4006 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4007 enforceModifyPermission();
4008 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4009 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4010 channel);
4011 }
4012
4013 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 if (channel < 0) {
4017 return false;
4018 }
Jordan Liu4c733742019-02-28 12:03:40 -08004019 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4020 null /* workSource */);
4021 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004022 return success;
4023 } finally {
4024 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004026 }
4027
4028 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004029 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004030 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004033 if (DBG) {
4034 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4035 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4036 + p3 + " data=" + data);
4037 }
4038 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4039 command, p1, p2, p3, data);
4040 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004041
Jordan Liu4c733742019-02-28 12:03:40 -08004042 @Override
4043 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4044 int command, int p1, int p2, int p3, String data) {
4045 enforceModifyPermission();
4046 if (DBG) {
4047 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4048 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4049 + p3 + " data=" + data);
4050 }
4051 return iccTransmitApduLogicalChannelWithPermission(
4052 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4053 data);
4054 }
4055
4056 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4057 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004058 final long identity = Binder.clearCallingIdentity();
4059 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004060 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004061 return "";
4062 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004065 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4066 null /* workSource */);
4067 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004069 // Append the returned status code to the end of the response payload.
4070 String s = Integer.toHexString(
4071 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4072 if (response.payload != null) {
4073 s = IccUtils.bytesToHexString(response.payload) + s;
4074 }
4075 return s;
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004078 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004079 }
Jake Hambye994d462014-02-03 13:10:13 -08004080
Evan Charltonc66da362014-05-16 14:06:40 -07004081 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004082 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4083 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004084 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4085 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004087 if (DBG) {
4088 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4089 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4090 }
4091 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4092 cla, command, p1, p2, p3, data);
4093 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004094
Jordan Liu4c733742019-02-28 12:03:40 -08004095 @Override
4096 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4097 int command, int p1, int p2, int p3, String data) {
4098 enforceModifyPermission();
4099 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4100 if (DBG) {
4101 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4102 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4103 + " data=" + data);
4104 }
4105
4106 return iccTransmitApduBasicChannelWithPermission(
4107 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4108 p2, p3, data);
4109 }
4110
4111 // open APDU basic channel assuming the caller has sufficient permissions
4112 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4113 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4117 && TextUtils.equals(ISDR_AID, data)) {
4118 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004119 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4120 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 if (bestComponent == null
4122 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4123 loge("The calling package is not allowed to select ISD-R.");
4124 throw new SecurityException(
4125 "The calling package is not allowed to select ISD-R.");
4126 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004127 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004128
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004129 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004130 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4131 null /* workSource */);
4132 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004133
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004134 // Append the returned status code to the end of the response payload.
4135 String s = Integer.toHexString(
4136 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4137 if (response.payload != null) {
4138 s = IccUtils.bytesToHexString(response.payload) + s;
4139 }
4140 return s;
4141 } finally {
4142 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004143 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004144 }
4145
4146 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004147 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004148 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4150 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004151
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 if (DBG) {
4155 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4156 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4157 }
4158
4159 IccIoResult response =
4160 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4161 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4162 subId);
4163
4164 if (DBG) {
4165 log("Exchange SIM_IO [R]" + response);
4166 }
4167
4168 byte[] result = null;
4169 int length = 2;
4170 if (response.payload != null) {
4171 length = 2 + response.payload.length;
4172 result = new byte[length];
4173 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4174 } else {
4175 result = new byte[length];
4176 }
4177
4178 result[length - 1] = (byte) response.sw2;
4179 result[length - 2] = (byte) response.sw1;
4180 return result;
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004183 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004184 }
4185
Nathan Haroldb3014052017-01-25 15:57:32 -08004186 /**
4187 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4188 * on a particular subscription
4189 */
sqianb6e41952018-03-12 14:54:01 -07004190 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4192 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4193 return null;
4194 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195
4196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 if (appType != TelephonyManager.APPTYPE_USIM
4199 && appType != TelephonyManager.APPTYPE_SIM) {
4200 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4201 return null;
4202 }
4203 Object response = sendRequest(
4204 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4205 if (response instanceof String[]) {
4206 return (String[]) response;
4207 }
yincheng zhao2737e882019-09-06 17:06:54 -07004208 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004210 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 } finally {
4212 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004213 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004214 }
4215
yincheng zhao2737e882019-09-06 17:06:54 -07004216 /**
4217 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4218 * subscription.
4219 *
4220 * @param subId the id of the subscription.
4221 * @param appType the uicc app type, must be USIM or SIM.
4222 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4223 * @param callingPackage the op Package name.
4224 * @return number of fplmns that is successfully written to the SIM.
4225 */
4226 public int setForbiddenPlmns(
4227 int subId, int appType, List<String> fplmns, String callingPackage) {
4228 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4229 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4230 if (DBG) logv("no permissions for setForbiddenplmns");
4231 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4232 }
4233 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4234 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4235 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4236 }
4237 if (fplmns == null) {
4238 throw new IllegalArgumentException("Fplmn List provided is null");
4239 }
4240 for (String fplmn : fplmns) {
4241 if (!CellIdentity.isValidPlmn(fplmn)) {
4242 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4243 }
4244 }
4245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 Object response = sendRequest(
4248 CMD_SET_FORBIDDEN_PLMNS,
4249 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4250 subId);
4251 return (int) response;
4252 } finally {
4253 Binder.restoreCallingIdentity(identity);
4254 }
4255 }
4256
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004257 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004258 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004259 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4260 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004261
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 final long identity = Binder.clearCallingIdentity();
4263 try {
4264 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4265 if (response.payload == null) {
4266 return "";
4267 }
Evan Charltonc66da362014-05-16 14:06:40 -07004268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004269 // Append the returned status code to the end of the response payload.
4270 String s = Integer.toHexString(
4271 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4272 s = IccUtils.bytesToHexString(response.payload) + s;
4273 return s;
4274 } finally {
4275 Binder.restoreCallingIdentity(identity);
4276 }
Evan Charltonc66da362014-05-16 14:06:40 -07004277 }
4278
Jake Hambye994d462014-02-03 13:10:13 -08004279 /**
4280 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4281 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4282 *
4283 * @param itemID the ID of the item to read
4284 * @return the NV item as a String, or null on error.
4285 */
4286 @Override
4287 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4290 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291
4292 final long identity = Binder.clearCallingIdentity();
4293 try {
4294 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004295 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4297 return value;
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
Jake Hambye994d462014-02-03 13:10:13 -08004301 }
4302
4303 /**
4304 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4305 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4306 *
4307 * @param itemID the ID of the item to read
4308 * @param itemValue the value to write, as a String
4309 * @return true on success; false on any failure
4310 */
4311 @Override
4312 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004313 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4315 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316
4317 final long identity = Binder.clearCallingIdentity();
4318 try {
4319 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4320 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004321 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4323 return success;
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Jake Hambye994d462014-02-03 13:10:13 -08004327 }
4328
4329 /**
4330 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4331 * Used for device configuration by some CDMA operators.
4332 *
4333 * @param preferredRoamingList byte array containing the new PRL
4334 * @return true on success; false on any failure
4335 */
4336 @Override
4337 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4339 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004340
4341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4344 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4345 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4346 return success;
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Jake Hambye994d462014-02-03 13:10:13 -08004350 }
4351
4352 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004353 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004354 * Used for device configuration by some CDMA operators.
4355 *
chen xu6dac5ab2018-10-26 17:39:23 -07004356 * @param slotIndex - device slot.
4357 *
Jake Hambye994d462014-02-03 13:10:13 -08004358 * @return true on success; false on any failure
4359 */
4360 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004361 public boolean resetModemConfig(int slotIndex) {
4362 Phone phone = PhoneFactory.getPhone(slotIndex);
4363 if (phone != null) {
4364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4365 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366
chen xu6dac5ab2018-10-26 17:39:23 -07004367 final long identity = Binder.clearCallingIdentity();
4368 try {
4369 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4370 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4371 return success;
4372 } finally {
4373 Binder.restoreCallingIdentity(identity);
4374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 }
chen xu6dac5ab2018-10-26 17:39:23 -07004376 return false;
4377 }
4378
4379 /**
4380 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4381 *
4382 * @param slotIndex - device slot.
4383 *
4384 * @return true on success; false on any failure
4385 */
4386 @Override
4387 public boolean rebootModem(int slotIndex) {
4388 Phone phone = PhoneFactory.getPhone(slotIndex);
4389 if (phone != null) {
4390 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4391 mApp, phone.getSubId(), "rebootModem");
4392
4393 final long identity = Binder.clearCallingIdentity();
4394 try {
4395 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4396 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4397 return success;
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
4400 }
4401 }
4402 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004403 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004404
Svet Ganovb320e182015-04-16 12:30:10 -07004405 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004406 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004408 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004409 return new String[0];
4410 }
4411
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004414 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Wink Saville36469e72014-06-11 15:17:00 -07004418 }
4419
Brad Ebinger51f743a2017-01-23 13:50:20 -08004420 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004421 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4422 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004423 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004424 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004425 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004429 ImsResolver resolver = PhoneFactory.getImsResolver();
4430 if (resolver == null) {
4431 // may happen if the device does not support IMS.
4432 return;
4433 }
4434 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004438 }
4439
4440 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004441 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4442 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004443 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004444 public void disableIms(int slotId) {
4445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446
4447 final long identity = Binder.clearCallingIdentity();
4448 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004449 ImsResolver resolver = PhoneFactory.getImsResolver();
4450 if (resolver == null) {
4451 // may happen if the device does not support IMS.
4452 return;
4453 }
4454 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 } finally {
4456 Binder.restoreCallingIdentity(identity);
4457 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004458 }
4459
4460 /**
4461 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4462 * feature or {@link null} if the service is not available. If the feature is available, the
4463 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4464 */
4465 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004466 IImsServiceFeatureCallback callback) {
4467 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004468
4469 final long identity = Binder.clearCallingIdentity();
4470 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004471 ImsResolver resolver = PhoneFactory.getImsResolver();
4472 if (resolver == null) {
4473 // may happen if the device does not support IMS.
4474 return null;
4475 }
4476 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004480 }
4481
4482 /**
4483 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4484 * feature during emergency calling or {@link null} if the service is not available. If the
4485 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4486 * listener for feature updates.
4487 */
4488 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004493 ImsResolver resolver = PhoneFactory.getImsResolver();
4494 if (resolver == null) {
4495 // may happen if the device does not support IMS.
4496 return null;
4497 }
4498 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004502 }
4503
Brad Ebinger5f64b052017-12-14 14:26:15 -08004504 /**
4505 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004506 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004507 */
4508 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004513 ImsResolver resolver = PhoneFactory.getImsResolver();
4514 if (resolver == null) {
4515 // may happen if the device does not support IMS.
4516 return null;
4517 }
4518 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004522 }
4523
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004524 /**
4525 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004526 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004527 */
4528 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004530
4531 final long identity = Binder.clearCallingIdentity();
4532 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004533 ImsResolver resolver = PhoneFactory.getImsResolver();
4534 if (resolver == null) {
4535 // may happen if the device does not support IMS.
4536 return null;
4537 }
4538 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
4541 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004542 }
4543
Brad Ebinger884c07b2018-02-15 16:17:40 -08004544 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004545 * Sets the ImsService Package Name that Telephony will bind to.
4546 *
4547 * @param slotId the slot ID that the ImsService should bind for.
4548 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4549 * ImsService is the device default ImsService.
4550 * @param packageName The package name of the application that contains the ImsService to bind
4551 * to.
4552 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4553 * @hide
4554 */
4555 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004556 int[] subIds = SubscriptionManager.getSubId(slotId);
4557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4558 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4559 "setImsService");
4560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561 final long identity = Binder.clearCallingIdentity();
4562 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004563 ImsResolver resolver = PhoneFactory.getImsResolver();
4564 if (resolver == null) {
4565 // may happen if the device does not support IMS.
4566 return false;
4567 }
4568 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4569 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 } finally {
4571 Binder.restoreCallingIdentity(identity);
4572 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004573 }
4574
4575 /**
4576 * Return the ImsService configuration.
4577 *
4578 * @param slotId The slot that the ImsService is associated with.
4579 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4580 * the device default.
4581 * @return the package name of the ImsService configuration.
4582 */
4583 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004584 int[] subIds = SubscriptionManager.getSubId(slotId);
4585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4586 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4587 "getImsService");
4588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 final long identity = Binder.clearCallingIdentity();
4590 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004591 ImsResolver resolver = PhoneFactory.getImsResolver();
4592 if (resolver == null) {
4593 // may happen if the device does not support IMS.
4594 return "";
4595 }
4596 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004600 }
4601
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004602 /**
4603 * Get the MmTelFeature state associated with the requested subscription id.
4604 * @param subId The subscription that the MmTelFeature is associated with.
4605 * @param callback A callback with an integer containing the
4606 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4607 */
4608 @Override
4609 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4610 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4611 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4612 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4613 "IMS not available on device.");
4614 }
4615 final long token = Binder.clearCallingIdentity();
4616 try {
4617 int slotId = getSlotIndex(subId);
4618 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4619 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4620 + subId + "'");
4621 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4622 }
4623 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4624 try {
4625 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4626 } catch (RemoteException e) {
4627 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4628 + "Ignore");
4629 }
4630 });
4631 } finally {
4632 Binder.restoreCallingIdentity(token);
4633 }
4634 }
4635
Wink Saville36469e72014-06-11 15:17:00 -07004636 public void setImsRegistrationState(boolean registered) {
4637 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638
4639 final long identity = Binder.clearCallingIdentity();
4640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004641 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 } finally {
4643 Binder.restoreCallingIdentity(identity);
4644 }
Wink Saville36469e72014-06-11 15:17:00 -07004645 }
4646
4647 /**
Stuart Scott54788802015-03-30 13:18:01 -07004648 * Set the network selection mode to automatic.
4649 *
4650 */
4651 @Override
4652 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4654 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004655
Pengquan Menge92a50d2018-09-21 15:54:48 -07004656 if (!isActiveSubscription(subId)) {
4657 return;
4658 }
4659
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4663 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
4666 }
Stuart Scott54788802015-03-30 13:18:01 -07004667 }
4668
Pengquan Mengea84e042018-09-20 14:57:26 -07004669 /**
4670 * Ask the radio to connect to the input network and change selection mode to manual.
4671 *
4672 * @param subId the id of the subscription.
4673 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4674 * the operator to attach to.
4675 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4676 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4677 * normal network selection next time.
4678 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004679 */
4680 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004681 public boolean setNetworkSelectionModeManual(
4682 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4684 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004685
4686 if (!isActiveSubscription(subId)) {
4687 return false;
4688 }
4689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004692 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004693 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004694 if (DBG) {
4695 log("setNetworkSelectionModeManual: subId: " + subId
4696 + " operator: " + operatorInfo);
4697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
4701 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004702 }
4703
4704 /**
4705 * Scans for available networks.
4706 */
4707 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004708 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4709 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4711 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004712 LocationAccessPolicy.LocationPermissionResult locationResult =
4713 LocationAccessPolicy.checkLocationPermission(mApp,
4714 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4715 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004716 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004717 .setCallingPid(Binder.getCallingPid())
4718 .setCallingUid(Binder.getCallingUid())
4719 .setMethod("getCellNetworkScanResults")
4720 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4721 .build());
4722 switch (locationResult) {
4723 case DENIED_HARD:
4724 throw new SecurityException("Not allowed to access scan results -- location");
4725 case DENIED_SOFT:
4726 return null;
4727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728
Pengquan Menga1bb6272018-09-06 09:59:22 -07004729 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 try {
4731 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004732 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004737 }
4738
4739 /**
yinxub1bed742017-04-17 11:45:04 -07004740 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004741 *
yinxub1bed742017-04-17 11:45:04 -07004742 * @param subId id of the subscription
4743 * @param request contains the radio access networks with bands/channels to scan
4744 * @param messenger callback messenger for scan results or errors
4745 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004746 * @return the id of the requested scan which can be used to stop the scan.
4747 */
4748 @Override
4749 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004750 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4752 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004753 LocationAccessPolicy.LocationPermissionResult locationResult =
4754 LocationAccessPolicy.checkLocationPermission(mApp,
4755 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4756 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004757 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004758 .setCallingPid(Binder.getCallingPid())
4759 .setCallingUid(Binder.getCallingUid())
4760 .setMethod("requestNetworkScan")
4761 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4762 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004763 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004764 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004765 if (e != null) {
4766 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4767 throw e;
4768 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004769 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004770 return TelephonyScanManager.INVALID_SCAN_ID;
4771 }
4772 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 }
Hall Liu912dfd32019-04-25 14:02:26 -07004774 int callingUid = Binder.getCallingUid();
4775 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 return mNetworkScanRequestTracker.startNetworkScan(
4779 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004780 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
yinxu504e1392017-04-12 16:03:22 -07004784 }
4785
Hall Liub2ac8ef2019-02-28 15:56:23 -08004786 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004787 NetworkScanRequest request, int subId) {
4788 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4789 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4790 boolean hasNetworkScanPermission =
4791 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4792 == PERMISSION_GRANTED;
4793
4794 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4795 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4796 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004797 }
4798
4799 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4800 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004801 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4802 return new SecurityException("Specific channels must not be"
4803 + " scanned without location access.");
4804 }
4805 }
4806 }
4807
Hall Liub2ac8ef2019-02-28 15:56:23 -08004808 return null;
4809 }
4810
yinxu504e1392017-04-12 16:03:22 -07004811 /**
4812 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004813 *
4814 * @param subId id of the subscription
4815 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004816 */
4817 @Override
4818 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004819 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4820 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821
Hall Liu912dfd32019-04-25 14:02:26 -07004822 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 final long identity = Binder.clearCallingIdentity();
4824 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004825 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 } finally {
4827 Binder.restoreCallingIdentity(identity);
4828 }
yinxu504e1392017-04-12 16:03:22 -07004829 }
4830
4831 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004832 * Get the calculated preferred network type.
4833 * Used for debugging incorrect network type.
4834 *
4835 * @return the preferred network type, defined in RILConstants.java.
4836 */
4837 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004838 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004839 final Phone defaultPhone = getDefaultPhone();
4840 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4841 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004842 return RILConstants.PREFERRED_NETWORK_MODE;
4843 }
4844
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004848 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Junda Liu84d15a22014-07-02 11:21:04 -07004852 }
4853
4854 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004855 * Get the preferred network type.
4856 * Used for device configuration by some CDMA operators.
4857 *
4858 * @return the preferred network type, defined in RILConstants.java.
4859 */
4860 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004861 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004862 TelephonyPermissions
4863 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4864 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865
4866 final long identity = Binder.clearCallingIdentity();
4867 try {
4868 if (DBG) log("getPreferredNetworkType");
4869 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4870 int networkType = (result != null ? result[0] : -1);
4871 if (DBG) log("getPreferredNetworkType: " + networkType);
4872 return networkType;
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
4875 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004876 }
4877
4878 /**
4879 * Set the preferred network type.
4880 * Used for device configuration by some CDMA operators.
4881 *
4882 * @param networkType the preferred network type, defined in RILConstants.java.
4883 * @return true on success; false on any failure.
4884 */
4885 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004886 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4888 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
4892 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4893 Boolean success = (Boolean) sendRequest(
4894 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4895 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4896 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004897 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004898 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4899 }
4900 return success;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004903 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004904 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004905
4906 /**
Miaoa84611c2019-03-15 09:21:10 +08004907 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004908 *
Miaoa84611c2019-03-15 09:21:10 +08004909 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004910 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004911 * @hide
4912 */
4913 @Override
Miaoa84611c2019-03-15 09:21:10 +08004914 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004915 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004917 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 try {
Miaoa84611c2019-03-15 09:21:10 +08004919 if (phone != null) {
4920 return phone.hasMatchedTetherApnSetting();
4921 } else {
4922 return false;
4923 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004926 }
Junda Liu475951f2014-11-07 16:45:03 -08004927 }
4928
4929 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004930 * Set mobile data enabled
4931 * Used by the user through settings etc to turn on/off mobile data
4932 *
4933 * @param enable {@code true} turn turn data on, else {@code false}
4934 */
4935 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004936 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4938 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939
4940 final long identity = Binder.clearCallingIdentity();
4941 try {
4942 int phoneId = mSubscriptionController.getPhoneId(subId);
4943 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4944 Phone phone = PhoneFactory.getPhone(phoneId);
4945 if (phone != null) {
4946 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004947 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004949 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950 }
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004953 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004954 }
4955
4956 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004957 * Get the user enabled state of Mobile Data.
4958 *
4959 * TODO: remove and use isUserDataEnabled.
4960 * This can't be removed now because some vendor codes
4961 * calls through ITelephony directly while they should
4962 * use TelephonyManager.
4963 *
4964 * @return true on enabled
4965 */
4966 @Override
4967 public boolean getDataEnabled(int subId) {
4968 return isUserDataEnabled(subId);
4969 }
4970
4971 /**
4972 * Get whether mobile data is enabled per user setting.
4973 *
4974 * There are other factors deciding whether mobile data is actually enabled, but they are
4975 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004976 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004977 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004978 *
4979 * @return {@code true} if data is enabled else {@code false}
4980 */
4981 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004982 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004983 try {
4984 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4985 null);
4986 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4988 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004989 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 int phoneId = mSubscriptionController.getPhoneId(subId);
4994 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4995 Phone phone = PhoneFactory.getPhone(phoneId);
4996 if (phone != null) {
4997 boolean retVal = phone.isUserDataEnabled();
4998 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4999 return retVal;
5000 } else {
5001 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5002 return false;
5003 }
5004 } finally {
5005 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005006 }
5007 }
5008
5009 /**
5010 * Get whether mobile data is enabled.
5011 *
5012 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5013 * whether mobile data is actually enabled.
5014 *
5015 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5016 *
5017 * @return {@code true} if data is enabled else {@code false}
5018 */
5019 @Override
5020 public boolean isDataEnabled(int subId) {
5021 try {
5022 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5023 null);
5024 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5026 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028
5029 final long identity = Binder.clearCallingIdentity();
5030 try {
5031 int phoneId = mSubscriptionController.getPhoneId(subId);
5032 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5033 Phone phone = PhoneFactory.getPhone(phoneId);
5034 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005035 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5037 return retVal;
5038 } else {
5039 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5040 return false;
5041 }
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005044 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005045 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005046
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005047 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5048 Phone phone) {
5049 //load access rules from carrier configs, and check those as well: b/139133814
5050 SubscriptionController subController = SubscriptionController.getInstance();
5051 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5052 || subController == null) return privilegeFromSim;
5053
5054 int uid = Binder.getCallingUid();
5055 PackageManager pkgMgr = phone.getContext().getPackageManager();
5056 String[] packages = pkgMgr.getPackagesForUid(uid);
5057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5061 SubscriptionManager subManager = (SubscriptionManager)
5062 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5063 for (String pkg : packages) {
5064 if (subManager.canManageSubscription(subInfo, pkg)) {
5065 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5066 }
5067 }
5068 return privilegeFromSim;
5069 } finally {
5070 Binder.restoreCallingIdentity(identity);
5071 }
5072 }
5073
5074 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5075 String pkgName) {
5076 //load access rules from carrier configs, and check those as well: b/139133814
5077 SubscriptionController subController = SubscriptionController.getInstance();
5078 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5079 || subController == null) return privilegeFromSim;
5080
5081 final long identity = Binder.clearCallingIdentity();
5082 try {
5083 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5084 SubscriptionManager subManager = (SubscriptionManager)
5085 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5086 return subManager.canManageSubscription(subInfo, pkgName)
5087 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5088 } finally {
5089 Binder.restoreCallingIdentity(identity);
5090 }
5091 }
5092
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005093 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005094 public int getCarrierPrivilegeStatus(int subId) {
5095 final Phone phone = getPhone(subId);
5096 if (phone == null) {
5097 loge("getCarrierPrivilegeStatus: Invalid subId");
5098 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5099 }
5100 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005101 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005102 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005103 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5104 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005105
5106 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5107 card.getCarrierPrivilegeStatusForCurrentTransaction(
5108 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005109 }
Junda Liu29340342014-07-10 15:23:27 -07005110
5111 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005112 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5113 final Phone phone = getPhone(subId);
5114 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005115 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005116 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5117 }
5118 UiccProfile profile =
5119 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5120 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005121 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005122 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5123 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005124 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5125 profile.getCarrierPrivilegeStatusForUid(
5126 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005127 }
5128
5129 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005130 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5131 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005132 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005133 }
5134
5135 int phoneId = SubscriptionManager.getPhoneId(subId);
5136 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005137 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005138 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005139 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5140 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005141 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5142 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5143 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005144 }
5145
5146 @Override
5147 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005148 if (TextUtils.isEmpty(pkgName))
5149 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005150 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5151 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5152 UiccCard card = UiccController.getInstance().getUiccCard(i);
5153 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005154 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005155 continue;
5156 }
5157
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005158 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5159 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5160 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005161 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5162 break;
5163 }
5164 }
5165
5166 return result;
Junda Liu29340342014-07-10 15:23:27 -07005167 }
Derek Tan89e89d42014-07-08 17:00:10 -07005168
5169 @Override
Junda Liue64de782015-04-16 17:19:16 -07005170 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5171 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5172 loge("phoneId " + phoneId + " is not valid.");
5173 return null;
5174 }
5175 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005176 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005177 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005178 return null ;
5179 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005180 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005181 }
5182
Amith Yamasani6e118872016-02-19 12:53:51 -08005183 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005184 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005185 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005186 List<String> privilegedPackages = new ArrayList<>();
5187 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005188 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5189 // has UICC in that slot.
5190 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005191 if (card.hasCarrierPrivilegeRules()) {
5192 if (packages == null) {
5193 // Only check packages in user 0 for now
5194 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005195 PackageManager.MATCH_DISABLED_COMPONENTS
5196 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005197 | PackageManager.GET_SIGNING_CERTIFICATES,
5198 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005199 }
5200 for (int p = packages.size() - 1; p >= 0; p--) {
5201 PackageInfo pkgInfo = packages.get(p);
5202 if (pkgInfo != null && pkgInfo.packageName != null
5203 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005204 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005205 privilegedPackages.add(pkgInfo.packageName);
5206 }
5207 }
5208 }
5209 }
5210 return privilegedPackages;
5211 }
5212
chen xuf7e9fe82019-05-09 19:31:02 -07005213 @Override
5214 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5215 List<String> privilegedPackages = new ArrayList<>();
5216 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5217 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5218 }
5219 return privilegedPackages;
5220 }
5221
Wink Savilleb564aae2014-10-23 10:18:09 -07005222 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005223 final Phone phone = getPhone(subId);
5224 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005225 if (card == null) {
5226 loge("getIccId: No UICC");
5227 return null;
5228 }
5229 String iccId = card.getIccId();
5230 if (TextUtils.isEmpty(iccId)) {
5231 loge("getIccId: ICC ID is null or empty.");
5232 return null;
5233 }
5234 return iccId;
5235 }
5236
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005237 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005238 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5239 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005240 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5241 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 final String iccId = getIccId(subId);
5246 final Phone phone = getPhone(subId);
5247 if (phone == null) {
5248 return false;
5249 }
5250 final String subscriberId = phone.getSubscriberId();
5251
5252 if (DBG_MERGE) {
5253 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5254 + subscriberId + " to " + number);
5255 }
5256
5257 if (TextUtils.isEmpty(iccId)) {
5258 return false;
5259 }
5260
5261 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5262
5263 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5264 if (alphaTag == null) {
5265 editor.remove(alphaTagPrefKey);
5266 } else {
5267 editor.putString(alphaTagPrefKey, alphaTag);
5268 }
5269
5270 // Record both the line number and IMSI for this ICCID, since we need to
5271 // track all merged IMSIs based on line number
5272 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5273 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5274 if (number == null) {
5275 editor.remove(numberPrefKey);
5276 editor.remove(subscriberPrefKey);
5277 } else {
5278 editor.putString(numberPrefKey, number);
5279 editor.putString(subscriberPrefKey, subscriberId);
5280 }
5281
5282 editor.commit();
5283 return true;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005286 }
Derek Tan7226c842014-07-02 17:42:23 -07005287 }
5288
5289 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005290 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005291 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005293 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005294 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005295 return null;
5296 }
Derek Tan97ebb422014-09-05 16:55:38 -07005297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 final long identity = Binder.clearCallingIdentity();
5299 try {
5300 String iccId = getIccId(subId);
5301 if (iccId != null) {
5302 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5303 if (DBG_MERGE) {
5304 log("getLine1NumberForDisplay returning "
5305 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5306 }
5307 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5310 return null;
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005313 }
Derek Tan7226c842014-07-02 17:42:23 -07005314 }
5315
5316 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005317 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005318 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005319 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005320 return null;
5321 }
Derek Tan97ebb422014-09-05 16:55:38 -07005322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 String iccId = getIccId(subId);
5326 if (iccId != null) {
5327 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5328 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5329 }
5330 return null;
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005333 }
Derek Tan7226c842014-07-02 17:42:23 -07005334 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005335
5336 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005337 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005338 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5339 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005341 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5342 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005343 return null;
5344 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005345
Jordan Liub49b04b2019-05-06 14:45:15 -07005346 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5347 // the process, where TelephonyManager was instantiated.
5348 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005349 final long identity = Binder.clearCallingIdentity();
5350 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005351 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 final TelephonyManager tele = TelephonyManager.from(context);
5353 final SubscriptionManager sub = SubscriptionManager.from(context);
5354
5355 // Figure out what subscribers are currently active
5356 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357
Jordan Liub49b04b2019-05-06 14:45:15 -07005358 // Only consider subs which match the current subId
5359 // This logic can be simplified. See b/131189269 for progress.
5360 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005361 activeSubscriberIds.add(tele.getSubscriberId(subId));
5362 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363
5364 // First pass, find a number override for an active subscriber
5365 String mergeNumber = null;
5366 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5367 for (String key : prefs.keySet()) {
5368 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5369 final String subscriberId = (String) prefs.get(key);
5370 if (activeSubscriberIds.contains(subscriberId)) {
5371 final String iccId = key.substring(
5372 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5373 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5374 mergeNumber = (String) prefs.get(numberKey);
5375 if (DBG_MERGE) {
5376 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5377 + " for active subscriber " + subscriberId);
5378 }
5379 if (!TextUtils.isEmpty(mergeNumber)) {
5380 break;
5381 }
5382 }
5383 }
5384 }
5385
5386 // Shortcut when no active merged subscribers
5387 if (TextUtils.isEmpty(mergeNumber)) {
5388 return null;
5389 }
5390
5391 // Second pass, find all subscribers under that line override
5392 final ArraySet<String> result = new ArraySet<>();
5393 for (String key : prefs.keySet()) {
5394 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5395 final String number = (String) prefs.get(key);
5396 if (mergeNumber.equals(number)) {
5397 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5398 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5399 final String subscriberId = (String) prefs.get(subscriberKey);
5400 if (!TextUtils.isEmpty(subscriberId)) {
5401 result.add(subscriberId);
5402 }
5403 }
5404 }
5405 }
5406
5407 final String[] resultArray = result.toArray(new String[result.size()]);
5408 Arrays.sort(resultArray);
5409 if (DBG_MERGE) {
5410 Slog.d(LOG_TAG,
5411 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5412 }
5413 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005416 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005417 }
5418
5419 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005420 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5421 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5422
5423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 final TelephonyManager telephonyManager = mApp.getSystemService(
5426 TelephonyManager.class);
5427 String subscriberId = telephonyManager.getSubscriberId(subId);
5428 if (subscriberId == null) {
5429 if (DBG) {
5430 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5431 + subId);
5432 }
5433 return null;
5434 }
5435
5436 final SubscriptionInfo info = SubscriptionController.getInstance()
5437 .getSubscriptionInfo(subId);
5438 final ParcelUuid groupUuid = info.getGroupUuid();
5439 // If it doesn't belong to any group, return just subscriberId of itself.
5440 if (groupUuid == null) {
5441 return new String[]{subscriberId};
5442 }
5443
5444 // Get all subscriberIds from the group.
5445 final List<String> mergedSubscriberIds = new ArrayList<>();
5446 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5447 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5448 for (SubscriptionInfo subInfo : groupInfos) {
5449 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5450 if (subscriberId != null) {
5451 mergedSubscriberIds.add(subscriberId);
5452 }
5453 }
5454
5455 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5456 } finally {
5457 Binder.restoreCallingIdentity(identity);
5458
5459 }
5460 }
5461
5462 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005463 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005464 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5465 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466
5467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 final Phone phone = getPhone(subId);
5470 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005474 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005475
5476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005477 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005478 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5479 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005480 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 final Phone phone = getPhone(subId);
5485 if (phone == null) {
5486 return false;
5487 }
5488 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5489 cdmaNonRoamingList);
5490 } finally {
5491 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005492 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005493 }
5494
5495 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005496 @Deprecated
5497 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5498 enforceModifyPermission();
5499
5500 int returnValue = 0;
5501 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005502 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005503 if(result.exception == null) {
5504 if (result.result != null) {
5505 byte[] responseData = (byte[])(result.result);
5506 if(responseData.length > oemResp.length) {
5507 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5508 responseData.length + "bytes. Buffer Size is " +
5509 oemResp.length + "bytes.");
5510 }
5511 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5512 returnValue = responseData.length;
5513 }
5514 } else {
5515 CommandException ex = (CommandException) result.exception;
5516 returnValue = ex.getCommandError().ordinal();
5517 if(returnValue > 0) returnValue *= -1;
5518 }
5519 } catch (RuntimeException e) {
5520 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5521 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5522 if(returnValue > 0) returnValue *= -1;
5523 }
5524
5525 return returnValue;
5526 }
5527
5528 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005529 public void setRadioCapability(RadioAccessFamily[] rafs) {
5530 try {
5531 ProxyController.getInstance().setRadioCapability(rafs);
5532 } catch (RuntimeException e) {
5533 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5534 }
5535 }
5536
5537 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005538 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005539 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005540 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005541 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005542 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005543 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 final long identity = Binder.clearCallingIdentity();
5545 try {
chen xub97461a2018-10-26 14:17:57 -07005546 TelephonyPermissions
5547 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5548 mApp, phone.getSubId(), "getRadioAccessFamily");
5549 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005550 } finally {
5551 Binder.restoreCallingIdentity(identity);
5552 }
chen xub97461a2018-10-26 14:17:57 -07005553 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005554 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005555
5556 @Override
5557 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005558 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005559 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005563 ImsManager.getInstance(defaultPhone.getContext(),
5564 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005568 }
5569
5570 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005571 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005574 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005575 return false;
5576 }
Svet Ganovb320e182015-04-16 12:30:10 -07005577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final long identity = Binder.clearCallingIdentity();
5579 try {
5580 // Check the user preference and the system-level IMS setting. Even if the user has
5581 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5582 // In the long run, we may instead need to check if there exists a connection service
5583 // which can support video calling.
5584 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005585 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586 return imsManager.isVtEnabledByPlatform()
5587 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5588 && imsManager.isVtEnabledByUser();
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
5591 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005592 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005593
Andrew Leea1239f22015-03-02 17:44:07 -08005594 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005595 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5597 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5598 return false;
5599 }
5600
5601 final long identity = Binder.clearCallingIdentity();
5602 try {
5603 CarrierConfigManager configManager =
5604 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005605 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
Andrew Leea1239f22015-03-02 17:44:07 -08005610 }
5611
5612 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 public boolean isWorldPhone(int subId, String callingPackage) {
5614 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5615 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5616 return false;
5617 }
5618
5619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 CarrierConfigManager configManager =
5622 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005623 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5625 } finally {
5626 Binder.restoreCallingIdentity(identity);
5627 }
Andrew Leea1239f22015-03-02 17:44:07 -08005628 }
5629
Andrew Lee9431b832015-03-09 18:46:45 -07005630 @Override
5631 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005632 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005633 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005634 }
5635
5636 @Override
5637 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005640 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Andrew Lee9431b832015-03-09 18:46:45 -07005644 }
5645
Hall Liuf6668912018-10-31 17:05:23 -07005646 /**
5647 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5648 * support for the feature and device firmware support.
5649 *
5650 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5651 */
5652 @Override
5653 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005655 final Phone phone = getPhone(subscriptionId);
5656 if (phone == null) {
5657 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5658 return false;
5659 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005661 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5663 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005664 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665 return isCarrierSupported && isDeviceSupported;
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
Hall Liu98187582018-01-22 19:15:32 -08005669 }
5670
Hall Liuf6668912018-10-31 17:05:23 -07005671 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005672 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5673 * RTT setting, will return true if the device and carrier both support RTT.
5674 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005675 */
5676 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005679 boolean isRttSupported = isRttSupported(subscriptionId);
5680 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005681 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005682 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5683 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5684 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005685 } finally {
5686 Binder.restoreCallingIdentity(identity);
5687 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005688 }
5689
Sanket Padawe7310cc72015-01-14 09:53:20 -08005690 /**
5691 * Returns the unique device ID of phone, for example, the IMEI for
5692 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5693 *
5694 * <p>Requires Permission:
5695 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5696 */
5697 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005698 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005699 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005700 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005701 return null;
5702 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005703 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005704 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5705 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005706 return null;
5707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
5710 try {
5711 return phone.getDeviceId();
5712 } finally {
5713 Binder.restoreCallingIdentity(identity);
5714 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005715 }
5716
Ping Sunc67b7c22016-03-02 19:16:45 +08005717 /**
5718 * {@hide}
5719 * Returns the IMS Registration Status on a particular subid
5720 *
5721 * @param subId
5722 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005723 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005724 Phone phone = getPhone(subId);
5725 if (phone != null) {
5726 return phone.isImsRegistered();
5727 } else {
5728 return false;
5729 }
5730 }
5731
Santos Cordon7a1885b2015-02-03 11:15:19 -08005732 @Override
5733 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005734 final long identity = Binder.clearCallingIdentity();
5735 try {
5736 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005740 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005741
Tyler Gunnf70ed162019-04-03 15:28:53 -07005742 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005743 public int getSubIdForPhoneAccountHandle(
5744 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5746 callingPackage, "getSubIdForPhoneAccountHandle")) {
5747 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5748 }
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
5754 }
5755 }
5756
5757 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005758 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 Phone phone = getPhone(subscriptionId);
5762 if (phone == null) {
5763 return null;
5764 }
5765 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005771 /**
5772 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005773 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005774 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 Phone phone = getPhone(subId);
5778 if (phone != null) {
5779 return phone.isWifiCallingEnabled();
5780 } else {
5781 return false;
5782 }
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005785 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005786 }
5787
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005788 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005789 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005790 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005791 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005792 final long identity = Binder.clearCallingIdentity();
5793 try {
5794 Phone phone = getPhone(subId);
5795 if (phone != null) {
5796 return phone.isVideoEnabled();
5797 } else {
5798 return false;
5799 }
5800 } finally {
5801 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005802 }
5803 }
5804
5805 /**
5806 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5807 * defined in {@link ImsRegistrationImplBase}.
5808 */
5809 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 Phone phone = getPhone(subId);
5813 if (phone != null) {
5814 return phone.getImsRegistrationTech();
5815 } else {
5816 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5817 }
5818 } finally {
5819 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005820 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005821 }
5822
Stuart Scott8eef64f2015-04-08 15:13:54 -07005823 @Override
5824 public void factoryReset(int subId) {
5825 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005826 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5827 return;
5828 }
5829
Svet Ganovcc087f82015-05-12 20:35:54 -07005830 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831
Svet Ganovcc087f82015-05-12 20:35:54 -07005832 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005833 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5834 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005835 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005836 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005837 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005838 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5839 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005840 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005841 // There has been issues when Sms raw table somehow stores orphan
5842 // fragments. They lead to garbled message when new fragments come
5843 // in and combined with those stale ones. In case this happens again,
5844 // user can reset all network settings which will clean up this table.
5845 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005846 // Clean up IMS settings as well here.
5847 int slotId = getSlotIndex(subId);
5848 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5849 ImsManager.getInstance(mApp, slotId).factoryReset();
5850 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005853 }
5854 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005855
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005856 private void cleanUpSmsRawTable(Context context) {
5857 ContentResolver resolver = context.getContentResolver();
5858 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5859 resolver.delete(uri, null, null);
5860 }
5861
Narayan Kamath1c496c22015-04-16 14:40:19 +01005862 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005863 public String getSimLocaleForSubscriber(int subId) {
5864 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5865 final Phone phone = getPhone(subId);
5866 if (phone == null) {
5867 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005868 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005869 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005870 final long identity = Binder.clearCallingIdentity();
5871 try {
chen xu5d3637b2019-01-21 23:31:38 -08005872 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5873 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005874 if (info == null) {
5875 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5876 return null;
5877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 // Try and fetch the locale from the carrier properties or from the SIM language
5879 // preferences (EF-PL and EF-LI)...
5880 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005882 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5883 if (localeFromDefaultSim != null) {
5884 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5885 if (DBG) log("Using locale from subId: " + subId + " locale: "
5886 + localeFromDefaultSim);
5887 return localeFromDefaultSim.toLanguageTag();
5888 } else {
5889 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 }
5891 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 // The SIM language preferences only store a language (e.g. fr = French), not an
5894 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5895 // the SIM and carrier preferences does not include a country we add the country
5896 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005897 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005899 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 return mccLocale.toLanguageTag();
5901 }
5902
5903 if (DBG) log("No locale found - returning null");
5904 return null;
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005908 }
5909
5910 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005911 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005912 }
5913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005914 /**
5915 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5916 */
5917 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005918 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005919 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005920
Chenjie Yu1ba97252018-01-11 18:16:20 -08005921 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005922 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005923
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005924 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005925 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5926 * representing the state of the modem.
5927 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005928 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5929 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005930 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005931 */
5932 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005933 public void requestModemActivityInfo(ResultReceiver result) {
5934 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005935 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005936
5937 final long identity = Binder.clearCallingIdentity();
5938 try {
5939 ModemActivityInfo ret = null;
5940 synchronized (mLastModemActivityInfo) {
5941 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5942 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005943 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005944 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005945 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005946 int[] txTimeMs = info.getTransmitTimeMillis();
5947 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005948 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005949 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 }
5951 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005952 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5953 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 mLastModemActivityInfo.setIdleTimeMillis(
5955 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005956 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5957 mLastModemActivityInfo.setReceiveTimeMillis(
5958 info.getReceiveTimeMillis() + mLastModemActivityInfo
5959 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005960 }
Chen Xud78231e2019-09-10 18:49:52 -07005961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5963 mLastModemActivityInfo.getSleepTimeMillis(),
5964 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005965 mLastModemActivityInfo.getTransmitTimeMillis(),
5966 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 Bundle bundle = new Bundle();
5969 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5970 result.send(0, bundle);
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005973 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005974 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005975
Siddharth Rayb8114062018-06-17 15:02:38 -07005976 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5977 // less than total activity duration.
5978 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5979 if (info == null) {
5980 return false;
5981 }
5982 int activityDurationMs =
5983 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5984 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005985 int[] txTimeMs = info.getTransmitTimeMillis();
5986 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5987 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005988 }
5989 return (info.isValid()
5990 && (info.getSleepTimeMillis() <= activityDurationMs)
5991 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005992 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005993 && (totalTxTimeMs <= activityDurationMs));
5994 }
5995
Jack Yu85bd38a2015-11-09 11:34:32 -08005996 /**
5997 * {@hide}
5998 * Returns the service state information on specified subscription.
5999 */
6000 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006001 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6002 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006004 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006005 return null;
6006 }
6007
Hall Liuf19c44f2018-11-27 14:38:17 -08006008 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6009 LocationAccessPolicy.checkLocationPermission(mApp,
6010 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6011 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006012 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006013 .setCallingPid(Binder.getCallingPid())
6014 .setCallingUid(Binder.getCallingUid())
6015 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006016 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006017 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6018 .build());
6019
6020 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6021 LocationAccessPolicy.checkLocationPermission(mApp,
6022 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6023 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006024 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006025 .setCallingPid(Binder.getCallingPid())
6026 .setCallingUid(Binder.getCallingUid())
6027 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006028 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006029 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6030 .build());
6031 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6032 boolean hasFinePermission =
6033 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6034 boolean hasCoarsePermission =
6035 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6036
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 final Phone phone = getPhone(subId);
6040 if (phone == null) {
6041 return null;
6042 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006043
Hall Liuf19c44f2018-11-27 14:38:17 -08006044 ServiceState ss = phone.getServiceState();
6045
6046 // Scrub out the location info in ServiceState depending on what level of access
6047 // the caller has.
6048 if (hasFinePermission) return ss;
6049 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6050 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 } finally {
6052 Binder.restoreCallingIdentity(identity);
6053 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006055
6056 /**
6057 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6058 *
6059 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6060 * voicemail ringtone.
6061 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6062 * PhoneAccount.
6063 */
6064 @Override
6065 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 final long identity = Binder.clearCallingIdentity();
6067 try {
6068 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6069 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006070 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006071 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006073 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006077 }
6078
6079 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006080 * Sets the per-account voicemail ringtone.
6081 *
6082 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6083 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6084 *
6085 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6086 * voicemail ringtone.
6087 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6088 * PhoneAccount.
6089 */
6090 @Override
6091 public void setVoicemailRingtoneUri(String callingPackage,
6092 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006093 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006094 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6095 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006096 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6098 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6099 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006100 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6105 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 }
6108 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006111 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006112 }
6113
6114 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006115 * Returns whether vibration is set for voicemail notification in Phone settings.
6116 *
6117 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6118 * voicemail vibration setting.
6119 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6120 */
6121 @Override
6122 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6126 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006127 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
6133 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006134 }
6135
Youhan Wange64578a2016-05-02 15:32:42 -07006136 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006137 * Sets the per-account voicemail vibration.
6138 *
6139 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6140 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6141 *
6142 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6143 * voicemail vibration setting.
6144 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6145 * specific PhoneAccount.
6146 */
6147 @Override
6148 public void setVoicemailVibrationEnabled(String callingPackage,
6149 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006150 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006151 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6152 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006153 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6155 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6156 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006157 }
6158
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 final long identity = Binder.clearCallingIdentity();
6160 try {
6161 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6162 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006163 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164 }
6165 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6166 } finally {
6167 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006168 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006169 }
6170
6171 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006172 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6173 *
6174 * @throws SecurityException if the caller does not have the required permission
6175 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006176 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006177 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006178 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006179 }
6180
6181 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006182 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6183 * permission.
6184 *
6185 * @throws SecurityException if the caller does not have the required permission
6186 */
6187 private void enforceSendSmsPermission() {
6188 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6189 }
6190
6191 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006192 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006193 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006194 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006195 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006196 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 final long identity = Binder.clearCallingIdentity();
6198 try {
6199 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006201 if (componentName == null) {
6202 throw new SecurityException(
6203 "Caller not current active visual voicemail package[null]");
6204 }
6205 String vvmPackage = componentName.getPackageName();
6206 if (!callingPackage.equals(vvmPackage)) {
6207 throw new SecurityException("Caller not current active visual voicemail package["
6208 + vvmPackage + "]");
6209 }
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006212 }
6213 }
6214
6215 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006216 * Return the application ID for the app type.
6217 *
6218 * @param subId the subscription ID that this request applies to.
6219 * @param appType the uicc app type.
6220 * @return Application ID for specificied app type, or null if no uicc.
6221 */
6222 @Override
6223 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006224 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006225 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
6227 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006228 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 if (phone == null) {
6230 return null;
6231 }
6232 String aid = null;
6233 try {
6234 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6235 .getApplicationByType(appType).getAid();
6236 } catch (Exception e) {
6237 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6238 }
6239 return aid;
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006242 }
Youhan Wange64578a2016-05-02 15:32:42 -07006243 }
6244
Youhan Wang4001d252016-05-11 10:29:41 -07006245 /**
6246 * Return the Electronic Serial Number.
6247 *
6248 * @param subId the subscription ID that this request applies to.
6249 * @return ESN or null if error.
6250 */
6251 @Override
6252 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006253 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006254 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255
6256 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006257 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258 if (phone == null) {
6259 return null;
6260 }
6261 String esn = null;
6262 try {
6263 esn = phone.getEsn();
6264 } catch (Exception e) {
6265 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6266 }
6267 return esn;
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006270 }
Youhan Wang4001d252016-05-11 10:29:41 -07006271 }
6272
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006273 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006274 * Return the Preferred Roaming List Version.
6275 *
6276 * @param subId the subscription ID that this request applies to.
6277 * @return PRLVersion or null if error.
6278 */
6279 @Override
6280 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006281 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006282 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283
6284 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006285 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006286 if (phone == null) {
6287 return null;
6288 }
6289 String cdmaPrlVersion = null;
6290 try {
6291 cdmaPrlVersion = phone.getCdmaPrlVersion();
6292 } catch (Exception e) {
6293 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6294 }
6295 return cdmaPrlVersion;
6296 } finally {
6297 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006298 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006299 }
6300
6301 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006302 * Get snapshot of Telephony histograms
6303 * @return List of Telephony histograms
6304 * @hide
6305 */
6306 @Override
6307 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006308 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6309 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 return RIL.getTelephonyRILTimingHistograms();
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006317 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006318
6319 /**
6320 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006321 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6322 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006323 * Require system privileges. In the future we may add this to carrier APIs.
6324 *
Michele Berionne482f8202018-11-27 18:57:59 -08006325 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006326 */
6327 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006328 @TelephonyManager.SetCarrierRestrictionResult
6329 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006330 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006331 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006332
Michele Berionne482f8202018-11-27 18:57:59 -08006333 if (carrierRestrictionRules == null) {
6334 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006335 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
6338 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006339 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006340 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 } finally {
6342 Binder.restoreCallingIdentity(identity);
6343 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006344 }
6345
6346 /**
6347 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006348 * Get the allowed carrier list and the excluded carrier list, including the priority between
6349 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006350 * Require system privileges. In the future we may add this to carrier APIs.
6351 *
Michele Berionne482f8202018-11-27 18:57:59 -08006352 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006353 */
6354 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006355 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006356 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358
6359 final long identity = Binder.clearCallingIdentity();
6360 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006361 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6362 if (response instanceof CarrierRestrictionRules) {
6363 return (CarrierRestrictionRules) response;
6364 }
6365 // Response is an Exception of some kind,
6366 // which is signalled to the user as a NULL retval
6367 return null;
6368 } catch (Exception e) {
6369 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6370 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006374 }
6375
fionaxu59545b42016-05-25 15:53:37 -07006376 /**
6377 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6378 * @param subId the subscription ID that this action applies to.
6379 * @param enabled control enable or disable metered apns.
6380 * {@hide}
6381 */
6382 @Override
6383 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6384 enforceModifyPermission();
6385 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006386
6387 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006388 if (phone == null) {
6389 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6390 return;
6391 }
6392 try {
6393 phone.carrierActionSetMeteredApnsEnabled(enabled);
6394 } catch (Exception e) {
6395 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 } finally {
6397 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006398 }
6399 }
6400
6401 /**
6402 * Action set from carrier signalling broadcast receivers to enable/disable radio
6403 * @param subId the subscription ID that this action applies to.
6404 * @param enabled control enable or disable radio.
6405 * {@hide}
6406 */
6407 @Override
6408 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6409 enforceModifyPermission();
6410 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411
6412 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006413 if (phone == null) {
6414 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6415 return;
6416 }
6417 try {
6418 phone.carrierActionSetRadioEnabled(enabled);
6419 } catch (Exception e) {
6420 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 } finally {
6422 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006423 }
6424 }
6425
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006426 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006427 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6428 * network status based on which carrier apps could apply actions accordingly,
6429 * enable/disable default url handler for example.
6430 *
6431 * @param subId the subscription ID that this action applies to.
6432 * @param report control start/stop reporting the default network status.
6433 * {@hide}
6434 */
6435 @Override
6436 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6437 enforceModifyPermission();
6438 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439
6440 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006441 if (phone == null) {
6442 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6443 return;
6444 }
6445 try {
6446 phone.carrierActionReportDefaultNetworkStatus(report);
6447 } catch (Exception e) {
6448 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 } finally {
6450 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006451 }
6452 }
6453
6454 /**
fionaxud9622282017-07-17 17:51:30 -07006455 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6456 * @param subId the subscription ID that this action applies to.
6457 * {@hide}
6458 */
6459 @Override
6460 public void carrierActionResetAll(int subId) {
6461 enforceModifyPermission();
6462 final Phone phone = getPhone(subId);
6463 if (phone == null) {
6464 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6465 return;
6466 }
6467 try {
6468 phone.carrierActionResetAll();
6469 } catch (Exception e) {
6470 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6471 }
6472 }
6473
6474 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006475 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6476 * bug report is being generated.
6477 */
6478 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006479 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006480 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6481 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006482 writer.println("Permission Denial: can't dump Phone from pid="
6483 + Binder.getCallingPid()
6484 + ", uid=" + Binder.getCallingUid()
6485 + "without permission "
6486 + android.Manifest.permission.DUMP);
6487 return;
6488 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006489 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006490 }
Jack Yueb89b242016-06-22 13:27:47 -07006491
Brad Ebingerdac2f002018-04-03 15:17:52 -07006492 @Override
6493 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6494 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6495 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006496 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6497 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006498 }
6499
Jack Yueb89b242016-06-22 13:27:47 -07006500 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006501 * Get aggregated video call data usage since boot.
6502 *
6503 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6504 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006505 * {@hide}
6506 */
6507 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006508 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006509 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6510 null);
6511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
6514 // NetworkStatsService keeps tracking the active network interface and identity. It
6515 // records the delta with the corresponding network identity.
6516 // We just return the total video call data usage snapshot since boot.
6517 Phone phone = getPhone(subId);
6518 if (phone != null) {
6519 return phone.getVtDataUsage(perUidStats);
6520 }
6521 return null;
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006524 }
Jack Yueb89b242016-06-22 13:27:47 -07006525 }
Jack Yu75ab2952016-07-08 14:29:33 -07006526
6527 /**
6528 * Policy control of data connection. Usually used when data limit is passed.
6529 * @param enabled True if enabling the data, otherwise disabling.
6530 * @param subId Subscription index
6531 * {@hide}
6532 */
6533 @Override
6534 public void setPolicyDataEnabled(boolean enabled, int subId) {
6535 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 Phone phone = getPhone(subId);
6540 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006541 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 }
6543 } finally {
6544 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006545 }
6546 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006547
6548 /**
6549 * Get Client request stats
6550 * @return List of Client Request Stats
6551 * @hide
6552 */
6553 @Override
6554 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006556 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006557 return null;
6558 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006559 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006560
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006561 final long identity = Binder.clearCallingIdentity();
6562 try {
6563 if (phone != null) {
6564 return phone.getClientRequestStats();
6565 }
6566
6567 return null;
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006571 }
6572
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006573 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006574 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006575 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006576 }
Jack Yueb4124c2017-02-16 15:32:43 -08006577
6578 /**
Grace Chen70990072017-03-24 17:21:30 -07006579 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006580 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006581 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006582 * @param state State of SIM (power down, power up, pass through)
6583 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6584 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6585 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006586 *
6587 **/
6588 @Override
Grace Chen70990072017-03-24 17:21:30 -07006589 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006590 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006591 Phone phone = PhoneFactory.getPhone(slotIndex);
6592
vagdeviaf9a5b92018-08-15 16:01:53 -07006593 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006598 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 }
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006602 }
6603 }
Shuo Qiandd210312017-04-12 22:11:33 +00006604
Tyler Gunn65d45c22017-06-05 11:22:26 -07006605 private boolean isUssdApiAllowed(int subId) {
6606 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006607 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006608 if (configManager == null) {
6609 return false;
6610 }
6611 PersistableBundle pb = configManager.getConfigForSubId(subId);
6612 if (pb == null) {
6613 return false;
6614 }
6615 return pb.getBoolean(
6616 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6617 }
6618
Shuo Qiandd210312017-04-12 22:11:33 +00006619 /**
6620 * Check if phone is in emergency callback mode
6621 * @return true if phone is in emergency callback mode
6622 * @param subId sub id
6623 */
goneil9c5f4872017-12-05 14:07:56 -08006624 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006625 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006626 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006627 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006628
6629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 if (phone != null) {
6632 return phone.isInEcm();
6633 } else {
6634 return false;
6635 }
6636 } finally {
6637 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006638 }
6639 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006640
6641 /**
6642 * Get the current signal strength information for the given subscription.
6643 * Because this information is not updated when the device is in a low power state
6644 * it should not be relied-upon to be current.
6645 * @param subId Subscription index
6646 * @return the most recent cached signal strength info from the modem
6647 */
6648 @Override
6649 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 Phone p = getPhone(subId);
6653 if (p == null) {
6654 return null;
6655 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006656
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006657 return p.getSignalStrength();
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006661 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006662
Pengquan Meng77b7f132018-08-22 14:49:57 -07006663 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006664 * Get the current modem radio state for the given slot.
6665 * @param slotIndex slot index.
6666 * @param callingPackage the name of the package making the call.
6667 * @return the current radio power state from the modem
6668 */
6669 @Override
6670 public int getRadioPowerState(int slotIndex, String callingPackage) {
6671 Phone phone = PhoneFactory.getPhone(slotIndex);
6672 if (phone != null) {
6673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6674 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6675 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6676 }
6677
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 return phone.getRadioPowerState();
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 }
6685 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6686 }
6687
6688 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006689 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6690 *
6691 * <p>Requires one of the following permissions:
6692 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6693 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6694 * privileges.
6695 *
6696 * @param subId subscription id
6697 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6698 * {@code false}.
6699 */
6700 @Override
6701 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006702 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6703 null /* message */);
6704
Pengquan Menga1bb6272018-09-06 09:59:22 -07006705 boolean isEnabled = false;
6706 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006707 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006708 Phone phone = getPhone(subId);
6709 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006710 } catch (Exception e) {
6711 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6712 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006713 } finally {
6714 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006715 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006716 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006717 }
6718
6719
6720 /**
6721 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6722 *
6723 * <p> Requires permission:
6724 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6725 * privileges.
6726 *
6727 * @param subId subscription id
6728 * @param isEnabled {@code true} means enable, {@code false} means disable.
6729 */
6730 @Override
6731 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6733 mApp, subId, "setDataRoamingEnabled");
6734
Pengquan Menga1bb6272018-09-06 09:59:22 -07006735 final long identity = Binder.clearCallingIdentity();
6736 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006737 Phone phone = getPhone(subId);
6738 if (phone != null) {
6739 phone.setDataRoamingEnabled(isEnabled);
6740 }
6741 } finally {
6742 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006743 }
6744 }
6745
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006746 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006747 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006748 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6749 mApp, subId, "isManualNetworkSelectionAllowed");
6750
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006751 boolean isAllowed = true;
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006754 Phone phone = getPhone(subId);
6755 if (phone != null) {
6756 isAllowed = phone.isCspPlmnEnabled();
6757 }
6758 } finally {
6759 Binder.restoreCallingIdentity(identity);
6760 }
6761 return isAllowed;
6762 }
6763
6764 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006765 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006766 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006767 try {
6768 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006769 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006770 } catch (SecurityException e) {
6771 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6772 // has carrier privileges on an active UICC
6773 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6774 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006775 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006776 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006777 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006781 UiccController uiccController = UiccController.getInstance();
6782 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006783 if (hasReadPermission) {
6784 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006785 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006786
6787 // Remove private info if the caller doesn't have access
6788 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6789 for (UiccCardInfo cardInfo : cardInfos) {
6790 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6791 // is available
6792 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6793 if (card == null || card.getUiccProfile() == null) {
6794 // assume no access if the card or profile is unavailable
6795 filteredInfos.add(cardInfo.getUnprivileged());
6796 continue;
6797 }
6798 UiccProfile profile = card.getUiccProfile();
6799 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6800 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6801 filteredInfos.add(cardInfo);
6802 } else {
6803 filteredInfos.add(cardInfo.getUnprivileged());
6804 }
6805 }
6806 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006807 } finally {
6808 Binder.restoreCallingIdentity(identity);
6809 }
6810 }
6811
6812 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006813 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006814 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6819 if (slots == null) {
6820 Rlog.i(LOG_TAG, "slots is null.");
6821 return null;
6822 }
6823
6824 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6825 for (int i = 0; i < slots.length; i++) {
6826 UiccSlot slot = slots[i];
6827 if (slot == null) {
6828 continue;
6829 }
6830
Jordan Liu7be7e652019-05-06 18:55:02 +00006831 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 UiccCard card = slot.getUiccCard();
6833 if (card != null) {
6834 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006835 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006836 cardId = slot.getEid();
6837 if (TextUtils.isEmpty(cardId)) {
6838 cardId = slot.getIccId();
6839 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 }
6841
Jordan Liu857451f2019-05-09 16:35:35 -07006842 if (cardId != null) {
6843 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6844 // if cardId is an EID, it's all digits so this is fine
6845 cardId = IccUtils.stripTrailingFs(cardId);
6846 }
6847
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006848 int cardState = 0;
6849 switch (slot.getCardState()) {
6850 case CARDSTATE_ABSENT:
6851 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6852 break;
6853 case CARDSTATE_PRESENT:
6854 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6855 break;
6856 case CARDSTATE_ERROR:
6857 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6858 break;
6859 case CARDSTATE_RESTRICTED:
6860 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6861 break;
6862 default:
6863 break;
6864
6865 }
6866
6867 infos[i] = new UiccSlotInfo(
6868 slot.isActive(),
6869 slot.isEuicc(),
6870 cardId,
6871 cardState,
6872 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006873 slot.isExtendedApduSupported(),
6874 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 }
6876 return infos;
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006879 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006880 }
6881
6882 @Override
6883 public boolean switchSlots(int[] physicalSlots) {
6884 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885
6886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006892 }
Jack Yu4c988042018-02-27 15:30:01 -08006893
6894 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006895 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006896 final long identity = Binder.clearCallingIdentity();
6897 try {
6898 return UiccController.getInstance().getCardIdForDefaultEuicc();
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
6901 }
6902 }
6903
6904 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006905 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6906 enforceModifyPermission();
6907 final Phone phone = getPhone(subId);
6908 if (phone == null) {
6909 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6910 return;
6911 }
6912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 phone.setRadioIndicationUpdateMode(filters, mode);
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
Jack Yu4c988042018-02-27 15:30:01 -08006919 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006920
6921 /**
goneil47ffb6e2018-04-06 15:40:58 -07006922 * A test API to reload the UICC profile.
6923 *
6924 * <p>Requires that the calling app has permission
6925 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6926 * @hide
6927 */
6928 @Override
6929 public void refreshUiccProfile(int subId) {
6930 enforceModifyPermission();
6931
6932 final long identity = Binder.clearCallingIdentity();
6933 try {
6934 Phone phone = getPhone(subId);
6935 if (phone == null) {
6936 return;
6937 }
6938 UiccCard uiccCard = phone.getUiccCard();
6939 if (uiccCard == null) {
6940 return;
6941 }
6942 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6943 if (uiccProfile == null) {
6944 return;
6945 }
6946 uiccProfile.refresh();
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
6949 }
6950 }
6951
6952 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006953 * Returns false if the mobile data is disabled by default, otherwise return true.
6954 */
6955 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006956 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006957 }
6958
6959 /**
6960 * Returns true if the data roaming is enabled by default, i.e the system property
6961 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6962 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6963 */
6964 private boolean getDefaultDataRoamingEnabled(int subId) {
6965 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006966 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09006967 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006968 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6969 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6970 return isDataRoamingEnabled;
6971 }
6972
6973 /**
6974 * Returns the default network type for the given {@code subId}, if the default network type is
6975 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6976 */
6977 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006978 List<Integer> list = TelephonyProperties.default_network();
6979 int phoneId = mSubscriptionController.getPhoneId(subId);
6980 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
6981 return list.get(phoneId);
6982 }
6983 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07006984 }
fionaxua13278b2018-03-21 00:08:13 -07006985
6986 @Override
6987 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006988 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006989 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990
6991 final long identity = Binder.clearCallingIdentity();
6992 try {
6993 final Phone phone = getPhone(subId);
6994 if (phone == null) {
6995 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6996 return;
6997 }
chen xueaba88a2019-03-15 13:15:10 -07006998 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6999 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 } finally {
7001 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007002 }
fionaxua13278b2018-03-21 00:08:13 -07007003 }
7004
7005 @Override
7006 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007007 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008
7009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 final Phone phone = getPhone(subId);
7012 if (phone == null) {
7013 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7014 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7015 }
7016 return phone.getCarrierIdListVersion();
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007019 }
fionaxua13278b2018-03-21 00:08:13 -07007020 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007021
7022 @Override
7023 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7025 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7026 return -1;
7027 }
7028
7029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7032 } finally {
7033 Binder.restoreCallingIdentity(identity);
7034 }
7035 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007036
7037 @Override
7038 public int getCdmaRoamingMode(int subId) {
7039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7040 mApp, subId, "getCdmaRoamingMode");
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
7048 }
7049
7050 @Override
7051 public boolean setCdmaRoamingMode(int subId, int mode) {
7052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7053 mApp, subId, "setCdmaRoamingMode");
7054
7055 final long identity = Binder.clearCallingIdentity();
7056 try {
7057 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
7061 }
7062
7063 @Override
7064 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7066 mApp, subId, "setCdmaSubscriptionMode");
7067
7068 final long identity = Binder.clearCallingIdentity();
7069 try {
7070 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
7074 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007075
sqianc5eccab2018-10-19 18:46:41 -07007076 @Override
sqian8c685422019-02-22 15:55:18 -08007077 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007078 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007079 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007080 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007081 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7082 }
7083 final long identity = Binder.clearCallingIdentity();
7084 try {
sqian854d44b2018-12-12 16:48:18 -08007085 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7086 for (Phone phone: PhoneFactory.getPhones()) {
7087 if (phone.getEmergencyNumberTracker() != null
7088 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7089 emergencyNumberListInternal.put(
7090 phone.getSubId(),
7091 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7092 }
sqian11b7a0e2018-12-05 18:48:28 -08007093 }
sqian854d44b2018-12-12 16:48:18 -08007094 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
sqianc5eccab2018-10-19 18:46:41 -07007098 }
7099
7100 @Override
sqian8c685422019-02-22 15:55:18 -08007101 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007102 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007103 if (!exactMatch) {
7104 TelephonyPermissions
7105 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007106 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007107 }
7108 final long identity = Binder.clearCallingIdentity();
7109 try {
sqian854d44b2018-12-12 16:48:18 -08007110 for (Phone phone: PhoneFactory.getPhones()) {
7111 if (phone.getEmergencyNumberTracker() != null
7112 && phone.getEmergencyNumberTracker() != null) {
7113 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7114 number, exactMatch)) {
7115 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007116 }
7117 }
sqian11b7a0e2018-12-05 18:48:28 -08007118 }
7119 return false;
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
7123 }
7124
sqianf4ca7ed2019-01-15 18:32:07 -08007125 /**
7126 * Update emergency number list for test mode.
7127 */
7128 @Override
7129 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7130 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7131 "updateEmergencyNumberListTestMode");
7132
7133 final long identity = Binder.clearCallingIdentity();
7134 try {
7135 for (Phone phone: PhoneFactory.getPhones()) {
7136 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7137 if (tracker != null) {
7138 tracker.executeEmergencyNumberTestModeCommand(action, num);
7139 }
7140 }
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
7145
7146 /**
7147 * Get the full emergency number list for test mode.
7148 */
7149 @Override
7150 public List<String> getEmergencyNumberListTestMode() {
7151 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7152 "getEmergencyNumberListTestMode");
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 Set<String> emergencyNumbers = new HashSet<>();
7157 for (Phone phone: PhoneFactory.getPhones()) {
7158 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7159 if (tracker != null) {
7160 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7161 emergencyNumbers.add(num.getNumber());
7162 }
7163 }
7164 }
7165 return new ArrayList<>(emergencyNumbers);
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
7168 }
7169 }
7170
chen xud6b45bd2018-10-30 22:27:10 -07007171 @Override
7172 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7173 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7174 Phone phone = getPhone(subId);
7175 if (phone == null) {
7176 return null;
7177 }
7178 final long identity = Binder.clearCallingIdentity();
7179 try {
7180 UiccProfile profile = UiccController.getInstance()
7181 .getUiccProfileForPhone(phone.getPhoneId());
7182 if (profile != null) {
7183 return profile.getCertsFromCarrierPrivilegeAccessRules();
7184 }
7185 } finally {
7186 Binder.restoreCallingIdentity(identity);
7187 }
7188 return null;
7189 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007190
7191 /**
7192 * Enable or disable a modem stack.
7193 */
7194 @Override
7195 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7196 enforceModifyPermission();
7197
7198 final long identity = Binder.clearCallingIdentity();
7199 try {
7200 Phone phone = PhoneFactory.getPhone(slotIndex);
7201 if (phone == null) {
7202 return false;
7203 } else {
7204 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7205 }
7206 } finally {
7207 Binder.restoreCallingIdentity(identity);
7208 }
7209 }
Michelecea4cf22018-12-21 15:00:11 -08007210
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007211 /**
7212 * Whether a modem stack is enabled or not.
7213 */
7214 @Override
7215 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7216 Phone phone = PhoneFactory.getPhone(slotIndex);
7217 if (phone == null) return false;
7218
7219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7220 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7221 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7222 }
7223
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007226 try {
7227 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7228 } catch (NoSuchElementException ex) {
7229 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7230 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
7235
Michelecea4cf22018-12-21 15:00:11 -08007236 @Override
Michele0ea7d782019-03-19 14:58:42 -07007237 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007238 enforceModifyPermission();
7239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007243 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007244 .commit();
7245 } finally {
7246 Binder.restoreCallingIdentity(identity);
7247 }
7248 }
7249
7250 @Override
Michele0ea7d782019-03-19 14:58:42 -07007251 @TelephonyManager.IsMultiSimSupportedResult
7252 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007253 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007254 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7255 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007256 }
Michelecea4cf22018-12-21 15:00:11 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
Michele0ea7d782019-03-19 14:58:42 -07007260 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
7263 }
7264 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007265
Michele0ea7d782019-03-19 14:58:42 -07007266 @TelephonyManager.IsMultiSimSupportedResult
7267 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007268 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7269 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7270 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007271 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7272 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007273 }
7274 // Check if the hardware supports multisim functionality. If usage of multisim is not
7275 // supported by the modem, indicate that it is restricted.
7276 PhoneCapability staticCapability =
7277 mPhoneConfigurationManager.getStaticPhoneCapability();
7278 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007279 loge("isMultiSimSupportedInternal: no static configuration available");
7280 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007281 }
7282 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007283 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7284 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007285 }
7286 // Check if support of multiple SIMs is restricted by carrier
7287 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007288 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007289 }
7290
Michele0ea7d782019-03-19 14:58:42 -07007291 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007292 }
7293
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007294 /**
7295 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007296 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7297 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7298 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007299 * @param numOfSims number of active sims we want to switch to
7300 */
7301 @Override
7302 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007303 if (numOfSims == 1) {
7304 enforceModifyPermission();
7305 } else {
7306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7307 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7308 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007309 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007310
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007311 try {
Michele30b57b22019-03-01 12:01:14 -08007312 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007313 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007314 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7315 return;
7316 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007317 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
7320 }
7321 }
7322
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007323 @Override
7324 public boolean isApplicationOnUicc(int subId, int appType) {
7325 enforceReadPrivilegedPermission("isApplicationOnUicc");
7326 Phone phone = getPhone(subId);
7327 if (phone == null) {
7328 return false;
7329 }
7330 final long identity = Binder.clearCallingIdentity();
7331 try {
7332 UiccCard uiccCard = phone.getUiccCard();
7333 if (uiccCard == null) {
7334 return false;
7335 }
7336 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7337 if (uiccProfile == null) {
7338 return false;
7339 }
7340 if (TelephonyManager.APPTYPE_SIM <= appType
7341 && appType <= TelephonyManager.APPTYPE_ISIM) {
7342 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7343 }
7344 return false;
7345 } finally {
7346 Binder.restoreCallingIdentity(identity);
7347 }
7348 }
7349
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007350 /**
chen xub4baa772019-04-03 10:23:41 -07007351 * Get whether making changes to modem configurations will trigger reboot.
7352 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007353 */
7354 @Override
chen xub4baa772019-04-03 10:23:41 -07007355 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7357 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7358 return false;
7359 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7363 } finally {
7364 Binder.restoreCallingIdentity(identity);
7365 }
7366 }
7367
Nathan Harold29f5f052019-02-15 13:41:57 -08007368 private void updateModemStateMetrics() {
7369 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7370 // TODO: check the state for each modem if the api is ready.
7371 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7372 }
7373
Pengquan Meng3889a572019-01-23 11:16:29 -08007374 @Override
7375 public int[] getSlotsMapping() {
7376 enforceReadPrivilegedPermission("getSlotsMapping");
7377
7378 final long identity = Binder.clearCallingIdentity();
7379 try {
7380 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7381 // All logical slots should have a mapping to a physical slot.
7382 int[] logicalSlotsMapping = new int[phoneCount];
7383 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7384 for (int i = 0; i < slotInfos.length; i++) {
7385 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7386 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7387 }
7388 }
7389 return logicalSlotsMapping;
7390 } finally {
7391 Binder.restoreCallingIdentity(identity);
7392 }
7393 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007394
7395 /**
7396 * Get the IRadio HAL Version
7397 */
7398 @Override
7399 public int getRadioHalVersion() {
7400 Phone phone = getDefaultPhone();
7401 if (phone == null) return -1;
7402 HalVersion hv = phone.getHalVersion();
7403 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7404 return hv.major * 100 + hv.minor;
7405 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007406
7407 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007408 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7409 * corresponding network requests on a subId.
7410 *
7411 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007412 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007413 * 2) APN is un-metered for this subscription, or
7414 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7415 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7416 *
7417 * @return whether data is allowed for a apn type.
7418 *
7419 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007420 */
7421 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007422 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007423 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7424 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007425
7426 // Now that all security checks passes, perform the operation as ourselves.
7427 final long identity = Binder.clearCallingIdentity();
7428 try {
7429 Phone phone = getPhone(subId);
7430 if (phone == null) return false;
7431
Jack Yu41407ee2019-05-13 16:54:09 -07007432 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007433 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
7437 }
7438
7439 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007440 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007441 enforceReadPrivilegedPermission("isApnMetered");
7442
7443 // Now that all security checks passes, perform the operation as ourselves.
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 Phone phone = getPhone(subId);
7447 if (phone == null) return true; // By default return true.
7448
Jack Yu41407ee2019-05-13 16:54:09 -07007449 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
7453 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007454
7455 @Override
7456 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7457 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7458 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7459 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7460 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7461 }
7462 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7463 Intent intent = new Intent();
7464 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7465 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7466 // Bring up choose default SMS subscription dialog right now
7467 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7468 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7469 mApp.startActivity(intent);
7470 }
chen xud5ca2d52019-05-28 15:20:57 -07007471
7472 @Override
7473 public String getMmsUAProfUrl(int subId) {
7474 //TODO investigate if this API should require proper permission check in R b/133791609
7475 final long identity = Binder.clearCallingIdentity();
7476 try {
7477 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7478 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
7482 }
7483
7484 @Override
7485 public String getMmsUserAgent(int subId) {
7486 //TODO investigate if this API should require proper permission check in R b/133791609
7487 final long identity = Binder.clearCallingIdentity();
7488 try {
7489 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7490 .getString(com.android.internal.R.string.config_mms_user_agent);
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
7494 }
Jack Yub07d4972019-05-28 16:12:25 -07007495
7496 @Override
7497 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7498 enforceModifyPermission();
7499
7500 // Now that all security checks passes, perform the operation as ourselves.
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
7503 Phone phone = getPhone(subId);
7504 if (phone == null) return false;
7505
7506 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
7509 }
7510 }
7511
7512 @Override
7513 public boolean isDataAllowedInVoiceCall(int subId) {
7514 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7515
7516 // Now that all security checks passes, perform the operation as ourselves.
7517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 Phone phone = getPhone(subId);
7520 if (phone == null) return false;
7521
7522 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7523 } finally {
7524 Binder.restoreCallingIdentity(identity);
7525 }
7526 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007527
7528 /**
7529 * Updates whether conference event pacakge handling is enabled.
7530 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7531 * otherwise.
7532 */
7533 @Override
7534 public void setCepEnabled(boolean isCepEnabled) {
7535 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7536
7537 final long identity = Binder.clearCallingIdentity();
7538 try {
7539 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7540 for (Phone phone : PhoneFactory.getPhones()) {
7541 Phone defaultPhone = phone.getImsPhone();
7542 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7543 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7544 ImsPhoneCallTracker imsPhoneCallTracker =
7545 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7546 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7547 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7548 + imsPhone.getMsisdn());
7549 }
7550 }
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007555}