blob: 6812136e2624c05682281200f50357e6723004db [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);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002649 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2650 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002651 if (!TextUtils.equals(callingPackage, systemDialer)) {
2652 throw new SecurityException("caller must be system dialer");
2653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2658 if (phoneAccountHandle == null) {
2659 return null;
2660 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002661 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002662 } finally {
2663 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002664 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002665 }
2666
2667 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002668 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002669 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002671 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002672 return null;
2673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002675 final long identity = Binder.clearCallingIdentity();
2676 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002677 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002681 }
2682
2683 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002684 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2685 VisualVoicemailSmsFilterSettings settings) {
2686 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002687
2688 final long identity = Binder.clearCallingIdentity();
2689 try {
2690 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002691 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002695 }
2696
2697 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002698 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2699 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002704 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002705 } finally {
2706 Binder.restoreCallingIdentity(identity);
2707 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002708 }
2709
2710 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002711 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2712 String callingPackage, int subId) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714
2715 final long identity = Binder.clearCallingIdentity();
2716 try {
2717 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002718 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 } finally {
2720 Binder.restoreCallingIdentity(identity);
2721 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002722 }
2723
2724 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002725 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002726 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727
2728 final long identity = Binder.clearCallingIdentity();
2729 try {
2730 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002731 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002732 } finally {
2733 Binder.restoreCallingIdentity(identity);
2734 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002735 }
2736
2737 @Override
2738 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2739 String number, int port, String text, PendingIntent sentIntent) {
2740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002741 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002742 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002743 SmsController smsController = PhoneFactory.getSmsController();
2744 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2745 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002746 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002747
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002748 /**
fionaxu0152e512016-11-14 13:36:14 -08002749 * Sets the voice activation state of a given subId.
2750 */
2751 @Override
2752 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2754 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
2756 final long identity = Binder.clearCallingIdentity();
2757 try {
2758 final Phone phone = getPhone(subId);
2759 if (phone != null) {
2760 phone.setVoiceActivationState(activationState);
2761 } else {
2762 loge("setVoiceActivationState fails with invalid subId: " + subId);
2763 }
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002766 }
2767 }
2768
2769 /**
2770 * Sets the data activation state of a given subId.
2771 */
2772 @Override
2773 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2775 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002776
2777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(subId);
2780 if (phone != null) {
2781 phone.setDataActivationState(activationState);
2782 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002783 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002787 }
2788 }
2789
2790 /**
2791 * Returns the voice activation state of a given subId.
2792 */
2793 @Override
2794 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002795 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
fionaxu0152e512016-11-14 13:36:14 -08002797 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 if (phone != null) {
2801 return phone.getVoiceActivationState();
2802 } else {
2803 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002807 }
2808 }
2809
2810 /**
2811 * Returns the data activation state of a given subId.
2812 */
2813 @Override
2814 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002815 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
fionaxu0152e512016-11-14 13:36:14 -08002817 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818 final long identity = Binder.clearCallingIdentity();
2819 try {
2820 if (phone != null) {
2821 return phone.getDataActivationState();
2822 } else {
2823 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002827 }
2828 }
2829
2830 /**
Wink Saville36469e72014-06-11 15:17:00 -07002831 * Returns the unread count of voicemails for a subId
2832 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002833 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002834 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2836 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2837 return 0;
2838 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002839 final long identity = Binder.clearCallingIdentity();
2840 try {
2841 final Phone phone = getPhone(subId);
2842 if (phone != null) {
2843 return phone.getVoiceMessageCount();
2844 } else {
2845 return 0;
2846 }
2847 } finally {
2848 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002849 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 }
2851
2852 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002853 * returns true, if the device is in a state where both voice and data
2854 * are supported simultaneously. This can change based on location or network condition.
2855 */
2856 @Override
2857 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858 final long identity = Binder.clearCallingIdentity();
2859 try {
2860 final Phone phone = getPhone(subId);
2861 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002865 }
2866
2867 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002868 * Send the dialer code if called from the current default dialer or the caller has
2869 * carrier privilege.
2870 * @param inputCode The dialer code to send
2871 */
2872 @Override
2873 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002874 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002876 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2877 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002878 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2880 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
fionaxu235cc5e2017-03-06 22:25:57 -08002889 }
2890
Pengquan Menga1bb6272018-09-06 09:59:22 -07002891 @Override
2892 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002893 if (!isActiveSubscription(subId)) {
2894 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2895 }
2896
Pengquan Menga1bb6272018-09-06 09:59:22 -07002897 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2898 }
2899
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002901 public boolean isInEmergencySmsMode() {
2902 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 for (Phone phone : PhoneFactory.getPhones()) {
2906 if (phone.isInEmergencySmsMode()) {
2907 return true;
2908 }
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
2912 }
2913 return false;
2914 }
2915
2916 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002917 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2918 throws RemoteException {
2919 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002920 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2921 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2922 "IMS not available on device.");
2923 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002924 final long token = Binder.clearCallingIdentity();
2925 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002926 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002927 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002929 } catch (ImsException e) {
2930 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 } finally {
2932 Binder.restoreCallingIdentity(token);
2933 }
2934 }
2935
2936 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002937 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2938 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002939 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2940 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2941 }
Meng Wangafbc5852019-09-19 17:37:13 -07002942 final long token = Binder.clearCallingIdentity();
2943 try {
2944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2945 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2946 .removeRegistrationCallbackForSubscription(c, subId);
2947 } catch (ImsException e) {
2948 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2949 + "is inactive, ignoring unregister.");
2950 // If the subscription is no longer active, just return, since the callback
2951 // will already have been removed internally.
2952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002955 }
2956
Brad Ebingera34a6c22019-10-22 17:36:18 -07002957 /**
2958 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2959 */
2960 @Override
2961 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2962 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2963 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2964 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2965 "IMS not available on device.");
2966 }
2967 final long token = Binder.clearCallingIdentity();
2968 try {
2969 Phone phone = getPhone(subId);
2970 if (phone == null) {
2971 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2972 + subId + "'");
2973 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2974 }
2975 phone.getImsRegistrationState(regState -> {
2976 try {
2977 consumer.accept((regState == null)
2978 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2979 } catch (RemoteException e) {
2980 // Ignore if the remote process is no longer available to call back.
2981 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2982 }
2983 });
2984 } finally {
2985 Binder.restoreCallingIdentity(token);
2986 }
2987 }
2988
2989 /**
2990 * Get the transport type for the IMS service registration state.
2991 */
2992 @Override
2993 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2994 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2995 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2996 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2997 "IMS not available on device.");
2998 }
2999 final long token = Binder.clearCallingIdentity();
3000 try {
3001 Phone phone = getPhone(subId);
3002 if (phone == null) {
3003 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3004 + subId + "'");
3005 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3006 }
3007 phone.getImsRegistrationTech(regTech -> {
3008 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3009 int regTechConverted = (regTech == null)
3010 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3011 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3012 regTechConverted);
3013 try {
3014 consumer.accept(regTechConverted);
3015 } catch (RemoteException e) {
3016 // Ignore if the remote process is no longer available to call back.
3017 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3018 }
3019 });
3020 } finally {
3021 Binder.restoreCallingIdentity(token);
3022 }
3023 }
3024
Brad Ebinger35c841c2018-10-01 10:40:55 -07003025 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003026 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3027 throws RemoteException {
3028 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3034 final long token = Binder.clearCallingIdentity();
3035 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003038 } catch (ImsException e) {
3039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 } finally {
3041 Binder.restoreCallingIdentity(token);
3042 }
3043 }
3044
3045 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003046 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3047 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003048 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3049 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3050 }
Meng Wangafbc5852019-09-19 17:37:13 -07003051
3052 final long token = Binder.clearCallingIdentity();
3053 try {
3054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3055 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003056 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003057 } catch (ImsException e) {
3058 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3059 + "is inactive, ignoring unregister.");
3060 // If the subscription is no longer active, just return, since the callback
3061 // will already have been removed internally.
3062 } finally {
3063 Binder.restoreCallingIdentity(token);
3064 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003065 }
3066
3067 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003068 public boolean isCapable(int subId, int capability, int regTech) {
3069 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3071 final long token = Binder.clearCallingIdentity();
3072 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003073 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003075 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3077 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003078 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003079 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3080 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003081 } finally {
3082 Binder.restoreCallingIdentity(token);
3083 }
3084 }
3085
3086 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003087 public boolean isAvailable(int subId, int capability, int regTech) {
3088 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003089 final long token = Binder.clearCallingIdentity();
3090 try {
3091 Phone phone = getPhone(subId);
3092 if (phone == null) return false;
3093 return phone.isImsCapabilityAvailable(capability, regTech);
3094 } finally {
3095 Binder.restoreCallingIdentity(token);
3096 }
3097 }
3098
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003099 /**
3100 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3101 * subscription.
3102 * @param subId The subscription to use to check the configuration.
3103 * @param callback The callback that will be used to send the result.
3104 * @param capability The MmTelFeature capability that will be used to send the result.
3105 * @param transportType The transport type of the MmTelFeature capability.
3106 */
3107 @Override
3108 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3109 int transportType) {
3110 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3111 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3112 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3113 "IMS not available on device.");
3114 }
3115 final long token = Binder.clearCallingIdentity();
3116 try {
3117 int slotId = getSlotIndex(subId);
3118 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3119 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3120 + subId + "'");
3121 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3122 }
3123 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3124 transportType, aBoolean -> {
3125 try {
3126 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3127 } catch (RemoteException e) {
3128 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3129 + "running. Ignore");
3130 }
3131 });
3132 } finally {
3133 Binder.restoreCallingIdentity(token);
3134 }
3135 }
3136
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 @Override
3138 public boolean isAdvancedCallingSettingEnabled(int subId) {
3139 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3141 final long token = Binder.clearCallingIdentity();
3142 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003145 } catch (ImsException e) {
3146 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(token);
3149 }
3150 }
3151
3152 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003153 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003155 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003156 final long identity = Binder.clearCallingIdentity();
3157 try {
3158 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003159 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003161 } catch (ImsException e) {
3162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003169 public boolean isVtSettingEnabled(int subId) {
3170 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003174 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3175 } catch (ImsException e) {
3176 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 } finally {
3178 Binder.restoreCallingIdentity(identity);
3179 }
3180 }
3181
3182 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003183 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003185 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003190 } catch (ImsException e) {
3191 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
3195 }
3196
3197 @Override
3198 public boolean isVoWiFiSettingEnabled(int subId) {
3199 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003203 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003205 } catch (ImsException e) {
3206 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 } finally {
3208 Binder.restoreCallingIdentity(identity);
3209 }
3210 }
3211
3212 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003213 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003215 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 final long identity = Binder.clearCallingIdentity();
3217 try {
3218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003220 } catch (ImsException e) {
3221 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
3226
3227 @Override
3228 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3229 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003234 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003235 } catch (ImsException e) {
3236 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 } finally {
3238 Binder.restoreCallingIdentity(identity);
3239 }
3240 }
3241
3242 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003243 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003245 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003249 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003251 } catch (ImsException e) {
3252 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 }
3257
3258 @Override
3259 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3261 "setVoWiFiNonPersistent");
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003265 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003266 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (ImsException e) {
3268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
3272 }
3273
3274 @Override
3275 public int getVoWiFiModeSetting(int subId) {
3276 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3277 final long identity = Binder.clearCallingIdentity();
3278 try {
3279 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003280 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003282 } catch (ImsException e) {
3283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
3287 }
3288
3289 @Override
3290 public void setVoWiFiModeSetting(int subId, int mode) {
3291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3292 "setVoWiFiModeSetting");
3293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003296 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003297 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003298 } catch (ImsException e) {
3299 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 } finally {
3301 Binder.restoreCallingIdentity(identity);
3302 }
3303 }
3304
3305 @Override
3306 public int getVoWiFiRoamingModeSetting(int subId) {
3307 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003311 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003313 } catch (ImsException e) {
3314 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 } finally {
3316 Binder.restoreCallingIdentity(identity);
3317 }
3318 }
3319
3320 @Override
3321 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3323 "setVoWiFiRoamingModeSetting");
3324 final long identity = Binder.clearCallingIdentity();
3325 try {
3326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003327 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003329 } catch (ImsException e) {
3330 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003331 } finally {
3332 Binder.restoreCallingIdentity(identity);
3333 }
3334 }
3335
3336 @Override
3337 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3339 "setRttCapabilityEnabled");
3340 final long identity = Binder.clearCallingIdentity();
3341 try {
3342 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003343 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3344 } catch (ImsException e) {
3345 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003346 } finally {
3347 Binder.restoreCallingIdentity(identity);
3348 }
3349 }
3350
3351 @Override
3352 public boolean isTtyOverVolteEnabled(int subId) {
3353 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003357 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003358 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003359 } catch (ImsException e) {
3360 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003361 } finally {
3362 Binder.restoreCallingIdentity(identity);
3363 }
3364 }
3365
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 @Override
3367 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3368 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3369 final long identity = Binder.clearCallingIdentity();
3370 try {
3371 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003373 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003374 } catch (ImsException e) {
3375 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
3379 }
3380
3381 @Override
3382 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3383 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3384 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003385 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3386 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3387 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003388 try {
3389 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003390 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003391 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003392 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003393 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3394 + "is inactive, ignoring unregister.");
3395 // If the subscription is no longer active, just return, since the callback will already
3396 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3404 boolean isProvisioned) {
3405 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3406 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3407 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3408 }
3409 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3410 "setProvisioningStatusForCapability");
3411 final long identity = Binder.clearCallingIdentity();
3412 try {
3413 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3414 Phone phone = getPhone(subId);
3415 if (phone == null) {
3416 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3417 + subId);
3418 return;
3419 }
3420 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3421 return;
3422 }
3423
3424 // this capability requires provisioning, route to the correct API.
3425 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3426 switch (capability) {
3427 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3428 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3429 ims.setVolteProvisioned(isProvisioned);
3430 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3431 ims.setWfcProvisioned(isProvisioned);
3432 }
3433 break;
3434 }
3435 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3436 // There is currently no difference in VT provisioning type.
3437 ims.setVtProvisioned(isProvisioned);
3438 break;
3439 }
3440 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3441 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3442 // change the capability of the feature instead if needed.
3443 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3444 == isProvisioned) {
3445 // No change in provisioning.
3446 return;
3447 }
3448 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3449 try {
3450 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003451 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3453 + ", Exception" + e.getMessage());
3454 }
3455 break;
3456 }
3457 default: {
3458 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3459 + capability + "', which does not require provisioning.");
3460 }
3461 }
3462
3463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
3468 @Override
3469 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3470 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3471 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3472 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3473 }
3474 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3478 Phone phone = getPhone(subId);
3479 if (phone == null) {
3480 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3481 + subId);
3482 // We will fail with "true" as the provisioning status because this is the default
3483 // if we do not require provisioning.
3484 return true;
3485 }
3486
3487 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3488 return true;
3489 }
3490
3491 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3492 switch (capability) {
3493 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3494 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3495 return ims.isVolteProvisionedOnDevice();
3496 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3497 return ims.isWfcProvisionedOnDevice();
3498 }
3499 // This should never happen, since we are checking tech above to make sure it
3500 // is either LTE or IWLAN.
3501 throw new IllegalArgumentException("Invalid radio technology for voice "
3502 + "capability.");
3503 }
3504 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3505 // There is currently no difference in VT provisioning type.
3506 return ims.isVtProvisionedOnDevice();
3507 }
3508 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3509 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3510 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3511 }
3512 default: {
3513 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3514 + capability + "', which does not require provisioning.");
3515 }
3516 }
3517
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
3520 }
3521 }
3522
3523 @Override
3524 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3525 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3526 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3527 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3528 }
3529 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3530 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3531 return (provisionedBits & capability) > 0;
3532 }
3533
3534 @Override
3535 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3536 boolean isProvisioned) {
3537 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3538 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3539 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3540 }
3541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3542 "setProvisioningStatusForCapability");
3543 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3544 // If the current provisioning status for capability already matches isProvisioned,
3545 // do nothing.
3546 if (((provisionedBits & capability) > 0) == isProvisioned) {
3547 return;
3548 }
3549 if (isProvisioned) {
3550 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3551 } else {
3552 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3553 }
3554 }
3555
3556 /**
3557 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3558 * technology. The bitfield should mirror the bitfield defined by
3559 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3560 */
3561 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3562 String key = getMmTelProvisioningKey(subId, tech);
3563 // Default is no capabilities are provisioned.
3564 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3565 }
3566
3567 /**
3568 * Sets the MmTel capability provisioning bitfield (defined by
3569 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3570 * technology specified.
3571 *
3572 * Note: This is a synchronous command and should not be called on UI thread.
3573 */
3574 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3575 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3576 String key = getMmTelProvisioningKey(subId, tech);
3577 editor.putInt(key, newField);
3578 editor.commit();
3579 }
3580
3581 private static String getMmTelProvisioningKey(int subId, int tech) {
3582 // resulting key is provision_ims_mmtel_{subId}_{tech}
3583 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3584 }
3585
3586 /**
3587 * Query CarrierConfig to see if the specified capability requires provisioning for the
3588 * carrier associated with the subscription id.
3589 */
3590 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3591 int capability) {
3592 CarrierConfigManager configManager = new CarrierConfigManager(context);
3593 PersistableBundle c = configManager.getConfigForSubId(subId);
3594 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003595 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003596 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3597 false);
3598 boolean requireVoiceVtProvisioning = c.getBoolean(
3599 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3600
3601 // First check to make sure that the capability requires provisioning.
3602 switch (capability) {
3603 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3604 // intentional fallthrough
3605 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3606 if (requireVoiceVtProvisioning) {
3607 // Voice and Video requires provisioning
3608 return true;
3609 }
3610 break;
3611 }
3612 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3613 if (requireUtProvisioning) {
3614 // UT requires provisioning
3615 return true;
3616 }
3617 break;
3618 }
3619 }
3620 return false;
3621 }
3622
3623 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003624 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003625 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3626 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3627 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003628 enforceReadPrivilegedPermission("getImsProvisioningInt");
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003632 int slotId = getSlotIndex(subId);
3633 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3634 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3635 + subId + "' for key:" + key);
3636 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3637 }
3638 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003639 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003640 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3641 + subId + "' for key:" + key);
3642 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
3646 }
3647
3648 @Override
3649 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003650 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3651 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3652 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003653 enforceReadPrivilegedPermission("getImsProvisioningString");
3654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003657 int slotId = getSlotIndex(subId);
3658 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3659 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3660 + subId + "' for key:" + key);
3661 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3662 }
3663 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003664 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3666 + subId + "' for key:" + key);
3667 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003668 } finally {
3669 Binder.restoreCallingIdentity(identity);
3670 }
3671 }
3672
3673 @Override
3674 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003675 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3676 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3677 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3679 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003680 final long identity = Binder.clearCallingIdentity();
3681 try {
3682 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003683 int slotId = getSlotIndex(subId);
3684 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3685 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3686 + subId + "' for key:" + key);
3687 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3688 }
3689 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3692 + "' for key:" + key);
3693 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
3700 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003701 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3702 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3703 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3705 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 int slotId = getSlotIndex(subId);
3710 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3711 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3712 + subId + "' for key:" + key);
3713 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3714 }
3715 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003717 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3718 + "' for key:" + key);
3719 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003720 } finally {
3721 Binder.restoreCallingIdentity(identity);
3722 }
3723 }
3724
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 int slotId = SubscriptionManager.getSlotIndex(subId);
3727 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003728 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3729 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 }
3731 return slotId;
3732 }
3733
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 private int getSlotIndex(int subId) {
3735 int slotId = SubscriptionManager.getSlotIndex(subId);
3736 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3737 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3738 }
3739 return slotId;
3740 }
3741
Wink Saville36469e72014-06-11 15:17:00 -07003742 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003743 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003744 */
3745 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003746 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003747 final int targetSdk = getTargetSdk(callingPackage);
3748 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3749 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3750 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003751 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3752 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003753 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3754 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003755
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003756 final long identity = Binder.clearCallingIdentity();
3757 try {
3758 final Phone phone = getPhone(subId);
3759 if (phone != null) {
3760 return phone.getServiceState().getDataNetworkType();
3761 } else {
3762 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3763 }
3764 } finally {
3765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003766 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003767 }
3768
3769 /**
3770 * Returns the data network type
3771 */
3772 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003773 public int getDataNetworkType(String callingPackage) {
3774 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003775 }
3776
3777 /**
3778 * Returns the data network type for a subId
3779 */
3780 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003781 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003783 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003784 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3785 }
3786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003787 final long identity = Binder.clearCallingIdentity();
3788 try {
3789 final Phone phone = getPhone(subId);
3790 if (phone != null) {
3791 return phone.getServiceState().getDataNetworkType();
3792 } else {
3793 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3794 }
3795 } finally {
3796 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003797 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003798 }
3799
3800 /**
Wink Saville36469e72014-06-11 15:17:00 -07003801 * Returns the Voice network type for a subId
3802 */
3803 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003804 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003806 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003807 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3808 }
3809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 final Phone phone = getPhone(subId);
3813 if (phone != null) {
3814 return phone.getServiceState().getVoiceNetworkType();
3815 } else {
3816 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3817 }
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003820 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003821 }
3822
3823 /**
3824 * @return true if a ICC card is present
3825 */
3826 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003827 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003828 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3829 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003830 }
3831
3832 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003833 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003834 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003835 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003836 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 final Phone phone = PhoneFactory.getPhone(slotIndex);
3840 if (phone != null) {
3841 return phone.getIccCard().hasIccCard();
3842 } else {
3843 return false;
3844 }
3845 } finally {
3846 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003848 }
3849
3850 /**
3851 * Return if the current radio is LTE on CDMA. This
3852 * is a tri-state return value as for a period of time
3853 * the mode may be unknown.
3854 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003855 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003857 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003858 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003859 @Override
3860 public int getLteOnCdmaMode(String callingPackage) {
3861 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003862 }
3863
Sanket Padawe356d7632015-06-22 14:03:32 -07003864 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003865 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003866 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003867 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003868 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3869 }
3870
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 final long identity = Binder.clearCallingIdentity();
3872 try {
3873 final Phone phone = getPhone(subId);
3874 if (phone == null) {
3875 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3876 } else {
3877 return phone.getLteOnCdmaMode();
3878 }
3879 } finally {
3880 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003881 }
Wink Saville36469e72014-06-11 15:17:00 -07003882 }
3883
Wink Saville36469e72014-06-11 15:17:00 -07003884 /**
3885 * {@hide}
3886 * Returns Default subId, 0 in the case of single standby.
3887 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003888 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003889 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003890 }
3891
Shishir Agrawala9f32182016-04-12 12:00:16 -07003892 private int getSlotForDefaultSubscription() {
3893 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3894 }
3895
Wink Savilleb564aae2014-10-23 10:18:09 -07003896 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003897 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003898 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003899
Pengquan Menge92a50d2018-09-21 15:54:48 -07003900 private boolean isActiveSubscription(int subId) {
3901 return mSubscriptionController.isActiveSubId(subId);
3902 }
3903
Ihab Awadf2177b72013-11-25 13:33:23 -08003904 /**
3905 * @see android.telephony.TelephonyManager.WifiCallingChoices
3906 */
3907 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003908 final long identity = Binder.clearCallingIdentity();
3909 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003910 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003911 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3912 getWhenToMakeWifiCallsDefaultPreference());
3913 } finally {
3914 Binder.restoreCallingIdentity(identity);
3915 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003916 }
3917
3918 /**
3919 * @see android.telephony.TelephonyManager.WifiCallingChoices
3920 */
3921 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003922 final long identity = Binder.clearCallingIdentity();
3923 try {
3924 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003925 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003926 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003930 }
3931
Sailesh Nepald1e68152013-12-12 19:08:02 -08003932 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003933 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003934 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003935 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003936
Jordan Liu4c733742019-02-28 12:03:40 -08003937 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3938 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3939 if (phoneId == -1) {
3940 throw new IllegalArgumentException("Given slot index: " + slotIndex
3941 + " does not correspond to an active phone");
3942 }
3943 return PhoneFactory.getPhone(phoneId);
3944 }
3945
Shishir Agrawal566b7612013-10-28 14:41:00 -07003946 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003947 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3948 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003949 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3950 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003951 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003952 if (DBG) {
3953 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3954 }
3955 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3956 p2);
3957 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003958
Jordan Liu4c733742019-02-28 12:03:40 -08003959
3960 @Override
3961 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3962 int slotIndex, String callingPackage, String aid, int p2) {
3963 enforceModifyPermission();
3964 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3965 if (DBG) {
3966 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3967 }
3968 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3969 callingPackage, aid, p2);
3970 }
3971
3972 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3973 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 if (TextUtils.equals(ISDR_AID, aid)) {
3977 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3979 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 if (bestComponent == null
3981 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3982 loge("The calling package is not allowed to access ISD-R.");
3983 throw new SecurityException(
3984 "The calling package is not allowed to access ISD-R.");
3985 }
Derek Tan740e1672017-06-27 14:56:27 -07003986 }
Derek Tan740e1672017-06-27 14:56:27 -07003987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003988 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003989 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3990 null /* workSource */);
3991 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003992 return response;
3993 } finally {
3994 Binder.restoreCallingIdentity(identity);
3995 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003996 }
3997
3998 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003999 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004002 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4003 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4004 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004005
Jordan Liu4c733742019-02-28 12:03:40 -08004006 @Override
4007 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4008 enforceModifyPermission();
4009 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4010 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4011 channel);
4012 }
4013
4014 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 final long identity = Binder.clearCallingIdentity();
4016 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004017 if (channel < 0) {
4018 return false;
4019 }
Jordan Liu4c733742019-02-28 12:03:40 -08004020 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4021 null /* workSource */);
4022 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 return success;
4024 } finally {
4025 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004026 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004027 }
4028
4029 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004030 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004031 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004032 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4033 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004034 if (DBG) {
4035 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4036 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4037 + p3 + " data=" + data);
4038 }
4039 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4040 command, p1, p2, p3, data);
4041 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004042
Jordan Liu4c733742019-02-28 12:03:40 -08004043 @Override
4044 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4045 int command, int p1, int p2, int p3, String data) {
4046 enforceModifyPermission();
4047 if (DBG) {
4048 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4049 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4050 + p3 + " data=" + data);
4051 }
4052 return iccTransmitApduLogicalChannelWithPermission(
4053 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4054 data);
4055 }
4056
4057 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4058 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 final long identity = Binder.clearCallingIdentity();
4060 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004061 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 return "";
4063 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004065 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004066 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4067 null /* workSource */);
4068 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004070 // Append the returned status code to the end of the response payload.
4071 String s = Integer.toHexString(
4072 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4073 if (response.payload != null) {
4074 s = IccUtils.bytesToHexString(response.payload) + s;
4075 }
4076 return s;
4077 } finally {
4078 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004079 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004080 }
Jake Hambye994d462014-02-03 13:10:13 -08004081
Evan Charltonc66da362014-05-16 14:06:40 -07004082 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004083 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4084 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4086 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004088 if (DBG) {
4089 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4090 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4091 }
4092 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4093 cla, command, p1, p2, p3, data);
4094 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004095
Jordan Liu4c733742019-02-28 12:03:40 -08004096 @Override
4097 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4098 int command, int p1, int p2, int p3, String data) {
4099 enforceModifyPermission();
4100 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4101 if (DBG) {
4102 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4103 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4104 + " data=" + data);
4105 }
4106
4107 return iccTransmitApduBasicChannelWithPermission(
4108 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4109 p2, p3, data);
4110 }
4111
4112 // open APDU basic channel assuming the caller has sufficient permissions
4113 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4114 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4118 && TextUtils.equals(ISDR_AID, data)) {
4119 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004120 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4121 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004122 if (bestComponent == null
4123 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4124 loge("The calling package is not allowed to select ISD-R.");
4125 throw new SecurityException(
4126 "The calling package is not allowed to select ISD-R.");
4127 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004128 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004130 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004131 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4132 null /* workSource */);
4133 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 // Append the returned status code to the end of the response payload.
4136 String s = Integer.toHexString(
4137 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4138 if (response.payload != null) {
4139 s = IccUtils.bytesToHexString(response.payload) + s;
4140 }
4141 return s;
4142 } finally {
4143 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004144 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004145 }
4146
4147 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004148 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004149 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4151 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004152
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 if (DBG) {
4156 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4157 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4158 }
4159
4160 IccIoResult response =
4161 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4162 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4163 subId);
4164
4165 if (DBG) {
4166 log("Exchange SIM_IO [R]" + response);
4167 }
4168
4169 byte[] result = null;
4170 int length = 2;
4171 if (response.payload != null) {
4172 length = 2 + response.payload.length;
4173 result = new byte[length];
4174 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4175 } else {
4176 result = new byte[length];
4177 }
4178
4179 result[length - 1] = (byte) response.sw2;
4180 result[length - 2] = (byte) response.sw1;
4181 return result;
4182 } finally {
4183 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004184 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004185 }
4186
Nathan Haroldb3014052017-01-25 15:57:32 -08004187 /**
4188 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4189 * on a particular subscription
4190 */
sqianb6e41952018-03-12 14:54:01 -07004191 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4193 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4194 return null;
4195 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196
4197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 if (appType != TelephonyManager.APPTYPE_USIM
4200 && appType != TelephonyManager.APPTYPE_SIM) {
4201 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4202 return null;
4203 }
4204 Object response = sendRequest(
4205 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4206 if (response instanceof String[]) {
4207 return (String[]) response;
4208 }
yincheng zhao2737e882019-09-06 17:06:54 -07004209 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004211 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004214 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004215 }
4216
yincheng zhao2737e882019-09-06 17:06:54 -07004217 /**
4218 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4219 * subscription.
4220 *
4221 * @param subId the id of the subscription.
4222 * @param appType the uicc app type, must be USIM or SIM.
4223 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4224 * @param callingPackage the op Package name.
4225 * @return number of fplmns that is successfully written to the SIM.
4226 */
4227 public int setForbiddenPlmns(
4228 int subId, int appType, List<String> fplmns, String callingPackage) {
4229 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4230 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4231 if (DBG) logv("no permissions for setForbiddenplmns");
4232 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4233 }
4234 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4235 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4236 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4237 }
4238 if (fplmns == null) {
4239 throw new IllegalArgumentException("Fplmn List provided is null");
4240 }
4241 for (String fplmn : fplmns) {
4242 if (!CellIdentity.isValidPlmn(fplmn)) {
4243 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4244 }
4245 }
4246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 Object response = sendRequest(
4249 CMD_SET_FORBIDDEN_PLMNS,
4250 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4251 subId);
4252 return (int) response;
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
4255 }
4256 }
4257
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004258 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004259 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4261 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004262
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004263 final long identity = Binder.clearCallingIdentity();
4264 try {
4265 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4266 if (response.payload == null) {
4267 return "";
4268 }
Evan Charltonc66da362014-05-16 14:06:40 -07004269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 // Append the returned status code to the end of the response payload.
4271 String s = Integer.toHexString(
4272 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4273 s = IccUtils.bytesToHexString(response.payload) + s;
4274 return s;
4275 } finally {
4276 Binder.restoreCallingIdentity(identity);
4277 }
Evan Charltonc66da362014-05-16 14:06:40 -07004278 }
4279
Jake Hambye994d462014-02-03 13:10:13 -08004280 /**
4281 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4282 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4283 *
4284 * @param itemID the ID of the item to read
4285 * @return the NV item as a String, or null on error.
4286 */
4287 @Override
4288 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004290 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4291 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292
4293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004296 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4298 return value;
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
Jake Hambye994d462014-02-03 13:10:13 -08004302 }
4303
4304 /**
4305 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4306 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4307 *
4308 * @param itemID the ID of the item to read
4309 * @param itemValue the value to write, as a String
4310 * @return true on success; false on any failure
4311 */
4312 @Override
4313 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004314 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004315 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4316 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4321 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004322 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4324 return success;
4325 } finally {
4326 Binder.restoreCallingIdentity(identity);
4327 }
Jake Hambye994d462014-02-03 13:10:13 -08004328 }
4329
4330 /**
4331 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4332 * Used for device configuration by some CDMA operators.
4333 *
4334 * @param preferredRoamingList byte array containing the new PRL
4335 * @return true on success; false on any failure
4336 */
4337 @Override
4338 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004339 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4340 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4345 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4346 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4347 return success;
4348 } finally {
4349 Binder.restoreCallingIdentity(identity);
4350 }
Jake Hambye994d462014-02-03 13:10:13 -08004351 }
4352
4353 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004354 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004355 * Used for device configuration by some CDMA operators.
4356 *
chen xu6dac5ab2018-10-26 17:39:23 -07004357 * @param slotIndex - device slot.
4358 *
Jake Hambye994d462014-02-03 13:10:13 -08004359 * @return true on success; false on any failure
4360 */
4361 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004362 public boolean resetModemConfig(int slotIndex) {
4363 Phone phone = PhoneFactory.getPhone(slotIndex);
4364 if (phone != null) {
4365 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4366 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004367
chen xu6dac5ab2018-10-26 17:39:23 -07004368 final long identity = Binder.clearCallingIdentity();
4369 try {
4370 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4371 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4372 return success;
4373 } finally {
4374 Binder.restoreCallingIdentity(identity);
4375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 }
chen xu6dac5ab2018-10-26 17:39:23 -07004377 return false;
4378 }
4379
4380 /**
4381 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4382 *
4383 * @param slotIndex - device slot.
4384 *
4385 * @return true on success; false on any failure
4386 */
4387 @Override
4388 public boolean rebootModem(int slotIndex) {
4389 Phone phone = PhoneFactory.getPhone(slotIndex);
4390 if (phone != null) {
4391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4392 mApp, phone.getSubId(), "rebootModem");
4393
4394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4397 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4398 return success;
4399 } finally {
4400 Binder.restoreCallingIdentity(identity);
4401 }
4402 }
4403 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004404 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004405
Svet Ganovb320e182015-04-16 12:30:10 -07004406 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004407 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004409 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004410 return new String[0];
4411 }
4412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004415 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 } finally {
4417 Binder.restoreCallingIdentity(identity);
4418 }
Wink Saville36469e72014-06-11 15:17:00 -07004419 }
4420
Brad Ebinger51f743a2017-01-23 13:50:20 -08004421 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004422 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4423 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004424 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004425 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427
4428 final long identity = Binder.clearCallingIdentity();
4429 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004430 ImsResolver resolver = PhoneFactory.getImsResolver();
4431 if (resolver == null) {
4432 // may happen if the device does not support IMS.
4433 return;
4434 }
4435 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004439 }
4440
4441 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004442 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4443 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004444 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004445 public void disableIms(int slotId) {
4446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447
4448 final long identity = Binder.clearCallingIdentity();
4449 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004450 ImsResolver resolver = PhoneFactory.getImsResolver();
4451 if (resolver == null) {
4452 // may happen if the device does not support IMS.
4453 return;
4454 }
4455 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 } finally {
4457 Binder.restoreCallingIdentity(identity);
4458 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004459 }
4460
4461 /**
4462 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4463 * feature or {@link null} if the service is not available. If the feature is available, the
4464 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4465 */
4466 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004467 IImsServiceFeatureCallback callback) {
4468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004472 ImsResolver resolver = PhoneFactory.getImsResolver();
4473 if (resolver == null) {
4474 // may happen if the device does not support IMS.
4475 return null;
4476 }
4477 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004478 } finally {
4479 Binder.restoreCallingIdentity(identity);
4480 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004481 }
4482
4483 /**
4484 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4485 * feature during emergency calling or {@link null} if the service is not available. If the
4486 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4487 * listener for feature updates.
4488 */
4489 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491
4492 final long identity = Binder.clearCallingIdentity();
4493 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004494 ImsResolver resolver = PhoneFactory.getImsResolver();
4495 if (resolver == null) {
4496 // may happen if the device does not support IMS.
4497 return null;
4498 }
4499 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004503 }
4504
Brad Ebinger5f64b052017-12-14 14:26:15 -08004505 /**
4506 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004507 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004508 */
4509 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004511
4512 final long identity = Binder.clearCallingIdentity();
4513 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004514 ImsResolver resolver = PhoneFactory.getImsResolver();
4515 if (resolver == null) {
4516 // may happen if the device does not support IMS.
4517 return null;
4518 }
4519 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 } finally {
4521 Binder.restoreCallingIdentity(identity);
4522 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004523 }
4524
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004525 /**
4526 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004527 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004528 */
4529 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4530 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004531
4532 final long identity = Binder.clearCallingIdentity();
4533 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004534 ImsResolver resolver = PhoneFactory.getImsResolver();
4535 if (resolver == null) {
4536 // may happen if the device does not support IMS.
4537 return null;
4538 }
4539 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004540 } finally {
4541 Binder.restoreCallingIdentity(identity);
4542 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004543 }
4544
Brad Ebinger884c07b2018-02-15 16:17:40 -08004545 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004546 * Sets the ImsService Package Name that Telephony will bind to.
4547 *
4548 * @param slotId the slot ID that the ImsService should bind for.
4549 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4550 * ImsService is the device default ImsService.
4551 * @param packageName The package name of the application that contains the ImsService to bind
4552 * to.
4553 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4554 * @hide
4555 */
4556 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004557 int[] subIds = SubscriptionManager.getSubId(slotId);
4558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4559 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4560 "setImsService");
4561
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 final long identity = Binder.clearCallingIdentity();
4563 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004564 ImsResolver resolver = PhoneFactory.getImsResolver();
4565 if (resolver == null) {
4566 // may happen if the device does not support IMS.
4567 return false;
4568 }
4569 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4570 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 } finally {
4572 Binder.restoreCallingIdentity(identity);
4573 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004574 }
4575
4576 /**
4577 * Return the ImsService configuration.
4578 *
4579 * @param slotId The slot that the ImsService is associated with.
4580 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4581 * the device default.
4582 * @return the package name of the ImsService configuration.
4583 */
4584 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004585 int[] subIds = SubscriptionManager.getSubId(slotId);
4586 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4587 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4588 "getImsService");
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004592 ImsResolver resolver = PhoneFactory.getImsResolver();
4593 if (resolver == null) {
4594 // may happen if the device does not support IMS.
4595 return "";
4596 }
4597 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
4600 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004601 }
4602
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004603 /**
4604 * Get the MmTelFeature state associated with the requested subscription id.
4605 * @param subId The subscription that the MmTelFeature is associated with.
4606 * @param callback A callback with an integer containing the
4607 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4608 */
4609 @Override
4610 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4611 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4612 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4613 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4614 "IMS not available on device.");
4615 }
4616 final long token = Binder.clearCallingIdentity();
4617 try {
4618 int slotId = getSlotIndex(subId);
4619 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4620 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4621 + subId + "'");
4622 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4623 }
4624 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4625 try {
4626 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4627 } catch (RemoteException e) {
4628 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4629 + "Ignore");
4630 }
4631 });
4632 } finally {
4633 Binder.restoreCallingIdentity(token);
4634 }
4635 }
4636
Wink Saville36469e72014-06-11 15:17:00 -07004637 public void setImsRegistrationState(boolean registered) {
4638 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639
4640 final long identity = Binder.clearCallingIdentity();
4641 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004642 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004643 } finally {
4644 Binder.restoreCallingIdentity(identity);
4645 }
Wink Saville36469e72014-06-11 15:17:00 -07004646 }
4647
4648 /**
Stuart Scott54788802015-03-30 13:18:01 -07004649 * Set the network selection mode to automatic.
4650 *
4651 */
4652 @Override
4653 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4655 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656
Pengquan Menge92a50d2018-09-21 15:54:48 -07004657 if (!isActiveSubscription(subId)) {
4658 return;
4659 }
4660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 final long identity = Binder.clearCallingIdentity();
4662 try {
4663 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4664 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4665 } finally {
4666 Binder.restoreCallingIdentity(identity);
4667 }
Stuart Scott54788802015-03-30 13:18:01 -07004668 }
4669
Pengquan Mengea84e042018-09-20 14:57:26 -07004670 /**
4671 * Ask the radio to connect to the input network and change selection mode to manual.
4672 *
4673 * @param subId the id of the subscription.
4674 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4675 * the operator to attach to.
4676 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4677 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4678 * normal network selection next time.
4679 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004680 */
4681 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004682 public boolean setNetworkSelectionModeManual(
4683 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4685 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004686
4687 if (!isActiveSubscription(subId)) {
4688 return false;
4689 }
4690
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 final long identity = Binder.clearCallingIdentity();
4692 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004693 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004695 if (DBG) {
4696 log("setNetworkSelectionModeManual: subId: " + subId
4697 + " operator: " + operatorInfo);
4698 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4700 } finally {
4701 Binder.restoreCallingIdentity(identity);
4702 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004703 }
4704
4705 /**
4706 * Scans for available networks.
4707 */
4708 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004709 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004711 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4712 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004713 LocationAccessPolicy.LocationPermissionResult locationResult =
4714 LocationAccessPolicy.checkLocationPermission(mApp,
4715 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4716 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004717 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004718 .setCallingPid(Binder.getCallingPid())
4719 .setCallingUid(Binder.getCallingUid())
4720 .setMethod("getCellNetworkScanResults")
4721 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4722 .build());
4723 switch (locationResult) {
4724 case DENIED_HARD:
4725 throw new SecurityException("Not allowed to access scan results -- location");
4726 case DENIED_SOFT:
4727 return null;
4728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729
Pengquan Menga1bb6272018-09-06 09:59:22 -07004730 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 try {
4732 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004733 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 } finally {
4736 Binder.restoreCallingIdentity(identity);
4737 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004738 }
4739
4740 /**
yinxub1bed742017-04-17 11:45:04 -07004741 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004742 *
yinxub1bed742017-04-17 11:45:04 -07004743 * @param subId id of the subscription
4744 * @param request contains the radio access networks with bands/channels to scan
4745 * @param messenger callback messenger for scan results or errors
4746 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004747 * @return the id of the requested scan which can be used to stop the scan.
4748 */
4749 @Override
4750 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004751 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4753 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004754 LocationAccessPolicy.LocationPermissionResult locationResult =
4755 LocationAccessPolicy.checkLocationPermission(mApp,
4756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4757 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004759 .setCallingPid(Binder.getCallingPid())
4760 .setCallingUid(Binder.getCallingUid())
4761 .setMethod("requestNetworkScan")
4762 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4763 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004764 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004765 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004766 if (e != null) {
4767 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4768 throw e;
4769 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004770 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004771 return TelephonyScanManager.INVALID_SCAN_ID;
4772 }
4773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774 }
Hall Liu912dfd32019-04-25 14:02:26 -07004775 int callingUid = Binder.getCallingUid();
4776 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 return mNetworkScanRequestTracker.startNetworkScan(
4780 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004781 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
yinxu504e1392017-04-12 16:03:22 -07004785 }
4786
Hall Liub2ac8ef2019-02-28 15:56:23 -08004787 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004788 NetworkScanRequest request, int subId) {
4789 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4790 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4791 boolean hasNetworkScanPermission =
4792 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4793 == PERMISSION_GRANTED;
4794
4795 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4796 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4797 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004798 }
4799
4800 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4801 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004802 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4803 return new SecurityException("Specific channels must not be"
4804 + " scanned without location access.");
4805 }
4806 }
4807 }
4808
Hall Liub2ac8ef2019-02-28 15:56:23 -08004809 return null;
4810 }
4811
yinxu504e1392017-04-12 16:03:22 -07004812 /**
4813 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004814 *
4815 * @param subId id of the subscription
4816 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004817 */
4818 @Override
4819 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4821 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822
Hall Liu912dfd32019-04-25 14:02:26 -07004823 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004826 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
yinxu504e1392017-04-12 16:03:22 -07004830 }
4831
4832 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004833 * Get the calculated preferred network type.
4834 * Used for debugging incorrect network type.
4835 *
4836 * @return the preferred network type, defined in RILConstants.java.
4837 */
4838 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004839 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004840 final Phone defaultPhone = getDefaultPhone();
4841 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4842 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004843 return RILConstants.PREFERRED_NETWORK_MODE;
4844 }
4845
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004849 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
Junda Liu84d15a22014-07-02 11:21:04 -07004853 }
4854
4855 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004856 * Get the preferred network type.
4857 * Used for device configuration by some CDMA operators.
4858 *
4859 * @return the preferred network type, defined in RILConstants.java.
4860 */
4861 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004862 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004863 TelephonyPermissions
4864 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4865 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004866
4867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 if (DBG) log("getPreferredNetworkType");
4870 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4871 int networkType = (result != null ? result[0] : -1);
4872 if (DBG) log("getPreferredNetworkType: " + networkType);
4873 return networkType;
4874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004877 }
4878
4879 /**
4880 * Set the preferred network type.
4881 * Used for device configuration by some CDMA operators.
4882 *
4883 * @param networkType the preferred network type, defined in RILConstants.java.
4884 * @return true on success; false on any failure.
4885 */
4886 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004887 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4889 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890
4891 final long identity = Binder.clearCallingIdentity();
4892 try {
4893 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4894 Boolean success = (Boolean) sendRequest(
4895 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4896 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4897 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004898 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004899 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4900 }
4901 return success;
4902 } finally {
4903 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004904 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004905 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004906
4907 /**
Miaoa84611c2019-03-15 09:21:10 +08004908 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004909 *
Miaoa84611c2019-03-15 09:21:10 +08004910 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004911 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004912 * @hide
4913 */
4914 @Override
SongFerngWangf3c7bf82019-11-07 17:27:26 +08004915 public boolean isTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004918 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919 try {
Miaoa84611c2019-03-15 09:21:10 +08004920 if (phone != null) {
4921 return phone.hasMatchedTetherApnSetting();
4922 } else {
4923 return false;
4924 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 } finally {
4926 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004927 }
Junda Liu475951f2014-11-07 16:45:03 -08004928 }
4929
4930 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004931 * Set mobile data enabled
4932 * Used by the user through settings etc to turn on/off mobile data
4933 *
4934 * @param enable {@code true} turn turn data on, else {@code false}
4935 */
4936 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004937 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4939 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940
4941 final long identity = Binder.clearCallingIdentity();
4942 try {
4943 int phoneId = mSubscriptionController.getPhoneId(subId);
4944 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4945 Phone phone = PhoneFactory.getPhone(phoneId);
4946 if (phone != null) {
4947 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004948 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004950 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951 }
4952 } finally {
4953 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004954 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004955 }
4956
4957 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004958 * Get the user enabled state of Mobile Data.
4959 *
4960 * TODO: remove and use isUserDataEnabled.
4961 * This can't be removed now because some vendor codes
4962 * calls through ITelephony directly while they should
4963 * use TelephonyManager.
4964 *
4965 * @return true on enabled
4966 */
4967 @Override
4968 public boolean getDataEnabled(int subId) {
4969 return isUserDataEnabled(subId);
4970 }
4971
4972 /**
4973 * Get whether mobile data is enabled per user setting.
4974 *
4975 * There are other factors deciding whether mobile data is actually enabled, but they are
4976 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004977 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004978 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004979 *
4980 * @return {@code true} if data is enabled else {@code false}
4981 */
4982 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004983 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004984 try {
4985 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4986 null);
4987 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004988 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4989 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004990 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 int phoneId = mSubscriptionController.getPhoneId(subId);
4995 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4996 Phone phone = PhoneFactory.getPhone(phoneId);
4997 if (phone != null) {
4998 boolean retVal = phone.isUserDataEnabled();
4999 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5000 return retVal;
5001 } else {
5002 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5003 return false;
5004 }
5005 } finally {
5006 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005007 }
5008 }
5009
5010 /**
5011 * Get whether mobile data is enabled.
5012 *
5013 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5014 * whether mobile data is actually enabled.
5015 *
5016 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5017 *
5018 * @return {@code true} if data is enabled else {@code false}
5019 */
5020 @Override
5021 public boolean isDataEnabled(int subId) {
5022 try {
5023 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5024 null);
5025 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5027 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005029
5030 final long identity = Binder.clearCallingIdentity();
5031 try {
5032 int phoneId = mSubscriptionController.getPhoneId(subId);
5033 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5034 Phone phone = PhoneFactory.getPhone(phoneId);
5035 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005036 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5038 return retVal;
5039 } else {
5040 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5041 return false;
5042 }
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005045 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005046 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005047
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005048 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5049 Phone phone) {
5050 //load access rules from carrier configs, and check those as well: b/139133814
5051 SubscriptionController subController = SubscriptionController.getInstance();
5052 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5053 || subController == null) return privilegeFromSim;
5054
5055 int uid = Binder.getCallingUid();
5056 PackageManager pkgMgr = phone.getContext().getPackageManager();
5057 String[] packages = pkgMgr.getPackagesForUid(uid);
5058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
5061 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5062 SubscriptionManager subManager = (SubscriptionManager)
5063 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5064 for (String pkg : packages) {
5065 if (subManager.canManageSubscription(subInfo, pkg)) {
5066 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5067 }
5068 }
5069 return privilegeFromSim;
5070 } finally {
5071 Binder.restoreCallingIdentity(identity);
5072 }
5073 }
5074
5075 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5076 String pkgName) {
5077 //load access rules from carrier configs, and check those as well: b/139133814
5078 SubscriptionController subController = SubscriptionController.getInstance();
5079 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5080 || subController == null) return privilegeFromSim;
5081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5085 SubscriptionManager subManager = (SubscriptionManager)
5086 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5087 return subManager.canManageSubscription(subInfo, pkgName)
5088 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5089 } finally {
5090 Binder.restoreCallingIdentity(identity);
5091 }
5092 }
5093
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005094 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005095 public int getCarrierPrivilegeStatus(int subId) {
5096 final Phone phone = getPhone(subId);
5097 if (phone == null) {
5098 loge("getCarrierPrivilegeStatus: Invalid subId");
5099 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5100 }
5101 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005102 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005103 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005104 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5105 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005106
5107 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5108 card.getCarrierPrivilegeStatusForCurrentTransaction(
5109 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005110 }
Junda Liu29340342014-07-10 15:23:27 -07005111
5112 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005113 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5114 final Phone phone = getPhone(subId);
5115 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005116 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005117 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5118 }
5119 UiccProfile profile =
5120 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5121 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005122 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005123 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5124 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005125 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5126 profile.getCarrierPrivilegeStatusForUid(
5127 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005128 }
5129
5130 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005131 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5132 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005133 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005134 }
5135
5136 int phoneId = SubscriptionManager.getPhoneId(subId);
5137 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005138 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005139 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005140 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5141 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005142 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5143 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5144 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005145 }
5146
5147 @Override
5148 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005149 if (TextUtils.isEmpty(pkgName))
5150 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005151 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5152 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5153 UiccCard card = UiccController.getInstance().getUiccCard(i);
5154 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005155 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005156 continue;
5157 }
5158
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005159 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5160 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5161 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005162 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5163 break;
5164 }
5165 }
5166
5167 return result;
Junda Liu29340342014-07-10 15:23:27 -07005168 }
Derek Tan89e89d42014-07-08 17:00:10 -07005169
5170 @Override
Junda Liue64de782015-04-16 17:19:16 -07005171 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5172 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5173 loge("phoneId " + phoneId + " is not valid.");
5174 return null;
5175 }
5176 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005177 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005178 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005179 return null ;
5180 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005181 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005182 }
5183
Amith Yamasani6e118872016-02-19 12:53:51 -08005184 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005185 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005187 List<String> privilegedPackages = new ArrayList<>();
5188 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005189 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5190 // has UICC in that slot.
5191 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005192 if (card.hasCarrierPrivilegeRules()) {
5193 if (packages == null) {
5194 // Only check packages in user 0 for now
5195 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005196 PackageManager.MATCH_DISABLED_COMPONENTS
5197 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005198 | PackageManager.GET_SIGNING_CERTIFICATES,
5199 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005200 }
5201 for (int p = packages.size() - 1; p >= 0; p--) {
5202 PackageInfo pkgInfo = packages.get(p);
5203 if (pkgInfo != null && pkgInfo.packageName != null
5204 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005205 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005206 privilegedPackages.add(pkgInfo.packageName);
5207 }
5208 }
5209 }
5210 }
5211 return privilegedPackages;
5212 }
5213
chen xuf7e9fe82019-05-09 19:31:02 -07005214 @Override
5215 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5216 List<String> privilegedPackages = new ArrayList<>();
5217 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5218 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5219 }
5220 return privilegedPackages;
5221 }
5222
Wink Savilleb564aae2014-10-23 10:18:09 -07005223 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005224 final Phone phone = getPhone(subId);
5225 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005226 if (card == null) {
5227 loge("getIccId: No UICC");
5228 return null;
5229 }
5230 String iccId = card.getIccId();
5231 if (TextUtils.isEmpty(iccId)) {
5232 loge("getIccId: ICC ID is null or empty.");
5233 return null;
5234 }
5235 return iccId;
5236 }
5237
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005238 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005239 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5240 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005241 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5242 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
5246 final String iccId = getIccId(subId);
5247 final Phone phone = getPhone(subId);
5248 if (phone == null) {
5249 return false;
5250 }
5251 final String subscriberId = phone.getSubscriberId();
5252
5253 if (DBG_MERGE) {
5254 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5255 + subscriberId + " to " + number);
5256 }
5257
5258 if (TextUtils.isEmpty(iccId)) {
5259 return false;
5260 }
5261
5262 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5263
5264 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5265 if (alphaTag == null) {
5266 editor.remove(alphaTagPrefKey);
5267 } else {
5268 editor.putString(alphaTagPrefKey, alphaTag);
5269 }
5270
5271 // Record both the line number and IMSI for this ICCID, since we need to
5272 // track all merged IMSIs based on line number
5273 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5274 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5275 if (number == null) {
5276 editor.remove(numberPrefKey);
5277 editor.remove(subscriberPrefKey);
5278 } else {
5279 editor.putString(numberPrefKey, number);
5280 editor.putString(subscriberPrefKey, subscriberId);
5281 }
5282
5283 editor.commit();
5284 return true;
5285 } finally {
5286 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005287 }
Derek Tan7226c842014-07-02 17:42:23 -07005288 }
5289
5290 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005291 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005292 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005294 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005295 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005296 return null;
5297 }
Derek Tan97ebb422014-09-05 16:55:38 -07005298
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 final long identity = Binder.clearCallingIdentity();
5300 try {
5301 String iccId = getIccId(subId);
5302 if (iccId != null) {
5303 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5304 if (DBG_MERGE) {
5305 log("getLine1NumberForDisplay returning "
5306 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5307 }
5308 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5311 return null;
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005314 }
Derek Tan7226c842014-07-02 17:42:23 -07005315 }
5316
5317 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005318 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005320 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005321 return null;
5322 }
Derek Tan97ebb422014-09-05 16:55:38 -07005323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 String iccId = getIccId(subId);
5327 if (iccId != null) {
5328 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5329 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5330 }
5331 return null;
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005334 }
Derek Tan7226c842014-07-02 17:42:23 -07005335 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005336
5337 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005338 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005339 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5340 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005342 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5343 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005344 return null;
5345 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005346
Jordan Liub49b04b2019-05-06 14:45:15 -07005347 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5348 // the process, where TelephonyManager was instantiated.
5349 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005350 final long identity = Binder.clearCallingIdentity();
5351 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005352 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353 final TelephonyManager tele = TelephonyManager.from(context);
5354 final SubscriptionManager sub = SubscriptionManager.from(context);
5355
5356 // Figure out what subscribers are currently active
5357 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358
Jordan Liub49b04b2019-05-06 14:45:15 -07005359 // Only consider subs which match the current subId
5360 // This logic can be simplified. See b/131189269 for progress.
5361 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005362 activeSubscriberIds.add(tele.getSubscriberId(subId));
5363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364
5365 // First pass, find a number override for an active subscriber
5366 String mergeNumber = null;
5367 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5368 for (String key : prefs.keySet()) {
5369 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5370 final String subscriberId = (String) prefs.get(key);
5371 if (activeSubscriberIds.contains(subscriberId)) {
5372 final String iccId = key.substring(
5373 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5374 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5375 mergeNumber = (String) prefs.get(numberKey);
5376 if (DBG_MERGE) {
5377 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5378 + " for active subscriber " + subscriberId);
5379 }
5380 if (!TextUtils.isEmpty(mergeNumber)) {
5381 break;
5382 }
5383 }
5384 }
5385 }
5386
5387 // Shortcut when no active merged subscribers
5388 if (TextUtils.isEmpty(mergeNumber)) {
5389 return null;
5390 }
5391
5392 // Second pass, find all subscribers under that line override
5393 final ArraySet<String> result = new ArraySet<>();
5394 for (String key : prefs.keySet()) {
5395 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5396 final String number = (String) prefs.get(key);
5397 if (mergeNumber.equals(number)) {
5398 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5399 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5400 final String subscriberId = (String) prefs.get(subscriberKey);
5401 if (!TextUtils.isEmpty(subscriberId)) {
5402 result.add(subscriberId);
5403 }
5404 }
5405 }
5406 }
5407
5408 final String[] resultArray = result.toArray(new String[result.size()]);
5409 Arrays.sort(resultArray);
5410 if (DBG_MERGE) {
5411 Slog.d(LOG_TAG,
5412 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5413 }
5414 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005415 } finally {
5416 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005417 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005418 }
5419
5420 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005421 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5422 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 final TelephonyManager telephonyManager = mApp.getSystemService(
5427 TelephonyManager.class);
5428 String subscriberId = telephonyManager.getSubscriberId(subId);
5429 if (subscriberId == null) {
5430 if (DBG) {
5431 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5432 + subId);
5433 }
5434 return null;
5435 }
5436
5437 final SubscriptionInfo info = SubscriptionController.getInstance()
5438 .getSubscriptionInfo(subId);
5439 final ParcelUuid groupUuid = info.getGroupUuid();
5440 // If it doesn't belong to any group, return just subscriberId of itself.
5441 if (groupUuid == null) {
5442 return new String[]{subscriberId};
5443 }
5444
5445 // Get all subscriberIds from the group.
5446 final List<String> mergedSubscriberIds = new ArrayList<>();
5447 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5448 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5449 for (SubscriptionInfo subInfo : groupInfos) {
5450 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5451 if (subscriberId != null) {
5452 mergedSubscriberIds.add(subscriberId);
5453 }
5454 }
5455
5456 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459
5460 }
5461 }
5462
5463 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005464 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005465 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5466 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467
5468 final long identity = Binder.clearCallingIdentity();
5469 try {
5470 final Phone phone = getPhone(subId);
5471 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005475 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005476
5477 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005478 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005479 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5480 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005481 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482
5483 final long identity = Binder.clearCallingIdentity();
5484 try {
5485 final Phone phone = getPhone(subId);
5486 if (phone == null) {
5487 return false;
5488 }
5489 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5490 cdmaNonRoamingList);
5491 } finally {
5492 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005493 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005494 }
5495
5496 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005497 @Deprecated
5498 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5499 enforceModifyPermission();
5500
5501 int returnValue = 0;
5502 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005503 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005504 if(result.exception == null) {
5505 if (result.result != null) {
5506 byte[] responseData = (byte[])(result.result);
5507 if(responseData.length > oemResp.length) {
5508 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5509 responseData.length + "bytes. Buffer Size is " +
5510 oemResp.length + "bytes.");
5511 }
5512 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5513 returnValue = responseData.length;
5514 }
5515 } else {
5516 CommandException ex = (CommandException) result.exception;
5517 returnValue = ex.getCommandError().ordinal();
5518 if(returnValue > 0) returnValue *= -1;
5519 }
5520 } catch (RuntimeException e) {
5521 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5522 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5523 if(returnValue > 0) returnValue *= -1;
5524 }
5525
5526 return returnValue;
5527 }
5528
5529 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005530 public void setRadioCapability(RadioAccessFamily[] rafs) {
5531 try {
5532 ProxyController.getInstance().setRadioCapability(rafs);
5533 } catch (RuntimeException e) {
5534 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5535 }
5536 }
5537
5538 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005539 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005540 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005541 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005542 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005543 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
chen xub97461a2018-10-26 14:17:57 -07005547 TelephonyPermissions
5548 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5549 mApp, phone.getSubId(), "getRadioAccessFamily");
5550 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553 }
chen xub97461a2018-10-26 14:17:57 -07005554 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005555 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005556
5557 @Override
5558 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005560 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564 ImsManager.getInstance(defaultPhone.getContext(),
5565 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005569 }
5570
5571 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005572 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005573 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005575 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005576 return false;
5577 }
Svet Ganovb320e182015-04-16 12:30:10 -07005578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 final long identity = Binder.clearCallingIdentity();
5580 try {
5581 // Check the user preference and the system-level IMS setting. Even if the user has
5582 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5583 // In the long run, we may instead need to check if there exists a connection service
5584 // which can support video calling.
5585 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005586 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 return imsManager.isVtEnabledByPlatform()
5588 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5589 && imsManager.isVtEnabledByUser();
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
5592 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005593 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005594
Andrew Leea1239f22015-03-02 17:44:07 -08005595 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5597 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5598 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5599 return false;
5600 }
5601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 CarrierConfigManager configManager =
5605 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005606 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
Andrew Leea1239f22015-03-02 17:44:07 -08005611 }
5612
5613 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 public boolean isWorldPhone(int subId, String callingPackage) {
5615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5616 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5617 return false;
5618 }
5619
5620 final long identity = Binder.clearCallingIdentity();
5621 try {
5622 CarrierConfigManager configManager =
5623 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005624 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005625 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
5628 }
Andrew Leea1239f22015-03-02 17:44:07 -08005629 }
5630
Andrew Lee9431b832015-03-09 18:46:45 -07005631 @Override
5632 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005633 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005634 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005635 }
5636
5637 @Override
5638 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005641 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 } finally {
5643 Binder.restoreCallingIdentity(identity);
5644 }
Andrew Lee9431b832015-03-09 18:46:45 -07005645 }
5646
Hall Liuf6668912018-10-31 17:05:23 -07005647 /**
5648 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5649 * support for the feature and device firmware support.
5650 *
5651 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5652 */
5653 @Override
5654 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005656 final Phone phone = getPhone(subscriptionId);
5657 if (phone == null) {
5658 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5659 return false;
5660 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005662 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5664 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005665 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 return isCarrierSupported && isDeviceSupported;
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Hall Liu98187582018-01-22 19:15:32 -08005670 }
5671
Hall Liuf6668912018-10-31 17:05:23 -07005672 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005673 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5674 * RTT setting, will return true if the device and carrier both support RTT.
5675 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005676 */
5677 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 final long identity = Binder.clearCallingIdentity();
5679 try {
Hall Liu30de3502019-10-29 16:50:20 -07005680 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005684 }
5685
Sanket Padawe7310cc72015-01-14 09:53:20 -08005686 /**
5687 * Returns the unique device ID of phone, for example, the IMEI for
5688 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5689 *
5690 * <p>Requires Permission:
5691 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5692 */
5693 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005694 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005695 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005696 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005697 return null;
5698 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005699 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005700 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5701 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005702 return null;
5703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 return phone.getDeviceId();
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005711 }
5712
Ping Sunc67b7c22016-03-02 19:16:45 +08005713 /**
5714 * {@hide}
5715 * Returns the IMS Registration Status on a particular subid
5716 *
5717 * @param subId
5718 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005719 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005720 Phone phone = getPhone(subId);
5721 if (phone != null) {
5722 return phone.isImsRegistered();
5723 } else {
5724 return false;
5725 }
5726 }
5727
Santos Cordon7a1885b2015-02-03 11:15:19 -08005728 @Override
5729 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005736 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005737
Tyler Gunnf70ed162019-04-03 15:28:53 -07005738 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005739 public int getSubIdForPhoneAccountHandle(
5740 PhoneAccountHandle phoneAccountHandle, String callingPackage) {
5741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
5742 callingPackage, "getSubIdForPhoneAccountHandle")) {
5743 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5744 }
5745 final long identity = Binder.clearCallingIdentity();
5746 try {
5747 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
5751 }
5752
5753 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005754 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 Phone phone = getPhone(subscriptionId);
5758 if (phone == null) {
5759 return null;
5760 }
5761 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
5764 }
5765 }
5766
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005767 /**
5768 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005769 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005770 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 Phone phone = getPhone(subId);
5774 if (phone != null) {
5775 return phone.isWifiCallingEnabled();
5776 } else {
5777 return false;
5778 }
5779 } finally {
5780 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005781 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005782 }
5783
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005784 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005785 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005786 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005787 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788 final long identity = Binder.clearCallingIdentity();
5789 try {
5790 Phone phone = getPhone(subId);
5791 if (phone != null) {
5792 return phone.isVideoEnabled();
5793 } else {
5794 return false;
5795 }
5796 } finally {
5797 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005798 }
5799 }
5800
5801 /**
5802 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5803 * defined in {@link ImsRegistrationImplBase}.
5804 */
5805 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 Phone phone = getPhone(subId);
5809 if (phone != null) {
5810 return phone.getImsRegistrationTech();
5811 } else {
5812 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5813 }
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005816 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005817 }
5818
Stuart Scott8eef64f2015-04-08 15:13:54 -07005819 @Override
5820 public void factoryReset(int subId) {
5821 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005822 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5823 return;
5824 }
5825
Svet Ganovcc087f82015-05-12 20:35:54 -07005826 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005827
Svet Ganovcc087f82015-05-12 20:35:54 -07005828 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005829 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5830 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005831 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005832 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005833 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005834 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5835 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005836 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005837 // There has been issues when Sms raw table somehow stores orphan
5838 // fragments. They lead to garbled message when new fragments come
5839 // in and combined with those stale ones. In case this happens again,
5840 // user can reset all network settings which will clean up this table.
5841 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005842 // Clean up IMS settings as well here.
5843 int slotId = getSlotIndex(subId);
5844 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5845 ImsManager.getInstance(mApp, slotId).factoryReset();
5846 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005847 } finally {
5848 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005849 }
5850 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005851
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005852 private void cleanUpSmsRawTable(Context context) {
5853 ContentResolver resolver = context.getContentResolver();
5854 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5855 resolver.delete(uri, null, null);
5856 }
5857
Narayan Kamath1c496c22015-04-16 14:40:19 +01005858 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005859 public String getSimLocaleForSubscriber(int subId) {
5860 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5861 final Phone phone = getPhone(subId);
5862 if (phone == null) {
5863 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005864 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866 final long identity = Binder.clearCallingIdentity();
5867 try {
chen xu5d3637b2019-01-21 23:31:38 -08005868 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5869 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005870 if (info == null) {
5871 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5872 return null;
5873 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 // Try and fetch the locale from the carrier properties or from the SIM language
5875 // preferences (EF-PL and EF-LI)...
5876 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005878 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5879 if (localeFromDefaultSim != null) {
5880 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5881 if (DBG) log("Using locale from subId: " + subId + " locale: "
5882 + localeFromDefaultSim);
5883 return localeFromDefaultSim.toLanguageTag();
5884 } else {
5885 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 }
5887 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 // The SIM language preferences only store a language (e.g. fr = French), not an
5890 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5891 // the SIM and carrier preferences does not include a country we add the country
5892 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005893 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005895 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 return mccLocale.toLanguageTag();
5897 }
5898
5899 if (DBG) log("No locale found - returning null");
5900 return null;
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005904 }
5905
5906 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005907 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005908 }
5909
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005910 /**
5911 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5912 */
5913 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005914 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005915 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005916
Chenjie Yu1ba97252018-01-11 18:16:20 -08005917 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005918 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005919
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005920 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005921 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5922 * representing the state of the modem.
5923 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005924 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5925 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005926 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005927 */
5928 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005929 public void requestModemActivityInfo(ResultReceiver result) {
5930 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005931 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932
5933 final long identity = Binder.clearCallingIdentity();
5934 try {
5935 ModemActivityInfo ret = null;
5936 synchronized (mLastModemActivityInfo) {
5937 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5938 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005939 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005940 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005942 int[] txTimeMs = info.getTransmitTimeMillis();
5943 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005945 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005946 }
5947 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005948 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5949 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005950 mLastModemActivityInfo.setIdleTimeMillis(
5951 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005952 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5953 mLastModemActivityInfo.setReceiveTimeMillis(
5954 info.getReceiveTimeMillis() + mLastModemActivityInfo
5955 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005956 }
Chen Xud78231e2019-09-10 18:49:52 -07005957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5959 mLastModemActivityInfo.getSleepTimeMillis(),
5960 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005961 mLastModemActivityInfo.getTransmitTimeMillis(),
5962 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005963 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005964 Bundle bundle = new Bundle();
5965 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5966 result.send(0, bundle);
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005969 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005970 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005971
Siddharth Rayb8114062018-06-17 15:02:38 -07005972 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5973 // less than total activity duration.
5974 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5975 if (info == null) {
5976 return false;
5977 }
5978 int activityDurationMs =
5979 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5980 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005981 int[] txTimeMs = info.getTransmitTimeMillis();
5982 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5983 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005984 }
5985 return (info.isValid()
5986 && (info.getSleepTimeMillis() <= activityDurationMs)
5987 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005988 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005989 && (totalTxTimeMs <= activityDurationMs));
5990 }
5991
Jack Yu85bd38a2015-11-09 11:34:32 -08005992 /**
5993 * {@hide}
5994 * Returns the service state information on specified subscription.
5995 */
5996 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005997 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
5998 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005999 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006000 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006001 return null;
6002 }
6003
Hall Liuf19c44f2018-11-27 14:38:17 -08006004 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6005 LocationAccessPolicy.checkLocationPermission(mApp,
6006 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6007 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006008 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006009 .setCallingPid(Binder.getCallingPid())
6010 .setCallingUid(Binder.getCallingUid())
6011 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006012 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006013 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6014 .build());
6015
6016 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6017 LocationAccessPolicy.checkLocationPermission(mApp,
6018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6019 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006021 .setCallingPid(Binder.getCallingPid())
6022 .setCallingUid(Binder.getCallingUid())
6023 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006024 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006025 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6026 .build());
6027 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6028 boolean hasFinePermission =
6029 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6030 boolean hasCoarsePermission =
6031 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 final Phone phone = getPhone(subId);
6036 if (phone == null) {
6037 return null;
6038 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006039
Hall Liuf19c44f2018-11-27 14:38:17 -08006040 ServiceState ss = phone.getServiceState();
6041
6042 // Scrub out the location info in ServiceState depending on what level of access
6043 // the caller has.
6044 if (hasFinePermission) return ss;
6045 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6046 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006050 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006051
6052 /**
6053 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6054 *
6055 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6056 * voicemail ringtone.
6057 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6058 * PhoneAccount.
6059 */
6060 @Override
6061 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
6064 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6065 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006066 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
6072 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006073 }
6074
6075 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006076 * Sets the per-account voicemail ringtone.
6077 *
6078 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6079 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6080 *
6081 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6082 * voicemail ringtone.
6083 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6084 * PhoneAccount.
6085 */
6086 @Override
6087 public void setVoicemailRingtoneUri(String callingPackage,
6088 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006089 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006090 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006091 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6092 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6094 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6095 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006096 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097
6098 final long identity = Binder.clearCallingIdentity();
6099 try {
6100 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6101 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006102 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006103 }
6104 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6105 } finally {
6106 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006107 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006108 }
6109
6110 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006111 * Returns whether vibration is set for voicemail notification in Phone settings.
6112 *
6113 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6114 * voicemail vibration setting.
6115 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6116 */
6117 @Override
6118 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 final long identity = Binder.clearCallingIdentity();
6120 try {
6121 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6122 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006123 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006125
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006126 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6127 } finally {
6128 Binder.restoreCallingIdentity(identity);
6129 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006130 }
6131
Youhan Wange64578a2016-05-02 15:32:42 -07006132 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006133 * Sets the per-account voicemail vibration.
6134 *
6135 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6136 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6137 *
6138 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6139 * voicemail vibration setting.
6140 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6141 * specific PhoneAccount.
6142 */
6143 @Override
6144 public void setVoicemailVibrationEnabled(String callingPackage,
6145 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006146 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006147 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006148 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6149 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6151 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6152 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006153 }
6154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006155 final long identity = Binder.clearCallingIdentity();
6156 try {
6157 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6158 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006159 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006160 }
6161 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006164 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006165 }
6166
6167 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006168 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6169 *
6170 * @throws SecurityException if the caller does not have the required permission
6171 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006172 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006173 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006174 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006175 }
6176
6177 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006178 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6179 * permission.
6180 *
6181 * @throws SecurityException if the caller does not have the required permission
6182 */
6183 private void enforceSendSmsPermission() {
6184 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6185 }
6186
6187 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006188 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006189 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006190 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006191 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006192 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006196 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 if (componentName == null) {
6198 throw new SecurityException(
6199 "Caller not current active visual voicemail package[null]");
6200 }
6201 String vvmPackage = componentName.getPackageName();
6202 if (!callingPackage.equals(vvmPackage)) {
6203 throw new SecurityException("Caller not current active visual voicemail package["
6204 + vvmPackage + "]");
6205 }
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006208 }
6209 }
6210
6211 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006212 * Return the application ID for the app type.
6213 *
6214 * @param subId the subscription ID that this request applies to.
6215 * @param appType the uicc app type.
6216 * @return Application ID for specificied app type, or null if no uicc.
6217 */
6218 @Override
6219 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006220 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006221 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222
6223 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006224 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006225 if (phone == null) {
6226 return null;
6227 }
6228 String aid = null;
6229 try {
6230 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6231 .getApplicationByType(appType).getAid();
6232 } catch (Exception e) {
6233 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6234 }
6235 return aid;
6236 } finally {
6237 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006238 }
Youhan Wange64578a2016-05-02 15:32:42 -07006239 }
6240
Youhan Wang4001d252016-05-11 10:29:41 -07006241 /**
6242 * Return the Electronic Serial Number.
6243 *
6244 * @param subId the subscription ID that this request applies to.
6245 * @return ESN or null if error.
6246 */
6247 @Override
6248 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006249 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006250 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251
6252 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006253 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006254 if (phone == null) {
6255 return null;
6256 }
6257 String esn = null;
6258 try {
6259 esn = phone.getEsn();
6260 } catch (Exception e) {
6261 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6262 }
6263 return esn;
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006266 }
Youhan Wang4001d252016-05-11 10:29:41 -07006267 }
6268
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006269 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006270 * Return the Preferred Roaming List Version.
6271 *
6272 * @param subId the subscription ID that this request applies to.
6273 * @return PRLVersion or null if error.
6274 */
6275 @Override
6276 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006277 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006278 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279
6280 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006281 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 if (phone == null) {
6283 return null;
6284 }
6285 String cdmaPrlVersion = null;
6286 try {
6287 cdmaPrlVersion = phone.getCdmaPrlVersion();
6288 } catch (Exception e) {
6289 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6290 }
6291 return cdmaPrlVersion;
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006294 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006295 }
6296
6297 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006298 * Get snapshot of Telephony histograms
6299 * @return List of Telephony histograms
6300 * @hide
6301 */
6302 @Override
6303 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6305 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306
6307 final long identity = Binder.clearCallingIdentity();
6308 try {
6309 return RIL.getTelephonyRILTimingHistograms();
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
6312 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006313 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006314
6315 /**
6316 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006317 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6318 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006319 * Require system privileges. In the future we may add this to carrier APIs.
6320 *
Michele Berionne482f8202018-11-27 18:57:59 -08006321 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006322 */
6323 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006324 @TelephonyManager.SetCarrierRestrictionResult
6325 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006326 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006327 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006328
Michele Berionne482f8202018-11-27 18:57:59 -08006329 if (carrierRestrictionRules == null) {
6330 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006331 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006332
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333 final long identity = Binder.clearCallingIdentity();
6334 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006335 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006336 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006340 }
6341
6342 /**
6343 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006344 * Get the allowed carrier list and the excluded carrier list, including the priority between
6345 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006346 * Require system privileges. In the future we may add this to carrier APIs.
6347 *
Michele Berionne482f8202018-11-27 18:57:59 -08006348 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006349 */
6350 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006351 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006352 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006357 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6358 if (response instanceof CarrierRestrictionRules) {
6359 return (CarrierRestrictionRules) response;
6360 }
6361 // Response is an Exception of some kind,
6362 // which is signalled to the user as a NULL retval
6363 return null;
6364 } catch (Exception e) {
6365 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6366 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006370 }
6371
fionaxu59545b42016-05-25 15:53:37 -07006372 /**
6373 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6374 * @param subId the subscription ID that this action applies to.
6375 * @param enabled control enable or disable metered apns.
6376 * {@hide}
6377 */
6378 @Override
6379 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6380 enforceModifyPermission();
6381 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382
6383 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006384 if (phone == null) {
6385 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6386 return;
6387 }
6388 try {
6389 phone.carrierActionSetMeteredApnsEnabled(enabled);
6390 } catch (Exception e) {
6391 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 } finally {
6393 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006394 }
6395 }
6396
6397 /**
6398 * Action set from carrier signalling broadcast receivers to enable/disable radio
6399 * @param subId the subscription ID that this action applies to.
6400 * @param enabled control enable or disable radio.
6401 * {@hide}
6402 */
6403 @Override
6404 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6405 enforceModifyPermission();
6406 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407
6408 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006409 if (phone == null) {
6410 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6411 return;
6412 }
6413 try {
6414 phone.carrierActionSetRadioEnabled(enabled);
6415 } catch (Exception e) {
6416 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417 } finally {
6418 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006419 }
6420 }
6421
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006422 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006423 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6424 * network status based on which carrier apps could apply actions accordingly,
6425 * enable/disable default url handler for example.
6426 *
6427 * @param subId the subscription ID that this action applies to.
6428 * @param report control start/stop reporting the default network status.
6429 * {@hide}
6430 */
6431 @Override
6432 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6433 enforceModifyPermission();
6434 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435
6436 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006437 if (phone == null) {
6438 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6439 return;
6440 }
6441 try {
6442 phone.carrierActionReportDefaultNetworkStatus(report);
6443 } catch (Exception e) {
6444 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 } finally {
6446 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006447 }
6448 }
6449
6450 /**
fionaxud9622282017-07-17 17:51:30 -07006451 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6452 * @param subId the subscription ID that this action applies to.
6453 * {@hide}
6454 */
6455 @Override
6456 public void carrierActionResetAll(int subId) {
6457 enforceModifyPermission();
6458 final Phone phone = getPhone(subId);
6459 if (phone == null) {
6460 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6461 return;
6462 }
6463 try {
6464 phone.carrierActionResetAll();
6465 } catch (Exception e) {
6466 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6467 }
6468 }
6469
6470 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006471 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6472 * bug report is being generated.
6473 */
6474 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006475 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006476 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6477 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006478 writer.println("Permission Denial: can't dump Phone from pid="
6479 + Binder.getCallingPid()
6480 + ", uid=" + Binder.getCallingUid()
6481 + "without permission "
6482 + android.Manifest.permission.DUMP);
6483 return;
6484 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006485 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006486 }
Jack Yueb89b242016-06-22 13:27:47 -07006487
Brad Ebingerdac2f002018-04-03 15:17:52 -07006488 @Override
6489 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6490 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6491 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006492 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6493 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006494 }
6495
Jack Yueb89b242016-06-22 13:27:47 -07006496 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006497 * Get aggregated video call data usage since boot.
6498 *
6499 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6500 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006501 * {@hide}
6502 */
6503 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006504 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006505 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6506 null);
6507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 // NetworkStatsService keeps tracking the active network interface and identity. It
6511 // records the delta with the corresponding network identity.
6512 // We just return the total video call data usage snapshot since boot.
6513 Phone phone = getPhone(subId);
6514 if (phone != null) {
6515 return phone.getVtDataUsage(perUidStats);
6516 }
6517 return null;
6518 } finally {
6519 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006520 }
Jack Yueb89b242016-06-22 13:27:47 -07006521 }
Jack Yu75ab2952016-07-08 14:29:33 -07006522
6523 /**
6524 * Policy control of data connection. Usually used when data limit is passed.
6525 * @param enabled True if enabling the data, otherwise disabling.
6526 * @param subId Subscription index
6527 * {@hide}
6528 */
6529 @Override
6530 public void setPolicyDataEnabled(boolean enabled, int subId) {
6531 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532
6533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 Phone phone = getPhone(subId);
6536 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006537 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 }
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006541 }
6542 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006543
6544 /**
6545 * Get Client request stats
6546 * @return List of Client Request Stats
6547 * @hide
6548 */
6549 @Override
6550 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006551 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006552 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006553 return null;
6554 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006555 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 final long identity = Binder.clearCallingIdentity();
6558 try {
6559 if (phone != null) {
6560 return phone.getClientRequestStats();
6561 }
6562
6563 return null;
6564 } finally {
6565 Binder.restoreCallingIdentity(identity);
6566 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006567 }
6568
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006569 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006570 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006571 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006572 }
Jack Yueb4124c2017-02-16 15:32:43 -08006573
6574 /**
Grace Chen70990072017-03-24 17:21:30 -07006575 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006576 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006577 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006578 * @param state State of SIM (power down, power up, pass through)
6579 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6580 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6581 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006582 *
6583 **/
6584 @Override
Grace Chen70990072017-03-24 17:21:30 -07006585 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006586 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006587 Phone phone = PhoneFactory.getPhone(slotIndex);
6588
vagdeviaf9a5b92018-08-15 16:01:53 -07006589 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006591 final long identity = Binder.clearCallingIdentity();
6592 try {
6593 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006594 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006598 }
6599 }
Shuo Qiandd210312017-04-12 22:11:33 +00006600
Tyler Gunn65d45c22017-06-05 11:22:26 -07006601 private boolean isUssdApiAllowed(int subId) {
6602 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006603 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006604 if (configManager == null) {
6605 return false;
6606 }
6607 PersistableBundle pb = configManager.getConfigForSubId(subId);
6608 if (pb == null) {
6609 return false;
6610 }
6611 return pb.getBoolean(
6612 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6613 }
6614
Shuo Qiandd210312017-04-12 22:11:33 +00006615 /**
6616 * Check if phone is in emergency callback mode
6617 * @return true if phone is in emergency callback mode
6618 * @param subId sub id
6619 */
goneil9c5f4872017-12-05 14:07:56 -08006620 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006621 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006622 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006623 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 if (phone != null) {
6628 return phone.isInEcm();
6629 } else {
6630 return false;
6631 }
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006634 }
6635 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006636
6637 /**
6638 * Get the current signal strength information for the given subscription.
6639 * Because this information is not updated when the device is in a low power state
6640 * it should not be relied-upon to be current.
6641 * @param subId Subscription index
6642 * @return the most recent cached signal strength info from the modem
6643 */
6644 @Override
6645 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 Phone p = getPhone(subId);
6649 if (p == null) {
6650 return null;
6651 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 return p.getSignalStrength();
6654 } finally {
6655 Binder.restoreCallingIdentity(identity);
6656 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006657 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006658
Pengquan Meng77b7f132018-08-22 14:49:57 -07006659 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006660 * Get the current modem radio state for the given slot.
6661 * @param slotIndex slot index.
6662 * @param callingPackage the name of the package making the call.
6663 * @return the current radio power state from the modem
6664 */
6665 @Override
6666 public int getRadioPowerState(int slotIndex, String callingPackage) {
6667 Phone phone = PhoneFactory.getPhone(slotIndex);
6668 if (phone != null) {
6669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6670 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6671 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6672 }
6673
6674 final long identity = Binder.clearCallingIdentity();
6675 try {
6676 return phone.getRadioPowerState();
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
6680 }
6681 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6682 }
6683
6684 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006685 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6686 *
6687 * <p>Requires one of the following permissions:
6688 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6689 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6690 * privileges.
6691 *
6692 * @param subId subscription id
6693 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6694 * {@code false}.
6695 */
6696 @Override
6697 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006698 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6699 null /* message */);
6700
Pengquan Menga1bb6272018-09-06 09:59:22 -07006701 boolean isEnabled = false;
6702 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006703 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006704 Phone phone = getPhone(subId);
6705 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006706 } catch (Exception e) {
6707 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6708 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006709 } finally {
6710 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006712 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006713 }
6714
6715
6716 /**
6717 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6718 *
6719 * <p> Requires permission:
6720 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6721 * privileges.
6722 *
6723 * @param subId subscription id
6724 * @param isEnabled {@code true} means enable, {@code false} means disable.
6725 */
6726 @Override
6727 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006728 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6729 mApp, subId, "setDataRoamingEnabled");
6730
Pengquan Menga1bb6272018-09-06 09:59:22 -07006731 final long identity = Binder.clearCallingIdentity();
6732 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006733 Phone phone = getPhone(subId);
6734 if (phone != null) {
6735 phone.setDataRoamingEnabled(isEnabled);
6736 }
6737 } finally {
6738 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006739 }
6740 }
6741
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006742 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006743 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006744 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6745 mApp, subId, "isManualNetworkSelectionAllowed");
6746
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006747 boolean isAllowed = true;
6748 final long identity = Binder.clearCallingIdentity();
6749 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006750 Phone phone = getPhone(subId);
6751 if (phone != null) {
6752 isAllowed = phone.isCspPlmnEnabled();
6753 }
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
6756 }
6757 return isAllowed;
6758 }
6759
6760 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006761 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006762 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006763 try {
6764 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006765 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006766 } catch (SecurityException e) {
6767 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6768 // has carrier privileges on an active UICC
6769 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6770 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006771 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006772 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006773 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006777 UiccController uiccController = UiccController.getInstance();
6778 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006779 if (hasReadPermission) {
6780 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006781 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006782
6783 // Remove private info if the caller doesn't have access
6784 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6785 for (UiccCardInfo cardInfo : cardInfos) {
6786 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6787 // is available
6788 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6789 if (card == null || card.getUiccProfile() == null) {
6790 // assume no access if the card or profile is unavailable
6791 filteredInfos.add(cardInfo.getUnprivileged());
6792 continue;
6793 }
6794 UiccProfile profile = card.getUiccProfile();
6795 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6796 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6797 filteredInfos.add(cardInfo);
6798 } else {
6799 filteredInfos.add(cardInfo.getUnprivileged());
6800 }
6801 }
6802 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006803 } finally {
6804 Binder.restoreCallingIdentity(identity);
6805 }
6806 }
6807
6808 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006809 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006810 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6815 if (slots == null) {
6816 Rlog.i(LOG_TAG, "slots is null.");
6817 return null;
6818 }
6819
6820 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6821 for (int i = 0; i < slots.length; i++) {
6822 UiccSlot slot = slots[i];
6823 if (slot == null) {
6824 continue;
6825 }
6826
Jordan Liu7be7e652019-05-06 18:55:02 +00006827 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 UiccCard card = slot.getUiccCard();
6829 if (card != null) {
6830 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006831 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006832 cardId = slot.getEid();
6833 if (TextUtils.isEmpty(cardId)) {
6834 cardId = slot.getIccId();
6835 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006836 }
6837
Jordan Liu857451f2019-05-09 16:35:35 -07006838 if (cardId != null) {
6839 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6840 // if cardId is an EID, it's all digits so this is fine
6841 cardId = IccUtils.stripTrailingFs(cardId);
6842 }
6843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006844 int cardState = 0;
6845 switch (slot.getCardState()) {
6846 case CARDSTATE_ABSENT:
6847 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6848 break;
6849 case CARDSTATE_PRESENT:
6850 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6851 break;
6852 case CARDSTATE_ERROR:
6853 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6854 break;
6855 case CARDSTATE_RESTRICTED:
6856 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6857 break;
6858 default:
6859 break;
6860
6861 }
6862
6863 infos[i] = new UiccSlotInfo(
6864 slot.isActive(),
6865 slot.isEuicc(),
6866 cardId,
6867 cardState,
6868 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006869 slot.isExtendedApduSupported(),
6870 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 }
6872 return infos;
6873 } finally {
6874 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006875 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006876 }
6877
6878 @Override
6879 public boolean switchSlots(int[] physicalSlots) {
6880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
6884 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6885 } finally {
6886 Binder.restoreCallingIdentity(identity);
6887 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006888 }
Jack Yu4c988042018-02-27 15:30:01 -08006889
6890 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006891 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 return UiccController.getInstance().getCardIdForDefaultEuicc();
6895 } finally {
6896 Binder.restoreCallingIdentity(identity);
6897 }
6898 }
6899
6900 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006901 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6902 enforceModifyPermission();
6903 final Phone phone = getPhone(subId);
6904 if (phone == null) {
6905 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6906 return;
6907 }
6908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 phone.setRadioIndicationUpdateMode(filters, mode);
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Jack Yu4c988042018-02-27 15:30:01 -08006915 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006916
6917 /**
goneil47ffb6e2018-04-06 15:40:58 -07006918 * A test API to reload the UICC profile.
6919 *
6920 * <p>Requires that the calling app has permission
6921 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6922 * @hide
6923 */
6924 @Override
6925 public void refreshUiccProfile(int subId) {
6926 enforceModifyPermission();
6927
6928 final long identity = Binder.clearCallingIdentity();
6929 try {
6930 Phone phone = getPhone(subId);
6931 if (phone == null) {
6932 return;
6933 }
6934 UiccCard uiccCard = phone.getUiccCard();
6935 if (uiccCard == null) {
6936 return;
6937 }
6938 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6939 if (uiccProfile == null) {
6940 return;
6941 }
6942 uiccProfile.refresh();
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
6947
6948 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006949 * Returns false if the mobile data is disabled by default, otherwise return true.
6950 */
6951 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006952 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006953 }
6954
6955 /**
6956 * Returns true if the data roaming is enabled by default, i.e the system property
6957 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6958 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6959 */
6960 private boolean getDefaultDataRoamingEnabled(int subId) {
6961 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006962 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09006963 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006964 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6965 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6966 return isDataRoamingEnabled;
6967 }
6968
6969 /**
6970 * Returns the default network type for the given {@code subId}, if the default network type is
6971 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6972 */
6973 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09006974 List<Integer> list = TelephonyProperties.default_network();
6975 int phoneId = mSubscriptionController.getPhoneId(subId);
6976 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
6977 return list.get(phoneId);
6978 }
6979 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07006980 }
fionaxua13278b2018-03-21 00:08:13 -07006981
6982 @Override
6983 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006984 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006985 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 final Phone phone = getPhone(subId);
6990 if (phone == null) {
6991 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6992 return;
6993 }
chen xueaba88a2019-03-15 13:15:10 -07006994 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6995 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006996 } finally {
6997 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006998 }
fionaxua13278b2018-03-21 00:08:13 -07006999 }
7000
7001 @Override
7002 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007003 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004
7005 final long identity = Binder.clearCallingIdentity();
7006 try {
7007 final Phone phone = getPhone(subId);
7008 if (phone == null) {
7009 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7010 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7011 }
7012 return phone.getCarrierIdListVersion();
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007015 }
fionaxua13278b2018-03-21 00:08:13 -07007016 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007017
7018 @Override
7019 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7021 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7022 return -1;
7023 }
7024
7025 final long identity = Binder.clearCallingIdentity();
7026 try {
7027 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
7030 }
7031 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007032
7033 @Override
7034 public int getCdmaRoamingMode(int subId) {
7035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7036 mApp, subId, "getCdmaRoamingMode");
7037
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
7040 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
7047 public boolean setCdmaRoamingMode(int subId, int mode) {
7048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7049 mApp, subId, "setCdmaRoamingMode");
7050
7051 final long identity = Binder.clearCallingIdentity();
7052 try {
7053 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
7057 }
7058
7059 @Override
7060 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7062 mApp, subId, "setCdmaSubscriptionMode");
7063
7064 final long identity = Binder.clearCallingIdentity();
7065 try {
7066 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7067 } finally {
7068 Binder.restoreCallingIdentity(identity);
7069 }
7070 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007071
sqianc5eccab2018-10-19 18:46:41 -07007072 @Override
sqian8c685422019-02-22 15:55:18 -08007073 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007074 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007076 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007077 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7078 }
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
sqian854d44b2018-12-12 16:48:18 -08007081 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7082 for (Phone phone: PhoneFactory.getPhones()) {
7083 if (phone.getEmergencyNumberTracker() != null
7084 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7085 emergencyNumberListInternal.put(
7086 phone.getSubId(),
7087 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7088 }
sqian11b7a0e2018-12-05 18:48:28 -08007089 }
sqian854d44b2018-12-12 16:48:18 -08007090 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
sqianc5eccab2018-10-19 18:46:41 -07007094 }
7095
7096 @Override
sqian8c685422019-02-22 15:55:18 -08007097 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007098 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007099 if (!exactMatch) {
7100 TelephonyPermissions
7101 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007102 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007103 }
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
sqian854d44b2018-12-12 16:48:18 -08007106 for (Phone phone: PhoneFactory.getPhones()) {
7107 if (phone.getEmergencyNumberTracker() != null
7108 && phone.getEmergencyNumberTracker() != null) {
7109 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7110 number, exactMatch)) {
7111 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007112 }
7113 }
sqian11b7a0e2018-12-05 18:48:28 -08007114 }
7115 return false;
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
7119 }
7120
sqianf4ca7ed2019-01-15 18:32:07 -08007121 /**
7122 * Update emergency number list for test mode.
7123 */
7124 @Override
7125 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7127 "updateEmergencyNumberListTestMode");
7128
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 for (Phone phone: PhoneFactory.getPhones()) {
7132 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7133 if (tracker != null) {
7134 tracker.executeEmergencyNumberTestModeCommand(action, num);
7135 }
7136 }
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
7140 }
7141
7142 /**
7143 * Get the full emergency number list for test mode.
7144 */
7145 @Override
7146 public List<String> getEmergencyNumberListTestMode() {
7147 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7148 "getEmergencyNumberListTestMode");
7149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 Set<String> emergencyNumbers = new HashSet<>();
7153 for (Phone phone: PhoneFactory.getPhones()) {
7154 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7155 if (tracker != null) {
7156 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7157 emergencyNumbers.add(num.getNumber());
7158 }
7159 }
7160 }
7161 return new ArrayList<>(emergencyNumbers);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
chen xud6b45bd2018-10-30 22:27:10 -07007167 @Override
7168 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7169 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7170 Phone phone = getPhone(subId);
7171 if (phone == null) {
7172 return null;
7173 }
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 UiccProfile profile = UiccController.getInstance()
7177 .getUiccProfileForPhone(phone.getPhoneId());
7178 if (profile != null) {
7179 return profile.getCertsFromCarrierPrivilegeAccessRules();
7180 }
7181 } finally {
7182 Binder.restoreCallingIdentity(identity);
7183 }
7184 return null;
7185 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007186
7187 /**
7188 * Enable or disable a modem stack.
7189 */
7190 @Override
7191 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7192 enforceModifyPermission();
7193
7194 final long identity = Binder.clearCallingIdentity();
7195 try {
7196 Phone phone = PhoneFactory.getPhone(slotIndex);
7197 if (phone == null) {
7198 return false;
7199 } else {
7200 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7201 }
7202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
7205 }
Michelecea4cf22018-12-21 15:00:11 -08007206
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007207 /**
7208 * Whether a modem stack is enabled or not.
7209 */
7210 @Override
7211 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7212 Phone phone = PhoneFactory.getPhone(slotIndex);
7213 if (phone == null) return false;
7214
7215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7216 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7217 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7218 }
7219
7220 final long identity = Binder.clearCallingIdentity();
7221 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007222 try {
7223 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7224 } catch (NoSuchElementException ex) {
7225 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7226 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007227 } finally {
7228 Binder.restoreCallingIdentity(identity);
7229 }
7230 }
7231
Michelecea4cf22018-12-21 15:00:11 -08007232 @Override
Michele0ea7d782019-03-19 14:58:42 -07007233 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007234 enforceModifyPermission();
7235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
7238 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007239 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007240 .commit();
7241 } finally {
7242 Binder.restoreCallingIdentity(identity);
7243 }
7244 }
7245
7246 @Override
Michele0ea7d782019-03-19 14:58:42 -07007247 @TelephonyManager.IsMultiSimSupportedResult
7248 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007249 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007250 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7251 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007252 }
Michelecea4cf22018-12-21 15:00:11 -08007253
7254 final long identity = Binder.clearCallingIdentity();
7255 try {
Michele0ea7d782019-03-19 14:58:42 -07007256 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007261
Michele0ea7d782019-03-19 14:58:42 -07007262 @TelephonyManager.IsMultiSimSupportedResult
7263 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007264 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7265 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7266 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007267 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7268 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007269 }
7270 // Check if the hardware supports multisim functionality. If usage of multisim is not
7271 // supported by the modem, indicate that it is restricted.
7272 PhoneCapability staticCapability =
7273 mPhoneConfigurationManager.getStaticPhoneCapability();
7274 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007275 loge("isMultiSimSupportedInternal: no static configuration available");
7276 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007277 }
7278 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007279 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7280 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007281 }
7282 // Check if support of multiple SIMs is restricted by carrier
7283 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007284 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007285 }
7286
Michele0ea7d782019-03-19 14:58:42 -07007287 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007288 }
7289
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007290 /**
7291 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007292 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7293 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7294 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007295 * @param numOfSims number of active sims we want to switch to
7296 */
7297 @Override
7298 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007299 if (numOfSims == 1) {
7300 enforceModifyPermission();
7301 } else {
7302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7303 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7304 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007305 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007306
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007307 try {
Michele30b57b22019-03-01 12:01:14 -08007308 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007309 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007310 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7311 return;
7312 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007313 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7314 } finally {
7315 Binder.restoreCallingIdentity(identity);
7316 }
7317 }
7318
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007319 @Override
7320 public boolean isApplicationOnUicc(int subId, int appType) {
7321 enforceReadPrivilegedPermission("isApplicationOnUicc");
7322 Phone phone = getPhone(subId);
7323 if (phone == null) {
7324 return false;
7325 }
7326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 UiccCard uiccCard = phone.getUiccCard();
7329 if (uiccCard == null) {
7330 return false;
7331 }
7332 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7333 if (uiccProfile == null) {
7334 return false;
7335 }
7336 if (TelephonyManager.APPTYPE_SIM <= appType
7337 && appType <= TelephonyManager.APPTYPE_ISIM) {
7338 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7339 }
7340 return false;
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007346 /**
chen xub4baa772019-04-03 10:23:41 -07007347 * Get whether making changes to modem configurations will trigger reboot.
7348 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007349 */
7350 @Override
chen xub4baa772019-04-03 10:23:41 -07007351 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7353 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7354 return false;
7355 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7359 } finally {
7360 Binder.restoreCallingIdentity(identity);
7361 }
7362 }
7363
Nathan Harold29f5f052019-02-15 13:41:57 -08007364 private void updateModemStateMetrics() {
7365 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7366 // TODO: check the state for each modem if the api is ready.
7367 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7368 }
7369
Pengquan Meng3889a572019-01-23 11:16:29 -08007370 @Override
7371 public int[] getSlotsMapping() {
7372 enforceReadPrivilegedPermission("getSlotsMapping");
7373
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7377 // All logical slots should have a mapping to a physical slot.
7378 int[] logicalSlotsMapping = new int[phoneCount];
7379 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7380 for (int i = 0; i < slotInfos.length; i++) {
7381 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7382 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7383 }
7384 }
7385 return logicalSlotsMapping;
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
7388 }
7389 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007390
7391 /**
7392 * Get the IRadio HAL Version
7393 */
7394 @Override
7395 public int getRadioHalVersion() {
7396 Phone phone = getDefaultPhone();
7397 if (phone == null) return -1;
7398 HalVersion hv = phone.getHalVersion();
7399 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7400 return hv.major * 100 + hv.minor;
7401 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007402
7403 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007404 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7405 * corresponding network requests on a subId.
7406 *
7407 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007408 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007409 * 2) APN is un-metered for this subscription, or
7410 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7411 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7412 *
7413 * @return whether data is allowed for a apn type.
7414 *
7415 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007416 */
7417 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007418 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007419 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7420 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007421
7422 // Now that all security checks passes, perform the operation as ourselves.
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 Phone phone = getPhone(subId);
7426 if (phone == null) return false;
7427
Jack Yu41407ee2019-05-13 16:54:09 -07007428 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007429 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
7433 }
7434
7435 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007436 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007437 enforceReadPrivilegedPermission("isApnMetered");
7438
7439 // Now that all security checks passes, perform the operation as ourselves.
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 Phone phone = getPhone(subId);
7443 if (phone == null) return true; // By default return true.
7444
Jack Yu41407ee2019-05-13 16:54:09 -07007445 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007446 } finally {
7447 Binder.restoreCallingIdentity(identity);
7448 }
7449 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007450
7451 @Override
7452 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7453 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7454 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7455 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7456 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7457 }
7458 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7459 Intent intent = new Intent();
7460 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7461 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7462 // Bring up choose default SMS subscription dialog right now
7463 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7464 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7465 mApp.startActivity(intent);
7466 }
chen xud5ca2d52019-05-28 15:20:57 -07007467
7468 @Override
7469 public String getMmsUAProfUrl(int subId) {
7470 //TODO investigate if this API should require proper permission check in R b/133791609
7471 final long identity = Binder.clearCallingIdentity();
7472 try {
7473 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7474 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7475 } finally {
7476 Binder.restoreCallingIdentity(identity);
7477 }
7478 }
7479
7480 @Override
7481 public String getMmsUserAgent(int subId) {
7482 //TODO investigate if this API should require proper permission check in R b/133791609
7483 final long identity = Binder.clearCallingIdentity();
7484 try {
7485 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7486 .getString(com.android.internal.R.string.config_mms_user_agent);
7487 } finally {
7488 Binder.restoreCallingIdentity(identity);
7489 }
7490 }
Jack Yub07d4972019-05-28 16:12:25 -07007491
7492 @Override
7493 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7494 enforceModifyPermission();
7495
7496 // Now that all security checks passes, perform the operation as ourselves.
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 Phone phone = getPhone(subId);
7500 if (phone == null) return false;
7501
7502 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
7505 }
7506 }
7507
7508 @Override
7509 public boolean isDataAllowedInVoiceCall(int subId) {
7510 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7511
7512 // Now that all security checks passes, perform the operation as ourselves.
7513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 Phone phone = getPhone(subId);
7516 if (phone == null) return false;
7517
7518 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
7522 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007523
7524 /**
7525 * Updates whether conference event pacakge handling is enabled.
7526 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7527 * otherwise.
7528 */
7529 @Override
7530 public void setCepEnabled(boolean isCepEnabled) {
7531 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7532
7533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7536 for (Phone phone : PhoneFactory.getPhones()) {
7537 Phone defaultPhone = phone.getImsPhone();
7538 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7539 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7540 ImsPhoneCallTracker imsPhoneCallTracker =
7541 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7542 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7543 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7544 + imsPhone.getMsisdn());
7545 }
7546 }
7547 } finally {
7548 Binder.restoreCallingIdentity(identity);
7549 }
7550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007551}