blob: ad517ee50ca57aa192f90ec93beec0339a66e1d2 [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;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070038import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.net.Uri;
40import android.os.AsyncResult;
41import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080042import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Bundle;
44import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070046import android.os.Looper;
47import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070048import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080049import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070050import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070051import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070086import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080087import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080088import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080089import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080090import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800112import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800114import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700115import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800116import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800130import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700131import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800132import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800134import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700135import com.android.internal.telephony.LocaleTracker;
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;
changbetty7157e9e2019-12-06 18:16:37 +0800160import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700163import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000167import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800168import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700169import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800170import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700171import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800173import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700175import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800176import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800177
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700178import java.io.FileDescriptor;
179import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800181import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800182import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800183import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800184import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100185import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700187import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700189
190/**
191 * Implementation of the ITelephony interface.
192 */
Santos Cordon117fee72014-05-16 17:56:12 -0700193public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194 private static final String LOG_TAG = "PhoneInterfaceManager";
195 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
196 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700198
199 // Message codes used with mMainThreadHandler
200 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700201 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
202 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700203 private static final int CMD_OPEN_CHANNEL = 9;
204 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
205 private static final int CMD_CLOSE_CHANNEL = 11;
206 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800207 private static final int CMD_NV_READ_ITEM = 13;
208 private static final int EVENT_NV_READ_ITEM_DONE = 14;
209 private static final int CMD_NV_WRITE_ITEM = 15;
210 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
211 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
212 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700213 private static final int CMD_RESET_MODEM_CONFIG = 19;
214 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800215 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
216 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
217 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
218 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800219 private static final int CMD_SEND_ENVELOPE = 25;
220 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000221 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
222 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700223 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
224 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
225 private static final int CMD_EXCHANGE_SIM_IO = 31;
226 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800227 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
228 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700229 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700231 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
232 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700233 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
234 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
235 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700237 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
238 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
239 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
240 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700241 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800242 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
243 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000244 private static final int CMD_SWITCH_SLOTS = 50;
245 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700246 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
247 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
248 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
249 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
250 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
251 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
252 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
253 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700254 private static final int CMD_GET_ALL_CELL_INFO = 60;
255 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
256 private static final int CMD_GET_CELL_LOCATION = 62;
257 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700258 private static final int CMD_MODEM_REBOOT = 64;
259 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700260 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
261 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800262 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
263 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700264 private static final int CMD_GET_MODEM_STATUS = 70;
265 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700266 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
267 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700268 private static final int CMD_ERASE_MODEM_CONFIG = 74;
269 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800270 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
271 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
272 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
273 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800275 // Parameters of select command.
276 private static final int SELECT_COMMAND = 0xA4;
277 private static final int SELECT_P1 = 0x04;
278 private static final int SELECT_P2 = 0;
279 private static final int SELECT_P3 = 0x10;
280
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281 /** The singleton instance. */
282 private static PhoneInterfaceManager sInstance;
283
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800286 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700287 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800288 private AppOpsManager mAppOps;
289 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800290 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800291 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700292 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700293
Derek Tan97ebb422014-09-05 16:55:38 -0700294 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
295 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800296 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800297 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700298
Michelecea4cf22018-12-21 15:00:11 -0800299 // String to store multi SIM allowed
300 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
301
Derek Tan740e1672017-06-27 14:56:27 -0700302 // The AID of ISD-R.
303 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
304
yinxub1bed742017-04-17 11:45:04 -0700305 private NetworkScanRequestTracker mNetworkScanRequestTracker;
306
David Kelly5e06a7f2018-03-12 14:10:59 +0000307 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
308 private static final int MANUFACTURER_CODE_LENGTH = 8;
309
Derek Tan89e89d42014-07-08 17:00:10 -0700310 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700311 * Experiment flag to enable erase modem config on reset network, default value is false
312 */
313 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
314 "reset_network_erase_modem_config_enabled";
315
316 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class IccAPDUArgument {
320 public int channel, cla, command, p1, p2, p3;
321 public String data;
322
323 public IccAPDUArgument(int channel, int cla, int command,
324 int p1, int p2, int p3, String data) {
325 this.channel = channel;
326 this.cla = cla;
327 this.command = command;
328 this.p1 = p1;
329 this.p2 = p2;
330 this.p3 = p3;
331 this.data = data;
332 }
333 }
334
335 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700336 * A request object to use for transmitting data to an ICC.
337 */
338 private static final class ManualNetworkSelectionArgument {
339 public OperatorInfo operatorInfo;
340 public boolean persistSelection;
341
342 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
343 this.operatorInfo = operatorInfo;
344 this.persistSelection = persistSelection;
345 }
346 }
347
348 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
350 * request after sending. The main thread will notify the request when it is complete.
351 */
352 private static final class MainThreadRequest {
353 /** The argument to use for the request */
354 public Object argument;
355 /** The result of the request that is run on the main thread */
356 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800357 // The subscriber id that this request applies to. Defaults to
358 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
359 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360
Nathan Harold92bed182018-10-12 18:16:49 -0700361 // In cases where subId is unavailable, the caller needs to specify the phone.
362 public Phone phone;
363
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 public WorkSource workSource;
365
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 public MainThreadRequest(Object argument) {
367 this.argument = argument;
368 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800369
Nathan Harold92bed182018-10-12 18:16:49 -0700370 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
371 this.argument = argument;
372 if (phone != null) {
373 this.phone = phone;
374 }
375 this.workSource = workSource;
376 }
377
vagdeviaf9a5b92018-08-15 16:01:53 -0700378 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800380 if (subId != null) {
381 this.subId = subId;
382 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700383 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800384 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385 }
386
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800387 private static final class IncomingThirdPartyCallArgs {
388 public final ComponentName component;
389 public final String callId;
390 public final String callerDisplayName;
391
392 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
393 String callerDisplayName) {
394 this.component = component;
395 this.callId = callId;
396 this.callerDisplayName = callerDisplayName;
397 }
398 }
399
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700400 /**
401 * A handler that processes messages on the main thread in the phone process. Since many
402 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
403 * inbound binder threads to the main thread in the phone process. The Binder thread
404 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
405 * on, which will be notified when the operation completes and will contain the result of the
406 * request.
407 *
408 * <p>If a MainThreadRequest object is provided in the msg.obj field,
409 * note that request.result must be set to something non-null for the calling thread to
410 * unblock.
411 */
412 private final class MainThreadHandler extends Handler {
413 @Override
414 public void handleMessage(Message msg) {
415 MainThreadRequest request;
416 Message onCompleted;
417 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800418 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700419 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800420 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
422 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 case CMD_HANDLE_USSD_REQUEST: {
424 request = (MainThreadRequest) msg.obj;
425 final Phone phone = getPhoneFromRequest(request);
426 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
427 String ussdRequest = ussdObject.first;
428 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700429
Pengquan Menga1bb6272018-09-06 09:59:22 -0700430 if (!isUssdApiAllowed(request.subId)) {
431 // Carrier does not support use of this API, return failure.
432 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
433 UssdResponse response = new UssdResponse(ussdRequest, null);
434 Bundle returnData = new Bundle();
435 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
436 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700437
Pengquan Menga1bb6272018-09-06 09:59:22 -0700438 request.result = true;
439 notifyRequester(request);
440 return;
441 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700442
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 try {
444 request.result = phone != null
445 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
446 } catch (CallStateException cse) {
447 request.result = false;
448 }
449 // Wake up the requesting thread
450 notifyRequester(request);
451 break;
pkanwar32d516d2016-10-14 19:37:38 -0700452 }
453
Yorke Lee716f67e2015-06-17 15:39:16 -0700454 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 final Phone phone = getPhoneFromRequest(request);
457 request.result = phone != null ?
458 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
459 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700461 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700462 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 if (uiccCard == null) {
470 loge("iccTransmitApduLogicalChannel: No UICC");
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
475 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700476 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 iccArgument.channel, iccArgument.cla, iccArgument.command,
478 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700479 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700480 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700484 ar = (AsyncResult) msg.obj;
485 request = (MainThreadRequest) ar.userObj;
486 if (ar.exception == null && ar.result != null) {
487 request.result = ar.result;
488 } else {
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
490 if (ar.result == null) {
491 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800492 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800494 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 } else {
496 loge("iccTransmitApduLogicalChannel: Unknown exception");
497 }
498 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 break;
501
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
503 request = (MainThreadRequest) msg.obj;
504 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800505 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 if (uiccCard == null) {
507 loge("iccTransmitApduBasicChannel: No UICC");
508 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 } else {
511 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
512 request);
513 uiccCard.iccTransmitApduBasicChannel(
514 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
515 iccArgument.p3, iccArgument.data, onCompleted);
516 }
517 break;
518
519 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
520 ar = (AsyncResult) msg.obj;
521 request = (MainThreadRequest) ar.userObj;
522 if (ar.exception == null && ar.result != null) {
523 request.result = ar.result;
524 } else {
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
526 if (ar.result == null) {
527 loge("iccTransmitApduBasicChannel: Empty response");
528 } else if (ar.exception instanceof CommandException) {
529 loge("iccTransmitApduBasicChannel: CommandException: " +
530 ar.exception);
531 } else {
532 loge("iccTransmitApduBasicChannel: Unknown exception");
533 }
534 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 break;
537
538 case CMD_EXCHANGE_SIM_IO:
539 request = (MainThreadRequest) msg.obj;
540 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800541 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700542 if (uiccCard == null) {
543 loge("iccExchangeSimIO: No UICC");
544 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 } else {
547 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
548 request);
549 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
550 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
551 iccArgument.data, onCompleted);
552 }
553 break;
554
555 case EVENT_EXCHANGE_SIM_IO_DONE:
556 ar = (AsyncResult) msg.obj;
557 request = (MainThreadRequest) ar.userObj;
558 if (ar.exception == null && ar.result != null) {
559 request.result = ar.result;
560 } else {
561 request.result = new IccIoResult(0x6f, 0, (byte[])null);
562 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700563 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 break;
565
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 case CMD_SEND_ENVELOPE:
567 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 if (uiccCard == null) {
570 loge("sendEnvelopeWithStatus: No UICC");
571 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700572 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700573 } else {
574 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
575 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
576 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
579 case EVENT_SEND_ENVELOPE_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700585 request.result = new IccIoResult(0x6F, 0, (byte[])null);
586 if (ar.result == null) {
587 loge("sendEnvelopeWithStatus: Empty response");
588 } else if (ar.exception instanceof CommandException) {
589 loge("sendEnvelopeWithStatus: CommandException: " +
590 ar.exception);
591 } else {
592 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
593 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800596 break;
597
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 case CMD_OPEN_CHANNEL:
599 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800600 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800601 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700602 if (uiccCard == null) {
603 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800604 request.result = new IccOpenLogicalChannelResponse(-1,
605 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800609 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
610 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700611 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 break;
613
614 case EVENT_OPEN_CHANNEL_DONE:
615 ar = (AsyncResult) msg.obj;
616 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700619 int[] result = (int[]) ar.result;
620 int channelId = result[0];
621 byte[] selectResponse = null;
622 if (result.length > 1) {
623 selectResponse = new byte[result.length - 1];
624 for (int i = 1; i < result.length; ++i) {
625 selectResponse[i - 1] = (byte) result[i];
626 }
627 }
628 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700629 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700630 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 if (ar.result == null) {
632 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 if (ar.exception != null) {
635 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
636 }
637
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700639 if (ar.exception instanceof CommandException) {
640 CommandException.Error error =
641 ((CommandException) (ar.exception)).getCommandError();
642 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700643 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700644 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700645 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700646 }
647 }
648 openChannelResp = new IccOpenLogicalChannelResponse(
649 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700651 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700652 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 break;
654
655 case CMD_CLOSE_CHANNEL:
656 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800657 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700658 if (uiccCard == null) {
659 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900660 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700661 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 } else {
663 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
664 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
665 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
668 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800669 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
670 break;
671
672 case CMD_NV_READ_ITEM:
673 request = (MainThreadRequest) msg.obj;
674 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800675 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
676 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800677 break;
678
679 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 ar = (AsyncResult) msg.obj;
681 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800682 if (ar.exception == null && ar.result != null) {
683 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 request.result = "";
686 if (ar.result == null) {
687 loge("nvReadItem: Empty response");
688 } else if (ar.exception instanceof CommandException) {
689 loge("nvReadItem: CommandException: " +
690 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800692 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 }
694 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700695 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 break;
697
Jake Hambye994d462014-02-03 13:10:13 -0800698 case CMD_NV_WRITE_ITEM:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
701 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800702 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700703 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800704 break;
705
706 case EVENT_NV_WRITE_ITEM_DONE:
707 handleNullReturnEvent(msg, "nvWriteItem");
708 break;
709
710 case CMD_NV_WRITE_CDMA_PRL:
711 request = (MainThreadRequest) msg.obj;
712 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800713 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
716 case EVENT_NV_WRITE_CDMA_PRL_DONE:
717 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800721 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700722 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
chen xu6dac5ab2018-10-26 17:39:23 -0700726 case EVENT_RESET_MODEM_CONFIG_DONE:
727 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 case CMD_GET_PREFERRED_NETWORK_TYPE:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700733 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
737 ar = (AsyncResult) msg.obj;
738 request = (MainThreadRequest) ar.userObj;
739 if (ar.exception == null && ar.result != null) {
740 request.result = ar.result; // Integer
741 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800742 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 if (ar.result == null) {
744 loge("getPreferredNetworkType: Empty response");
745 } else if (ar.exception instanceof CommandException) {
746 loge("getPreferredNetworkType: CommandException: " +
747 ar.exception);
748 } else {
749 loge("getPreferredNetworkType: Unknown exception");
750 }
751 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700752 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case CMD_SET_PREFERRED_NETWORK_TYPE:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
758 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700759 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800760 break;
761
762 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
763 handleNullReturnEvent(msg, "setPreferredNetworkType");
764 break;
765
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000766 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
767 request = (MainThreadRequest)msg.obj;
768 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800769 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
772 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
773 ar = (AsyncResult)msg.obj;
774 request = (MainThreadRequest)ar.userObj;
775 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000777 break;
778
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 case CMD_SET_VOICEMAIL_NUMBER:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
782 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800783 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
784 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800785 break;
786
787 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
788 handleNullReturnEvent(msg, "setVoicemailNumber");
789 break;
790
Stuart Scott54788802015-03-30 13:18:01 -0700791 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
794 request);
795 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
796 break;
797
798 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
799 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
800 break;
801
Shishir Agrawal302c8692015-06-19 13:49:39 -0700802 case CMD_PERFORM_NETWORK_SCAN:
803 request = (MainThreadRequest) msg.obj;
804 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
805 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
806 break;
807
808 case EVENT_PERFORM_NETWORK_SCAN_DONE:
809 ar = (AsyncResult) msg.obj;
810 request = (MainThreadRequest) ar.userObj;
811 CellNetworkScanResult cellScanResult;
812 if (ar.exception == null && ar.result != null) {
813 cellScanResult = new CellNetworkScanResult(
814 CellNetworkScanResult.STATUS_SUCCESS,
815 (List<OperatorInfo>) ar.result);
816 } else {
817 if (ar.result == null) {
818 loge("getCellNetworkScanResults: Empty response");
819 }
820 if (ar.exception != null) {
821 loge("getCellNetworkScanResults: Exception: " + ar.exception);
822 }
823 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
824 if (ar.exception instanceof CommandException) {
825 CommandException.Error error =
826 ((CommandException) (ar.exception)).getCommandError();
827 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
828 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
829 } else if (error == CommandException.Error.GENERIC_FAILURE) {
830 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
831 }
832 }
833 cellScanResult = new CellNetworkScanResult(errorCode, null);
834 }
835 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700836 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 break;
838
839 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
840 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700841 ManualNetworkSelectionArgument selArg =
842 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
844 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700845 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
846 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700847 break;
848
849 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700850 ar = (AsyncResult) msg.obj;
851 request = (MainThreadRequest) ar.userObj;
852 if (ar.exception == null) {
853 request.result = true;
854 } else {
855 request.result = false;
856 loge("setNetworkSelectionModeManual " + ar.exception);
857 }
858 notifyRequester(request);
859 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700860 break;
861
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 case CMD_GET_MODEM_ACTIVITY_INFO:
863 request = (MainThreadRequest) msg.obj;
864 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700865 if (defaultPhone != null) {
866 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
867 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700868 break;
869
870 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
876 if (ar.result == null) {
877 loge("queryModemActivityInfo: Empty response");
878 } else if (ar.exception instanceof CommandException) {
879 loge("queryModemActivityInfo: CommandException: " +
880 ar.exception);
881 } else {
882 loge("queryModemActivityInfo: Unknown exception");
883 }
884 }
Amit Mahajand4766222016-01-28 15:28:28 -0800885 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
886 if (request.result == null) {
Peter Collingbournec00e9022019-11-26 09:56:26 -0800887 request.result = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800888 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700889 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700890 break;
891
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 case CMD_SET_ALLOWED_CARRIERS:
893 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800894 CarrierRestrictionRules argument =
895 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800897 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 break;
899
900 case EVENT_SET_ALLOWED_CARRIERS_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null && ar.result != null) {
904 request.result = ar.result;
905 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800906 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
907 if (ar.exception instanceof CommandException) {
908 loge("setAllowedCarriers: CommandException: " + ar.exception);
909 CommandException.Error error =
910 ((CommandException) (ar.exception)).getCommandError();
911 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
912 request.result =
913 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
914 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700915 } else {
916 loge("setAllowedCarriers: Unknown exception");
917 }
918 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700919 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case CMD_GET_ALLOWED_CARRIERS:
923 request = (MainThreadRequest) msg.obj;
924 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800925 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700926 break;
927
928 case EVENT_GET_ALLOWED_CARRIERS_DONE:
929 ar = (AsyncResult) msg.obj;
930 request = (MainThreadRequest) ar.userObj;
931 if (ar.exception == null && ar.result != null) {
932 request.result = ar.result;
933 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800934 request.result = new IllegalStateException(
935 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700936 if (ar.result == null) {
937 loge("getAllowedCarriers: Empty response");
938 } else if (ar.exception instanceof CommandException) {
939 loge("getAllowedCarriers: CommandException: " +
940 ar.exception);
941 } else {
942 loge("getAllowedCarriers: Unknown exception");
943 }
944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700946 break;
947
Nathan Haroldb3014052017-01-25 15:57:32 -0800948 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null && ar.result != null) {
952 request.result = ar.result;
953 } else {
954 request.result = new IllegalArgumentException(
955 "Failed to retrieve Forbidden Plmns");
956 if (ar.result == null) {
957 loge("getForbiddenPlmns: Empty response");
958 } else {
959 loge("getForbiddenPlmns: Unknown exception");
960 }
961 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964
965 case CMD_GET_FORBIDDEN_PLMNS:
966 request = (MainThreadRequest) msg.obj;
967 uiccCard = getUiccCardFromRequest(request);
968 if (uiccCard == null) {
969 loge("getForbiddenPlmns() UiccCard is null");
970 request.result = new IllegalArgumentException(
971 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700972 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800973 break;
974 }
975 Integer appType = (Integer) request.argument;
976 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
977 if (uiccApp == null) {
978 loge("getForbiddenPlmns() no app with specified type -- "
979 + appType);
980 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700981 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800982 break;
983 } else {
984 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
985 + " specified type -- " + appType);
986 }
987 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
988 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
989 onCompleted);
990 break;
991
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000992 case CMD_SWITCH_SLOTS:
993 request = (MainThreadRequest) msg.obj;
994 int[] physicalSlots = (int[]) request.argument;
995 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
996 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
997 break;
998
999 case EVENT_SWITCH_SLOTS_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001003 notifyRequester(request);
1004 break;
1005 case CMD_GET_NETWORK_SELECTION_MODE:
1006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1008 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1009 break;
1010
1011 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1012 ar = (AsyncResult) msg.obj;
1013 request = (MainThreadRequest) ar.userObj;
1014 if (ar.exception != null) {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1016 } else {
1017 int mode = ((int[]) ar.result)[0];
1018 if (mode == 0) {
1019 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1020 } else {
1021 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1022 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001023 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001024 notifyRequester(request);
1025 break;
1026 case CMD_GET_CDMA_ROAMING_MODE:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1029 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1030 break;
1031 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1032 ar = (AsyncResult) msg.obj;
1033 request = (MainThreadRequest) ar.userObj;
1034 if (ar.exception != null) {
1035 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1036 } else {
1037 request.result = ((int[]) ar.result)[0];
1038 }
1039 notifyRequester(request);
1040 break;
1041 case CMD_SET_CDMA_ROAMING_MODE:
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1044 int mode = (int) request.argument;
1045 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1046 break;
1047 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 request.result = ar.exception == null;
1051 notifyRequester(request);
1052 break;
1053 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1054 request = (MainThreadRequest) msg.obj;
1055 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1056 int subscriptionMode = (int) request.argument;
1057 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1058 break;
1059 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1060 ar = (AsyncResult) msg.obj;
1061 request = (MainThreadRequest) ar.userObj;
1062 request.result = ar.exception == null;
1063 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001064 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001065 case CMD_GET_ALL_CELL_INFO:
1066 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001067 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001068 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 case EVENT_GET_ALL_CELL_INFO_DONE:
1071 ar = (AsyncResult) msg.obj;
1072 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001073 // If a timeout occurs, the response will be null
1074 request.result = (ar.exception == null && ar.result != null)
1075 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 synchronized (request) {
1077 request.notifyAll();
1078 }
1079 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 case CMD_REQUEST_CELL_INFO_UPDATE:
1081 request = (MainThreadRequest) msg.obj;
1082 request.phone.requestCellInfoUpdate(request.workSource,
1083 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1084 break;
1085 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1086 ar = (AsyncResult) msg.obj;
1087 request = (MainThreadRequest) ar.userObj;
1088 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1089 try {
1090 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001092 cb.onError(
1093 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1094 ar.exception.getClass().getName(),
1095 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001097 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001098 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 } else {
1100 // use the result as returned
1101 cb.onCellInfo((List<CellInfo>) ar.result);
1102 }
1103 } catch (RemoteException re) {
1104 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1105 }
1106 break;
1107 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 request = (MainThreadRequest) msg.obj;
1109 WorkSource ws = (WorkSource) request.argument;
1110 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001111 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001112 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 ar = (AsyncResult) msg.obj;
1115 request = (MainThreadRequest) ar.userObj;
1116 if (ar.exception == null) {
1117 request.result = ar.result;
1118 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001119 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001120 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001121 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001122 }
1123
1124 synchronized (request) {
1125 request.notifyAll();
1126 }
1127 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001128 case CMD_MODEM_REBOOT:
1129 request = (MainThreadRequest) msg.obj;
1130 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001131 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001132 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001133 case EVENT_CMD_MODEM_REBOOT_DONE:
1134 handleNullReturnEvent(msg, "rebootModem");
1135 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001136 case CMD_REQUEST_ENABLE_MODEM:
1137 request = (MainThreadRequest) msg.obj;
1138 boolean enable = (boolean) request.argument;
1139 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001140 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001141 PhoneConfigurationManager.getInstance()
1142 .enablePhone(request.phone, enable, onCompleted);
1143 break;
1144 case EVENT_ENABLE_MODEM_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001148 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001149 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001150 if ((boolean) request.result) {
1151 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1152 updateModemStateMetrics();
1153 } else {
1154 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1155 + ar.exception);
1156 }
1157 notifyRequester(request);
1158 break;
1159 case CMD_GET_MODEM_STATUS:
1160 request = (MainThreadRequest) msg.obj;
1161 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1162 PhoneConfigurationManager.getInstance()
1163 .getPhoneStatusFromModem(request.phone, onCompleted);
1164 break;
1165 case EVENT_GET_MODEM_STATUS_DONE:
1166 ar = (AsyncResult) msg.obj;
1167 request = (MainThreadRequest) ar.userObj;
1168 int id = request.phone.getPhoneId();
1169 if (ar.exception == null && ar.result != null) {
1170 request.result = ar.result;
1171 //update the cache as modem status has changed
1172 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1173 (boolean) request.result);
1174 } else {
1175 // Return true if modem status cannot be retrieved. For most cases,
1176 // modem status is on. And for older version modems, GET_MODEM_STATUS
1177 // and disable modem are not supported. Modem is always on.
1178 // TODO: this should be fixed in R to support a third
1179 // status UNKNOWN b/131631629
1180 request.result = true;
1181 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1182 + ar.exception);
1183 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001184 notifyRequester(request);
1185 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001186 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1187 ar = (AsyncResult) msg.obj;
1188 request = (MainThreadRequest) ar.userObj;
1189 if (ar.exception == null && ar.result != null) {
1190 request.result = ar.result;
1191 } else {
1192 request.result = -1;
1193 loge("Failed to set Forbidden Plmns");
1194 if (ar.result == null) {
1195 loge("setForbidenPlmns: Empty response");
1196 } else if (ar.exception != null) {
1197 loge("setForbiddenPlmns: Exception: " + ar.exception);
1198 request.result = -1;
1199 } else {
1200 loge("setForbiddenPlmns: Unknown exception");
1201 }
1202 }
1203 notifyRequester(request);
1204 break;
1205 case CMD_SET_FORBIDDEN_PLMNS:
1206 request = (MainThreadRequest) msg.obj;
1207 uiccCard = getUiccCardFromRequest(request);
1208 if (uiccCard == null) {
1209 loge("setForbiddenPlmns: UiccCard is null");
1210 request.result = -1;
1211 notifyRequester(request);
1212 break;
1213 }
1214 Pair<Integer, List<String>> setFplmnsArgs =
1215 (Pair<Integer, List<String>>) request.argument;
1216 appType = setFplmnsArgs.first;
1217 List<String> fplmns = setFplmnsArgs.second;
1218 uiccApp = uiccCard.getApplicationByType(appType);
1219 if (uiccApp == null) {
1220 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1221 request.result = -1;
1222 loge("Failed to get UICC App");
1223 notifyRequester(request);
1224 } else {
1225 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1226 ((SIMRecords) uiccApp.getIccRecords())
1227 .setForbiddenPlmns(onCompleted, fplmns);
1228 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001229 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001230 case CMD_ERASE_MODEM_CONFIG:
1231 request = (MainThreadRequest) msg.obj;
1232 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1233 defaultPhone.eraseModemConfig(onCompleted);
1234 break;
1235 case EVENT_ERASE_MODEM_CONFIG_DONE:
1236 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001237 break;
zoey chene02881a2019-12-30 16:11:23 +08001238
1239 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1242 Pair<String, String> changed = (Pair<String, String>) request.argument;
1243 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1244 changed.first, changed.second, onCompleted);
1245 break;
1246 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1247 ar = (AsyncResult) msg.obj;
1248 request = (MainThreadRequest) ar.userObj;
1249 if (ar.exception == null) {
1250 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1251 } else {
1252 request.result = msg.arg1;
1253 }
1254 notifyRequester(request);
1255 break;
1256
1257 case CMD_SET_ICC_LOCK_ENABLED:
1258 request = (MainThreadRequest) msg.obj;
1259 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1260 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1261 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1262 enabled.first, enabled.second, onCompleted);
1263 break;
1264 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1265 ar = (AsyncResult) msg.obj;
1266 request = (MainThreadRequest) ar.userObj;
1267 if (ar.exception == null) {
1268 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1269 } else {
1270 request.result = msg.arg1;
1271 }
1272 notifyRequester(request);
1273 break;
1274
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 default:
1276 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1277 break;
1278 }
1279 }
Jake Hambye994d462014-02-03 13:10:13 -08001280
Pengquan Menga1bb6272018-09-06 09:59:22 -07001281 private void notifyRequester(MainThreadRequest request) {
1282 synchronized (request) {
1283 request.notifyAll();
1284 }
1285 }
1286
Jake Hambye994d462014-02-03 13:10:13 -08001287 private void handleNullReturnEvent(Message msg, String command) {
1288 AsyncResult ar = (AsyncResult) msg.obj;
1289 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1290 if (ar.exception == null) {
1291 request.result = true;
1292 } else {
1293 request.result = false;
1294 if (ar.exception instanceof CommandException) {
1295 loge(command + ": CommandException: " + ar.exception);
1296 } else {
1297 loge(command + ": Unknown exception");
1298 }
1299 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001300 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 }
1303
1304 /**
1305 * Posts the specified command to be executed on the main thread,
1306 * waits for the request to complete, and returns the result.
1307 * @see #sendRequestAsync
1308 */
1309 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001310 return sendRequest(
1311 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001312 }
1313
1314 /**
1315 * Posts the specified command to be executed on the main thread,
1316 * waits for the request to complete, and returns the result.
1317 * @see #sendRequestAsync
1318 */
1319 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1320 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001321 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001322 }
1323
1324 /**
1325 * Posts the specified command to be executed on the main thread,
1326 * waits for the request to complete, and returns the result.
1327 * @see #sendRequestAsync
1328 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001329 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001330 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001331 }
1332
1333 /**
1334 * Posts the specified command to be executed on the main thread,
1335 * waits for the request to complete, and returns the result.
1336 * @see #sendRequestAsync
1337 */
Nathan Harold92bed182018-10-12 18:16:49 -07001338 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1339 return sendRequest(command, argument, subId, null, workSource);
1340 }
1341
1342 /**
1343 * Posts the specified command to be executed on the main thread,
1344 * waits for the request to complete, and returns the result.
1345 * @see #sendRequestAsync
1346 */
1347 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1348 return sendRequest(
1349 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1350 }
1351
1352 /**
1353 * Posts the specified command to be executed on the main thread,
1354 * waits for the request to complete, and returns the result.
1355 * @see #sendRequestAsync
1356 */
1357 private Object sendRequest(
1358 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001359 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1360 throw new RuntimeException("This method will deadlock if called from the main thread.");
1361 }
1362
Nathan Harold92bed182018-10-12 18:16:49 -07001363 MainThreadRequest request = null;
1364 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1365 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1366 } else if (phone != null) {
1367 request = new MainThreadRequest(argument, phone, workSource);
1368 } else {
1369 request = new MainThreadRequest(argument, subId, workSource);
1370 }
1371
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372 Message msg = mMainThreadHandler.obtainMessage(command, request);
1373 msg.sendToTarget();
1374
1375 // Wait for the request to complete
1376 synchronized (request) {
1377 while (request.result == null) {
1378 try {
1379 request.wait();
1380 } catch (InterruptedException e) {
1381 // Do nothing, go back and wait until the request is complete
1382 }
1383 }
1384 }
1385 return request.result;
1386 }
1387
1388 /**
1389 * Asynchronous ("fire and forget") version of sendRequest():
1390 * Posts the specified command to be executed on the main thread, and
1391 * returns immediately.
1392 * @see #sendRequest
1393 */
1394 private void sendRequestAsync(int command) {
1395 mMainThreadHandler.sendEmptyMessage(command);
1396 }
1397
1398 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001399 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001400 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001401 */
1402 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001403 sendRequestAsync(command, argument, null, null);
1404 }
1405
1406 /**
1407 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1408 * @see {@link #sendRequest(int,Object)}
1409 */
1410 private void sendRequestAsync(
1411 int command, Object argument, Phone phone, WorkSource workSource) {
1412 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001413 Message msg = mMainThreadHandler.obtainMessage(command, request);
1414 msg.sendToTarget();
1415 }
1416
1417 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 * Initialize the singleton PhoneInterfaceManager instance.
1419 * This is only done once, at startup, from PhoneApp.onCreate().
1420 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001421 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001422 synchronized (PhoneInterfaceManager.class) {
1423 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001424 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 } else {
1426 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1427 }
1428 return sInstance;
1429 }
1430 }
1431
1432 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001433 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001434 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001436 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001437 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1439 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001440 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001441 mTelephonySharedPreferences =
1442 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001443 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001444 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 publish();
1447 }
1448
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001449 private Phone getDefaultPhone() {
1450 Phone thePhone = getPhone(getDefaultSubscription());
1451 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1452 }
1453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 private void publish() {
1455 if (DBG) log("publish: " + this);
1456
Peter Wangc035ce42020-01-08 21:00:22 -08001457 TelephonyFrameworkInitializer
1458 .getTelephonyServiceManager()
1459 .getTelephonyServiceRegisterer()
1460 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001461 }
1462
Stuart Scott584921c2015-01-15 17:10:34 -08001463 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001464 if (request.phone != null) {
1465 return request.phone;
1466 } else {
1467 return getPhoneFromSubId(request.subId);
1468 }
1469 }
1470
1471 private Phone getPhoneFromSubId(int subId) {
1472 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1473 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001474 }
1475
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001476 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1477 Phone phone = getPhoneFromRequest(request);
1478 return phone == null ? null :
1479 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1480 }
1481
Wink Saville36469e72014-06-11 15:17:00 -07001482 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001483 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001484 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001486
Naina Nallurid63128d2019-09-17 14:10:30 -07001487 private void sendEraseModemConfig(Phone phone) {
1488 if (phone != null) {
1489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1490 mApp, phone.getSubId(), "eraseModemConfig");
1491 final long identity = Binder.clearCallingIdentity();
1492 try {
1493 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1494 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1495 } finally {
1496 Binder.restoreCallingIdentity(identity);
1497 }
1498 }
1499 }
1500
Peter Wang44b186e2020-01-13 23:33:09 -08001501 private boolean isImsAvailableOnDevice() {
1502 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1503 if (pm == null) {
1504 // For some reason package manger is not available.. This will fail internally anyway,
1505 // so do not throw error and allow.
1506 return true;
1507 }
1508 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1509 }
1510
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516 if (DBG) log("dial: " + number);
1517 // No permission check needed here: This is just a wrapper around the
1518 // ACTION_DIAL intent, which is available to any app since it puts up
1519 // the UI before it does anything.
1520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 final long identity = Binder.clearCallingIdentity();
1522 try {
1523 String url = createTelUrl(number);
1524 if (url == null) {
1525 return;
1526 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001528 // PENDING: should we just silently fail if phone is offhook or ringing?
1529 PhoneConstants.State state = mCM.getState(subId);
1530 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1531 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1532 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1533 mApp.startActivity(intent);
1534 }
1535 } finally {
1536 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001537 }
1538 }
1539
1540 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001545 if (DBG) log("call: " + number);
1546
1547 // This is just a wrapper around the ACTION_CALL intent, but we still
1548 // need to do a permission check since we're calling startActivity()
1549 // from the context of the phone app.
1550 enforceCallPermission();
1551
Jordan Liu1617b712019-07-10 15:06:26 -07001552 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 != AppOpsManager.MODE_ALLOWED) {
1554 return;
1555 }
1556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 String url = createTelUrl(number);
1560 if (url == null) {
1561 return;
1562 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001564 boolean isValid = false;
1565 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1566 if (slist != null) {
1567 for (SubscriptionInfo subInfoRecord : slist) {
1568 if (subInfoRecord.getSubscriptionId() == subId) {
1569 isValid = true;
1570 break;
1571 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001572 }
Wink Saville08874612014-08-31 19:19:58 -07001573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574 if (!isValid) {
1575 return;
1576 }
Wink Saville08874612014-08-31 19:19:58 -07001577
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001578 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1579 intent.putExtra(SUBSCRIPTION_KEY, subId);
1580 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1581 mApp.startActivity(intent);
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
1584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001585 }
1586
Wink Savilleb564aae2014-10-23 10:18:09 -07001587 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001588 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001589 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1590 }
1591
Wink Savilleb564aae2014-10-23 10:18:09 -07001592 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001593 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001594 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1595 }
1596
Wink Savilleb564aae2014-10-23 10:18:09 -07001597 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001599
1600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1603 checkSimPin.start();
1604 return checkSimPin.unlockSim(null, pin);
1605 } finally {
1606 Binder.restoreCallingIdentity(identity);
1607 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 }
1609
Wink Savilleb564aae2014-10-23 10:18:09 -07001610 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612
1613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1616 checkSimPuk.start();
1617 return checkSimPuk.unlockSim(puk, pin);
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
1620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
1623 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001624 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001625 * a synchronous one.
1626 */
1627 private static class UnlockSim extends Thread {
1628
1629 private final IccCard mSimCard;
1630
1631 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001632 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1633 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634
1635 // For replies from SimCard interface
1636 private Handler mHandler;
1637
1638 // For async handler to identify request type
1639 private static final int SUPPLY_PIN_COMPLETE = 100;
1640
1641 public UnlockSim(IccCard simCard) {
1642 mSimCard = simCard;
1643 }
1644
1645 @Override
1646 public void run() {
1647 Looper.prepare();
1648 synchronized (UnlockSim.this) {
1649 mHandler = new Handler() {
1650 @Override
1651 public void handleMessage(Message msg) {
1652 AsyncResult ar = (AsyncResult) msg.obj;
1653 switch (msg.what) {
1654 case SUPPLY_PIN_COMPLETE:
1655 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1656 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001657 mRetryCount = msg.arg1;
1658 if (ar.exception != null) {
1659 if (ar.exception instanceof CommandException &&
1660 ((CommandException)(ar.exception)).getCommandError()
1661 == CommandException.Error.PASSWORD_INCORRECT) {
1662 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1663 } else {
1664 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1665 }
1666 } else {
1667 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1668 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 mDone = true;
1670 UnlockSim.this.notifyAll();
1671 }
1672 break;
1673 }
1674 }
1675 };
1676 UnlockSim.this.notifyAll();
1677 }
1678 Looper.loop();
1679 }
1680
1681 /*
1682 * Use PIN or PUK to unlock SIM card
1683 *
1684 * If PUK is null, unlock SIM card with PIN
1685 *
1686 * If PUK is not null, unlock SIM card with PUK and set PIN code
1687 */
Wink Saville9de0f752013-10-22 19:04:03 -07001688 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689
1690 while (mHandler == null) {
1691 try {
1692 wait();
1693 } catch (InterruptedException e) {
1694 Thread.currentThread().interrupt();
1695 }
1696 }
1697 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1698
1699 if (puk == null) {
1700 mSimCard.supplyPin(pin, callback);
1701 } else {
1702 mSimCard.supplyPuk(puk, pin, callback);
1703 }
1704
1705 while (!mDone) {
1706 try {
1707 Log.d(LOG_TAG, "wait for done");
1708 wait();
1709 } catch (InterruptedException e) {
1710 // Restore the interrupted status
1711 Thread.currentThread().interrupt();
1712 }
1713 }
1714 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001715 int[] resultArray = new int[2];
1716 resultArray[0] = mResult;
1717 resultArray[1] = mRetryCount;
1718 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 }
1720 }
1721
1722 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001723 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001724
1725 }
1726
Wink Savilleb564aae2014-10-23 10:18:09 -07001727 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 // No permission check needed here: this call is harmless, and it's
1729 // needed for the ServiceState.requestStateUpdate() call (which is
1730 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 final Phone phone = getPhone(subId);
1734 if (phone != null) {
1735 phone.updateServiceLocation();
1736 }
1737 } finally {
1738 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001739 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 }
1741
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001742 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001743 @Override
1744 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001745 return isRadioOnWithFeature(callingPackage, null);
1746 }
1747
1748
1749 @Override
1750 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1751 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1752 callingFeatureId);
1753 }
1754
1755 @Deprecated
1756 @Override
1757 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1758 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001759 }
1760
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001761 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001762 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1763 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001764 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001765 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001766 return false;
1767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768
1769 final long identity = Binder.clearCallingIdentity();
1770 try {
1771 return isRadioOnForSubscriber(subId);
1772 } finally {
1773 Binder.restoreCallingIdentity(identity);
1774 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001775 }
1776
1777 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
1782 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
1791 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001792 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
Wink Saville36469e72014-06-11 15:17:00 -07001794
Wink Savilleb564aae2014-10-23 10:18:09 -07001795 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797
1798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 final Phone phone = getPhone(subId);
1801 if (phone != null) {
1802 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1803 }
1804 } finally {
1805 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001806 }
Wink Saville36469e72014-06-11 15:17:00 -07001807 }
1808
1809 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001810 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001814 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815
1816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 final Phone phone = getPhone(subId);
1819 if (phone == null) {
1820 return false;
1821 }
1822 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1823 toggleRadioOnOffForSubscriber(subId);
1824 }
1825 return true;
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
Wink Saville36469e72014-06-11 15:17:00 -07001830
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001831 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08001832 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001833 /*
1834 * If any of the Radios are available, it will need to be
1835 * shutdown. So return true if any Radio is available.
1836 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1840 Phone phone = PhoneFactory.getPhone(i);
1841 if (phone != null && phone.isRadioAvailable()) return true;
1842 }
1843 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1844 return false;
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001847 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001848 }
1849
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001850 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001851 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852 enforceModifyPermission();
1853
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1857 logv("Shutting down Phone " + i);
1858 shutdownRadioUsingPhoneId(i);
1859 }
1860 } finally {
1861 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001862 }
1863 }
1864
1865 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001866 Phone phone = PhoneFactory.getPhone(phoneId);
1867 if (phone != null && phone.isRadioAvailable()) {
1868 phone.shutdownRadio();
1869 }
1870 }
1871
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001873 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001874
1875 final long identity = Binder.clearCallingIdentity();
1876 try {
1877 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1878 if (defaultPhone != null) {
1879 defaultPhone.setRadioPower(turnOn);
1880 return true;
1881 } else {
1882 loge("There's no default phone.");
1883 return false;
1884 }
1885 } finally {
1886 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001887 }
Wink Saville36469e72014-06-11 15:17:00 -07001888 }
1889
Wink Savilleb564aae2014-10-23 10:18:09 -07001890 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892
1893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
1897 phone.setRadioPower(turnOn);
1898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Wink Saville36469e72014-06-11 15:17:00 -07001907 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001909 public boolean enableDataConnectivity() {
1910 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001911
1912 final long identity = Binder.clearCallingIdentity();
1913 try {
1914 int subId = mSubscriptionController.getDefaultDataSubId();
1915 final Phone phone = getPhone(subId);
1916 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001917 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001918 return true;
1919 } else {
1920 return false;
1921 }
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Wink Saville36469e72014-06-11 15:17:00 -07001927 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 public boolean disableDataConnectivity() {
1930 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001931
1932 final long identity = Binder.clearCallingIdentity();
1933 try {
1934 int subId = mSubscriptionController.getDefaultDataSubId();
1935 final Phone phone = getPhone(subId);
1936 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001937 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938 return true;
1939 } else {
1940 return false;
1941 }
1942 } finally {
1943 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946
Sanket Padawe356d7632015-06-22 14:03:32 -07001947 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001948 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 final Phone phone = getPhone(subId);
1952 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001953 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001954 } else {
1955 return false;
1956 }
1957 } finally {
1958 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001959 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001960 }
1961
1962 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001963 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001964 }
1965
pkanwarae03a6b2016-11-06 20:37:09 -08001966 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 enforceCallPermission();
1968
1969 final long identity = Binder.clearCallingIdentity();
1970 try {
1971 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1972 return;
1973 }
1974 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1975 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1976 } finally {
1977 Binder.restoreCallingIdentity(identity);
1978 }
pkanwar32d516d2016-10-14 19:37:38 -07001979 };
1980
Wink Savilleb564aae2014-10-23 10:18:09 -07001981 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983
1984 final long identity = Binder.clearCallingIdentity();
1985 try {
1986 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1987 return false;
1988 }
1989 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1990 } finally {
1991 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 }
1994
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001995 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001996 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001997 }
1998
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001999 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 Phone phone = PhoneFactory.getPhone(slotIndex);
2003 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2004 PhoneConstantConversions.convertCallState(phone.getState());
2005 } finally {
2006 Binder.restoreCallingIdentity(identity);
2007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008 }
2009
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002011 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002012 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2013 }
2014
2015 @Override
2016 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002017 final long identity = Binder.clearCallingIdentity();
2018 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002019 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020 if (phone != null) {
2021 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2022 } else {
2023 return PhoneConstantConversions.convertDataState(
2024 PhoneConstants.DataState.DISCONNECTED);
2025 }
2026 } finally {
2027 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002028 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 }
2030
Sanket Padawe356d7632015-06-22 14:03:32 -07002031 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002032 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002033 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2034 }
2035
2036 @Override
2037 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002040 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041 if (phone != null) {
2042 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2043 } else {
2044 return TelephonyManager.DATA_ACTIVITY_NONE;
2045 }
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050
2051 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002052 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002053 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002054 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002055
2056 LocationAccessPolicy.LocationPermissionResult locationResult =
2057 LocationAccessPolicy.checkLocationPermission(mApp,
2058 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2059 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002060 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002061 .setCallingPid(Binder.getCallingPid())
2062 .setCallingUid(Binder.getCallingUid())
2063 .setMethod("getCellLocation")
2064 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2065 .build());
2066 switch (locationResult) {
2067 case DENIED_HARD:
2068 throw new SecurityException("Not allowed to access cell location");
2069 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002070 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2071 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002074 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 final long identity = Binder.clearCallingIdentity();
2076 try {
2077 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002078 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002079 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 } finally {
2081 Binder.restoreCallingIdentity(identity);
2082 }
Svetoslav64fad262015-04-14 14:35:21 -07002083 }
2084
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002086 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2087 String callingFeatureId) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002088 if (!TextUtils.isEmpty(callingPackage)) {
2089 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2091 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu1e81ccd2019-09-26 11:48:33 -07002092 return "";
2093 }
2094 }
2095
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002096 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2097 // registered cell info, so return a NULL country instead.
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002100 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2101 // Get default phone in this case.
2102 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2103 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002104 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002105 // Todo: fix this when we can get the actual cellular network info when the device
2106 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002107 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002108 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2109 mApp.getFeatureId())) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002110 return "";
2111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 Phone phone = PhoneFactory.getPhone(phoneId);
2113 if (phone != null) {
2114 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002115 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116 if (sst != null) {
2117 LocaleTracker lt = sst.getLocaleTracker();
2118 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002119 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2120 return lt.getCurrentCountry();
2121 } else if (emergencyNumberTracker != null) {
2122 return emergencyNumberTracker.getEmergencyCountryIso();
2123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002124 }
2125 }
2126 }
2127 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002128 } finally {
2129 Binder.restoreCallingIdentity(identity);
2130 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002131 }
2132
2133 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002135 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002136 }
2137
Sanket Padawe356d7632015-06-22 14:03:32 -07002138 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002139 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140 mApp.enforceCallingOrSelfPermission(
2141 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142
2143 final long identity = Binder.clearCallingIdentity();
2144 try {
2145 final Phone phone = getPhone(subId);
2146 if (phone != null) {
2147 phone.enableLocationUpdates();
2148 }
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 }
2153
2154 @Override
2155 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002156 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002157 }
2158
Sanket Padawe356d7632015-06-22 14:03:32 -07002159 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002160 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 mApp.enforceCallingOrSelfPermission(
2162 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 final Phone phone = getPhone(subId);
2167 if (phone != null) {
2168 phone.disableLocationUpdates();
2169 }
2170 } finally {
2171 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 }
2174
Nathan Harold31d7ff32018-10-15 20:20:30 -07002175 /**
2176 * Returns the target SDK version number for a given package name.
2177 *
Nathan Haroldec184742019-07-10 17:04:16 -07002178 * This call MUST be invoked before clearing the calling UID.
2179 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002180 * @return target SDK if the package is found or INT_MAX.
2181 */
2182 private int getTargetSdk(String packageName) {
2183 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002184 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002185 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002186 if (ai != null) return ai.targetSdkVersion;
2187 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002188 loge("Failed to get package info for pkg="
2189 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002190 }
2191 return Integer.MAX_VALUE;
2192 }
2193
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 @Override
2195 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002196 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2197 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002198 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002199 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2200 throw new SecurityException(
2201 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2202 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002203
Jordan Liu1617b712019-07-10 15:06:26 -07002204 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2206 return null;
2207 }
Svetoslav64fad262015-04-14 14:35:21 -07002208
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002209 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002210
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002211 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002212 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213
Nathan Haroldf180aac2018-06-01 18:43:55 -07002214 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2215 for (CellInfo ci : info) {
2216 if (ci instanceof CellInfoGsm) {
2217 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2218 } else if (ci instanceof CellInfoWcdma) {
2219 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002221 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002222 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002225 private List<CellInfo> getCachedCellInfo() {
2226 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2227 for (Phone phone : PhoneFactory.getPhones()) {
2228 List<CellInfo> info = phone.getAllCellInfo();
2229 if (info != null) cellInfos.addAll(info);
2230 }
2231 return cellInfos;
2232 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233
2234 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002235 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002236 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002237 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002238
2239 LocationAccessPolicy.LocationPermissionResult locationResult =
2240 LocationAccessPolicy.checkLocationPermission(mApp,
2241 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2242 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002243 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002244 .setCallingPid(Binder.getCallingPid())
2245 .setCallingUid(Binder.getCallingUid())
2246 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002247 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002248 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2249 .build());
2250 switch (locationResult) {
2251 case DENIED_HARD:
2252 throw new SecurityException("Not allowed to access cell info");
2253 case DENIED_SOFT:
2254 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 }
2256
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002257 final int targetSdk = getTargetSdk(callingPackage);
2258 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2259 return getCachedCellInfo();
2260 }
2261
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002262 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 final long identity = Binder.clearCallingIdentity();
2265 try {
2266 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2267 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002268 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002269 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002270 if (info != null) cellInfos.addAll(info);
2271 }
2272 return cellInfos;
2273 } finally {
2274 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002275 }
2276 }
2277
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002278 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002279 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2280 String callingFeatureId) {
2281 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2282 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002283 }
2284
2285 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002286 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2287 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002288 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002289 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002290 }
2291
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002292 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2293 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002294 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002295 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002296
2297 LocationAccessPolicy.LocationPermissionResult locationResult =
2298 LocationAccessPolicy.checkLocationPermission(mApp,
2299 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2300 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002301 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002302 .setCallingPid(Binder.getCallingPid())
2303 .setCallingUid(Binder.getCallingUid())
2304 .setMethod("requestCellInfoUpdate")
2305 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2306 .build());
2307 switch (locationResult) {
2308 case DENIED_HARD:
2309 throw new SecurityException("Not allowed to access cell info");
2310 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002311 try {
2312 cb.onCellInfo(new ArrayList<CellInfo>());
2313 } catch (RemoteException re) {
2314 // Drop without consequences
2315 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002316 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002317 }
2318
Nathan Harolda939a962019-05-09 10:13:47 -07002319
2320 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002321 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2322
2323 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2324 }
2325
2326 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002328 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002329 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002330
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002333 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 }
2338
Shishir Agrawala9f32182016-04-12 12:00:16 -07002339 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002340 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002341 Phone phone = PhoneFactory.getPhone(slotIndex);
2342 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002343 return null;
2344 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002345 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002346 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002347 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002348 return null;
2349 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 return phone.getImei();
2354 } finally {
2355 Binder.restoreCallingIdentity(identity);
2356 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002357 }
2358
2359 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002360 public String getTypeAllocationCodeForSlot(int slotIndex) {
2361 Phone phone = PhoneFactory.getPhone(slotIndex);
2362 String tac = null;
2363 if (phone != null) {
2364 String imei = phone.getImei();
2365 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2366 }
2367 return tac;
2368 }
2369
2370 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002371 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 Phone phone = PhoneFactory.getPhone(slotIndex);
2373 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002374 return null;
2375 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002376
Jeff Davidson913390f2018-02-23 17:11:49 -08002377 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002378 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002379 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002380 return null;
2381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002382
2383 final long identity = Binder.clearCallingIdentity();
2384 try {
2385 return phone.getMeid();
2386 } finally {
2387 Binder.restoreCallingIdentity(identity);
2388 }
Jack Yu2af8d712017-03-15 17:14:14 -07002389 }
2390
2391 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002392 public String getManufacturerCodeForSlot(int slotIndex) {
2393 Phone phone = PhoneFactory.getPhone(slotIndex);
2394 String manufacturerCode = null;
2395 if (phone != null) {
2396 String meid = phone.getMeid();
2397 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2398 }
2399 return manufacturerCode;
2400 }
2401
2402 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002403 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2404 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002405 Phone phone = PhoneFactory.getPhone(slotIndex);
2406 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002407 return null;
2408 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 int subId = phone.getSubId();
2410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002411 mApp, subId, callingPackage, callingFeatureId,
2412 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002413 return null;
2414 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002415
2416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 return phone.getDeviceSvn();
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
2421 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002422 }
2423
fionaxu43304da2017-11-27 22:51:16 -08002424 @Override
2425 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
2429 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2430 } finally {
2431 Binder.restoreCallingIdentity(identity);
2432 }
fionaxu43304da2017-11-27 22:51:16 -08002433 }
2434
2435 @Override
2436 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 final Phone phone = getPhone(subId);
2440 return phone == null ? null : phone.getCarrierName();
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
fionaxu43304da2017-11-27 22:51:16 -08002444 }
2445
calvinpanffe225e2018-11-01 19:43:06 +08002446 @Override
chen xu0026ca62019-03-06 15:28:50 -08002447 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = getPhone(subId);
2451 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002452 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002453 } finally {
2454 Binder.restoreCallingIdentity(identity);
2455 }
2456 }
2457
2458 @Override
chen xu0026ca62019-03-06 15:28:50 -08002459 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002460 final long identity = Binder.clearCallingIdentity();
2461 try {
2462 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002463 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002464 } finally {
2465 Binder.restoreCallingIdentity(identity);
2466 }
2467 }
2468
chen xu651eec72018-11-11 19:03:44 -08002469 @Override
chen xu864e11c2018-12-06 22:10:03 -08002470 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2471 if (!isSubscriptionMccMnc) {
2472 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2473 }
chen xu651eec72018-11-11 19:03:44 -08002474 final Phone phone = PhoneFactory.getPhone(slotIndex);
2475 if (phone == null) {
2476 return TelephonyManager.UNKNOWN_CARRIER_ID;
2477 }
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
2484 }
2485
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 //
2487 // Internal helper methods.
2488 //
2489
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002490 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2492 *
2493 * @throws SecurityException if the caller does not have the required permission
2494 */
2495 private void enforceModifyPermission() {
2496 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2497 }
2498
Shuo Qian3b6ee772019-11-13 17:43:31 -08002499 private void enforceActiveEmergencySessionPermission() {
2500 mApp.enforceCallingOrSelfPermission(
2501 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2502 }
2503
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002504 /**
2505 * Make sure the caller has the CALL_PHONE permission.
2506 *
2507 * @throws SecurityException if the caller does not have the required permission
2508 */
2509 private void enforceCallPermission() {
2510 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2511 }
2512
paulhu5a773602019-08-23 19:17:33 +08002513 private void enforceSettingsPermission() {
2514 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002515 }
2516
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002517 private String createTelUrl(String number) {
2518 if (TextUtils.isEmpty(number)) {
2519 return null;
2520 }
2521
Jake Hambye994d462014-02-03 13:10:13 -08002522 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002523 }
2524
Ihab Awadf9e92732013-12-05 18:02:52 -08002525 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002526 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2527 }
2528
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002529 private static void logv(String msg) {
2530 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2531 }
2532
Ihab Awadf9e92732013-12-05 18:02:52 -08002533 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2535 }
2536
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002537 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002539 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002540 }
2541
Sanket Padawe356d7632015-06-22 14:03:32 -07002542 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002543 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 final Phone phone = PhoneFactory.getPhone(slotIndex);
2547 if (phone == null) {
2548 return PhoneConstants.PHONE_TYPE_NONE;
2549 } else {
2550 return phone.getPhoneType();
2551 }
2552 } finally {
2553 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002554 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 }
2556
2557 /**
2558 * Returns the CDMA ERI icon index to display
2559 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002560 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002561 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2562 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2563 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002564 }
2565
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002567 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2568 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002570 mApp, subId, callingPackage, callingFeatureId,
2571 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002572 return -1;
2573 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone phone = getPhone(subId);
2578 if (phone != null) {
2579 return phone.getCdmaEriIconIndex();
2580 } else {
2581 return -1;
2582 }
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 }
2587
2588 /**
2589 * Returns the CDMA ERI icon mode,
2590 * 0 - ON
2591 * 1 - FLASHING
2592 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002593 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002594 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2595 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2596 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002597 }
2598
Sanket Padawe356d7632015-06-22 14:03:32 -07002599 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002600 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2601 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002603 mApp, subId, callingPackage, callingFeatureId,
2604 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002605 return -1;
2606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
2611 if (phone != null) {
2612 return phone.getCdmaEriIconMode();
2613 } else {
2614 return -1;
2615 }
2616 } finally {
2617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002619 }
2620
2621 /**
2622 * Returns the CDMA ERI text,
2623 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002624 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002625 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2626 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2627 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002628 }
2629
Sanket Padawe356d7632015-06-22 14:03:32 -07002630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002631 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2632 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002634 mApp, subId, callingPackage, callingFeatureId,
2635 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002636 return null;
2637 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638
2639 final long identity = Binder.clearCallingIdentity();
2640 try {
2641 final Phone phone = getPhone(subId);
2642 if (phone != null) {
2643 return phone.getCdmaEriText();
2644 } else {
2645 return null;
2646 }
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002650 }
2651
2652 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002653 * Returns the CDMA MDN.
2654 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002655 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002656 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2658 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002659
2660 final long identity = Binder.clearCallingIdentity();
2661 try {
2662 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002663 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 return phone.getLine1Number();
2665 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002666 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002667 return null;
2668 }
2669 } finally {
2670 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002671 }
2672 }
2673
2674 /**
2675 * Returns the CDMA MIN.
2676 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002677 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002679 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2680 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 final Phone phone = getPhone(subId);
2685 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2686 return phone.getCdmaMin();
2687 } else {
2688 return null;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002692 }
2693 }
2694
Hall Liud892bec2018-11-30 14:51:45 -08002695 @Override
2696 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2697 INumberVerificationCallback callback, String callingPackage) {
2698 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2699 != PERMISSION_GRANTED) {
2700 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2701 }
2702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2703
2704 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2705 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2706 throw new SecurityException("Calling package must be configured in the device config");
2707 }
2708
2709 if (range == null) {
2710 throw new NullPointerException("Range must be non-null");
2711 }
2712
2713 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002714 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002715
2716 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2717 }
2718
Junda Liuca05d5d2014-08-14 22:36:34 -07002719 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 * Returns true if CDMA provisioning needs to run.
2721 */
2722 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002725 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 } finally {
2727 Binder.restoreCallingIdentity(identity);
2728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002729 }
2730
2731 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002732 * Sets the voice mail number of a given subId.
2733 */
2734 @Override
2735 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002736 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2737 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
2739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2742 new Pair<String, String>(alphaTag, number), new Integer(subId));
2743 return success;
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
2746 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002747 }
2748
Ta-wei Yen87c49842016-05-13 21:19:52 -07002749 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002750 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002752 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2753 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002754 if (!TextUtils.equals(callingPackage, systemDialer)) {
2755 throw new SecurityException("caller must be system dialer");
2756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
2758 final long identity = Binder.clearCallingIdentity();
2759 try {
2760 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2761 if (phoneAccountHandle == null) {
2762 return null;
2763 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002764 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 } finally {
2766 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002767 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002768 }
2769
2770 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002771 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2772 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002775 mApp, subId, callingPackage, callingFeatureId,
2776 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002777 return null;
2778 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002780 final long identity = Binder.clearCallingIdentity();
2781 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002786 }
2787
2788 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002789 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2790 VisualVoicemailSmsFilterSettings settings) {
2791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002792
2793 final long identity = Binder.clearCallingIdentity();
2794 try {
2795 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002796 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 } finally {
2798 Binder.restoreCallingIdentity(identity);
2799 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002800 }
2801
2802 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002803 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805
2806 final long identity = Binder.clearCallingIdentity();
2807 try {
2808 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002809 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810 } finally {
2811 Binder.restoreCallingIdentity(identity);
2812 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002813 }
2814
2815 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002816 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2817 String callingPackage, int subId) {
2818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002824 } finally {
2825 Binder.restoreCallingIdentity(identity);
2826 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002827 }
2828
2829 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002830 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002831 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002832
2833 final long identity = Binder.clearCallingIdentity();
2834 try {
2835 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002836 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 } finally {
2838 Binder.restoreCallingIdentity(identity);
2839 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002840 }
2841
2842 @Override
2843 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2844 String number, int port, String text, PendingIntent sentIntent) {
2845 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002846 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002847 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002848 SmsController smsController = PhoneFactory.getSmsController();
2849 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2850 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002851 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002852
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002853 /**
fionaxu0152e512016-11-14 13:36:14 -08002854 * Sets the voice activation state of a given subId.
2855 */
2856 @Override
2857 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2859 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 final Phone phone = getPhone(subId);
2864 if (phone != null) {
2865 phone.setVoiceActivationState(activationState);
2866 } else {
2867 loge("setVoiceActivationState fails with invalid subId: " + subId);
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002871 }
2872 }
2873
2874 /**
2875 * Sets the data activation state of a given subId.
2876 */
2877 @Override
2878 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
2885 if (phone != null) {
2886 phone.setDataActivationState(activationState);
2887 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002888 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 }
2890 } finally {
2891 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002892 }
2893 }
2894
2895 /**
2896 * Returns the voice activation state of a given subId.
2897 */
2898 @Override
2899 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901
fionaxu0152e512016-11-14 13:36:14 -08002902 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 if (phone != null) {
2906 return phone.getVoiceActivationState();
2907 } else {
2908 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2909 }
2910 } finally {
2911 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002912 }
2913 }
2914
2915 /**
2916 * Returns the data activation state of a given subId.
2917 */
2918 @Override
2919 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921
fionaxu0152e512016-11-14 13:36:14 -08002922 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923 final long identity = Binder.clearCallingIdentity();
2924 try {
2925 if (phone != null) {
2926 return phone.getDataActivationState();
2927 } else {
2928 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002932 }
2933 }
2934
2935 /**
Wink Saville36469e72014-06-11 15:17:00 -07002936 * Returns the unread count of voicemails for a subId
2937 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002939 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2940 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002942 mApp, subId, callingPackage, callingFeatureId,
2943 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002944 return 0;
2945 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 final Phone phone = getPhone(subId);
2949 if (phone != null) {
2950 return phone.getVoiceMessageCount();
2951 } else {
2952 return 0;
2953 }
2954 } finally {
2955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
2959 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002960 * returns true, if the device is in a state where both voice and data
2961 * are supported simultaneously. This can change based on location or network condition.
2962 */
2963 @Override
2964 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone phone = getPhone(subId);
2968 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002972 }
2973
2974 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002975 * Send the dialer code if called from the current default dialer or the caller has
2976 * carrier privilege.
2977 * @param inputCode The dialer code to send
2978 */
2979 @Override
2980 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002981 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002982 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002983 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2984 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002985 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002986 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08002987 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002989
2990 final long identity = Binder.clearCallingIdentity();
2991 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
fionaxu235cc5e2017-03-06 22:25:57 -08002996 }
2997
Pengquan Menga1bb6272018-09-06 09:59:22 -07002998 @Override
2999 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07003000 if (!isActiveSubscription(subId)) {
3001 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3002 }
3003
Pengquan Menga1bb6272018-09-06 09:59:22 -07003004 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3005 }
3006
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003008 public boolean isInEmergencySmsMode() {
3009 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 for (Phone phone : PhoneFactory.getPhones()) {
3013 if (phone.isInEmergencySmsMode()) {
3014 return true;
3015 }
3016 }
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 return false;
3021 }
3022
shilu366312e2019-12-17 09:28:10 -08003023 /**
3024 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3025 * @param subId The subscription to use to check the configuration.
3026 * @param c The callback that will be used to send the result.
3027 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003028 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003029 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3030 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003031 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003032 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003033
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003034 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3035 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3036 "IMS not available on device.");
3037 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 final long token = Binder.clearCallingIdentity();
3039 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003040 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003041 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003042 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003043 } catch (ImsException e) {
3044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 } finally {
3046 Binder.restoreCallingIdentity(token);
3047 }
3048 }
3049
shilu366312e2019-12-17 09:28:10 -08003050 /**
3051 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3052 * @param subId The subscription to use to check the configuration.
3053 * @param c The callback that will be used to send the result.
3054 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003055 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003056 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
shilu366312e2019-12-17 09:28:10 -08003057 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003058 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003059 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3060 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3061 }
Meng Wangafbc5852019-09-19 17:37:13 -07003062 final long token = Binder.clearCallingIdentity();
3063 try {
3064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3065 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3066 .removeRegistrationCallbackForSubscription(c, subId);
3067 } catch (ImsException e) {
3068 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3069 + "is inactive, ignoring unregister.");
3070 // If the subscription is no longer active, just return, since the callback
3071 // will already have been removed internally.
3072 } finally {
3073 Binder.restoreCallingIdentity(token);
3074 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 }
3076
Brad Ebingera34a6c22019-10-22 17:36:18 -07003077 /**
3078 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3079 */
3080 @Override
3081 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3082 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3083 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3084 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3085 "IMS not available on device.");
3086 }
3087 final long token = Binder.clearCallingIdentity();
3088 try {
3089 Phone phone = getPhone(subId);
3090 if (phone == null) {
3091 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3092 + subId + "'");
3093 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3094 }
3095 phone.getImsRegistrationState(regState -> {
3096 try {
3097 consumer.accept((regState == null)
3098 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3099 } catch (RemoteException e) {
3100 // Ignore if the remote process is no longer available to call back.
3101 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3102 }
3103 });
3104 } finally {
3105 Binder.restoreCallingIdentity(token);
3106 }
3107 }
3108
3109 /**
3110 * Get the transport type for the IMS service registration state.
3111 */
3112 @Override
3113 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
shilu366312e2019-12-17 09:28:10 -08003114 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebingera34a6c22019-10-22 17:36:18 -07003115 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3116 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3117 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3118 "IMS not available on device.");
3119 }
3120 final long token = Binder.clearCallingIdentity();
3121 try {
3122 Phone phone = getPhone(subId);
3123 if (phone == null) {
3124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3125 + subId + "'");
3126 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3127 }
3128 phone.getImsRegistrationTech(regTech -> {
3129 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3130 int regTechConverted = (regTech == null)
3131 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3132 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3133 regTechConverted);
3134 try {
3135 consumer.accept(regTechConverted);
3136 } catch (RemoteException e) {
3137 // Ignore if the remote process is no longer available to call back.
3138 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3139 }
3140 });
3141 } finally {
3142 Binder.restoreCallingIdentity(token);
3143 }
3144 }
3145
shilu366312e2019-12-17 09:28:10 -08003146 /**
3147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3148 * @param subId The subscription to use to check the configuration.
3149 * @param c The callback that will be used to send the result.
3150 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003152 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3153 throws RemoteException {
shilu366312e2019-12-17 09:28:10 -08003154 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003155 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003156 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3157 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3158 "IMS not available on device.");
3159 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003160 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3161 final long token = Binder.clearCallingIdentity();
3162 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003163 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003165 } catch (ImsException e) {
3166 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003167 } finally {
3168 Binder.restoreCallingIdentity(token);
3169 }
3170 }
3171
shilu366312e2019-12-17 09:28:10 -08003172 /**
3173 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3174 * @param subId The subscription to use to check the configuration.
3175 * @param c The callback that will be used to send the result.
3176 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003178 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
shilu366312e2019-12-17 09:28:10 -08003179 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003180 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003181 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3182 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3183 }
Meng Wangafbc5852019-09-19 17:37:13 -07003184
3185 final long token = Binder.clearCallingIdentity();
3186 try {
3187 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3188 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003189 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003190 } catch (ImsException e) {
3191 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3192 + "is inactive, ignoring unregister.");
3193 // If the subscription is no longer active, just return, since the callback
3194 // will already have been removed internally.
3195 } finally {
3196 Binder.restoreCallingIdentity(token);
3197 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003198 }
3199
3200 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003201 public boolean isCapable(int subId, int capability, int regTech) {
3202 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3204 final long token = Binder.clearCallingIdentity();
3205 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003207 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003208 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003209 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3210 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003212 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3213 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 } finally {
3215 Binder.restoreCallingIdentity(token);
3216 }
3217 }
3218
3219 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003220 public boolean isAvailable(int subId, int capability, int regTech) {
3221 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 final long token = Binder.clearCallingIdentity();
3223 try {
3224 Phone phone = getPhone(subId);
3225 if (phone == null) return false;
3226 return phone.isImsCapabilityAvailable(capability, regTech);
3227 } finally {
3228 Binder.restoreCallingIdentity(token);
3229 }
3230 }
3231
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003232 /**
3233 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3234 * subscription.
3235 * @param subId The subscription to use to check the configuration.
3236 * @param callback The callback that will be used to send the result.
3237 * @param capability The MmTelFeature capability that will be used to send the result.
3238 * @param transportType The transport type of the MmTelFeature capability.
3239 */
3240 @Override
3241 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3242 int transportType) {
3243 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3244 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3245 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3246 "IMS not available on device.");
3247 }
3248 final long token = Binder.clearCallingIdentity();
3249 try {
3250 int slotId = getSlotIndex(subId);
3251 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3252 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3253 + subId + "'");
3254 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3255 }
3256 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3257 transportType, aBoolean -> {
3258 try {
3259 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3260 } catch (RemoteException e) {
3261 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3262 + "running. Ignore");
3263 }
3264 });
3265 } finally {
3266 Binder.restoreCallingIdentity(token);
3267 }
3268 }
3269
shilu366312e2019-12-17 09:28:10 -08003270 /**
3271 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3272 * @param subId The subscription to use to check the configuration.
3273 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 @Override
3275 public boolean isAdvancedCallingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003276 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
3277 enforceReadPrivilegedPermission("isAdvancedCallingSettingEnabled");
3278
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3280 final long token = Binder.clearCallingIdentity();
3281 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003282 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003284 } catch (ImsException e) {
3285 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 } finally {
3287 Binder.restoreCallingIdentity(token);
3288 }
3289 }
3290
3291 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003292 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003294 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 final long identity = Binder.clearCallingIdentity();
3296 try {
3297 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003298 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003300 } catch (ImsException e) {
3301 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003302 } finally {
3303 Binder.restoreCallingIdentity(identity);
3304 }
3305 }
3306
shilu366312e2019-12-17 09:28:10 -08003307 /**
3308 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3309 * @param subId The subscription to use to check the configuration.
3310 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003312 public boolean isVtSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003313 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003314 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003318 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3319 } catch (ImsException e) {
3320 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 } finally {
3322 Binder.restoreCallingIdentity(identity);
3323 }
3324 }
3325
3326 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003327 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003329 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 final long identity = Binder.clearCallingIdentity();
3331 try {
3332 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003334 } catch (ImsException e) {
3335 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
3339 }
3340
shilu366312e2019-12-17 09:28:10 -08003341 /**
3342 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3343 * @param subId The subscription to use to check the configuration.
3344 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003345 @Override
3346 public boolean isVoWiFiSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003347 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003348 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003354 } catch (ImsException e) {
3355 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 } finally {
3357 Binder.restoreCallingIdentity(identity);
3358 }
3359 }
3360
3361 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003362 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003364 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003365 final long identity = Binder.clearCallingIdentity();
3366 try {
3367 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003368 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003369 } catch (ImsException e) {
3370 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
3374 }
3375
shilu366312e2019-12-17 09:28:10 -08003376 /**
3377 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3378 * @param subId The subscription to use to check the configuration.
3379 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 @Override
3381 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003382 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003383 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3384 final long identity = Binder.clearCallingIdentity();
3385 try {
3386 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003397 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003399 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 final long identity = Binder.clearCallingIdentity();
3401 try {
3402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003403 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003404 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003405 } catch (ImsException e) {
3406 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 } finally {
3408 Binder.restoreCallingIdentity(identity);
3409 }
3410 }
3411
3412 @Override
3413 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3415 "setVoWiFiNonPersistent");
3416 final long identity = Binder.clearCallingIdentity();
3417 try {
3418 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003419 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003420 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003421 } catch (ImsException e) {
3422 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003423 } finally {
3424 Binder.restoreCallingIdentity(identity);
3425 }
3426 }
3427
shilu366312e2019-12-17 09:28:10 -08003428 /**
3429 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3430 * @param subId The subscription to use to check the configuration.
3431 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 @Override
3433 public int getVoWiFiModeSetting(int subId) {
shilu366312e2019-12-17 09:28:10 -08003434 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003439 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (ImsException e) {
3442 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
3448 @Override
3449 public void setVoWiFiModeSetting(int subId, int mode) {
3450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3451 "setVoWiFiModeSetting");
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003455 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003457 } catch (ImsException e) {
3458 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 } finally {
3460 Binder.restoreCallingIdentity(identity);
3461 }
3462 }
3463
3464 @Override
3465 public int getVoWiFiRoamingModeSetting(int subId) {
3466 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003470 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003471 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003472 } catch (ImsException e) {
3473 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
3477 }
3478
3479 @Override
3480 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3482 "setVoWiFiRoamingModeSetting");
3483 final long identity = Binder.clearCallingIdentity();
3484 try {
3485 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003486 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003487 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003488 } catch (ImsException e) {
3489 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003490 } finally {
3491 Binder.restoreCallingIdentity(identity);
3492 }
3493 }
3494
3495 @Override
3496 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3498 "setRttCapabilityEnabled");
3499 final long identity = Binder.clearCallingIdentity();
3500 try {
3501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003502 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3503 } catch (ImsException e) {
3504 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
3508 }
3509
shilu366312e2019-12-17 09:28:10 -08003510 /**
3511 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3512 * @param subId The subscription to use to check the configuration.
3513 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003514 @Override
3515 public boolean isTtyOverVolteEnabled(int subId) {
shilu366312e2019-12-17 09:28:10 -08003516 //TODO: b/147498511 will add TelephonyPermissions#checkCallingOrSelfReadPrecisePhoneState
Brad Ebinger35c841c2018-10-01 10:40:55 -07003517 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3518 final long identity = Binder.clearCallingIdentity();
3519 try {
3520 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003523 } catch (ImsException e) {
3524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 } finally {
3526 Binder.restoreCallingIdentity(identity);
3527 }
3528 }
3529
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003530 @Override
3531 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3532 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3533 final long identity = Binder.clearCallingIdentity();
3534 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003535 if (!isImsAvailableOnDevice()) {
3536 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3537 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003538 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003539 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003540 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003541 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003542 } catch (ImsException e) {
3543 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003544 } finally {
3545 Binder.restoreCallingIdentity(identity);
3546 }
3547 }
3548
3549 @Override
3550 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3551 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3552 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003553 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3554 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3555 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003556 try {
3557 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003559 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003560 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003561 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3562 + "is inactive, ignoring unregister.");
3563 // If the subscription is no longer active, just return, since the callback will already
3564 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003565 } finally {
3566 Binder.restoreCallingIdentity(identity);
3567 }
3568 }
3569
allenwtsu99c623b2020-01-03 18:24:23 +08003570
3571 private void checkModifyPhoneStatePermission(int subId, String message) {
3572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3573 message);
3574 }
3575
3576 private boolean isImsProvisioningRequired(int subId, int capability,
3577 boolean isMmtelCapability) {
3578 Phone phone = getPhone(subId);
3579 if (phone == null) {
3580 loge("phone instance null for subid " + subId);
3581 return false;
3582 }
3583 if (isMmtelCapability) {
3584 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3585 return false;
3586 }
3587 } else {
3588 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3589 return false;
3590 }
3591 }
3592 return true;
3593 }
3594
3595 @Override
3596 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3597 boolean isProvisioned) {
3598 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3599
3600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3603 if (!isImsProvisioningRequired(subId, capability, false)) {
3604 return;
3605 }
3606
3607 // this capability requires provisioning, route to the correct API.
3608 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3609 switch (capability) {
3610 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3611 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3612 ims.setEabProvisioned(isProvisioned);
3613 break;
3614 default: {
3615 throw new IllegalArgumentException("Tried to set provisioning for "
3616 + "rcs capability '" + capability + "', which does not require "
3617 + "provisioning.");
3618 }
3619 }
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
3622 }
3623
3624 }
3625
3626
3627 @Override
3628 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3629 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3630 final long identity = Binder.clearCallingIdentity();
3631 try {
3632 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3633 if (!isImsProvisioningRequired(subId, capability, false)) {
3634 return true;
3635 }
3636
3637 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3638 switch (capability) {
3639 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3640 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3641 return ims.isEabProvisionedOnDevice();
3642
3643 default: {
3644 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3645 + "capability '" + capability + "', which does not require "
3646 + "provisioning.");
3647 }
3648 }
3649
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
3654
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003655 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003656 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3657 boolean isProvisioned) {
3658 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3659 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3660 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3661 }
allenwtsu99c623b2020-01-03 18:24:23 +08003662 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003666 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003667 return;
3668 }
3669
3670 // this capability requires provisioning, route to the correct API.
3671 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3672 switch (capability) {
3673 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3674 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3675 ims.setVolteProvisioned(isProvisioned);
3676 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3677 ims.setWfcProvisioned(isProvisioned);
3678 }
3679 break;
3680 }
3681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3682 // There is currently no difference in VT provisioning type.
3683 ims.setVtProvisioned(isProvisioned);
3684 break;
3685 }
3686 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3687 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3688 // change the capability of the feature instead if needed.
3689 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3690 == isProvisioned) {
3691 // No change in provisioning.
3692 return;
3693 }
3694 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3695 try {
3696 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003697 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3699 + ", Exception" + e.getMessage());
3700 }
3701 break;
3702 }
3703 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003704 throw new IllegalArgumentException("Tried to set provisioning for "
3705 + "MmTel capability '" + capability + "', which does not require "
3706 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003707 }
3708 }
3709
3710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3717 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3718 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3719 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3720 }
3721 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003725 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 return true;
3727 }
3728
3729 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3730 switch (capability) {
3731 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3732 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3733 return ims.isVolteProvisionedOnDevice();
3734 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3735 return ims.isWfcProvisionedOnDevice();
3736 }
3737 // This should never happen, since we are checking tech above to make sure it
3738 // is either LTE or IWLAN.
3739 throw new IllegalArgumentException("Invalid radio technology for voice "
3740 + "capability.");
3741 }
3742 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3743 // There is currently no difference in VT provisioning type.
3744 return ims.isVtProvisionedOnDevice();
3745 }
3746 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3747 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3748 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3749 }
3750 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003751 throw new IllegalArgumentException(
3752 "Tried to get provisioning for MmTel capability '" + capability
3753 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003754 }
3755 }
3756
3757 } finally {
3758 Binder.restoreCallingIdentity(identity);
3759 }
3760 }
3761
3762 @Override
3763 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3764 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3765 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3766 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3767 }
3768 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3769 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3770 return (provisionedBits & capability) > 0;
3771 }
3772
3773 @Override
3774 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3775 boolean isProvisioned) {
3776 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3777 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3778 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3779 }
3780 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3781 "setProvisioningStatusForCapability");
3782 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3783 // If the current provisioning status for capability already matches isProvisioned,
3784 // do nothing.
3785 if (((provisionedBits & capability) > 0) == isProvisioned) {
3786 return;
3787 }
3788 if (isProvisioned) {
3789 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3790 } else {
3791 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3792 }
3793 }
3794
3795 /**
3796 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3797 * technology. The bitfield should mirror the bitfield defined by
3798 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3799 */
3800 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3801 String key = getMmTelProvisioningKey(subId, tech);
3802 // Default is no capabilities are provisioned.
3803 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3804 }
3805
3806 /**
3807 * Sets the MmTel capability provisioning bitfield (defined by
3808 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3809 * technology specified.
3810 *
3811 * Note: This is a synchronous command and should not be called on UI thread.
3812 */
3813 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3814 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3815 String key = getMmTelProvisioningKey(subId, tech);
3816 editor.putInt(key, newField);
3817 editor.commit();
3818 }
3819
3820 private static String getMmTelProvisioningKey(int subId, int tech) {
3821 // resulting key is provision_ims_mmtel_{subId}_{tech}
3822 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3823 }
3824
3825 /**
3826 * Query CarrierConfig to see if the specified capability requires provisioning for the
3827 * carrier associated with the subscription id.
3828 */
3829 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3830 int capability) {
3831 CarrierConfigManager configManager = new CarrierConfigManager(context);
3832 PersistableBundle c = configManager.getConfigForSubId(subId);
3833 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003834 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003835 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3836 false);
3837 boolean requireVoiceVtProvisioning = c.getBoolean(
3838 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3839
3840 // First check to make sure that the capability requires provisioning.
3841 switch (capability) {
3842 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3843 // intentional fallthrough
3844 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3845 if (requireVoiceVtProvisioning) {
3846 // Voice and Video requires provisioning
3847 return true;
3848 }
3849 break;
3850 }
3851 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3852 if (requireUtProvisioning) {
3853 // UT requires provisioning
3854 return true;
3855 }
3856 break;
3857 }
3858 }
3859 return false;
3860 }
3861
allenwtsu99c623b2020-01-03 18:24:23 +08003862 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3863 int capability) {
3864 CarrierConfigManager configManager = new CarrierConfigManager(context);
3865 PersistableBundle c = configManager.getConfigForSubId(subId);
3866
3867 boolean requireRcsProvisioning = c.getBoolean(
3868 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3869
3870 // First check to make sure that the capability requires provisioning.
3871 switch (capability) {
3872 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3873 // intentional fallthrough
3874 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3875 if (requireRcsProvisioning) {
3876 // OPTION or PRESENCE requires provisioning
3877 return true;
3878 }
3879 break;
3880 }
3881 }
3882 return false;
3883 }
3884
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003885 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003886 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003887 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3888 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3889 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003890 enforceReadPrivilegedPermission("getImsProvisioningInt");
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003894 int slotId = getSlotIndex(subId);
3895 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3896 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3897 + subId + "' for key:" + key);
3898 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3899 }
3900 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003901 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003902 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3903 + subId + "' for key:" + key);
3904 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003905 } finally {
3906 Binder.restoreCallingIdentity(identity);
3907 }
3908 }
3909
3910 @Override
3911 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003912 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3913 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3914 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003915 enforceReadPrivilegedPermission("getImsProvisioningString");
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003919 int slotId = getSlotIndex(subId);
3920 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3921 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3922 + subId + "' for key:" + key);
3923 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3924 }
3925 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003926 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003927 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3928 + subId + "' for key:" + key);
3929 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003930 } finally {
3931 Binder.restoreCallingIdentity(identity);
3932 }
3933 }
3934
3935 @Override
3936 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3938 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3939 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3941 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003945 int slotId = getSlotIndex(subId);
3946 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3947 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3948 + subId + "' for key:" + key);
3949 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3950 }
3951 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003952 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003953 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3954 + "' for key:" + key);
3955 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003956 } finally {
3957 Binder.restoreCallingIdentity(identity);
3958 }
3959 }
3960
3961 @Override
3962 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003963 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3964 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3965 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3967 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003971 int slotId = getSlotIndex(subId);
3972 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3973 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3974 + subId + "' for key:" + key);
3975 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3976 }
3977 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003979 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3980 + "' for key:" + key);
3981 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
3985 }
3986
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003987 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003988 int slotId = SubscriptionManager.getSlotIndex(subId);
3989 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3991 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 }
3993 return slotId;
3994 }
3995
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003996 private int getSlotIndex(int subId) {
3997 int slotId = SubscriptionManager.getSlotIndex(subId);
3998 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3999 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4000 }
4001 return slotId;
4002 }
4003
Wink Saville36469e72014-06-11 15:17:00 -07004004 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004005 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004006 */
4007 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004008 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4009 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004010 final int targetSdk = getTargetSdk(callingPackage);
4011 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004012 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004013 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004014 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004015 mApp, subId, callingPackage, callingFeatureId,
4016 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004017 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4018 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 final Phone phone = getPhone(subId);
4023 if (phone != null) {
4024 return phone.getServiceState().getDataNetworkType();
4025 } else {
4026 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4027 }
4028 } finally {
4029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004031 }
4032
4033 /**
4034 * Returns the data network type
4035 */
4036 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004037 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4038 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4039 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004040 }
4041
4042 /**
4043 * Returns the data network type for a subId
4044 */
4045 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004046 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4047 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004049 mApp, subId, callingPackage, callingFeatureId,
4050 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004051 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4052 }
4053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 final Phone phone = getPhone(subId);
4057 if (phone != null) {
4058 return phone.getServiceState().getDataNetworkType();
4059 } else {
4060 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4061 }
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004064 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004065 }
4066
4067 /**
Wink Saville36469e72014-06-11 15:17:00 -07004068 * Returns the Voice network type for a subId
4069 */
4070 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004071 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4072 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004074 mApp, subId, callingPackage, callingFeatureId,
4075 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004076 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4077 }
4078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 final Phone phone = getPhone(subId);
4082 if (phone != null) {
4083 return phone.getServiceState().getVoiceNetworkType();
4084 } else {
4085 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4086 }
4087 } finally {
4088 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004089 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004090 }
4091
4092 /**
4093 * @return true if a ICC card is present
4094 */
4095 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004096 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004097 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4098 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004099 }
4100
4101 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004102 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004103 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004104 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004105 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106 final long identity = Binder.clearCallingIdentity();
4107 try {
4108 final Phone phone = PhoneFactory.getPhone(slotIndex);
4109 if (phone != null) {
4110 return phone.getIccCard().hasIccCard();
4111 } else {
4112 return false;
4113 }
4114 } finally {
4115 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004116 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004117 }
4118
4119 /**
4120 * Return if the current radio is LTE on CDMA. This
4121 * is a tri-state return value as for a period of time
4122 * the mode may be unknown.
4123 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004124 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004125 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004126 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004127 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004129 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4130 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4131 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004132 }
4133
Sanket Padawe356d7632015-06-22 14:03:32 -07004134 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004135 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4136 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004137 try {
4138 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4139 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004140 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4141 }
4142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 final Phone phone = getPhone(subId);
4146 if (phone == null) {
4147 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4148 } else {
4149 return phone.getLteOnCdmaMode();
4150 }
4151 } finally {
4152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004153 }
Wink Saville36469e72014-06-11 15:17:00 -07004154 }
4155
Wink Saville36469e72014-06-11 15:17:00 -07004156 /**
4157 * {@hide}
4158 * Returns Default subId, 0 in the case of single standby.
4159 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004160 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004161 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004162 }
4163
Shishir Agrawala9f32182016-04-12 12:00:16 -07004164 private int getSlotForDefaultSubscription() {
4165 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4166 }
4167
Wink Savilleb564aae2014-10-23 10:18:09 -07004168 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004169 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004170 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004171
Pengquan Menge92a50d2018-09-21 15:54:48 -07004172 private boolean isActiveSubscription(int subId) {
4173 return mSubscriptionController.isActiveSubId(subId);
4174 }
4175
Ihab Awadf2177b72013-11-25 13:33:23 -08004176 /**
4177 * @see android.telephony.TelephonyManager.WifiCallingChoices
4178 */
4179 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004180 final long identity = Binder.clearCallingIdentity();
4181 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004182 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4184 getWhenToMakeWifiCallsDefaultPreference());
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004188 }
4189
4190 /**
4191 * @see android.telephony.TelephonyManager.WifiCallingChoices
4192 */
4193 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004197 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004202 }
4203
Sailesh Nepald1e68152013-12-12 19:08:02 -08004204 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004205 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004206 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004207 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004208
Jordan Liu4c733742019-02-28 12:03:40 -08004209 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4210 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4211 if (phoneId == -1) {
4212 throw new IllegalArgumentException("Given slot index: " + slotIndex
4213 + " does not correspond to an active phone");
4214 }
4215 return PhoneFactory.getPhone(phoneId);
4216 }
4217
Shishir Agrawal566b7612013-10-28 14:41:00 -07004218 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004219 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4220 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4222 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004224 if (DBG) {
4225 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4226 }
4227 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4228 p2);
4229 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004230
Jordan Liu4c733742019-02-28 12:03:40 -08004231
4232 @Override
4233 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4234 int slotIndex, String callingPackage, String aid, int p2) {
4235 enforceModifyPermission();
4236 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4237 if (DBG) {
4238 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4239 }
4240 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4241 callingPackage, aid, p2);
4242 }
4243
4244 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4245 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004246 final long identity = Binder.clearCallingIdentity();
4247 try {
4248 if (TextUtils.equals(ISDR_AID, aid)) {
4249 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004250 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4251 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004252 if (bestComponent == null
4253 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4254 loge("The calling package is not allowed to access ISD-R.");
4255 throw new SecurityException(
4256 "The calling package is not allowed to access ISD-R.");
4257 }
Derek Tan740e1672017-06-27 14:56:27 -07004258 }
Derek Tan740e1672017-06-27 14:56:27 -07004259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004261 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4262 null /* workSource */);
4263 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 return response;
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
4267 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004268 }
4269
4270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004271 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004272 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4273 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004274 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4275 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4276 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004277
Jordan Liu4c733742019-02-28 12:03:40 -08004278 @Override
4279 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4280 enforceModifyPermission();
4281 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4282 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4283 channel);
4284 }
4285
4286 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 if (channel < 0) {
4290 return false;
4291 }
Jordan Liu4c733742019-02-28 12:03:40 -08004292 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4293 null /* workSource */);
4294 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 return success;
4296 } finally {
4297 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004298 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004299 }
4300
4301 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004302 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004303 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4305 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004306 if (DBG) {
4307 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4308 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4309 + p3 + " data=" + data);
4310 }
4311 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4312 command, p1, p2, p3, data);
4313 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004314
Jordan Liu4c733742019-02-28 12:03:40 -08004315 @Override
4316 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4317 int command, int p1, int p2, int p3, String data) {
4318 enforceModifyPermission();
4319 if (DBG) {
4320 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4321 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4322 + p3 + " data=" + data);
4323 }
4324 return iccTransmitApduLogicalChannelWithPermission(
4325 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4326 data);
4327 }
4328
4329 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4330 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004331 final long identity = Binder.clearCallingIdentity();
4332 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004333 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 return "";
4335 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004337 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004338 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4339 null /* workSource */);
4340 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004341
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004342 // Append the returned status code to the end of the response payload.
4343 String s = Integer.toHexString(
4344 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4345 if (response.payload != null) {
4346 s = IccUtils.bytesToHexString(response.payload) + s;
4347 }
4348 return s;
4349 } finally {
4350 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004351 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004352 }
Jake Hambye994d462014-02-03 13:10:13 -08004353
Evan Charltonc66da362014-05-16 14:06:40 -07004354 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004355 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4356 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4358 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004360 if (DBG) {
4361 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4362 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4363 }
4364 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4365 cla, command, p1, p2, p3, data);
4366 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004367
Jordan Liu4c733742019-02-28 12:03:40 -08004368 @Override
4369 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4370 int command, int p1, int p2, int p3, String data) {
4371 enforceModifyPermission();
4372 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4373 if (DBG) {
4374 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4375 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4376 + " data=" + data);
4377 }
4378
4379 return iccTransmitApduBasicChannelWithPermission(
4380 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4381 p2, p3, data);
4382 }
4383
4384 // open APDU basic channel assuming the caller has sufficient permissions
4385 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4386 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 final long identity = Binder.clearCallingIdentity();
4388 try {
4389 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4390 && TextUtils.equals(ISDR_AID, data)) {
4391 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004392 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4393 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 if (bestComponent == null
4395 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4396 loge("The calling package is not allowed to select ISD-R.");
4397 throw new SecurityException(
4398 "The calling package is not allowed to select ISD-R.");
4399 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004400 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004403 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4404 null /* workSource */);
4405 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 // Append the returned status code to the end of the response payload.
4408 String s = Integer.toHexString(
4409 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4410 if (response.payload != null) {
4411 s = IccUtils.bytesToHexString(response.payload) + s;
4412 }
4413 return s;
4414 } finally {
4415 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004416 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004417 }
4418
4419 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004420 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004421 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004422 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4423 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004424
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425 final long identity = Binder.clearCallingIdentity();
4426 try {
4427 if (DBG) {
4428 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4429 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4430 }
4431
4432 IccIoResult response =
4433 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4434 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4435 subId);
4436
4437 if (DBG) {
4438 log("Exchange SIM_IO [R]" + response);
4439 }
4440
4441 byte[] result = null;
4442 int length = 2;
4443 if (response.payload != null) {
4444 length = 2 + response.payload.length;
4445 result = new byte[length];
4446 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4447 } else {
4448 result = new byte[length];
4449 }
4450
4451 result[length - 1] = (byte) response.sw2;
4452 result[length - 2] = (byte) response.sw1;
4453 return result;
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004456 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004457 }
4458
Nathan Haroldb3014052017-01-25 15:57:32 -08004459 /**
4460 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4461 * on a particular subscription
4462 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004463 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4464 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004465 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004466 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004467 return null;
4468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 if (appType != TelephonyManager.APPTYPE_USIM
4473 && appType != TelephonyManager.APPTYPE_SIM) {
4474 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4475 return null;
4476 }
4477 Object response = sendRequest(
4478 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4479 if (response instanceof String[]) {
4480 return (String[]) response;
4481 }
yincheng zhao2737e882019-09-06 17:06:54 -07004482 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004484 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004487 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004488 }
4489
yincheng zhao2737e882019-09-06 17:06:54 -07004490 /**
4491 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4492 * subscription.
4493 *
4494 * @param subId the id of the subscription.
4495 * @param appType the uicc app type, must be USIM or SIM.
4496 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4497 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004498 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004499 * @return number of fplmns that is successfully written to the SIM.
4500 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004501 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4502 String callingFeatureId) {
4503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4504 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004505 if (DBG) logv("no permissions for setForbiddenplmns");
4506 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4507 }
4508 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4509 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4510 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4511 }
4512 if (fplmns == null) {
4513 throw new IllegalArgumentException("Fplmn List provided is null");
4514 }
4515 for (String fplmn : fplmns) {
4516 if (!CellIdentity.isValidPlmn(fplmn)) {
4517 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4518 }
4519 }
4520 final long identity = Binder.clearCallingIdentity();
4521 try {
4522 Object response = sendRequest(
4523 CMD_SET_FORBIDDEN_PLMNS,
4524 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4525 subId);
4526 return (int) response;
4527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
4530 }
4531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004532 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004533 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4535 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004536
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004537 final long identity = Binder.clearCallingIdentity();
4538 try {
4539 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4540 if (response.payload == null) {
4541 return "";
4542 }
Evan Charltonc66da362014-05-16 14:06:40 -07004543
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004544 // Append the returned status code to the end of the response payload.
4545 String s = Integer.toHexString(
4546 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4547 s = IccUtils.bytesToHexString(response.payload) + s;
4548 return s;
4549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Evan Charltonc66da362014-05-16 14:06:40 -07004552 }
4553
Jake Hambye994d462014-02-03 13:10:13 -08004554 /**
4555 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4556 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4557 *
4558 * @param itemID the ID of the item to read
4559 * @return the NV item as a String, or null on error.
4560 */
4561 @Override
4562 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004563 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4565 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566
4567 final long identity = Binder.clearCallingIdentity();
4568 try {
4569 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004570 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4572 return value;
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
Jake Hambye994d462014-02-03 13:10:13 -08004576 }
4577
4578 /**
4579 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4580 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4581 *
4582 * @param itemID the ID of the item to read
4583 * @param itemValue the value to write, as a String
4584 * @return true on success; false on any failure
4585 */
4586 @Override
4587 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004588 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004589 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4590 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591
4592 final long identity = Binder.clearCallingIdentity();
4593 try {
4594 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4595 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004596 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4598 return success;
4599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Jake Hambye994d462014-02-03 13:10:13 -08004602 }
4603
4604 /**
4605 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4606 * Used for device configuration by some CDMA operators.
4607 *
4608 * @param preferredRoamingList byte array containing the new PRL
4609 * @return true on success; false on any failure
4610 */
4611 @Override
4612 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4614 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615
4616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4619 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4620 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4621 return success;
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
4624 }
Jake Hambye994d462014-02-03 13:10:13 -08004625 }
4626
4627 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004628 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004629 * Used for device configuration by some CDMA operators.
4630 *
chen xu6dac5ab2018-10-26 17:39:23 -07004631 * @param slotIndex - device slot.
4632 *
Jake Hambye994d462014-02-03 13:10:13 -08004633 * @return true on success; false on any failure
4634 */
4635 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004636 public boolean resetModemConfig(int slotIndex) {
4637 Phone phone = PhoneFactory.getPhone(slotIndex);
4638 if (phone != null) {
4639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4640 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641
chen xu6dac5ab2018-10-26 17:39:23 -07004642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4645 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4646 return success;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
4649 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 }
chen xu6dac5ab2018-10-26 17:39:23 -07004651 return false;
4652 }
4653
4654 /**
4655 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4656 *
4657 * @param slotIndex - device slot.
4658 *
4659 * @return true on success; false on any failure
4660 */
4661 @Override
4662 public boolean rebootModem(int slotIndex) {
4663 Phone phone = PhoneFactory.getPhone(slotIndex);
4664 if (phone != null) {
4665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4666 mApp, phone.getSubId(), "rebootModem");
4667
4668 final long identity = Binder.clearCallingIdentity();
4669 try {
4670 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4671 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4672 return success;
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
4676 }
4677 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004678 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004679
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004680 public String[] getPcscfAddress(String apnType, String callingPackage,
4681 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004682 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4684 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004685 return new String[0];
4686 }
4687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 final long identity = Binder.clearCallingIdentity();
4689 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004690 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004691 } finally {
4692 Binder.restoreCallingIdentity(identity);
4693 }
Wink Saville36469e72014-06-11 15:17:00 -07004694 }
4695
Brad Ebinger51f743a2017-01-23 13:50:20 -08004696 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004697 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4698 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004699 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004700 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004701 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004705 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004706 // may happen if the device does not support IMS.
4707 return;
4708 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004709 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 } finally {
4711 Binder.restoreCallingIdentity(identity);
4712 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004713 }
4714
4715 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004716 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4717 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004718 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004719 public void disableIms(int slotId) {
4720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004724 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004725 // may happen if the device does not support IMS.
4726 return;
4727 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004728 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 } finally {
4730 Binder.restoreCallingIdentity(identity);
4731 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004732 }
4733
4734 /**
4735 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4736 * feature or {@link null} if the service is not available. If the feature is available, the
4737 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4738 */
4739 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004740 IImsServiceFeatureCallback callback) {
4741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742
4743 final long identity = Binder.clearCallingIdentity();
4744 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004745 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004746 // may happen if the device does not support IMS.
4747 return null;
4748 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004749 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004753 }
4754
4755 /**
4756 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4757 * feature during emergency calling or {@link null} if the service is not available. If the
4758 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4759 * listener for feature updates.
4760 */
4761 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763
4764 final long identity = Binder.clearCallingIdentity();
4765 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004766 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004767 // may happen if the device does not support IMS.
4768 return null;
4769 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004770 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 } finally {
4772 Binder.restoreCallingIdentity(identity);
4773 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004774 }
4775
Brad Ebinger5f64b052017-12-14 14:26:15 -08004776 /**
4777 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004778 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004779 */
4780 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782
4783 final long identity = Binder.clearCallingIdentity();
4784 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004785 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004786 // may happen if the device does not support IMS.
4787 return null;
4788 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004789 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 } finally {
4791 Binder.restoreCallingIdentity(identity);
4792 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004793 }
4794
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004795 /**
4796 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004797 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004798 */
4799 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4800 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801
4802 final long identity = Binder.clearCallingIdentity();
4803 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004804 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004805 // may happen if the device does not support IMS.
4806 return null;
4807 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004808 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 } finally {
4810 Binder.restoreCallingIdentity(identity);
4811 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004812 }
4813
Brad Ebinger884c07b2018-02-15 16:17:40 -08004814 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004815 * Sets the ImsService Package Name that Telephony will bind to.
4816 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004817 * @param slotIndex the slot ID that the ImsService should bind for.
4818 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004819 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004820 * @param featureTypes An integer array of feature types associated with a packageName.
4821 * @param packageName The name of the package that the current configuration will be replaced
4822 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004823 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004824 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004825 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4826 int[] featureTypes, String packageName) {
4827 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4830 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004831 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004833 final long identity = Binder.clearCallingIdentity();
4834 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004835 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004836 // may happen if the device does not support IMS.
4837 return false;
4838 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004839 Map<Integer, String> featureConfig = new HashMap<>();
4840 for (int featureType : featureTypes) {
4841 featureConfig.put(featureType, packageName);
4842 }
4843 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4844 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004848 }
4849
4850 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004851 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004852 *
4853 * @param slotId The slot that the ImsService is associated with.
4854 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4855 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004856 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004857 * @return the package name of the ImsService configuration.
4858 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004859 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4860 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004861 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004862 TelephonyPermissions
4863 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4864 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4865 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004869 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004870 // may happen if the device does not support IMS.
4871 return "";
4872 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004873 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004874 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4875 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004879 }
4880
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004881 /**
4882 * Get the MmTelFeature state associated with the requested subscription id.
4883 * @param subId The subscription that the MmTelFeature is associated with.
4884 * @param callback A callback with an integer containing the
4885 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4886 */
4887 @Override
4888 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4889 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4890 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4891 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4892 "IMS not available on device.");
4893 }
4894 final long token = Binder.clearCallingIdentity();
4895 try {
4896 int slotId = getSlotIndex(subId);
4897 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4898 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4899 + subId + "'");
4900 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4901 }
4902 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4903 try {
4904 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4905 } catch (RemoteException e) {
4906 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4907 + "Ignore");
4908 }
4909 });
4910 } finally {
4911 Binder.restoreCallingIdentity(token);
4912 }
4913 }
4914
Wink Saville36469e72014-06-11 15:17:00 -07004915 public void setImsRegistrationState(boolean registered) {
4916 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004917
4918 final long identity = Binder.clearCallingIdentity();
4919 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004920 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 } finally {
4922 Binder.restoreCallingIdentity(identity);
4923 }
Wink Saville36469e72014-06-11 15:17:00 -07004924 }
4925
4926 /**
Stuart Scott54788802015-03-30 13:18:01 -07004927 * Set the network selection mode to automatic.
4928 *
4929 */
4930 @Override
4931 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4933 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004934
Pengquan Menge92a50d2018-09-21 15:54:48 -07004935 if (!isActiveSubscription(subId)) {
4936 return;
4937 }
4938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 final long identity = Binder.clearCallingIdentity();
4940 try {
4941 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4942 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
Stuart Scott54788802015-03-30 13:18:01 -07004946 }
4947
Pengquan Mengea84e042018-09-20 14:57:26 -07004948 /**
4949 * Ask the radio to connect to the input network and change selection mode to manual.
4950 *
4951 * @param subId the id of the subscription.
4952 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4953 * the operator to attach to.
4954 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4955 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4956 * normal network selection next time.
4957 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004958 */
4959 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004960 public boolean setNetworkSelectionModeManual(
4961 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004962 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4963 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004964
4965 if (!isActiveSubscription(subId)) {
4966 return false;
4967 }
4968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 final long identity = Binder.clearCallingIdentity();
4970 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004971 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004973 if (DBG) {
4974 log("setNetworkSelectionModeManual: subId: " + subId
4975 + " operator: " + operatorInfo);
4976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004981 }
4982
4983 /**
4984 * Scans for available networks.
4985 */
4986 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004987 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4988 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4990 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004991 LocationAccessPolicy.LocationPermissionResult locationResult =
4992 LocationAccessPolicy.checkLocationPermission(mApp,
4993 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4994 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004995 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004996 .setCallingPid(Binder.getCallingPid())
4997 .setCallingUid(Binder.getCallingUid())
4998 .setMethod("getCellNetworkScanResults")
4999 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5000 .build());
5001 switch (locationResult) {
5002 case DENIED_HARD:
5003 throw new SecurityException("Not allowed to access scan results -- location");
5004 case DENIED_SOFT:
5005 return null;
5006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007
Pengquan Menga1bb6272018-09-06 09:59:22 -07005008 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 try {
5010 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005011 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 } finally {
5014 Binder.restoreCallingIdentity(identity);
5015 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005016 }
5017
5018 /**
yinxub1bed742017-04-17 11:45:04 -07005019 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005020 *
yinxub1bed742017-04-17 11:45:04 -07005021 * @param subId id of the subscription
5022 * @param request contains the radio access networks with bands/channels to scan
5023 * @param messenger callback messenger for scan results or errors
5024 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005025 * @return the id of the requested scan which can be used to stop the scan.
5026 */
5027 @Override
5028 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005029 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5031 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005032 LocationAccessPolicy.LocationPermissionResult locationResult =
5033 LocationAccessPolicy.checkLocationPermission(mApp,
5034 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5035 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005036 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005037 .setCallingPid(Binder.getCallingPid())
5038 .setCallingUid(Binder.getCallingUid())
5039 .setMethod("requestNetworkScan")
5040 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5041 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005042 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005043 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005044 if (e != null) {
5045 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5046 throw e;
5047 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005048 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005049 return TelephonyScanManager.INVALID_SCAN_ID;
5050 }
5051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 }
Hall Liu912dfd32019-04-25 14:02:26 -07005053 int callingUid = Binder.getCallingUid();
5054 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005055 final long identity = Binder.clearCallingIdentity();
5056 try {
5057 return mNetworkScanRequestTracker.startNetworkScan(
5058 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005059 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
yinxu504e1392017-04-12 16:03:22 -07005063 }
5064
Hall Liub2ac8ef2019-02-28 15:56:23 -08005065 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005066 NetworkScanRequest request, int subId) {
5067 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5068 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5069 boolean hasNetworkScanPermission =
5070 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5071 == PERMISSION_GRANTED;
5072
5073 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5074 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5075 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005076 }
5077
5078 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5079 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005080 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5081 return new SecurityException("Specific channels must not be"
5082 + " scanned without location access.");
5083 }
5084 }
5085 }
5086
Hall Liub2ac8ef2019-02-28 15:56:23 -08005087 return null;
5088 }
5089
yinxu504e1392017-04-12 16:03:22 -07005090 /**
5091 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005092 *
5093 * @param subId id of the subscription
5094 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005095 */
5096 @Override
5097 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5099 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100
Hall Liu912dfd32019-04-25 14:02:26 -07005101 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 final long identity = Binder.clearCallingIdentity();
5103 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005104 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 } finally {
5106 Binder.restoreCallingIdentity(identity);
5107 }
yinxu504e1392017-04-12 16:03:22 -07005108 }
5109
5110 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005111 * Get the calculated preferred network type.
5112 * Used for debugging incorrect network type.
5113 *
5114 * @return the preferred network type, defined in RILConstants.java.
5115 */
5116 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005117 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005118 final Phone defaultPhone = getDefaultPhone();
5119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005120 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005121 return RILConstants.PREFERRED_NETWORK_MODE;
5122 }
5123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
5126 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005127 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 } finally {
5129 Binder.restoreCallingIdentity(identity);
5130 }
Junda Liu84d15a22014-07-02 11:21:04 -07005131 }
5132
5133 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005134 * Get the preferred network type.
5135 * Used for device configuration by some CDMA operators.
5136 *
5137 * @return the preferred network type, defined in RILConstants.java.
5138 */
5139 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005140 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005141 TelephonyPermissions
5142 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5143 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144
5145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 if (DBG) log("getPreferredNetworkType");
5148 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5149 int networkType = (result != null ? result[0] : -1);
5150 if (DBG) log("getPreferredNetworkType: " + networkType);
5151 return networkType;
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005155 }
5156
5157 /**
5158 * Set the preferred network type.
5159 * Used for device configuration by some CDMA operators.
5160 *
5161 * @param networkType the preferred network type, defined in RILConstants.java.
5162 * @return true on success; false on any failure.
5163 */
5164 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005165 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5167 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005171 Settings.Global.putInt(mApp.getContentResolver(),
5172 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5173 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005176 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005177 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005178
5179 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005180 * Get the allowed network types that store in the telephony provider.
5181 *
5182 * @param subId the id of the subscription.
5183 * @return allowedNetworkTypes the allowed network types.
5184 */
5185 @Override
5186 public long getAllowedNetworkTypes(int subId) {
5187 TelephonyPermissions
5188 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5189 mApp, subId, "getAllowedNetworkTypes");
5190
5191 final long identity = Binder.clearCallingIdentity();
5192 try {
5193 return SubscriptionManager.getLongSubscriptionProperty(
5194 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5195 } finally {
5196 Binder.restoreCallingIdentity(identity);
5197 }
5198 }
5199
5200 /**
5201 * Set the allowed network types.
5202 *
5203 * @param subId the id of the subscription.
5204 * @param allowedNetworkTypes the allowed network types.
5205 * @return true on success; false on any failure.
5206 */
5207 @Override
5208 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5210 mApp, subId, "setAllowedNetworkTypes");
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 SubscriptionManager.setSubscriptionProperty(subId,
5214 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5215 String.valueOf(allowedNetworkTypes));
5216 return setPreferredNetworkTypesInternal(subId);
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
5220 }
5221
5222 private boolean setPreferredNetworkTypesInternal(int subId) {
5223 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5224 Settings.Global.getInt(mApp.getContentResolver(),
5225 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5226 RILConstants.PREFERRED_NETWORK_MODE));
5227 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5228 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5229 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5230 (int) (networkTypeBitMask & allowedNetworkTypes));
5231
5232 if (DBG) {
5233 log("setPreferredNetworkTypesInternal: subId " + subId
5234 + " networkTypes " + networkTypeBitMask
5235 + " allowedNetworkTypes " + allowedNetworkTypes
5236 + " networkMode " + networkMode);
5237 }
5238
5239 Boolean success = (Boolean) sendRequest(
5240 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5241 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5242 return success;
5243 }
5244
5245 /**
Miaoa84611c2019-03-15 09:21:10 +08005246 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005247 *
Miaoa84611c2019-03-15 09:21:10 +08005248 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005249 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005250 * @hide
5251 */
5252 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005253 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005255 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005256 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005257 try {
Miaoa84611c2019-03-15 09:21:10 +08005258 if (phone != null) {
5259 return phone.hasMatchedTetherApnSetting();
5260 } else {
5261 return false;
5262 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005263 } finally {
5264 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005265 }
Junda Liu475951f2014-11-07 16:45:03 -08005266 }
5267
5268 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005269 * Set mobile data enabled
5270 * Used by the user through settings etc to turn on/off mobile data
5271 *
5272 * @param enable {@code true} turn turn data on, else {@code false}
5273 */
5274 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005275 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
5281 int phoneId = mSubscriptionController.getPhoneId(subId);
5282 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5283 Phone phone = PhoneFactory.getPhone(phoneId);
5284 if (phone != null) {
5285 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005286 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 }
5290 } finally {
5291 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005292 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005293 }
5294
5295 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005296 * Get the user enabled state of Mobile Data.
5297 *
5298 * TODO: remove and use isUserDataEnabled.
5299 * This can't be removed now because some vendor codes
5300 * calls through ITelephony directly while they should
5301 * use TelephonyManager.
5302 *
5303 * @return true on enabled
5304 */
5305 @Override
5306 public boolean getDataEnabled(int subId) {
5307 return isUserDataEnabled(subId);
5308 }
5309
5310 /**
5311 * Get whether mobile data is enabled per user setting.
5312 *
5313 * There are other factors deciding whether mobile data is actually enabled, but they are
5314 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005315 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005316 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005317 *
5318 * @return {@code true} if data is enabled else {@code false}
5319 */
5320 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005321 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005322 try {
5323 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5324 null);
5325 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5327 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329
5330 final long identity = Binder.clearCallingIdentity();
5331 try {
5332 int phoneId = mSubscriptionController.getPhoneId(subId);
5333 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5334 Phone phone = PhoneFactory.getPhone(phoneId);
5335 if (phone != null) {
5336 boolean retVal = phone.isUserDataEnabled();
5337 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5338 return retVal;
5339 } else {
5340 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5341 return false;
5342 }
5343 } finally {
5344 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005345 }
5346 }
5347
5348 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005349 * Checks if the device is capable of mobile data by considering whether whether the
5350 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5351 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005352 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005353 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005354 */
5355 @Override
5356 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005357 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005358
5359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 int phoneId = mSubscriptionController.getPhoneId(subId);
5362 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5363 Phone phone = PhoneFactory.getPhone(phoneId);
5364 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005365 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5367 return retVal;
5368 } else {
5369 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5370 return false;
5371 }
5372 } finally {
5373 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005374 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005375 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005376
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005377 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5378 Phone phone) {
5379 //load access rules from carrier configs, and check those as well: b/139133814
5380 SubscriptionController subController = SubscriptionController.getInstance();
5381 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5382 || subController == null) return privilegeFromSim;
5383
5384 int uid = Binder.getCallingUid();
5385 PackageManager pkgMgr = phone.getContext().getPackageManager();
5386 String[] packages = pkgMgr.getPackagesForUid(uid);
5387
5388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5391 SubscriptionManager subManager = (SubscriptionManager)
5392 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5393 for (String pkg : packages) {
5394 if (subManager.canManageSubscription(subInfo, pkg)) {
5395 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5396 }
5397 }
5398 return privilegeFromSim;
5399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
5402 }
5403
5404 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5405 String pkgName) {
5406 //load access rules from carrier configs, and check those as well: b/139133814
5407 SubscriptionController subController = SubscriptionController.getInstance();
5408 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5409 || subController == null) return privilegeFromSim;
5410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
5413 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5414 SubscriptionManager subManager = (SubscriptionManager)
5415 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5416 return subManager.canManageSubscription(subInfo, pkgName)
5417 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
5421 }
5422
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005424 public int getCarrierPrivilegeStatus(int subId) {
5425 final Phone phone = getPhone(subId);
5426 if (phone == null) {
5427 loge("getCarrierPrivilegeStatus: Invalid subId");
5428 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5429 }
5430 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005431 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005432 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005433 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5434 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005435
5436 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5437 card.getCarrierPrivilegeStatusForCurrentTransaction(
5438 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005439 }
Junda Liu29340342014-07-10 15:23:27 -07005440
5441 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005442 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005443 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005444 final Phone phone = getPhone(subId);
5445 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005446 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005447 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5448 }
5449 UiccProfile profile =
5450 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5451 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005452 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005453 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5454 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005455 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005456 profile.getCarrierPrivilegeStatusForUid(
5457 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005458 }
5459
5460 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005461 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5462 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005464 }
5465
5466 int phoneId = SubscriptionManager.getPhoneId(subId);
5467 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005468 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005469 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005470 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5471 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005472 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5473 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5474 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005475 }
5476
5477 @Override
5478 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005479 if (TextUtils.isEmpty(pkgName))
5480 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005481 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5482 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5483 UiccCard card = UiccController.getInstance().getUiccCard(i);
5484 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005485 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005486 continue;
5487 }
5488
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005489 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5490 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5491 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005492 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5493 break;
5494 }
5495 }
5496
5497 return result;
Junda Liu29340342014-07-10 15:23:27 -07005498 }
Derek Tan89e89d42014-07-08 17:00:10 -07005499
5500 @Override
Junda Liue64de782015-04-16 17:19:16 -07005501 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5502 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5503 loge("phoneId " + phoneId + " is not valid.");
5504 return null;
5505 }
5506 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005507 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005508 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005509 return null ;
5510 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005511 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005512 }
5513
Amith Yamasani6e118872016-02-19 12:53:51 -08005514 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005515 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005516 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005517 List<String> privilegedPackages = new ArrayList<>();
5518 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005519 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5520 // has UICC in that slot.
5521 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005522 if (card.hasCarrierPrivilegeRules()) {
5523 if (packages == null) {
5524 // Only check packages in user 0 for now
5525 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005526 PackageManager.MATCH_DISABLED_COMPONENTS
5527 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005528 | PackageManager.GET_SIGNING_CERTIFICATES,
5529 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005530 }
5531 for (int p = packages.size() - 1; p >= 0; p--) {
5532 PackageInfo pkgInfo = packages.get(p);
5533 if (pkgInfo != null && pkgInfo.packageName != null
5534 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005535 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005536 privilegedPackages.add(pkgInfo.packageName);
5537 }
5538 }
5539 }
5540 }
5541 return privilegedPackages;
5542 }
5543
chen xuf7e9fe82019-05-09 19:31:02 -07005544 @Override
5545 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005546 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5547
5548 final long identity = Binder.clearCallingIdentity();
5549
chen xuf7e9fe82019-05-09 19:31:02 -07005550 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005551 try {
5552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5553 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5554 }
5555 } finally {
5556 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005557 }
5558 return privilegedPackages;
5559 }
5560
Wink Savilleb564aae2014-10-23 10:18:09 -07005561 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005562 final Phone phone = getPhone(subId);
5563 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005564 if (card == null) {
5565 loge("getIccId: No UICC");
5566 return null;
5567 }
5568 String iccId = card.getIccId();
5569 if (TextUtils.isEmpty(iccId)) {
5570 loge("getIccId: ICC ID is null or empty.");
5571 return null;
5572 }
5573 return iccId;
5574 }
5575
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005576 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005577 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5578 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005579 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005580 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 final String iccId = getIccId(subId);
5585 final Phone phone = getPhone(subId);
5586 if (phone == null) {
5587 return false;
5588 }
5589 final String subscriberId = phone.getSubscriberId();
5590
5591 if (DBG_MERGE) {
5592 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5593 + subscriberId + " to " + number);
5594 }
5595
5596 if (TextUtils.isEmpty(iccId)) {
5597 return false;
5598 }
5599
5600 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5601
5602 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5603 if (alphaTag == null) {
5604 editor.remove(alphaTagPrefKey);
5605 } else {
5606 editor.putString(alphaTagPrefKey, alphaTag);
5607 }
5608
5609 // Record both the line number and IMSI for this ICCID, since we need to
5610 // track all merged IMSIs based on line number
5611 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5612 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5613 if (number == null) {
5614 editor.remove(numberPrefKey);
5615 editor.remove(subscriberPrefKey);
5616 } else {
5617 editor.putString(numberPrefKey, number);
5618 editor.putString(subscriberPrefKey, subscriberId);
5619 }
5620
5621 editor.commit();
5622 return true;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005625 }
Derek Tan7226c842014-07-02 17:42:23 -07005626 }
5627
5628 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005629 public String getLine1NumberForDisplay(int subId, String callingPackage,
5630 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005631 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005633 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005634 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005635 return null;
5636 }
Derek Tan97ebb422014-09-05 16:55:38 -07005637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 String iccId = getIccId(subId);
5641 if (iccId != null) {
5642 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5643 if (DBG_MERGE) {
5644 log("getLine1NumberForDisplay returning "
5645 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5646 }
5647 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005648 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5650 return null;
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005653 }
Derek Tan7226c842014-07-02 17:42:23 -07005654 }
5655
5656 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005657 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5658 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005659 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005660 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005661 return null;
5662 }
Derek Tan97ebb422014-09-05 16:55:38 -07005663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
5666 String iccId = getIccId(subId);
5667 if (iccId != null) {
5668 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5669 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5670 }
5671 return null;
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005674 }
Derek Tan7226c842014-07-02 17:42:23 -07005675 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005676
5677 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005678 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5679 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005680 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5681 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005683 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005684 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005685 return null;
5686 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005687
Jordan Liub49b04b2019-05-06 14:45:15 -07005688 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5689 // the process, where TelephonyManager was instantiated.
5690 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005691 final long identity = Binder.clearCallingIdentity();
5692 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005693 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final TelephonyManager tele = TelephonyManager.from(context);
5695 final SubscriptionManager sub = SubscriptionManager.from(context);
5696
5697 // Figure out what subscribers are currently active
5698 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005699
Jordan Liub49b04b2019-05-06 14:45:15 -07005700 // Only consider subs which match the current subId
5701 // This logic can be simplified. See b/131189269 for progress.
5702 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005703 activeSubscriberIds.add(tele.getSubscriberId(subId));
5704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705
5706 // First pass, find a number override for an active subscriber
5707 String mergeNumber = null;
5708 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5709 for (String key : prefs.keySet()) {
5710 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5711 final String subscriberId = (String) prefs.get(key);
5712 if (activeSubscriberIds.contains(subscriberId)) {
5713 final String iccId = key.substring(
5714 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5715 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5716 mergeNumber = (String) prefs.get(numberKey);
5717 if (DBG_MERGE) {
5718 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5719 + " for active subscriber " + subscriberId);
5720 }
5721 if (!TextUtils.isEmpty(mergeNumber)) {
5722 break;
5723 }
5724 }
5725 }
5726 }
5727
5728 // Shortcut when no active merged subscribers
5729 if (TextUtils.isEmpty(mergeNumber)) {
5730 return null;
5731 }
5732
5733 // Second pass, find all subscribers under that line override
5734 final ArraySet<String> result = new ArraySet<>();
5735 for (String key : prefs.keySet()) {
5736 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5737 final String number = (String) prefs.get(key);
5738 if (mergeNumber.equals(number)) {
5739 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5740 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5741 final String subscriberId = (String) prefs.get(subscriberKey);
5742 if (!TextUtils.isEmpty(subscriberId)) {
5743 result.add(subscriberId);
5744 }
5745 }
5746 }
5747 }
5748
5749 final String[] resultArray = result.toArray(new String[result.size()]);
5750 Arrays.sort(resultArray);
5751 if (DBG_MERGE) {
5752 Slog.d(LOG_TAG,
5753 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5754 }
5755 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005756 } finally {
5757 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005758 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005759 }
5760
5761 @Override
zoey chen38003472019-12-13 17:16:31 +08005762 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5763 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005764
5765 final long identity = Binder.clearCallingIdentity();
5766 try {
5767 final TelephonyManager telephonyManager = mApp.getSystemService(
5768 TelephonyManager.class);
5769 String subscriberId = telephonyManager.getSubscriberId(subId);
5770 if (subscriberId == null) {
5771 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005772 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005773 + subId);
5774 }
5775 return null;
5776 }
5777
5778 final SubscriptionInfo info = SubscriptionController.getInstance()
5779 .getSubscriptionInfo(subId);
5780 final ParcelUuid groupUuid = info.getGroupUuid();
5781 // If it doesn't belong to any group, return just subscriberId of itself.
5782 if (groupUuid == null) {
5783 return new String[]{subscriberId};
5784 }
5785
5786 // Get all subscriberIds from the group.
5787 final List<String> mergedSubscriberIds = new ArrayList<>();
5788 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005789 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5790 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005791 for (SubscriptionInfo subInfo : groupInfos) {
5792 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5793 if (subscriberId != null) {
5794 mergedSubscriberIds.add(subscriberId);
5795 }
5796 }
5797
5798 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801
5802 }
5803 }
5804
5805 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005806 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005807 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005808 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 final Phone phone = getPhone(subId);
5813 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005817 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005818
5819 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005820 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005821 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5822 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005823 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5824 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825
5826 final long identity = Binder.clearCallingIdentity();
5827 try {
5828 final Phone phone = getPhone(subId);
5829 if (phone == null) {
5830 return false;
5831 }
5832 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5833 cdmaNonRoamingList);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005836 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005837 }
5838
5839 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005840 @Deprecated
5841 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5842 enforceModifyPermission();
5843
5844 int returnValue = 0;
5845 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005846 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005847 if(result.exception == null) {
5848 if (result.result != null) {
5849 byte[] responseData = (byte[])(result.result);
5850 if(responseData.length > oemResp.length) {
5851 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5852 responseData.length + "bytes. Buffer Size is " +
5853 oemResp.length + "bytes.");
5854 }
5855 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5856 returnValue = responseData.length;
5857 }
5858 } else {
5859 CommandException ex = (CommandException) result.exception;
5860 returnValue = ex.getCommandError().ordinal();
5861 if(returnValue > 0) returnValue *= -1;
5862 }
5863 } catch (RuntimeException e) {
5864 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5865 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5866 if(returnValue > 0) returnValue *= -1;
5867 }
5868
5869 return returnValue;
5870 }
5871
5872 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005873 public void setRadioCapability(RadioAccessFamily[] rafs) {
5874 try {
5875 ProxyController.getInstance().setRadioCapability(rafs);
5876 } catch (RuntimeException e) {
5877 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5878 }
5879 }
5880
5881 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005882 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005883 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005884 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005885 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005886 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005888 final long identity = Binder.clearCallingIdentity();
5889 try {
chen xub97461a2018-10-26 14:17:57 -07005890 TelephonyPermissions
5891 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5892 mApp, phone.getSubId(), "getRadioAccessFamily");
5893 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
chen xub97461a2018-10-26 14:17:57 -07005897 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005898 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005899
5900 @Override
5901 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005902 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005903 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005904
5905 final long identity = Binder.clearCallingIdentity();
5906 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005907 ImsManager.getInstance(defaultPhone.getContext(),
5908 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
5911 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005912 }
5913
5914 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005915 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005916 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005917 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5918 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005919 return false;
5920 }
Svet Ganovb320e182015-04-16 12:30:10 -07005921
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 final long identity = Binder.clearCallingIdentity();
5923 try {
5924 // Check the user preference and the system-level IMS setting. Even if the user has
5925 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5926 // In the long run, we may instead need to check if there exists a connection service
5927 // which can support video calling.
5928 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 return imsManager.isVtEnabledByPlatform()
5931 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5932 && imsManager.isVtEnabledByUser();
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
5935 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005936 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005937
Andrew Leea1239f22015-03-02 17:44:07 -08005938 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005939 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5940 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005942 mApp, subId, callingPackage, callingFeatureId,
5943 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 return false;
5945 }
5946
5947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 CarrierConfigManager configManager =
5950 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005951 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
5955 }
Andrew Leea1239f22015-03-02 17:44:07 -08005956 }
5957
5958 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005959 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005961 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 return false;
5963 }
5964
5965 final long identity = Binder.clearCallingIdentity();
5966 try {
5967 CarrierConfigManager configManager =
5968 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005969 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Andrew Leea1239f22015-03-02 17:44:07 -08005974 }
5975
Andrew Lee9431b832015-03-09 18:46:45 -07005976 @Override
5977 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005978 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005979 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005980 }
5981
5982 @Override
5983 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005984 final long identity = Binder.clearCallingIdentity();
5985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005986 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
Andrew Lee9431b832015-03-09 18:46:45 -07005990 }
5991
Hall Liuf6668912018-10-31 17:05:23 -07005992 /**
5993 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5994 * support for the feature and device firmware support.
5995 *
5996 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5997 */
5998 @Override
5999 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006001 final Phone phone = getPhone(subscriptionId);
6002 if (phone == null) {
6003 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6004 return false;
6005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006007 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6009 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006010 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 return isCarrierSupported && isDeviceSupported;
6012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
Hall Liu98187582018-01-22 19:15:32 -08006015 }
6016
Hall Liuf6668912018-10-31 17:05:23 -07006017 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006018 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6019 * RTT setting, will return true if the device and carrier both support RTT.
6020 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006021 */
6022 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 final long identity = Binder.clearCallingIdentity();
6024 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006025 boolean isRttSupported = isRttSupported(subscriptionId);
6026 boolean isUserRttSettingOn = Settings.Secure.getInt(
6027 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6028 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6029 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6030 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 } finally {
6032 Binder.restoreCallingIdentity(identity);
6033 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006034 }
6035
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006036 @Deprecated
6037 @Override
6038 public String getDeviceId(String callingPackage) {
6039 return getDeviceIdWithFeature(callingPackage, null);
6040 }
6041
Sanket Padawe7310cc72015-01-14 09:53:20 -08006042 /**
6043 * Returns the unique device ID of phone, for example, the IMEI for
6044 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6045 *
6046 * <p>Requires Permission:
6047 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6048 */
6049 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006050 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006051 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006052 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006053 return null;
6054 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006055 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006056 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006057 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006058 return null;
6059 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 return phone.getDeviceId();
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006067 }
6068
Ping Sunc67b7c22016-03-02 19:16:45 +08006069 /**
6070 * {@hide}
6071 * Returns the IMS Registration Status on a particular subid
6072 *
6073 * @param subId
6074 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006075 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006076 Phone phone = getPhone(subId);
6077 if (phone != null) {
6078 return phone.isImsRegistered();
6079 } else {
6080 return false;
6081 }
6082 }
6083
Santos Cordon7a1885b2015-02-03 11:15:19 -08006084 @Override
6085 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006086 final long identity = Binder.clearCallingIdentity();
6087 try {
6088 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006092 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006093
Tyler Gunnf70ed162019-04-03 15:28:53 -07006094 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006095 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006096 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006098 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006099 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6100 }
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
6107 }
6108
6109 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006110 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 Phone phone = getPhone(subscriptionId);
6114 if (phone == null) {
6115 return null;
6116 }
6117 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
6121 }
6122
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006123 /**
6124 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006125 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006126 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 Phone phone = getPhone(subId);
6130 if (phone != null) {
6131 return phone.isWifiCallingEnabled();
6132 } else {
6133 return false;
6134 }
6135 } finally {
6136 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006137 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006138 }
6139
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006140 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006141 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006142 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006143 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 Phone phone = getPhone(subId);
6147 if (phone != null) {
6148 return phone.isVideoEnabled();
6149 } else {
6150 return false;
6151 }
6152 } finally {
6153 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006154 }
6155 }
6156
6157 /**
6158 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6159 * defined in {@link ImsRegistrationImplBase}.
6160 */
6161 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162 final long identity = Binder.clearCallingIdentity();
6163 try {
6164 Phone phone = getPhone(subId);
6165 if (phone != null) {
6166 return phone.getImsRegistrationTech();
6167 } else {
6168 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6169 }
6170 } finally {
6171 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006172 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006173 }
6174
Stuart Scott8eef64f2015-04-08 15:13:54 -07006175 @Override
6176 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006177 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006178 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6179 return;
6180 }
6181
Svet Ganovcc087f82015-05-12 20:35:54 -07006182 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006183
Svet Ganovcc087f82015-05-12 20:35:54 -07006184 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006185 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6186 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006187 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006188 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006189 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6191 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006192 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006193 // There has been issues when Sms raw table somehow stores orphan
6194 // fragments. They lead to garbled message when new fragments come
6195 // in and combined with those stale ones. In case this happens again,
6196 // user can reset all network settings which will clean up this table.
6197 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006198 // Clean up IMS settings as well here.
6199 int slotId = getSlotIndex(subId);
6200 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6201 ImsManager.getInstance(mApp, slotId).factoryReset();
6202 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006203
6204 // Erase modem config if erase modem on network setting is enabled.
6205 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6206 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6207 if (configValue != null && Boolean.parseBoolean(configValue)) {
6208 sendEraseModemConfig(getDefaultPhone());
6209 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006210 } finally {
6211 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006212 }
6213 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006214
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006215 private void cleanUpSmsRawTable(Context context) {
6216 ContentResolver resolver = context.getContentResolver();
6217 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6218 resolver.delete(uri, null, null);
6219 }
6220
Narayan Kamath1c496c22015-04-16 14:40:19 +01006221 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006222 public String getSimLocaleForSubscriber(int subId) {
6223 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6224 final Phone phone = getPhone(subId);
6225 if (phone == null) {
6226 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006227 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006229 final long identity = Binder.clearCallingIdentity();
6230 try {
chen xu5d3637b2019-01-21 23:31:38 -08006231 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006232 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006233 if (info == null) {
6234 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6235 return null;
6236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 // Try and fetch the locale from the carrier properties or from the SIM language
6238 // preferences (EF-PL and EF-LI)...
6239 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006241 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6242 if (localeFromDefaultSim != null) {
6243 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6244 if (DBG) log("Using locale from subId: " + subId + " locale: "
6245 + localeFromDefaultSim);
6246 return localeFromDefaultSim.toLanguageTag();
6247 } else {
6248 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006249 }
6250 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006251
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006252 // The SIM language preferences only store a language (e.g. fr = French), not an
6253 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6254 // the SIM and carrier preferences does not include a country we add the country
6255 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006256 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006258 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 return mccLocale.toLanguageTag();
6260 }
6261
6262 if (DBG) log("No locale found - returning null");
6263 return null;
6264 } finally {
6265 Binder.restoreCallingIdentity(identity);
6266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006267 }
6268
6269 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006270 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6271 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006272 }
6273
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 /**
6275 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6276 */
6277 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006278 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6279 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006280 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006281
Chenjie Yu1ba97252018-01-11 18:16:20 -08006282 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006283 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006284
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006285 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006286 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6287 * representing the state of the modem.
6288 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006289 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6290 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006291 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006292 */
6293 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006294 public void requestModemActivityInfo(ResultReceiver result) {
6295 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006296 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 ModemActivityInfo ret = null;
6301 synchronized (mLastModemActivityInfo) {
6302 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6303 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006304 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006305 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006307 int[] txTimeMs = info.getTransmitTimeMillis();
6308 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006310 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 }
6312 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006313 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6314 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 mLastModemActivityInfo.setIdleTimeMillis(
6316 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006317 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6318 mLastModemActivityInfo.setReceiveTimeMillis(
6319 info.getReceiveTimeMillis() + mLastModemActivityInfo
6320 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006321 }
Chen Xud78231e2019-09-10 18:49:52 -07006322
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6324 mLastModemActivityInfo.getSleepTimeMillis(),
6325 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006326 mLastModemActivityInfo.getTransmitTimeMillis(),
6327 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006329 Bundle bundle = new Bundle();
6330 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6331 result.send(0, bundle);
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006334 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006335 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006336
Siddharth Rayb8114062018-06-17 15:02:38 -07006337 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6338 // less than total activity duration.
6339 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6340 if (info == null) {
6341 return false;
6342 }
6343 int activityDurationMs =
6344 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6345 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006346 int[] txTimeMs = info.getTransmitTimeMillis();
6347 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6348 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006349 }
6350 return (info.isValid()
6351 && (info.getSleepTimeMillis() <= activityDurationMs)
6352 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006353 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006354 && (totalTxTimeMs <= activityDurationMs));
6355 }
6356
Jack Yu85bd38a2015-11-09 11:34:32 -08006357 /**
6358 * {@hide}
6359 * Returns the service state information on specified subscription.
6360 */
6361 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006362 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6363 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006365 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006366 return null;
6367 }
6368
Hall Liuf19c44f2018-11-27 14:38:17 -08006369 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6370 LocationAccessPolicy.checkLocationPermission(mApp,
6371 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6372 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006373 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006374 .setCallingPid(Binder.getCallingPid())
6375 .setCallingUid(Binder.getCallingUid())
6376 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006377 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006378 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6379 .build());
6380
6381 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6382 LocationAccessPolicy.checkLocationPermission(mApp,
6383 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6384 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006385 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006386 .setCallingPid(Binder.getCallingPid())
6387 .setCallingUid(Binder.getCallingUid())
6388 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006389 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006390 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6391 .build());
6392 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6393 boolean hasFinePermission =
6394 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6395 boolean hasCoarsePermission =
6396 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6397
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006398 final long identity = Binder.clearCallingIdentity();
6399 try {
6400 final Phone phone = getPhone(subId);
6401 if (phone == null) {
6402 return null;
6403 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006404
Hall Liuf19c44f2018-11-27 14:38:17 -08006405 ServiceState ss = phone.getServiceState();
6406
6407 // Scrub out the location info in ServiceState depending on what level of access
6408 // the caller has.
6409 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006410 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6411 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006415 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006416
6417 /**
6418 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6419 *
6420 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6421 * voicemail ringtone.
6422 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6423 * PhoneAccount.
6424 */
6425 @Override
6426 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6430 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006431 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006433
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006438 }
6439
6440 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006441 * Sets the per-account voicemail ringtone.
6442 *
6443 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6444 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6445 *
6446 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6447 * voicemail ringtone.
6448 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6449 * PhoneAccount.
6450 */
6451 @Override
6452 public void setVoicemailRingtoneUri(String callingPackage,
6453 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006454 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006456 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6457 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6459 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6460 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006461 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462
6463 final long identity = Binder.clearCallingIdentity();
6464 try {
6465 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6466 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006467 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468 }
6469 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006472 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006473 }
6474
6475 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006476 * Returns whether vibration is set for voicemail notification in Phone settings.
6477 *
6478 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6479 * voicemail vibration setting.
6480 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6481 */
6482 @Override
6483 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006484 final long identity = Binder.clearCallingIdentity();
6485 try {
6486 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6487 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006488 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6492 } finally {
6493 Binder.restoreCallingIdentity(identity);
6494 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006495 }
6496
Youhan Wange64578a2016-05-02 15:32:42 -07006497 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006498 * Sets the per-account voicemail vibration.
6499 *
6500 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6501 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6502 *
6503 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6504 * voicemail vibration setting.
6505 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6506 * specific PhoneAccount.
6507 */
6508 @Override
6509 public void setVoicemailVibrationEnabled(String callingPackage,
6510 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006512 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006513 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6514 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6516 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6517 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006518 }
6519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 final long identity = Binder.clearCallingIdentity();
6521 try {
6522 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6523 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006524 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006525 }
6526 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006529 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006530 }
6531
6532 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006533 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6534 *
6535 * @throws SecurityException if the caller does not have the required permission
6536 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006537 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006538 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006539 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006540 }
6541
6542 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006543 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6544 * permission.
6545 *
6546 * @throws SecurityException if the caller does not have the required permission
6547 */
6548 private void enforceSendSmsPermission() {
6549 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6550 }
6551
6552 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006553 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006554 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006555 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006556 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006557 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 final long identity = Binder.clearCallingIdentity();
6559 try {
6560 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006561 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 if (componentName == null) {
6563 throw new SecurityException(
6564 "Caller not current active visual voicemail package[null]");
6565 }
6566 String vvmPackage = componentName.getPackageName();
6567 if (!callingPackage.equals(vvmPackage)) {
6568 throw new SecurityException("Caller not current active visual voicemail package["
6569 + vvmPackage + "]");
6570 }
6571 } finally {
6572 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006573 }
6574 }
6575
6576 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006577 * Return the application ID for the app type.
6578 *
6579 * @param subId the subscription ID that this request applies to.
6580 * @param appType the uicc app type.
6581 * @return Application ID for specificied app type, or null if no uicc.
6582 */
6583 @Override
6584 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006585 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006586 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587
6588 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006589 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006590 if (phone == null) {
6591 return null;
6592 }
6593 String aid = null;
6594 try {
6595 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6596 .getApplicationByType(appType).getAid();
6597 } catch (Exception e) {
6598 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6599 }
6600 return aid;
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006603 }
Youhan Wange64578a2016-05-02 15:32:42 -07006604 }
6605
Youhan Wang4001d252016-05-11 10:29:41 -07006606 /**
6607 * Return the Electronic Serial Number.
6608 *
6609 * @param subId the subscription ID that this request applies to.
6610 * @return ESN or null if error.
6611 */
6612 @Override
6613 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006614 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006615 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006618 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 if (phone == null) {
6620 return null;
6621 }
6622 String esn = null;
6623 try {
6624 esn = phone.getEsn();
6625 } catch (Exception e) {
6626 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6627 }
6628 return esn;
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006631 }
Youhan Wang4001d252016-05-11 10:29:41 -07006632 }
6633
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006634 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006635 * Return the Preferred Roaming List Version.
6636 *
6637 * @param subId the subscription ID that this request applies to.
6638 * @return PRLVersion or null if error.
6639 */
6640 @Override
6641 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006642 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006643 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006646 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 if (phone == null) {
6648 return null;
6649 }
6650 String cdmaPrlVersion = null;
6651 try {
6652 cdmaPrlVersion = phone.getCdmaPrlVersion();
6653 } catch (Exception e) {
6654 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6655 }
6656 return cdmaPrlVersion;
6657 } finally {
6658 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006659 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006660 }
6661
6662 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006663 * Get snapshot of Telephony histograms
6664 * @return List of Telephony histograms
6665 * @hide
6666 */
6667 @Override
6668 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6670 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006671
6672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 return RIL.getTelephonyRILTimingHistograms();
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
6677 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006678 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006679
6680 /**
6681 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006682 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6683 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006684 * Require system privileges. In the future we may add this to carrier APIs.
6685 *
Michele Berionne482f8202018-11-27 18:57:59 -08006686 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006687 */
6688 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006689 @TelephonyManager.SetCarrierRestrictionResult
6690 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006691 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006692 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006693
Michele Berionne482f8202018-11-27 18:57:59 -08006694 if (carrierRestrictionRules == null) {
6695 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006696 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 final long identity = Binder.clearCallingIdentity();
6699 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006700 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006701 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006702 } finally {
6703 Binder.restoreCallingIdentity(identity);
6704 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006705 }
6706
6707 /**
6708 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006709 * Get the allowed carrier list and the excluded carrier list, including the priority between
6710 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006711 * Require system privileges. In the future we may add this to carrier APIs.
6712 *
Michele Berionne482f8202018-11-27 18:57:59 -08006713 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006714 */
6715 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006716 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006717 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006718 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719
6720 final long identity = Binder.clearCallingIdentity();
6721 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006722 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6723 if (response instanceof CarrierRestrictionRules) {
6724 return (CarrierRestrictionRules) response;
6725 }
6726 // Response is an Exception of some kind,
6727 // which is signalled to the user as a NULL retval
6728 return null;
6729 } catch (Exception e) {
6730 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6731 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006735 }
6736
fionaxu59545b42016-05-25 15:53:37 -07006737 /**
6738 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6739 * @param subId the subscription ID that this action applies to.
6740 * @param enabled control enable or disable metered apns.
6741 * {@hide}
6742 */
6743 @Override
6744 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6745 enforceModifyPermission();
6746 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
6748 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006749 if (phone == null) {
6750 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6751 return;
6752 }
6753 try {
6754 phone.carrierActionSetMeteredApnsEnabled(enabled);
6755 } catch (Exception e) {
6756 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757 } finally {
6758 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006759 }
6760 }
6761
6762 /**
6763 * Action set from carrier signalling broadcast receivers to enable/disable radio
6764 * @param subId the subscription ID that this action applies to.
6765 * @param enabled control enable or disable radio.
6766 * {@hide}
6767 */
6768 @Override
6769 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6770 enforceModifyPermission();
6771 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772
6773 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006774 if (phone == null) {
6775 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6776 return;
6777 }
6778 try {
6779 phone.carrierActionSetRadioEnabled(enabled);
6780 } catch (Exception e) {
6781 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 } finally {
6783 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006784 }
6785 }
6786
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006787 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006788 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6789 * network status based on which carrier apps could apply actions accordingly,
6790 * enable/disable default url handler for example.
6791 *
6792 * @param subId the subscription ID that this action applies to.
6793 * @param report control start/stop reporting the default network status.
6794 * {@hide}
6795 */
6796 @Override
6797 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6798 enforceModifyPermission();
6799 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800
6801 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006802 if (phone == null) {
6803 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6804 return;
6805 }
6806 try {
6807 phone.carrierActionReportDefaultNetworkStatus(report);
6808 } catch (Exception e) {
6809 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006810 } finally {
6811 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006812 }
6813 }
6814
6815 /**
fionaxud9622282017-07-17 17:51:30 -07006816 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6817 * @param subId the subscription ID that this action applies to.
6818 * {@hide}
6819 */
6820 @Override
6821 public void carrierActionResetAll(int subId) {
6822 enforceModifyPermission();
6823 final Phone phone = getPhone(subId);
6824 if (phone == null) {
6825 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6826 return;
6827 }
6828 try {
6829 phone.carrierActionResetAll();
6830 } catch (Exception e) {
6831 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6832 }
6833 }
6834
6835 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006836 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6837 * bug report is being generated.
6838 */
6839 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006840 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006841 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6842 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006843 writer.println("Permission Denial: can't dump Phone from pid="
6844 + Binder.getCallingPid()
6845 + ", uid=" + Binder.getCallingUid()
6846 + "without permission "
6847 + android.Manifest.permission.DUMP);
6848 return;
6849 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006850 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006851 }
Jack Yueb89b242016-06-22 13:27:47 -07006852
Brad Ebingerdac2f002018-04-03 15:17:52 -07006853 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006854 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6855 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6856 @NonNull String[] args) {
6857 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6858 this, in.getFileDescriptor(), out.getFileDescriptor(),
6859 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006860 }
6861
Jack Yueb89b242016-06-22 13:27:47 -07006862 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006863 * Get aggregated video call data usage since boot.
6864 *
6865 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6866 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006867 * {@hide}
6868 */
6869 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006870 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006871 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6872 null);
6873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 final long identity = Binder.clearCallingIdentity();
6875 try {
6876 // NetworkStatsService keeps tracking the active network interface and identity. It
6877 // records the delta with the corresponding network identity.
6878 // We just return the total video call data usage snapshot since boot.
6879 Phone phone = getPhone(subId);
6880 if (phone != null) {
6881 return phone.getVtDataUsage(perUidStats);
6882 }
6883 return null;
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006886 }
Jack Yueb89b242016-06-22 13:27:47 -07006887 }
Jack Yu75ab2952016-07-08 14:29:33 -07006888
6889 /**
6890 * Policy control of data connection. Usually used when data limit is passed.
6891 * @param enabled True if enabling the data, otherwise disabling.
6892 * @param subId Subscription index
6893 * {@hide}
6894 */
6895 @Override
6896 public void setPolicyDataEnabled(boolean enabled, int subId) {
6897 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898
6899 final long identity = Binder.clearCallingIdentity();
6900 try {
6901 Phone phone = getPhone(subId);
6902 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006903 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 }
6905 } finally {
6906 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006907 }
6908 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006909
6910 /**
6911 * Get Client request stats
6912 * @return List of Client Request Stats
6913 * @hide
6914 */
6915 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006916 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6917 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006919 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006920 return null;
6921 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006922 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006923
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 if (phone != null) {
6927 return phone.getClientRequestStats();
6928 }
6929
6930 return null;
6931 } finally {
6932 Binder.restoreCallingIdentity(identity);
6933 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006934 }
6935
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006936 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006937 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006938 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006939 }
Jack Yueb4124c2017-02-16 15:32:43 -08006940
6941 /**
Grace Chen70990072017-03-24 17:21:30 -07006942 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006943 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006944 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006945 * @param state State of SIM (power down, power up, pass through)
6946 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6947 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6948 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006949 *
6950 **/
6951 @Override
Grace Chen70990072017-03-24 17:21:30 -07006952 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006953 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006954 Phone phone = PhoneFactory.getPhone(slotIndex);
6955
vagdeviaf9a5b92018-08-15 16:01:53 -07006956 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 final long identity = Binder.clearCallingIdentity();
6959 try {
6960 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006961 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 }
6963 } finally {
6964 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006965 }
6966 }
Shuo Qiandd210312017-04-12 22:11:33 +00006967
Tyler Gunn65d45c22017-06-05 11:22:26 -07006968 private boolean isUssdApiAllowed(int subId) {
6969 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006970 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006971 if (configManager == null) {
6972 return false;
6973 }
6974 PersistableBundle pb = configManager.getConfigForSubId(subId);
6975 if (pb == null) {
6976 return false;
6977 }
6978 return pb.getBoolean(
6979 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6980 }
6981
Shuo Qiandd210312017-04-12 22:11:33 +00006982 /**
6983 * Check if phone is in emergency callback mode
6984 * @return true if phone is in emergency callback mode
6985 * @param subId sub id
6986 */
goneil9c5f4872017-12-05 14:07:56 -08006987 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006988 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006989 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006990 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 if (phone != null) {
6995 return phone.isInEcm();
6996 } else {
6997 return false;
6998 }
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007001 }
7002 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007003
7004 /**
7005 * Get the current signal strength information for the given subscription.
7006 * Because this information is not updated when the device is in a low power state
7007 * it should not be relied-upon to be current.
7008 * @param subId Subscription index
7009 * @return the most recent cached signal strength info from the modem
7010 */
7011 @Override
7012 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 final long identity = Binder.clearCallingIdentity();
7014 try {
7015 Phone p = getPhone(subId);
7016 if (p == null) {
7017 return null;
7018 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 return p.getSignalStrength();
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007024 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007025
Pengquan Meng77b7f132018-08-22 14:49:57 -07007026 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007027 * Get the current modem radio state for the given slot.
7028 * @param slotIndex slot index.
7029 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007030 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007031 * @return the current radio power state from the modem
7032 */
7033 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007034 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007035 Phone phone = PhoneFactory.getPhone(slotIndex);
7036 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7038 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007039 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7040 }
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 return phone.getRadioPowerState();
7045 } finally {
7046 Binder.restoreCallingIdentity(identity);
7047 }
7048 }
7049 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7050 }
7051
7052 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007053 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7054 *
7055 * <p>Requires one of the following permissions:
7056 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7057 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7058 * privileges.
7059 *
7060 * @param subId subscription id
7061 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7062 * {@code false}.
7063 */
7064 @Override
7065 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007066 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7067 null /* message */);
7068
Pengquan Menga1bb6272018-09-06 09:59:22 -07007069 boolean isEnabled = false;
7070 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007071 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007072 Phone phone = getPhone(subId);
7073 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007074 } catch (Exception e) {
7075 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7076 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007079 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007080 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007081 }
7082
7083
7084 /**
7085 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7086 *
7087 * <p> Requires permission:
7088 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7089 * privileges.
7090 *
7091 * @param subId subscription id
7092 * @param isEnabled {@code true} means enable, {@code false} means disable.
7093 */
7094 @Override
7095 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7097 mApp, subId, "setDataRoamingEnabled");
7098
Pengquan Menga1bb6272018-09-06 09:59:22 -07007099 final long identity = Binder.clearCallingIdentity();
7100 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007101 Phone phone = getPhone(subId);
7102 if (phone != null) {
7103 phone.setDataRoamingEnabled(isEnabled);
7104 }
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007107 }
7108 }
7109
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007110 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007111 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007112 TelephonyPermissions
7113 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007114 mApp, subId, "isManualNetworkSelectionAllowed");
7115
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007116 boolean isAllowed = true;
7117 final long identity = Binder.clearCallingIdentity();
7118 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007119 Phone phone = getPhone(subId);
7120 if (phone != null) {
7121 isAllowed = phone.isCspPlmnEnabled();
7122 }
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
7126 return isAllowed;
7127 }
7128
7129 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007130 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007131 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007132 try {
7133 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007134 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007135 } catch (SecurityException e) {
7136 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7137 // has carrier privileges on an active UICC
7138 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7139 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007140 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007141 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007142 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007143
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007146 UiccController uiccController = UiccController.getInstance();
7147 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007148 if (hasReadPermission) {
7149 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007150 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007151
7152 // Remove private info if the caller doesn't have access
7153 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7154 for (UiccCardInfo cardInfo : cardInfos) {
7155 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7156 // is available
7157 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7158 if (card == null || card.getUiccProfile() == null) {
7159 // assume no access if the card or profile is unavailable
7160 filteredInfos.add(cardInfo.getUnprivileged());
7161 continue;
7162 }
7163 UiccProfile profile = card.getUiccProfile();
7164 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7165 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7166 filteredInfos.add(cardInfo);
7167 } else {
7168 filteredInfos.add(cardInfo.getUnprivileged());
7169 }
7170 }
7171 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
7175 }
7176
7177 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007178 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007179 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7184 if (slots == null) {
7185 Rlog.i(LOG_TAG, "slots is null.");
7186 return null;
7187 }
7188
7189 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7190 for (int i = 0; i < slots.length; i++) {
7191 UiccSlot slot = slots[i];
7192 if (slot == null) {
7193 continue;
7194 }
7195
Jordan Liu7be7e652019-05-06 18:55:02 +00007196 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 UiccCard card = slot.getUiccCard();
7198 if (card != null) {
7199 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007200 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007201 cardId = slot.getEid();
7202 if (TextUtils.isEmpty(cardId)) {
7203 cardId = slot.getIccId();
7204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007205 }
7206
Jordan Liu857451f2019-05-09 16:35:35 -07007207 if (cardId != null) {
7208 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7209 // if cardId is an EID, it's all digits so this is fine
7210 cardId = IccUtils.stripTrailingFs(cardId);
7211 }
7212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 int cardState = 0;
7214 switch (slot.getCardState()) {
7215 case CARDSTATE_ABSENT:
7216 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7217 break;
7218 case CARDSTATE_PRESENT:
7219 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7220 break;
7221 case CARDSTATE_ERROR:
7222 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7223 break;
7224 case CARDSTATE_RESTRICTED:
7225 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7226 break;
7227 default:
7228 break;
7229
7230 }
7231
7232 infos[i] = new UiccSlotInfo(
7233 slot.isActive(),
7234 slot.isEuicc(),
7235 cardId,
7236 cardState,
7237 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007238 slot.isExtendedApduSupported(),
7239 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 }
7241 return infos;
7242 } finally {
7243 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007244 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007245 }
7246
7247 @Override
7248 public boolean switchSlots(int[] physicalSlots) {
7249 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250
7251 final long identity = Binder.clearCallingIdentity();
7252 try {
7253 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007257 }
Jack Yu4c988042018-02-27 15:30:01 -08007258
7259 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007260 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007261 final long identity = Binder.clearCallingIdentity();
7262 try {
7263 return UiccController.getInstance().getCardIdForDefaultEuicc();
7264 } finally {
7265 Binder.restoreCallingIdentity(identity);
7266 }
7267 }
7268
7269 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007270 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7271 enforceModifyPermission();
7272 final Phone phone = getPhone(subId);
7273 if (phone == null) {
7274 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7275 return;
7276 }
7277
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007278 final long identity = Binder.clearCallingIdentity();
7279 try {
7280 phone.setRadioIndicationUpdateMode(filters, mode);
7281 } finally {
7282 Binder.restoreCallingIdentity(identity);
7283 }
Jack Yu4c988042018-02-27 15:30:01 -08007284 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007285
7286 /**
goneil47ffb6e2018-04-06 15:40:58 -07007287 * A test API to reload the UICC profile.
7288 *
7289 * <p>Requires that the calling app has permission
7290 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7291 * @hide
7292 */
7293 @Override
7294 public void refreshUiccProfile(int subId) {
7295 enforceModifyPermission();
7296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 Phone phone = getPhone(subId);
7300 if (phone == null) {
7301 return;
7302 }
7303 UiccCard uiccCard = phone.getUiccCard();
7304 if (uiccCard == null) {
7305 return;
7306 }
7307 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7308 if (uiccProfile == null) {
7309 return;
7310 }
7311 uiccProfile.refresh();
7312 } finally {
7313 Binder.restoreCallingIdentity(identity);
7314 }
7315 }
7316
7317 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007318 * Returns false if the mobile data is disabled by default, otherwise return true.
7319 */
7320 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007321 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007322 }
7323
7324 /**
7325 * Returns true if the data roaming is enabled by default, i.e the system property
7326 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7327 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7328 */
7329 private boolean getDefaultDataRoamingEnabled(int subId) {
7330 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007331 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007332 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007333 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7334 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7335 return isDataRoamingEnabled;
7336 }
7337
7338 /**
7339 * Returns the default network type for the given {@code subId}, if the default network type is
7340 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7341 */
7342 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007343 List<Integer> list = TelephonyProperties.default_network();
7344 int phoneId = mSubscriptionController.getPhoneId(subId);
7345 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7346 return list.get(phoneId);
7347 }
7348 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007349 }
fionaxua13278b2018-03-21 00:08:13 -07007350
7351 @Override
7352 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007353 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007354 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355
7356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 final Phone phone = getPhone(subId);
7359 if (phone == null) {
7360 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7361 return;
7362 }
chen xueaba88a2019-03-15 13:15:10 -07007363 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7364 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 } finally {
7366 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007367 }
fionaxua13278b2018-03-21 00:08:13 -07007368 }
7369
7370 @Override
7371 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007372 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373
7374 final long identity = Binder.clearCallingIdentity();
7375 try {
7376 final Phone phone = getPhone(subId);
7377 if (phone == null) {
7378 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7379 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7380 }
7381 return phone.getCarrierIdListVersion();
7382 } finally {
7383 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007384 }
fionaxua13278b2018-03-21 00:08:13 -07007385 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007386
7387 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007388 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7389 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007391 mApp, subId, callingPackage, callingFeatureId,
7392 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007393 return -1;
7394 }
7395
7396 final long identity = Binder.clearCallingIdentity();
7397 try {
7398 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7399 } finally {
7400 Binder.restoreCallingIdentity(identity);
7401 }
7402 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007403
7404 @Override
7405 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007406 TelephonyPermissions
7407 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007408 mApp, subId, "getCdmaRoamingMode");
7409
7410 final long identity = Binder.clearCallingIdentity();
7411 try {
7412 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7413 } finally {
7414 Binder.restoreCallingIdentity(identity);
7415 }
7416 }
7417
7418 @Override
7419 public boolean setCdmaRoamingMode(int subId, int mode) {
7420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7421 mApp, subId, "setCdmaRoamingMode");
7422
7423 final long identity = Binder.clearCallingIdentity();
7424 try {
7425 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
7428 }
7429 }
7430
7431 @Override
7432 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7434 mApp, subId, "setCdmaSubscriptionMode");
7435
7436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
7442 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007443
sqianc5eccab2018-10-19 18:46:41 -07007444 @Override
sqian8c685422019-02-22 15:55:18 -08007445 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007446 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007448 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7449 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007450 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7451 }
7452 final long identity = Binder.clearCallingIdentity();
7453 try {
sqian854d44b2018-12-12 16:48:18 -08007454 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7455 for (Phone phone: PhoneFactory.getPhones()) {
7456 if (phone.getEmergencyNumberTracker() != null
7457 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7458 emergencyNumberListInternal.put(
7459 phone.getSubId(),
7460 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7461 }
sqian11b7a0e2018-12-05 18:48:28 -08007462 }
sqian854d44b2018-12-12 16:48:18 -08007463 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
sqianc5eccab2018-10-19 18:46:41 -07007467 }
7468
7469 @Override
sqian8c685422019-02-22 15:55:18 -08007470 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007471 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007472 if (!exactMatch) {
7473 TelephonyPermissions
7474 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007475 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007476 }
7477 final long identity = Binder.clearCallingIdentity();
7478 try {
sqian854d44b2018-12-12 16:48:18 -08007479 for (Phone phone: PhoneFactory.getPhones()) {
7480 if (phone.getEmergencyNumberTracker() != null
7481 && phone.getEmergencyNumberTracker() != null) {
7482 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7483 number, exactMatch)) {
7484 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007485 }
7486 }
sqian11b7a0e2018-12-05 18:48:28 -08007487 }
7488 return false;
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
7492 }
7493
sqianf4ca7ed2019-01-15 18:32:07 -08007494 /**
7495 * Update emergency number list for test mode.
7496 */
7497 @Override
7498 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7499 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7500 "updateEmergencyNumberListTestMode");
7501
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 for (Phone phone: PhoneFactory.getPhones()) {
7505 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7506 if (tracker != null) {
7507 tracker.executeEmergencyNumberTestModeCommand(action, num);
7508 }
7509 }
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
7513 }
7514
7515 /**
7516 * Get the full emergency number list for test mode.
7517 */
7518 @Override
7519 public List<String> getEmergencyNumberListTestMode() {
7520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7521 "getEmergencyNumberListTestMode");
7522
7523 final long identity = Binder.clearCallingIdentity();
7524 try {
7525 Set<String> emergencyNumbers = new HashSet<>();
7526 for (Phone phone: PhoneFactory.getPhones()) {
7527 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7528 if (tracker != null) {
7529 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7530 emergencyNumbers.add(num.getNumber());
7531 }
7532 }
7533 }
7534 return new ArrayList<>(emergencyNumbers);
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
7538 }
7539
chen xud6b45bd2018-10-30 22:27:10 -07007540 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007541 public int getEmergencyNumberDbVersion(int subId) {
7542 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7543
7544 final long identity = Binder.clearCallingIdentity();
7545 try {
7546 final Phone phone = getPhone(subId);
7547 if (phone == null) {
7548 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7549 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7550 }
7551 return phone.getEmergencyNumberDbVersion();
7552 } finally {
7553 Binder.restoreCallingIdentity(identity);
7554 }
7555 }
7556
7557 @Override
7558 public void notifyOtaEmergencyNumberDbInstalled() {
7559 enforceModifyPermission();
7560
7561 final long identity = Binder.clearCallingIdentity();
7562 try {
7563 for (Phone phone: PhoneFactory.getPhones()) {
7564 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7565 if (tracker != null) {
7566 tracker.updateOtaEmergencyNumberDatabase();
7567 }
7568 }
7569 } finally {
7570 Binder.restoreCallingIdentity(identity);
7571 }
7572 }
7573
7574 @Override
7575 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7576 enforceActiveEmergencySessionPermission();
7577
7578 final long identity = Binder.clearCallingIdentity();
7579 try {
7580 for (Phone phone: PhoneFactory.getPhones()) {
7581 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7582 if (tracker != null) {
7583 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7584 }
7585 }
7586 } finally {
7587 Binder.restoreCallingIdentity(identity);
7588 }
7589 }
7590
7591 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007592 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7593 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7594 Phone phone = getPhone(subId);
7595 if (phone == null) {
7596 return null;
7597 }
7598 final long identity = Binder.clearCallingIdentity();
7599 try {
7600 UiccProfile profile = UiccController.getInstance()
7601 .getUiccProfileForPhone(phone.getPhoneId());
7602 if (profile != null) {
7603 return profile.getCertsFromCarrierPrivilegeAccessRules();
7604 }
7605 } finally {
7606 Binder.restoreCallingIdentity(identity);
7607 }
7608 return null;
7609 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007610
7611 /**
7612 * Enable or disable a modem stack.
7613 */
7614 @Override
7615 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7616 enforceModifyPermission();
7617
7618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 Phone phone = PhoneFactory.getPhone(slotIndex);
7621 if (phone == null) {
7622 return false;
7623 } else {
7624 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7625 }
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
7629 }
Michelecea4cf22018-12-21 15:00:11 -08007630
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007631 /**
7632 * Whether a modem stack is enabled or not.
7633 */
7634 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007635 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7636 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007637 Phone phone = PhoneFactory.getPhone(slotIndex);
7638 if (phone == null) return false;
7639
7640 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007641 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7642 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007643 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7644 }
7645
7646 final long identity = Binder.clearCallingIdentity();
7647 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007648 try {
7649 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7650 } catch (NoSuchElementException ex) {
7651 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7652 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
7656 }
7657
Michelecea4cf22018-12-21 15:00:11 -08007658 @Override
Michele0ea7d782019-03-19 14:58:42 -07007659 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007660 enforceModifyPermission();
7661
7662 final long identity = Binder.clearCallingIdentity();
7663 try {
7664 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007665 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007666 .commit();
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
7670 }
7671
7672 @Override
Michele0ea7d782019-03-19 14:58:42 -07007673 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007674 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007676 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7677 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007678 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007679 }
Michelecea4cf22018-12-21 15:00:11 -08007680
7681 final long identity = Binder.clearCallingIdentity();
7682 try {
Michele0ea7d782019-03-19 14:58:42 -07007683 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007684 } finally {
7685 Binder.restoreCallingIdentity(identity);
7686 }
7687 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007688
Michele0ea7d782019-03-19 14:58:42 -07007689 @TelephonyManager.IsMultiSimSupportedResult
7690 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007691 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7692 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7693 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007694 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7695 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007696 }
7697 // Check if the hardware supports multisim functionality. If usage of multisim is not
7698 // supported by the modem, indicate that it is restricted.
7699 PhoneCapability staticCapability =
7700 mPhoneConfigurationManager.getStaticPhoneCapability();
7701 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007702 loge("isMultiSimSupportedInternal: no static configuration available");
7703 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007704 }
7705 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007706 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7707 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007708 }
7709 // Check if support of multiple SIMs is restricted by carrier
7710 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007711 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007712 }
7713
Michele0ea7d782019-03-19 14:58:42 -07007714 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007715 }
7716
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007717 /**
7718 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007719 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7720 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7721 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007722 * @param numOfSims number of active sims we want to switch to
7723 */
7724 @Override
7725 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007726 if (numOfSims == 1) {
7727 enforceModifyPermission();
7728 } else {
7729 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7730 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7731 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007732 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007733
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007734 try {
Michele30b57b22019-03-01 12:01:14 -08007735 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007736 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007737 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7738 return;
7739 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007740 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7741 } finally {
7742 Binder.restoreCallingIdentity(identity);
7743 }
7744 }
7745
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007746 @Override
7747 public boolean isApplicationOnUicc(int subId, int appType) {
7748 enforceReadPrivilegedPermission("isApplicationOnUicc");
7749 Phone phone = getPhone(subId);
7750 if (phone == null) {
7751 return false;
7752 }
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 UiccCard uiccCard = phone.getUiccCard();
7756 if (uiccCard == null) {
7757 return false;
7758 }
7759 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7760 if (uiccProfile == null) {
7761 return false;
7762 }
7763 if (TelephonyManager.APPTYPE_SIM <= appType
7764 && appType <= TelephonyManager.APPTYPE_ISIM) {
7765 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7766 }
7767 return false;
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
7770 }
7771 }
7772
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007773 /**
chen xub4baa772019-04-03 10:23:41 -07007774 * Get whether making changes to modem configurations will trigger reboot.
7775 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007776 */
7777 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007778 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7779 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007781 mApp, subId, callingPackage, callingFeatureId,
7782 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007783 return false;
7784 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007785 final long identity = Binder.clearCallingIdentity();
7786 try {
7787 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7788 } finally {
7789 Binder.restoreCallingIdentity(identity);
7790 }
7791 }
7792
Nathan Harold29f5f052019-02-15 13:41:57 -08007793 private void updateModemStateMetrics() {
7794 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7795 // TODO: check the state for each modem if the api is ready.
7796 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7797 }
7798
Pengquan Meng3889a572019-01-23 11:16:29 -08007799 @Override
7800 public int[] getSlotsMapping() {
7801 enforceReadPrivilegedPermission("getSlotsMapping");
7802
7803 final long identity = Binder.clearCallingIdentity();
7804 try {
7805 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7806 // All logical slots should have a mapping to a physical slot.
7807 int[] logicalSlotsMapping = new int[phoneCount];
7808 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7809 for (int i = 0; i < slotInfos.length; i++) {
7810 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7811 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7812 }
7813 }
7814 return logicalSlotsMapping;
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
7818 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007819
7820 /**
7821 * Get the IRadio HAL Version
7822 */
7823 @Override
7824 public int getRadioHalVersion() {
7825 Phone phone = getDefaultPhone();
7826 if (phone == null) return -1;
7827 HalVersion hv = phone.getHalVersion();
7828 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7829 return hv.major * 100 + hv.minor;
7830 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007831
7832 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007833 * Get the current calling package name.
7834 * @return the current calling package name
7835 */
7836 @Override
7837 public String getCurrentPackageName() {
7838 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7839 }
7840
7841 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007842 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7843 * corresponding network requests on a subId.
7844 *
7845 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007846 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007847 * 2) APN is un-metered for this subscription, or
7848 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007849 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007850 *
7851 * @return whether data is allowed for a apn type.
7852 *
7853 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007854 */
7855 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007856 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007857 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7858 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007859
7860 // Now that all security checks passes, perform the operation as ourselves.
7861 final long identity = Binder.clearCallingIdentity();
7862 try {
7863 Phone phone = getPhone(subId);
7864 if (phone == null) return false;
7865
Jack Yu41407ee2019-05-13 16:54:09 -07007866 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007867 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7868 } finally {
7869 Binder.restoreCallingIdentity(identity);
7870 }
7871 }
7872
7873 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007874 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007875 enforceReadPrivilegedPermission("isApnMetered");
7876
7877 // Now that all security checks passes, perform the operation as ourselves.
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 Phone phone = getPhone(subId);
7881 if (phone == null) return true; // By default return true.
7882
Jack Yu41407ee2019-05-13 16:54:09 -07007883 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
7887 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007888
7889 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007890 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7891 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7892 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7893 if (iccRecords == null) {
7894 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7895 return false;
7896 }
7897 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7898 }
7899
7900 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007901 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007902 if (callingPackage == null) {
7903 callingPackage = getCurrentPackageName();
7904 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007905 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7906 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7907 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7908 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7909 }
7910 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7911 Intent intent = new Intent();
7912 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7913 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7914 // Bring up choose default SMS subscription dialog right now
7915 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7916 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7917 mApp.startActivity(intent);
7918 }
chen xud5ca2d52019-05-28 15:20:57 -07007919
7920 @Override
7921 public String getMmsUAProfUrl(int subId) {
7922 //TODO investigate if this API should require proper permission check in R b/133791609
7923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7926 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7927 } finally {
7928 Binder.restoreCallingIdentity(identity);
7929 }
7930 }
7931
7932 @Override
7933 public String getMmsUserAgent(int subId) {
7934 //TODO investigate if this API should require proper permission check in R b/133791609
7935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7938 .getString(com.android.internal.R.string.config_mms_user_agent);
7939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
7942 }
Jack Yub07d4972019-05-28 16:12:25 -07007943
7944 @Override
7945 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7946 enforceModifyPermission();
7947
7948 // Now that all security checks passes, perform the operation as ourselves.
7949 final long identity = Binder.clearCallingIdentity();
7950 try {
7951 Phone phone = getPhone(subId);
7952 if (phone == null) return false;
7953
7954 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
7958 }
7959
7960 @Override
7961 public boolean isDataAllowedInVoiceCall(int subId) {
7962 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7963
7964 // Now that all security checks passes, perform the operation as ourselves.
7965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 Phone phone = getPhone(subId);
7968 if (phone == null) return false;
7969
7970 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
7974 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007975
changbettyd5c246e2019-12-24 15:40:37 +08007976 @Override
7977 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7978 enforceModifyPermission();
7979
7980 // Now that all security checks passes, perform the operation as ourselves.
7981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 Phone phone = getPhone(subId);
7984 if (phone == null) return false;
7985
7986 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7987 } finally {
7988 Binder.restoreCallingIdentity(identity);
7989 }
7990 }
7991
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007992 /**
7993 * Updates whether conference event pacakge handling is enabled.
7994 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7995 * otherwise.
7996 */
7997 @Override
7998 public void setCepEnabled(boolean isCepEnabled) {
7999 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8000
8001 final long identity = Binder.clearCallingIdentity();
8002 try {
8003 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8004 for (Phone phone : PhoneFactory.getPhones()) {
8005 Phone defaultPhone = phone.getImsPhone();
8006 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8007 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8008 ImsPhoneCallTracker imsPhoneCallTracker =
8009 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8010 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8011 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8012 + imsPhone.getMsisdn());
8013 }
8014 }
8015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
8018 }
allenwtsu46dcc572020-01-08 18:24:03 +08008019
8020 /**
8021 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8022 *
8023 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8024 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8025 * before being read.
8026 */
8027 @Override
8028 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8029 isCompressed) {
8030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8031 mApp, subId, "notifyRcsAutoConfigurationReceived");
8032 try {
8033 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8034 if (configBinder == null) {
8035 Rlog.e(LOG_TAG, "null result for getImsConfig");
8036 } else {
8037 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8038 }
8039 } catch (RemoteException e) {
8040 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8041 }
8042 }
zoey chene02881a2019-12-30 16:11:23 +08008043
8044 @Override
8045 public boolean isIccLockEnabled(int subId) {
8046 enforceReadPrivilegedPermission("isIccLockEnabled");
8047
8048 // Now that all security checks passes, perform the operation as ourselves.
8049 final long identity = Binder.clearCallingIdentity();
8050 try {
8051 Phone phone = getPhone(subId);
8052 if (phone != null && phone.getIccCard() != null) {
8053 return phone.getIccCard().getIccLockEnabled();
8054 } else {
8055 return false;
8056 }
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
8060 }
8061
8062 /**
8063 * Set the ICC pin lock enabled or disabled.
8064 *
8065 * @return an integer representing the status of IccLock enabled or disabled in the following
8066 * three cases:
8067 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8068 * successfully.
8069 * - Positive number and zero for remaining password attempts.
8070 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8071 *
8072 */
8073 @Override
8074 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8075 enforceModifyPermission();
8076
8077 Phone phone = getPhone(subId);
8078 if (phone == null) {
8079 return 0;
8080 }
8081 // Now that all security checks passes, perform the operation as ourselves.
8082 final long identity = Binder.clearCallingIdentity();
8083 try {
8084 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8085 new Pair<Boolean, String>(enabled, password), phone, null);
8086 return attemptsRemaining;
8087
8088 } catch (Exception e) {
8089 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8090 } finally {
8091 Binder.restoreCallingIdentity(identity);
8092 }
8093 return 0;
8094 }
8095
8096 /**
8097 * Change the ICC password used in ICC pin lock.
8098 *
8099 * @return an integer representing the status of IccLock changed in the following three cases:
8100 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8101 * - Positive number and zero for remaining password attempts.
8102 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8103 *
8104 */
8105 @Override
8106 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8107 enforceModifyPermission();
8108
8109 Phone phone = getPhone(subId);
8110 if (phone == null) {
8111 return 0;
8112 }
8113 // Now that all security checks passes, perform the operation as ourselves.
8114 final long identity = Binder.clearCallingIdentity();
8115 try {
8116 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8117 new Pair<String, String>(oldPassword, newPassword), phone, null);
8118 return attemptsRemaining;
8119
8120 } catch (Exception e) {
8121 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8122 } finally {
8123 Binder.restoreCallingIdentity(identity);
8124 }
8125 return 0;
8126 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008127}