blob: f63b1df657e1f7f503847d35c2c7792bdb718c1c [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 }
shilu84f6e8b2019-12-19 13:58:01 -08004982 /**
4983 * Get the manual network selection
4984 *
4985 * @param subId the id of the subscription.
4986 *
4987 * @return the previously saved user selected PLMN
4988 */
4989 @Override
4990 public String getManualNetworkSelectionPlmn(int subId) {
4991 TelephonyPermissions
4992 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4993 mApp, subId, "getManualNetworkSelectionPlmn");
4994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 if (!isActiveSubscription(subId)) {
4998 return "";
4999 }
5000
5001 final Phone phone = getPhone(subId);
5002 if (phone == null) {
5003 return "";
5004 }
5005 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5006 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5007 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
5011 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005012
5013 /**
5014 * Scans for available networks.
5015 */
5016 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005017 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5018 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5020 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005021 LocationAccessPolicy.LocationPermissionResult locationResult =
5022 LocationAccessPolicy.checkLocationPermission(mApp,
5023 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5024 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005025 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005026 .setCallingPid(Binder.getCallingPid())
5027 .setCallingUid(Binder.getCallingUid())
5028 .setMethod("getCellNetworkScanResults")
5029 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5030 .build());
5031 switch (locationResult) {
5032 case DENIED_HARD:
5033 throw new SecurityException("Not allowed to access scan results -- location");
5034 case DENIED_SOFT:
5035 return null;
5036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005037
Pengquan Menga1bb6272018-09-06 09:59:22 -07005038 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 try {
5040 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005041 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005042 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005046 }
5047
5048 /**
yinxub1bed742017-04-17 11:45:04 -07005049 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005050 *
yinxub1bed742017-04-17 11:45:04 -07005051 * @param subId id of the subscription
5052 * @param request contains the radio access networks with bands/channels to scan
5053 * @param messenger callback messenger for scan results or errors
5054 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005055 * @return the id of the requested scan which can be used to stop the scan.
5056 */
5057 @Override
5058 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005059 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5061 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005062 LocationAccessPolicy.LocationPermissionResult locationResult =
5063 LocationAccessPolicy.checkLocationPermission(mApp,
5064 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5065 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005066 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005067 .setCallingPid(Binder.getCallingPid())
5068 .setCallingUid(Binder.getCallingUid())
5069 .setMethod("requestNetworkScan")
5070 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5071 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005072 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005073 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005074 if (e != null) {
5075 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5076 throw e;
5077 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005078 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005079 return TelephonyScanManager.INVALID_SCAN_ID;
5080 }
5081 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 }
Hall Liu912dfd32019-04-25 14:02:26 -07005083 int callingUid = Binder.getCallingUid();
5084 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005085 final long identity = Binder.clearCallingIdentity();
5086 try {
5087 return mNetworkScanRequestTracker.startNetworkScan(
5088 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005089 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
yinxu504e1392017-04-12 16:03:22 -07005093 }
5094
Hall Liub2ac8ef2019-02-28 15:56:23 -08005095 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005096 NetworkScanRequest request, int subId) {
5097 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5098 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5099 boolean hasNetworkScanPermission =
5100 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5101 == PERMISSION_GRANTED;
5102
5103 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5104 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5105 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005106 }
5107
5108 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5109 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005110 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5111 return new SecurityException("Specific channels must not be"
5112 + " scanned without location access.");
5113 }
5114 }
5115 }
5116
Hall Liub2ac8ef2019-02-28 15:56:23 -08005117 return null;
5118 }
5119
yinxu504e1392017-04-12 16:03:22 -07005120 /**
5121 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005122 *
5123 * @param subId id of the subscription
5124 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005125 */
5126 @Override
5127 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5129 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005130
Hall Liu912dfd32019-04-25 14:02:26 -07005131 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005134 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 } finally {
5136 Binder.restoreCallingIdentity(identity);
5137 }
yinxu504e1392017-04-12 16:03:22 -07005138 }
5139
5140 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005141 * Get the calculated preferred network type.
5142 * Used for debugging incorrect network type.
5143 *
5144 * @return the preferred network type, defined in RILConstants.java.
5145 */
5146 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005147 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 final Phone defaultPhone = getDefaultPhone();
5149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005150 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005151 return RILConstants.PREFERRED_NETWORK_MODE;
5152 }
5153
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005157 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 } finally {
5159 Binder.restoreCallingIdentity(identity);
5160 }
Junda Liu84d15a22014-07-02 11:21:04 -07005161 }
5162
5163 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005164 * Get the preferred network type.
5165 * Used for device configuration by some CDMA operators.
5166 *
5167 * @return the preferred network type, defined in RILConstants.java.
5168 */
5169 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005170 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005171 TelephonyPermissions
5172 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5173 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174
5175 final long identity = Binder.clearCallingIdentity();
5176 try {
5177 if (DBG) log("getPreferredNetworkType");
5178 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5179 int networkType = (result != null ? result[0] : -1);
5180 if (DBG) log("getPreferredNetworkType: " + networkType);
5181 return networkType;
5182 } finally {
5183 Binder.restoreCallingIdentity(identity);
5184 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005185 }
5186
5187 /**
5188 * Set the preferred network type.
5189 * Used for device configuration by some CDMA operators.
5190 *
5191 * @param networkType the preferred network type, defined in RILConstants.java.
5192 * @return true on success; false on any failure.
5193 */
5194 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005195 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5197 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005201 Settings.Global.putInt(mApp.getContentResolver(),
5202 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5203 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204 } finally {
5205 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005206 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005207 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005208
5209 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005210 * Get the allowed network types that store in the telephony provider.
5211 *
5212 * @param subId the id of the subscription.
5213 * @return allowedNetworkTypes the allowed network types.
5214 */
5215 @Override
5216 public long getAllowedNetworkTypes(int subId) {
5217 TelephonyPermissions
5218 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5219 mApp, subId, "getAllowedNetworkTypes");
5220
5221 final long identity = Binder.clearCallingIdentity();
5222 try {
5223 return SubscriptionManager.getLongSubscriptionProperty(
5224 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
5227 }
5228 }
5229
5230 /**
5231 * Set the allowed network types.
5232 *
5233 * @param subId the id of the subscription.
5234 * @param allowedNetworkTypes the allowed network types.
5235 * @return true on success; false on any failure.
5236 */
5237 @Override
5238 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5239 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5240 mApp, subId, "setAllowedNetworkTypes");
5241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 SubscriptionManager.setSubscriptionProperty(subId,
5244 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5245 String.valueOf(allowedNetworkTypes));
5246 return setPreferredNetworkTypesInternal(subId);
5247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
5250 }
5251
5252 private boolean setPreferredNetworkTypesInternal(int subId) {
5253 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5254 Settings.Global.getInt(mApp.getContentResolver(),
5255 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5256 RILConstants.PREFERRED_NETWORK_MODE));
5257 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5258 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5259 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5260 (int) (networkTypeBitMask & allowedNetworkTypes));
5261
5262 if (DBG) {
5263 log("setPreferredNetworkTypesInternal: subId " + subId
5264 + " networkTypes " + networkTypeBitMask
5265 + " allowedNetworkTypes " + allowedNetworkTypes
5266 + " networkMode " + networkMode);
5267 }
5268
5269 Boolean success = (Boolean) sendRequest(
5270 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5271 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5272 return success;
5273 }
5274
5275 /**
Miaoa84611c2019-03-15 09:21:10 +08005276 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005277 *
Miaoa84611c2019-03-15 09:21:10 +08005278 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005279 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005280 * @hide
5281 */
5282 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005283 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005284 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005286 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 try {
Miaoa84611c2019-03-15 09:21:10 +08005288 if (phone != null) {
5289 return phone.hasMatchedTetherApnSetting();
5290 } else {
5291 return false;
5292 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005293 } finally {
5294 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005295 }
Junda Liu475951f2014-11-07 16:45:03 -08005296 }
5297
5298 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005299 * Set mobile data enabled
5300 * Used by the user through settings etc to turn on/off mobile data
5301 *
5302 * @param enable {@code true} turn turn data on, else {@code false}
5303 */
5304 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005305 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005306 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5307 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308
5309 final long identity = Binder.clearCallingIdentity();
5310 try {
5311 int phoneId = mSubscriptionController.getPhoneId(subId);
5312 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5313 Phone phone = PhoneFactory.getPhone(phoneId);
5314 if (phone != null) {
5315 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005316 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 }
5320 } finally {
5321 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005322 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005323 }
5324
5325 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005326 * Get the user enabled state of Mobile Data.
5327 *
5328 * TODO: remove and use isUserDataEnabled.
5329 * This can't be removed now because some vendor codes
5330 * calls through ITelephony directly while they should
5331 * use TelephonyManager.
5332 *
5333 * @return true on enabled
5334 */
5335 @Override
5336 public boolean getDataEnabled(int subId) {
5337 return isUserDataEnabled(subId);
5338 }
5339
5340 /**
5341 * Get whether mobile data is enabled per user setting.
5342 *
5343 * There are other factors deciding whether mobile data is actually enabled, but they are
5344 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005345 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005346 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005347 *
5348 * @return {@code true} if data is enabled else {@code false}
5349 */
5350 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005351 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005352 try {
5353 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5354 null);
5355 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5357 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359
5360 final long identity = Binder.clearCallingIdentity();
5361 try {
5362 int phoneId = mSubscriptionController.getPhoneId(subId);
5363 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5364 Phone phone = PhoneFactory.getPhone(phoneId);
5365 if (phone != null) {
5366 boolean retVal = phone.isUserDataEnabled();
5367 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5368 return retVal;
5369 } else {
5370 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5371 return false;
5372 }
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005375 }
5376 }
5377
5378 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005379 * Checks if the device is capable of mobile data by considering whether whether the
5380 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5381 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005382 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005383 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005384 */
5385 @Override
5386 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005387 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 int phoneId = mSubscriptionController.getPhoneId(subId);
5392 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5393 Phone phone = PhoneFactory.getPhone(phoneId);
5394 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005395 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5397 return retVal;
5398 } else {
5399 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5400 return false;
5401 }
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005404 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005405 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005406
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005407 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5408 Phone phone) {
5409 //load access rules from carrier configs, and check those as well: b/139133814
5410 SubscriptionController subController = SubscriptionController.getInstance();
5411 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5412 || subController == null) return privilegeFromSim;
5413
5414 int uid = Binder.getCallingUid();
5415 PackageManager pkgMgr = phone.getContext().getPackageManager();
5416 String[] packages = pkgMgr.getPackagesForUid(uid);
5417
5418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5421 SubscriptionManager subManager = (SubscriptionManager)
5422 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5423 for (String pkg : packages) {
5424 if (subManager.canManageSubscription(subInfo, pkg)) {
5425 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5426 }
5427 }
5428 return privilegeFromSim;
5429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
5432 }
5433
5434 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5435 String pkgName) {
5436 //load access rules from carrier configs, and check those as well: b/139133814
5437 SubscriptionController subController = SubscriptionController.getInstance();
5438 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5439 || subController == null) return privilegeFromSim;
5440
5441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5444 SubscriptionManager subManager = (SubscriptionManager)
5445 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5446 return subManager.canManageSubscription(subInfo, pkgName)
5447 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
5451 }
5452
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005453 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005454 public int getCarrierPrivilegeStatus(int subId) {
5455 final Phone phone = getPhone(subId);
5456 if (phone == null) {
5457 loge("getCarrierPrivilegeStatus: Invalid subId");
5458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5459 }
5460 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005461 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005462 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5464 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005465
5466 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5467 card.getCarrierPrivilegeStatusForCurrentTransaction(
5468 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005469 }
Junda Liu29340342014-07-10 15:23:27 -07005470
5471 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005472 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005473 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 final Phone phone = getPhone(subId);
5475 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005476 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005477 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5478 }
5479 UiccProfile profile =
5480 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5481 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005482 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005483 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5484 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005485 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005486 profile.getCarrierPrivilegeStatusForUid(
5487 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005488 }
5489
5490 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005491 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5492 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005493 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005494 }
5495
5496 int phoneId = SubscriptionManager.getPhoneId(subId);
5497 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005498 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005499 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005500 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5501 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005502 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5503 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5504 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005505 }
5506
5507 @Override
5508 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005509 if (TextUtils.isEmpty(pkgName))
5510 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005511 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5512 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5513 UiccCard card = UiccController.getInstance().getUiccCard(i);
5514 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005515 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005516 continue;
5517 }
5518
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005519 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5520 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5521 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005522 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5523 break;
5524 }
5525 }
5526
5527 return result;
Junda Liu29340342014-07-10 15:23:27 -07005528 }
Derek Tan89e89d42014-07-08 17:00:10 -07005529
5530 @Override
Junda Liue64de782015-04-16 17:19:16 -07005531 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5532 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5533 loge("phoneId " + phoneId + " is not valid.");
5534 return null;
5535 }
5536 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005537 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005538 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005539 return null ;
5540 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005541 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005542 }
5543
Amith Yamasani6e118872016-02-19 12:53:51 -08005544 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005545 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005546 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005547 List<String> privilegedPackages = new ArrayList<>();
5548 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005549 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5550 // has UICC in that slot.
5551 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005552 if (card.hasCarrierPrivilegeRules()) {
5553 if (packages == null) {
5554 // Only check packages in user 0 for now
5555 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005556 PackageManager.MATCH_DISABLED_COMPONENTS
5557 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005558 | PackageManager.GET_SIGNING_CERTIFICATES,
5559 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005560 }
5561 for (int p = packages.size() - 1; p >= 0; p--) {
5562 PackageInfo pkgInfo = packages.get(p);
5563 if (pkgInfo != null && pkgInfo.packageName != null
5564 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005565 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005566 privilegedPackages.add(pkgInfo.packageName);
5567 }
5568 }
5569 }
5570 }
5571 return privilegedPackages;
5572 }
5573
chen xuf7e9fe82019-05-09 19:31:02 -07005574 @Override
5575 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005576 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5577
5578 final long identity = Binder.clearCallingIdentity();
5579
chen xuf7e9fe82019-05-09 19:31:02 -07005580 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005581 try {
5582 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5583 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5584 }
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005587 }
5588 return privilegedPackages;
5589 }
5590
Wink Savilleb564aae2014-10-23 10:18:09 -07005591 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005592 final Phone phone = getPhone(subId);
5593 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005594 if (card == null) {
5595 loge("getIccId: No UICC");
5596 return null;
5597 }
5598 String iccId = card.getIccId();
5599 if (TextUtils.isEmpty(iccId)) {
5600 loge("getIccId: ICC ID is null or empty.");
5601 return null;
5602 }
5603 return iccId;
5604 }
5605
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005606 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005607 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5608 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005609 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005610 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612 final long identity = Binder.clearCallingIdentity();
5613 try {
5614 final String iccId = getIccId(subId);
5615 final Phone phone = getPhone(subId);
5616 if (phone == null) {
5617 return false;
5618 }
5619 final String subscriberId = phone.getSubscriberId();
5620
5621 if (DBG_MERGE) {
5622 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5623 + subscriberId + " to " + number);
5624 }
5625
5626 if (TextUtils.isEmpty(iccId)) {
5627 return false;
5628 }
5629
5630 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5631
5632 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5633 if (alphaTag == null) {
5634 editor.remove(alphaTagPrefKey);
5635 } else {
5636 editor.putString(alphaTagPrefKey, alphaTag);
5637 }
5638
5639 // Record both the line number and IMSI for this ICCID, since we need to
5640 // track all merged IMSIs based on line number
5641 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5642 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5643 if (number == null) {
5644 editor.remove(numberPrefKey);
5645 editor.remove(subscriberPrefKey);
5646 } else {
5647 editor.putString(numberPrefKey, number);
5648 editor.putString(subscriberPrefKey, subscriberId);
5649 }
5650
5651 editor.commit();
5652 return true;
5653 } finally {
5654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005655 }
Derek Tan7226c842014-07-02 17:42:23 -07005656 }
5657
5658 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005659 public String getLine1NumberForDisplay(int subId, String callingPackage,
5660 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005661 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005663 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005664 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005665 return null;
5666 }
Derek Tan97ebb422014-09-05 16:55:38 -07005667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 final long identity = Binder.clearCallingIdentity();
5669 try {
5670 String iccId = getIccId(subId);
5671 if (iccId != null) {
5672 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5673 if (DBG_MERGE) {
5674 log("getLine1NumberForDisplay returning "
5675 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5676 }
5677 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005678 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5680 return null;
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005683 }
Derek Tan7226c842014-07-02 17:42:23 -07005684 }
5685
5686 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005687 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5688 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005690 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005691 return null;
5692 }
Derek Tan97ebb422014-09-05 16:55:38 -07005693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 String iccId = getIccId(subId);
5697 if (iccId != null) {
5698 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5699 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5700 }
5701 return null;
5702 } finally {
5703 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005704 }
Derek Tan7226c842014-07-02 17:42:23 -07005705 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005706
5707 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005708 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5709 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005710 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5711 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005713 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005714 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005715 return null;
5716 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005717
Jordan Liub49b04b2019-05-06 14:45:15 -07005718 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5719 // the process, where TelephonyManager was instantiated.
5720 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005721 final long identity = Binder.clearCallingIdentity();
5722 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 final TelephonyManager tele = TelephonyManager.from(context);
5725 final SubscriptionManager sub = SubscriptionManager.from(context);
5726
5727 // Figure out what subscribers are currently active
5728 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005729
Jordan Liub49b04b2019-05-06 14:45:15 -07005730 // Only consider subs which match the current subId
5731 // This logic can be simplified. See b/131189269 for progress.
5732 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005733 activeSubscriberIds.add(tele.getSubscriberId(subId));
5734 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 // First pass, find a number override for an active subscriber
5737 String mergeNumber = null;
5738 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5739 for (String key : prefs.keySet()) {
5740 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5741 final String subscriberId = (String) prefs.get(key);
5742 if (activeSubscriberIds.contains(subscriberId)) {
5743 final String iccId = key.substring(
5744 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5745 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5746 mergeNumber = (String) prefs.get(numberKey);
5747 if (DBG_MERGE) {
5748 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5749 + " for active subscriber " + subscriberId);
5750 }
5751 if (!TextUtils.isEmpty(mergeNumber)) {
5752 break;
5753 }
5754 }
5755 }
5756 }
5757
5758 // Shortcut when no active merged subscribers
5759 if (TextUtils.isEmpty(mergeNumber)) {
5760 return null;
5761 }
5762
5763 // Second pass, find all subscribers under that line override
5764 final ArraySet<String> result = new ArraySet<>();
5765 for (String key : prefs.keySet()) {
5766 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5767 final String number = (String) prefs.get(key);
5768 if (mergeNumber.equals(number)) {
5769 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5770 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5771 final String subscriberId = (String) prefs.get(subscriberKey);
5772 if (!TextUtils.isEmpty(subscriberId)) {
5773 result.add(subscriberId);
5774 }
5775 }
5776 }
5777 }
5778
5779 final String[] resultArray = result.toArray(new String[result.size()]);
5780 Arrays.sort(resultArray);
5781 if (DBG_MERGE) {
5782 Slog.d(LOG_TAG,
5783 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5784 }
5785 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005786 } finally {
5787 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005788 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005789 }
5790
5791 @Override
zoey chen38003472019-12-13 17:16:31 +08005792 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5793 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 final TelephonyManager telephonyManager = mApp.getSystemService(
5798 TelephonyManager.class);
5799 String subscriberId = telephonyManager.getSubscriberId(subId);
5800 if (subscriberId == null) {
5801 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005802 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005803 + subId);
5804 }
5805 return null;
5806 }
5807
5808 final SubscriptionInfo info = SubscriptionController.getInstance()
5809 .getSubscriptionInfo(subId);
5810 final ParcelUuid groupUuid = info.getGroupUuid();
5811 // If it doesn't belong to any group, return just subscriberId of itself.
5812 if (groupUuid == null) {
5813 return new String[]{subscriberId};
5814 }
5815
5816 // Get all subscriberIds from the group.
5817 final List<String> mergedSubscriberIds = new ArrayList<>();
5818 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005819 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5820 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005821 for (SubscriptionInfo subInfo : groupInfos) {
5822 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5823 if (subscriberId != null) {
5824 mergedSubscriberIds.add(subscriberId);
5825 }
5826 }
5827
5828 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5829 } finally {
5830 Binder.restoreCallingIdentity(identity);
5831
5832 }
5833 }
5834
5835 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005836 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005837 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005838 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005839
5840 final long identity = Binder.clearCallingIdentity();
5841 try {
5842 final Phone phone = getPhone(subId);
5843 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005847 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005848
5849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005850 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005851 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5852 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005853 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5854 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855
5856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 final Phone phone = getPhone(subId);
5859 if (phone == null) {
5860 return false;
5861 }
5862 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5863 cdmaNonRoamingList);
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005866 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005867 }
5868
5869 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005870 @Deprecated
5871 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5872 enforceModifyPermission();
5873
5874 int returnValue = 0;
5875 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005876 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005877 if(result.exception == null) {
5878 if (result.result != null) {
5879 byte[] responseData = (byte[])(result.result);
5880 if(responseData.length > oemResp.length) {
5881 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5882 responseData.length + "bytes. Buffer Size is " +
5883 oemResp.length + "bytes.");
5884 }
5885 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5886 returnValue = responseData.length;
5887 }
5888 } else {
5889 CommandException ex = (CommandException) result.exception;
5890 returnValue = ex.getCommandError().ordinal();
5891 if(returnValue > 0) returnValue *= -1;
5892 }
5893 } catch (RuntimeException e) {
5894 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5895 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5896 if(returnValue > 0) returnValue *= -1;
5897 }
5898
5899 return returnValue;
5900 }
5901
5902 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005903 public void setRadioCapability(RadioAccessFamily[] rafs) {
5904 try {
5905 ProxyController.getInstance().setRadioCapability(rafs);
5906 } catch (RuntimeException e) {
5907 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5908 }
5909 }
5910
5911 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005912 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005913 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005914 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005915 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005916 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005917 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
chen xub97461a2018-10-26 14:17:57 -07005920 TelephonyPermissions
5921 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5922 mApp, phone.getSubId(), "getRadioAccessFamily");
5923 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
chen xub97461a2018-10-26 14:17:57 -07005927 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005928 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005929
5930 @Override
5931 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005932 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005933 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005937 ImsManager.getInstance(defaultPhone.getContext(),
5938 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939 } finally {
5940 Binder.restoreCallingIdentity(identity);
5941 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005942 }
5943
5944 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005945 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005946 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005947 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5948 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005949 return false;
5950 }
Svet Ganovb320e182015-04-16 12:30:10 -07005951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 // Check the user preference and the system-level IMS setting. Even if the user has
5955 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5956 // In the long run, we may instead need to check if there exists a connection service
5957 // which can support video calling.
5958 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005959 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960 return imsManager.isVtEnabledByPlatform()
5961 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5962 && imsManager.isVtEnabledByUser();
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
5965 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005966 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005967
Andrew Leea1239f22015-03-02 17:44:07 -08005968 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005969 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5970 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005972 mApp, subId, callingPackage, callingFeatureId,
5973 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005974 return false;
5975 }
5976
5977 final long identity = Binder.clearCallingIdentity();
5978 try {
5979 CarrierConfigManager configManager =
5980 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005981 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
Andrew Leea1239f22015-03-02 17:44:07 -08005986 }
5987
5988 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005989 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005991 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005992 return false;
5993 }
5994
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 CarrierConfigManager configManager =
5998 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005999 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006000 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6001 } finally {
6002 Binder.restoreCallingIdentity(identity);
6003 }
Andrew Leea1239f22015-03-02 17:44:07 -08006004 }
6005
Andrew Lee9431b832015-03-09 18:46:45 -07006006 @Override
6007 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006008 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006009 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006010 }
6011
6012 @Override
6013 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006014 final long identity = Binder.clearCallingIdentity();
6015 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006016 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006017 } finally {
6018 Binder.restoreCallingIdentity(identity);
6019 }
Andrew Lee9431b832015-03-09 18:46:45 -07006020 }
6021
Hall Liuf6668912018-10-31 17:05:23 -07006022 /**
6023 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6024 * support for the feature and device firmware support.
6025 *
6026 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6027 */
6028 @Override
6029 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006031 final Phone phone = getPhone(subscriptionId);
6032 if (phone == null) {
6033 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6034 return false;
6035 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006037 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6039 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006040 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 return isCarrierSupported && isDeviceSupported;
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
6044 }
Hall Liu98187582018-01-22 19:15:32 -08006045 }
6046
Hall Liuf6668912018-10-31 17:05:23 -07006047 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006048 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6049 * RTT setting, will return true if the device and carrier both support RTT.
6050 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006051 */
6052 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 final long identity = Binder.clearCallingIdentity();
6054 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006055 boolean isRttSupported = isRttSupported(subscriptionId);
6056 boolean isUserRttSettingOn = Settings.Secure.getInt(
6057 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6058 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6059 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6060 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 } finally {
6062 Binder.restoreCallingIdentity(identity);
6063 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006064 }
6065
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006066 @Deprecated
6067 @Override
6068 public String getDeviceId(String callingPackage) {
6069 return getDeviceIdWithFeature(callingPackage, null);
6070 }
6071
Sanket Padawe7310cc72015-01-14 09:53:20 -08006072 /**
6073 * Returns the unique device ID of phone, for example, the IMEI for
6074 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6075 *
6076 * <p>Requires Permission:
6077 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6078 */
6079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006080 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006081 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006082 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006083 return null;
6084 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006085 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006086 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006087 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006088 return null;
6089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006090
6091 final long identity = Binder.clearCallingIdentity();
6092 try {
6093 return phone.getDeviceId();
6094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006097 }
6098
Ping Sunc67b7c22016-03-02 19:16:45 +08006099 /**
6100 * {@hide}
6101 * Returns the IMS Registration Status on a particular subid
6102 *
6103 * @param subId
6104 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006105 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006106 Phone phone = getPhone(subId);
6107 if (phone != null) {
6108 return phone.isImsRegistered();
6109 } else {
6110 return false;
6111 }
6112 }
6113
Santos Cordon7a1885b2015-02-03 11:15:19 -08006114 @Override
6115 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006116 final long identity = Binder.clearCallingIdentity();
6117 try {
6118 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6119 } finally {
6120 Binder.restoreCallingIdentity(identity);
6121 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006122 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006123
Tyler Gunnf70ed162019-04-03 15:28:53 -07006124 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006125 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006126 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006128 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006129 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6130 }
6131 final long identity = Binder.clearCallingIdentity();
6132 try {
6133 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006140 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6141 final long identity = Binder.clearCallingIdentity();
6142 try {
6143 Phone phone = getPhone(subscriptionId);
6144 if (phone == null) {
6145 return null;
6146 }
6147 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
6151 }
6152
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006153 /**
6154 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006155 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006156 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 Phone phone = getPhone(subId);
6160 if (phone != null) {
6161 return phone.isWifiCallingEnabled();
6162 } else {
6163 return false;
6164 }
6165 } finally {
6166 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006167 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006168 }
6169
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006170 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006171 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006172 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006173 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 Phone phone = getPhone(subId);
6177 if (phone != null) {
6178 return phone.isVideoEnabled();
6179 } else {
6180 return false;
6181 }
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006184 }
6185 }
6186
6187 /**
6188 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6189 * defined in {@link ImsRegistrationImplBase}.
6190 */
6191 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 final long identity = Binder.clearCallingIdentity();
6193 try {
6194 Phone phone = getPhone(subId);
6195 if (phone != null) {
6196 return phone.getImsRegistrationTech();
6197 } else {
6198 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6199 }
6200 } finally {
6201 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006202 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006203 }
6204
Stuart Scott8eef64f2015-04-08 15:13:54 -07006205 @Override
6206 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006207 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006208 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6209 return;
6210 }
6211
Svet Ganovcc087f82015-05-12 20:35:54 -07006212 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006213
Svet Ganovcc087f82015-05-12 20:35:54 -07006214 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006215 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6216 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006217 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006218 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006219 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006220 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6221 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006222 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006223 // There has been issues when Sms raw table somehow stores orphan
6224 // fragments. They lead to garbled message when new fragments come
6225 // in and combined with those stale ones. In case this happens again,
6226 // user can reset all network settings which will clean up this table.
6227 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006228 // Clean up IMS settings as well here.
6229 int slotId = getSlotIndex(subId);
6230 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6231 ImsManager.getInstance(mApp, slotId).factoryReset();
6232 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006233
6234 // Erase modem config if erase modem on network setting is enabled.
6235 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6236 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6237 if (configValue != null && Boolean.parseBoolean(configValue)) {
6238 sendEraseModemConfig(getDefaultPhone());
6239 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006242 }
6243 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006244
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006245 private void cleanUpSmsRawTable(Context context) {
6246 ContentResolver resolver = context.getContentResolver();
6247 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6248 resolver.delete(uri, null, null);
6249 }
6250
Narayan Kamath1c496c22015-04-16 14:40:19 +01006251 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006252 public String getSimLocaleForSubscriber(int subId) {
6253 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6254 final Phone phone = getPhone(subId);
6255 if (phone == null) {
6256 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006257 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006258 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006259 final long identity = Binder.clearCallingIdentity();
6260 try {
chen xu5d3637b2019-01-21 23:31:38 -08006261 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006262 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006263 if (info == null) {
6264 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6265 return null;
6266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 // Try and fetch the locale from the carrier properties or from the SIM language
6268 // preferences (EF-PL and EF-LI)...
6269 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006271 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6272 if (localeFromDefaultSim != null) {
6273 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6274 if (DBG) log("Using locale from subId: " + subId + " locale: "
6275 + localeFromDefaultSim);
6276 return localeFromDefaultSim.toLanguageTag();
6277 } else {
6278 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006279 }
6280 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 // The SIM language preferences only store a language (e.g. fr = French), not an
6283 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6284 // the SIM and carrier preferences does not include a country we add the country
6285 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006286 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006288 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 return mccLocale.toLanguageTag();
6290 }
6291
6292 if (DBG) log("No locale found - returning null");
6293 return null;
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006297 }
6298
6299 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006300 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6301 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006302 }
6303
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 /**
6305 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6306 */
6307 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006308 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6309 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006310 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006311
Chenjie Yu1ba97252018-01-11 18:16:20 -08006312 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006313 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006314
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006315 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006316 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6317 * representing the state of the modem.
6318 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006319 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6320 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006321 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006322 */
6323 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006324 public void requestModemActivityInfo(ResultReceiver result) {
6325 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006326 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
6330 ModemActivityInfo ret = null;
6331 synchronized (mLastModemActivityInfo) {
6332 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6333 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006334 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006335 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006337 int[] txTimeMs = info.getTransmitTimeMillis();
6338 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006340 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006341 }
6342 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006343 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6344 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 mLastModemActivityInfo.setIdleTimeMillis(
6346 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006347 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6348 mLastModemActivityInfo.setReceiveTimeMillis(
6349 info.getReceiveTimeMillis() + mLastModemActivityInfo
6350 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006351 }
Chen Xud78231e2019-09-10 18:49:52 -07006352
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6354 mLastModemActivityInfo.getSleepTimeMillis(),
6355 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006356 mLastModemActivityInfo.getTransmitTimeMillis(),
6357 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 Bundle bundle = new Bundle();
6360 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6361 result.send(0, bundle);
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006364 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006365 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006366
Siddharth Rayb8114062018-06-17 15:02:38 -07006367 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6368 // less than total activity duration.
6369 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6370 if (info == null) {
6371 return false;
6372 }
6373 int activityDurationMs =
6374 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6375 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006376 int[] txTimeMs = info.getTransmitTimeMillis();
6377 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6378 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006379 }
6380 return (info.isValid()
6381 && (info.getSleepTimeMillis() <= activityDurationMs)
6382 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006383 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006384 && (totalTxTimeMs <= activityDurationMs));
6385 }
6386
Jack Yu85bd38a2015-11-09 11:34:32 -08006387 /**
6388 * {@hide}
6389 * Returns the service state information on specified subscription.
6390 */
6391 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006392 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6393 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006395 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006396 return null;
6397 }
6398
Hall Liuf19c44f2018-11-27 14:38:17 -08006399 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6400 LocationAccessPolicy.checkLocationPermission(mApp,
6401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6402 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006404 .setCallingPid(Binder.getCallingPid())
6405 .setCallingUid(Binder.getCallingUid())
6406 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006407 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6409 .build());
6410
6411 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6412 LocationAccessPolicy.checkLocationPermission(mApp,
6413 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6414 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006415 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006416 .setCallingPid(Binder.getCallingPid())
6417 .setCallingUid(Binder.getCallingUid())
6418 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006419 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006420 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6421 .build());
6422 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6423 boolean hasFinePermission =
6424 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6425 boolean hasCoarsePermission =
6426 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 final long identity = Binder.clearCallingIdentity();
6429 try {
6430 final Phone phone = getPhone(subId);
6431 if (phone == null) {
6432 return null;
6433 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006434
Hall Liuf19c44f2018-11-27 14:38:17 -08006435 ServiceState ss = phone.getServiceState();
6436
6437 // Scrub out the location info in ServiceState depending on what level of access
6438 // the caller has.
6439 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006440 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6441 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 } finally {
6443 Binder.restoreCallingIdentity(identity);
6444 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006445 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006446
6447 /**
6448 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6449 *
6450 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6451 * voicemail ringtone.
6452 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6453 * PhoneAccount.
6454 */
6455 @Override
6456 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 final long identity = Binder.clearCallingIdentity();
6458 try {
6459 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6460 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006461 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006462 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
6467 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006468 }
6469
6470 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006471 * Sets the per-account voicemail ringtone.
6472 *
6473 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6474 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6475 *
6476 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6477 * voicemail ringtone.
6478 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6479 * PhoneAccount.
6480 */
6481 @Override
6482 public void setVoicemailRingtoneUri(String callingPackage,
6483 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006484 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006486 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6487 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6490 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006491 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6496 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006497 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006498 }
6499 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006502 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006503 }
6504
6505 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006506 * Returns whether vibration is set for voicemail notification in Phone settings.
6507 *
6508 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6509 * voicemail vibration setting.
6510 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6511 */
6512 @Override
6513 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6517 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006518 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006525 }
6526
Youhan Wange64578a2016-05-02 15:32:42 -07006527 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006528 * Sets the per-account voicemail vibration.
6529 *
6530 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6531 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6532 *
6533 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6534 * voicemail vibration setting.
6535 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6536 * specific PhoneAccount.
6537 */
6538 @Override
6539 public void setVoicemailVibrationEnabled(String callingPackage,
6540 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006541 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006543 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6544 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6546 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6547 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006548 }
6549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6553 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006554 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 }
6556 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6557 } finally {
6558 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006559 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006560 }
6561
6562 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006563 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6564 *
6565 * @throws SecurityException if the caller does not have the required permission
6566 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006567 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006568 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006569 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006570 }
6571
6572 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006573 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6574 * permission.
6575 *
6576 * @throws SecurityException if the caller does not have the required permission
6577 */
6578 private void enforceSendSmsPermission() {
6579 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6580 }
6581
6582 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006583 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006584 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006585 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006586 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006587 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006591 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 if (componentName == null) {
6593 throw new SecurityException(
6594 "Caller not current active visual voicemail package[null]");
6595 }
6596 String vvmPackage = componentName.getPackageName();
6597 if (!callingPackage.equals(vvmPackage)) {
6598 throw new SecurityException("Caller not current active visual voicemail package["
6599 + vvmPackage + "]");
6600 }
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006603 }
6604 }
6605
6606 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006607 * Return the application ID for the app type.
6608 *
6609 * @param subId the subscription ID that this request applies to.
6610 * @param appType the uicc app type.
6611 * @return Application ID for specificied app type, or null if no uicc.
6612 */
6613 @Override
6614 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006615 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006616 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617
6618 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006619 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006620 if (phone == null) {
6621 return null;
6622 }
6623 String aid = null;
6624 try {
6625 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6626 .getApplicationByType(appType).getAid();
6627 } catch (Exception e) {
6628 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6629 }
6630 return aid;
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006633 }
Youhan Wange64578a2016-05-02 15:32:42 -07006634 }
6635
Youhan Wang4001d252016-05-11 10:29:41 -07006636 /**
6637 * Return the Electronic Serial Number.
6638 *
6639 * @param subId the subscription ID that this request applies to.
6640 * @return ESN or null if error.
6641 */
6642 @Override
6643 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006644 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006645 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646
6647 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006648 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 if (phone == null) {
6650 return null;
6651 }
6652 String esn = null;
6653 try {
6654 esn = phone.getEsn();
6655 } catch (Exception e) {
6656 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6657 }
6658 return esn;
6659 } finally {
6660 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006661 }
Youhan Wang4001d252016-05-11 10:29:41 -07006662 }
6663
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006664 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006665 * Return the Preferred Roaming List Version.
6666 *
6667 * @param subId the subscription ID that this request applies to.
6668 * @return PRLVersion or null if error.
6669 */
6670 @Override
6671 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006672 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006673 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674
6675 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006676 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 if (phone == null) {
6678 return null;
6679 }
6680 String cdmaPrlVersion = null;
6681 try {
6682 cdmaPrlVersion = phone.getCdmaPrlVersion();
6683 } catch (Exception e) {
6684 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6685 }
6686 return cdmaPrlVersion;
6687 } finally {
6688 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006689 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006690 }
6691
6692 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006693 * Get snapshot of Telephony histograms
6694 * @return List of Telephony histograms
6695 * @hide
6696 */
6697 @Override
6698 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6700 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701
6702 final long identity = Binder.clearCallingIdentity();
6703 try {
6704 return RIL.getTelephonyRILTimingHistograms();
6705 } finally {
6706 Binder.restoreCallingIdentity(identity);
6707 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006708 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006709
6710 /**
6711 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006712 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6713 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006714 * Require system privileges. In the future we may add this to carrier APIs.
6715 *
Michele Berionne482f8202018-11-27 18:57:59 -08006716 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006717 */
6718 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006719 @TelephonyManager.SetCarrierRestrictionResult
6720 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006721 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006722 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006723
Michele Berionne482f8202018-11-27 18:57:59 -08006724 if (carrierRestrictionRules == null) {
6725 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006726 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 final long identity = Binder.clearCallingIdentity();
6729 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006730 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006731 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006732 } finally {
6733 Binder.restoreCallingIdentity(identity);
6734 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006735 }
6736
6737 /**
6738 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006739 * Get the allowed carrier list and the excluded carrier list, including the priority between
6740 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006741 * Require system privileges. In the future we may add this to carrier APIs.
6742 *
Michele Berionne482f8202018-11-27 18:57:59 -08006743 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006744 */
6745 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006746 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006747 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006748 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006749
6750 final long identity = Binder.clearCallingIdentity();
6751 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006752 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6753 if (response instanceof CarrierRestrictionRules) {
6754 return (CarrierRestrictionRules) response;
6755 }
6756 // Response is an Exception of some kind,
6757 // which is signalled to the user as a NULL retval
6758 return null;
6759 } catch (Exception e) {
6760 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6761 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 } finally {
6763 Binder.restoreCallingIdentity(identity);
6764 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006765 }
6766
fionaxu59545b42016-05-25 15:53:37 -07006767 /**
6768 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6769 * @param subId the subscription ID that this action applies to.
6770 * @param enabled control enable or disable metered apns.
6771 * {@hide}
6772 */
6773 @Override
6774 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6775 enforceModifyPermission();
6776 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006777
6778 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006779 if (phone == null) {
6780 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6781 return;
6782 }
6783 try {
6784 phone.carrierActionSetMeteredApnsEnabled(enabled);
6785 } catch (Exception e) {
6786 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 } finally {
6788 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006789 }
6790 }
6791
6792 /**
6793 * Action set from carrier signalling broadcast receivers to enable/disable radio
6794 * @param subId the subscription ID that this action applies to.
6795 * @param enabled control enable or disable radio.
6796 * {@hide}
6797 */
6798 @Override
6799 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6800 enforceModifyPermission();
6801 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802
6803 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006804 if (phone == null) {
6805 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6806 return;
6807 }
6808 try {
6809 phone.carrierActionSetRadioEnabled(enabled);
6810 } catch (Exception e) {
6811 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006812 } finally {
6813 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006814 }
6815 }
6816
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006817 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006818 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6819 * network status based on which carrier apps could apply actions accordingly,
6820 * enable/disable default url handler for example.
6821 *
6822 * @param subId the subscription ID that this action applies to.
6823 * @param report control start/stop reporting the default network status.
6824 * {@hide}
6825 */
6826 @Override
6827 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6828 enforceModifyPermission();
6829 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006830
6831 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006832 if (phone == null) {
6833 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6834 return;
6835 }
6836 try {
6837 phone.carrierActionReportDefaultNetworkStatus(report);
6838 } catch (Exception e) {
6839 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006840 } finally {
6841 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006842 }
6843 }
6844
6845 /**
fionaxud9622282017-07-17 17:51:30 -07006846 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6847 * @param subId the subscription ID that this action applies to.
6848 * {@hide}
6849 */
6850 @Override
6851 public void carrierActionResetAll(int subId) {
6852 enforceModifyPermission();
6853 final Phone phone = getPhone(subId);
6854 if (phone == null) {
6855 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6856 return;
6857 }
6858 try {
6859 phone.carrierActionResetAll();
6860 } catch (Exception e) {
6861 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6862 }
6863 }
6864
6865 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006866 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6867 * bug report is being generated.
6868 */
6869 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006870 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006871 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6872 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006873 writer.println("Permission Denial: can't dump Phone from pid="
6874 + Binder.getCallingPid()
6875 + ", uid=" + Binder.getCallingUid()
6876 + "without permission "
6877 + android.Manifest.permission.DUMP);
6878 return;
6879 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006880 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006881 }
Jack Yueb89b242016-06-22 13:27:47 -07006882
Brad Ebingerdac2f002018-04-03 15:17:52 -07006883 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006884 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6885 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6886 @NonNull String[] args) {
6887 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6888 this, in.getFileDescriptor(), out.getFileDescriptor(),
6889 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006890 }
6891
Jack Yueb89b242016-06-22 13:27:47 -07006892 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006893 * Get aggregated video call data usage since boot.
6894 *
6895 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6896 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006897 * {@hide}
6898 */
6899 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006900 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006901 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6902 null);
6903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 // NetworkStatsService keeps tracking the active network interface and identity. It
6907 // records the delta with the corresponding network identity.
6908 // We just return the total video call data usage snapshot since boot.
6909 Phone phone = getPhone(subId);
6910 if (phone != null) {
6911 return phone.getVtDataUsage(perUidStats);
6912 }
6913 return null;
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006916 }
Jack Yueb89b242016-06-22 13:27:47 -07006917 }
Jack Yu75ab2952016-07-08 14:29:33 -07006918
6919 /**
6920 * Policy control of data connection. Usually used when data limit is passed.
6921 * @param enabled True if enabling the data, otherwise disabling.
6922 * @param subId Subscription index
6923 * {@hide}
6924 */
6925 @Override
6926 public void setPolicyDataEnabled(boolean enabled, int subId) {
6927 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 Phone phone = getPhone(subId);
6932 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006933 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 }
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006937 }
6938 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006939
6940 /**
6941 * Get Client request stats
6942 * @return List of Client Request Stats
6943 * @hide
6944 */
6945 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006946 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6947 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006948 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006949 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006950 return null;
6951 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006952 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 final long identity = Binder.clearCallingIdentity();
6955 try {
6956 if (phone != null) {
6957 return phone.getClientRequestStats();
6958 }
6959
6960 return null;
6961 } finally {
6962 Binder.restoreCallingIdentity(identity);
6963 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006964 }
6965
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006966 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006967 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006968 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006969 }
Jack Yueb4124c2017-02-16 15:32:43 -08006970
6971 /**
Grace Chen70990072017-03-24 17:21:30 -07006972 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006973 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006974 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006975 * @param state State of SIM (power down, power up, pass through)
6976 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6978 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006979 *
6980 **/
6981 @Override
Grace Chen70990072017-03-24 17:21:30 -07006982 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006983 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006984 Phone phone = PhoneFactory.getPhone(slotIndex);
6985
vagdeviaf9a5b92018-08-15 16:01:53 -07006986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6987
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006991 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 }
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006995 }
6996 }
Shuo Qiandd210312017-04-12 22:11:33 +00006997
Tyler Gunn65d45c22017-06-05 11:22:26 -07006998 private boolean isUssdApiAllowed(int subId) {
6999 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007000 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007001 if (configManager == null) {
7002 return false;
7003 }
7004 PersistableBundle pb = configManager.getConfigForSubId(subId);
7005 if (pb == null) {
7006 return false;
7007 }
7008 return pb.getBoolean(
7009 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7010 }
7011
Shuo Qiandd210312017-04-12 22:11:33 +00007012 /**
7013 * Check if phone is in emergency callback mode
7014 * @return true if phone is in emergency callback mode
7015 * @param subId sub id
7016 */
goneil9c5f4872017-12-05 14:07:56 -08007017 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007018 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007019 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007020 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021
7022 final long identity = Binder.clearCallingIdentity();
7023 try {
7024 if (phone != null) {
7025 return phone.isInEcm();
7026 } else {
7027 return false;
7028 }
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007031 }
7032 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007033
7034 /**
7035 * Get the current signal strength information for the given subscription.
7036 * Because this information is not updated when the device is in a low power state
7037 * it should not be relied-upon to be current.
7038 * @param subId Subscription index
7039 * @return the most recent cached signal strength info from the modem
7040 */
7041 @Override
7042 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007043 final long identity = Binder.clearCallingIdentity();
7044 try {
7045 Phone p = getPhone(subId);
7046 if (p == null) {
7047 return null;
7048 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 return p.getSignalStrength();
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007054 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007055
Pengquan Meng77b7f132018-08-22 14:49:57 -07007056 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007057 * Get the current modem radio state for the given slot.
7058 * @param slotIndex slot index.
7059 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007060 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007061 * @return the current radio power state from the modem
7062 */
7063 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007064 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007065 Phone phone = PhoneFactory.getPhone(slotIndex);
7066 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007067 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7068 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007069 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7070 }
7071
7072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 return phone.getRadioPowerState();
7075 } finally {
7076 Binder.restoreCallingIdentity(identity);
7077 }
7078 }
7079 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7080 }
7081
7082 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007083 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7084 *
7085 * <p>Requires one of the following permissions:
7086 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7087 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7088 * privileges.
7089 *
7090 * @param subId subscription id
7091 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7092 * {@code false}.
7093 */
7094 @Override
7095 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007096 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7097 null /* message */);
7098
Pengquan Menga1bb6272018-09-06 09:59:22 -07007099 boolean isEnabled = false;
7100 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007101 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007102 Phone phone = getPhone(subId);
7103 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007104 } catch (Exception e) {
7105 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7106 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007107 } finally {
7108 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007109 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007110 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007111 }
7112
7113
7114 /**
7115 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7116 *
7117 * <p> Requires permission:
7118 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7119 * privileges.
7120 *
7121 * @param subId subscription id
7122 * @param isEnabled {@code true} means enable, {@code false} means disable.
7123 */
7124 @Override
7125 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7127 mApp, subId, "setDataRoamingEnabled");
7128
Pengquan Menga1bb6272018-09-06 09:59:22 -07007129 final long identity = Binder.clearCallingIdentity();
7130 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007131 Phone phone = getPhone(subId);
7132 if (phone != null) {
7133 phone.setDataRoamingEnabled(isEnabled);
7134 }
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007137 }
7138 }
7139
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007140 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007141 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007142 TelephonyPermissions
7143 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007144 mApp, subId, "isManualNetworkSelectionAllowed");
7145
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007146 boolean isAllowed = true;
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007149 Phone phone = getPhone(subId);
7150 if (phone != null) {
7151 isAllowed = phone.isCspPlmnEnabled();
7152 }
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
7156 return isAllowed;
7157 }
7158
7159 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007160 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007161 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007162 try {
7163 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007164 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007165 } catch (SecurityException e) {
7166 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7167 // has carrier privileges on an active UICC
7168 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7169 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007170 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007171 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007172 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007176 UiccController uiccController = UiccController.getInstance();
7177 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007178 if (hasReadPermission) {
7179 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007180 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007181
7182 // Remove private info if the caller doesn't have access
7183 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7184 for (UiccCardInfo cardInfo : cardInfos) {
7185 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7186 // is available
7187 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7188 if (card == null || card.getUiccProfile() == null) {
7189 // assume no access if the card or profile is unavailable
7190 filteredInfos.add(cardInfo.getUnprivileged());
7191 continue;
7192 }
7193 UiccProfile profile = card.getUiccProfile();
7194 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7195 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7196 filteredInfos.add(cardInfo);
7197 } else {
7198 filteredInfos.add(cardInfo.getUnprivileged());
7199 }
7200 }
7201 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
7204 }
7205 }
7206
7207 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007208 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007209 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 final long identity = Binder.clearCallingIdentity();
7212 try {
7213 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7214 if (slots == null) {
7215 Rlog.i(LOG_TAG, "slots is null.");
7216 return null;
7217 }
7218
7219 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7220 for (int i = 0; i < slots.length; i++) {
7221 UiccSlot slot = slots[i];
7222 if (slot == null) {
7223 continue;
7224 }
7225
Jordan Liu7be7e652019-05-06 18:55:02 +00007226 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007227 UiccCard card = slot.getUiccCard();
7228 if (card != null) {
7229 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007230 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007231 cardId = slot.getEid();
7232 if (TextUtils.isEmpty(cardId)) {
7233 cardId = slot.getIccId();
7234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235 }
7236
Jordan Liu857451f2019-05-09 16:35:35 -07007237 if (cardId != null) {
7238 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7239 // if cardId is an EID, it's all digits so this is fine
7240 cardId = IccUtils.stripTrailingFs(cardId);
7241 }
7242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007243 int cardState = 0;
7244 switch (slot.getCardState()) {
7245 case CARDSTATE_ABSENT:
7246 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7247 break;
7248 case CARDSTATE_PRESENT:
7249 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7250 break;
7251 case CARDSTATE_ERROR:
7252 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7253 break;
7254 case CARDSTATE_RESTRICTED:
7255 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7256 break;
7257 default:
7258 break;
7259
7260 }
7261
7262 infos[i] = new UiccSlotInfo(
7263 slot.isActive(),
7264 slot.isEuicc(),
7265 cardId,
7266 cardState,
7267 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007268 slot.isExtendedApduSupported(),
7269 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 }
7271 return infos;
7272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007274 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007275 }
7276
7277 @Override
7278 public boolean switchSlots(int[] physicalSlots) {
7279 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007287 }
Jack Yu4c988042018-02-27 15:30:01 -08007288
7289 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007290 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 return UiccController.getInstance().getCardIdForDefaultEuicc();
7294 } finally {
7295 Binder.restoreCallingIdentity(identity);
7296 }
7297 }
7298
7299 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007300 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7301 enforceModifyPermission();
7302 final Phone phone = getPhone(subId);
7303 if (phone == null) {
7304 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7305 return;
7306 }
7307
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 phone.setRadioIndicationUpdateMode(filters, mode);
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
Jack Yu4c988042018-02-27 15:30:01 -08007314 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007315
7316 /**
goneil47ffb6e2018-04-06 15:40:58 -07007317 * A test API to reload the UICC profile.
7318 *
7319 * <p>Requires that the calling app has permission
7320 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7321 * @hide
7322 */
7323 @Override
7324 public void refreshUiccProfile(int subId) {
7325 enforceModifyPermission();
7326
7327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 Phone phone = getPhone(subId);
7330 if (phone == null) {
7331 return;
7332 }
7333 UiccCard uiccCard = phone.getUiccCard();
7334 if (uiccCard == null) {
7335 return;
7336 }
7337 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7338 if (uiccProfile == null) {
7339 return;
7340 }
7341 uiccProfile.refresh();
7342 } finally {
7343 Binder.restoreCallingIdentity(identity);
7344 }
7345 }
7346
7347 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007348 * Returns false if the mobile data is disabled by default, otherwise return true.
7349 */
7350 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007351 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007352 }
7353
7354 /**
7355 * Returns true if the data roaming is enabled by default, i.e the system property
7356 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7357 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7358 */
7359 private boolean getDefaultDataRoamingEnabled(int subId) {
7360 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007361 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007362 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007363 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7364 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7365 return isDataRoamingEnabled;
7366 }
7367
7368 /**
7369 * Returns the default network type for the given {@code subId}, if the default network type is
7370 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7371 */
7372 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007373 List<Integer> list = TelephonyProperties.default_network();
7374 int phoneId = mSubscriptionController.getPhoneId(subId);
7375 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7376 return list.get(phoneId);
7377 }
7378 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007379 }
fionaxua13278b2018-03-21 00:08:13 -07007380
7381 @Override
7382 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007383 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 final Phone phone = getPhone(subId);
7389 if (phone == null) {
7390 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7391 return;
7392 }
chen xueaba88a2019-03-15 13:15:10 -07007393 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7394 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007395 } finally {
7396 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007397 }
fionaxua13278b2018-03-21 00:08:13 -07007398 }
7399
7400 @Override
7401 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007402 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007403
7404 final long identity = Binder.clearCallingIdentity();
7405 try {
7406 final Phone phone = getPhone(subId);
7407 if (phone == null) {
7408 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7409 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7410 }
7411 return phone.getCarrierIdListVersion();
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007414 }
fionaxua13278b2018-03-21 00:08:13 -07007415 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007416
7417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007418 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7419 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007421 mApp, subId, callingPackage, callingFeatureId,
7422 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007423 return -1;
7424 }
7425
7426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
7432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007433
7434 @Override
7435 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007436 TelephonyPermissions
7437 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007438 mApp, subId, "getCdmaRoamingMode");
7439
7440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7443 } finally {
7444 Binder.restoreCallingIdentity(identity);
7445 }
7446 }
7447
7448 @Override
7449 public boolean setCdmaRoamingMode(int subId, int mode) {
7450 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7451 mApp, subId, "setCdmaRoamingMode");
7452
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7456 } finally {
7457 Binder.restoreCallingIdentity(identity);
7458 }
7459 }
7460
7461 @Override
7462 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7463 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7464 mApp, subId, "setCdmaSubscriptionMode");
7465
7466 final long identity = Binder.clearCallingIdentity();
7467 try {
7468 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
7472 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007473
sqianc5eccab2018-10-19 18:46:41 -07007474 @Override
sqian8c685422019-02-22 15:55:18 -08007475 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007476 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007477 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007478 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7479 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007480 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7481 }
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
sqian854d44b2018-12-12 16:48:18 -08007484 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7485 for (Phone phone: PhoneFactory.getPhones()) {
7486 if (phone.getEmergencyNumberTracker() != null
7487 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7488 emergencyNumberListInternal.put(
7489 phone.getSubId(),
7490 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7491 }
sqian11b7a0e2018-12-05 18:48:28 -08007492 }
sqian854d44b2018-12-12 16:48:18 -08007493 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007494 } finally {
7495 Binder.restoreCallingIdentity(identity);
7496 }
sqianc5eccab2018-10-19 18:46:41 -07007497 }
7498
7499 @Override
sqian8c685422019-02-22 15:55:18 -08007500 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007501 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007502 if (!exactMatch) {
7503 TelephonyPermissions
7504 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007505 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007506 }
7507 final long identity = Binder.clearCallingIdentity();
7508 try {
sqian854d44b2018-12-12 16:48:18 -08007509 for (Phone phone: PhoneFactory.getPhones()) {
7510 if (phone.getEmergencyNumberTracker() != null
7511 && phone.getEmergencyNumberTracker() != null) {
7512 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7513 number, exactMatch)) {
7514 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007515 }
7516 }
sqian11b7a0e2018-12-05 18:48:28 -08007517 }
7518 return false;
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
7522 }
7523
sqianf4ca7ed2019-01-15 18:32:07 -08007524 /**
7525 * Update emergency number list for test mode.
7526 */
7527 @Override
7528 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7529 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7530 "updateEmergencyNumberListTestMode");
7531
7532 final long identity = Binder.clearCallingIdentity();
7533 try {
7534 for (Phone phone: PhoneFactory.getPhones()) {
7535 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7536 if (tracker != null) {
7537 tracker.executeEmergencyNumberTestModeCommand(action, num);
7538 }
7539 }
7540 } finally {
7541 Binder.restoreCallingIdentity(identity);
7542 }
7543 }
7544
7545 /**
7546 * Get the full emergency number list for test mode.
7547 */
7548 @Override
7549 public List<String> getEmergencyNumberListTestMode() {
7550 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7551 "getEmergencyNumberListTestMode");
7552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Set<String> emergencyNumbers = new HashSet<>();
7556 for (Phone phone: PhoneFactory.getPhones()) {
7557 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7558 if (tracker != null) {
7559 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7560 emergencyNumbers.add(num.getNumber());
7561 }
7562 }
7563 }
7564 return new ArrayList<>(emergencyNumbers);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
7567 }
7568 }
7569
chen xud6b45bd2018-10-30 22:27:10 -07007570 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007571 public int getEmergencyNumberDbVersion(int subId) {
7572 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7573
7574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 final Phone phone = getPhone(subId);
7577 if (phone == null) {
7578 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7579 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7580 }
7581 return phone.getEmergencyNumberDbVersion();
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
7585 }
7586
7587 @Override
7588 public void notifyOtaEmergencyNumberDbInstalled() {
7589 enforceModifyPermission();
7590
7591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 for (Phone phone: PhoneFactory.getPhones()) {
7594 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7595 if (tracker != null) {
7596 tracker.updateOtaEmergencyNumberDatabase();
7597 }
7598 }
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
7602 }
7603
7604 @Override
7605 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7606 enforceActiveEmergencySessionPermission();
7607
7608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 for (Phone phone: PhoneFactory.getPhones()) {
7611 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7612 if (tracker != null) {
7613 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7614 }
7615 }
7616 } finally {
7617 Binder.restoreCallingIdentity(identity);
7618 }
7619 }
7620
7621 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007622 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7623 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7624 Phone phone = getPhone(subId);
7625 if (phone == null) {
7626 return null;
7627 }
7628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 UiccProfile profile = UiccController.getInstance()
7631 .getUiccProfileForPhone(phone.getPhoneId());
7632 if (profile != null) {
7633 return profile.getCertsFromCarrierPrivilegeAccessRules();
7634 }
7635 } finally {
7636 Binder.restoreCallingIdentity(identity);
7637 }
7638 return null;
7639 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007640
7641 /**
7642 * Enable or disable a modem stack.
7643 */
7644 @Override
7645 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7646 enforceModifyPermission();
7647
7648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 Phone phone = PhoneFactory.getPhone(slotIndex);
7651 if (phone == null) {
7652 return false;
7653 } else {
7654 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7655 }
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
7658 }
7659 }
Michelecea4cf22018-12-21 15:00:11 -08007660
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007661 /**
7662 * Whether a modem stack is enabled or not.
7663 */
7664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7666 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007667 Phone phone = PhoneFactory.getPhone(slotIndex);
7668 if (phone == null) return false;
7669
7670 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007671 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7672 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007673 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7674 }
7675
7676 final long identity = Binder.clearCallingIdentity();
7677 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007678 try {
7679 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7680 } catch (NoSuchElementException ex) {
7681 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7682 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
Michelecea4cf22018-12-21 15:00:11 -08007688 @Override
Michele0ea7d782019-03-19 14:58:42 -07007689 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007690 enforceModifyPermission();
7691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007695 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007696 .commit();
7697 } finally {
7698 Binder.restoreCallingIdentity(identity);
7699 }
7700 }
7701
7702 @Override
Michele0ea7d782019-03-19 14:58:42 -07007703 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007704 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007705 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007706 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7707 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007708 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007709 }
Michelecea4cf22018-12-21 15:00:11 -08007710
7711 final long identity = Binder.clearCallingIdentity();
7712 try {
Michele0ea7d782019-03-19 14:58:42 -07007713 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007718
Michele0ea7d782019-03-19 14:58:42 -07007719 @TelephonyManager.IsMultiSimSupportedResult
7720 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007721 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7722 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7723 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007724 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7725 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007726 }
7727 // Check if the hardware supports multisim functionality. If usage of multisim is not
7728 // supported by the modem, indicate that it is restricted.
7729 PhoneCapability staticCapability =
7730 mPhoneConfigurationManager.getStaticPhoneCapability();
7731 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007732 loge("isMultiSimSupportedInternal: no static configuration available");
7733 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007734 }
7735 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007736 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7737 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007738 }
7739 // Check if support of multiple SIMs is restricted by carrier
7740 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007741 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007742 }
7743
Michele0ea7d782019-03-19 14:58:42 -07007744 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007745 }
7746
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007747 /**
7748 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007749 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7750 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7751 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007752 * @param numOfSims number of active sims we want to switch to
7753 */
7754 @Override
7755 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007756 if (numOfSims == 1) {
7757 enforceModifyPermission();
7758 } else {
7759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7760 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7761 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007762 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007763
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007764 try {
Michele30b57b22019-03-01 12:01:14 -08007765 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007766 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007767 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7768 return;
7769 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007770 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
7774 }
7775
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007776 @Override
7777 public boolean isApplicationOnUicc(int subId, int appType) {
7778 enforceReadPrivilegedPermission("isApplicationOnUicc");
7779 Phone phone = getPhone(subId);
7780 if (phone == null) {
7781 return false;
7782 }
7783 final long identity = Binder.clearCallingIdentity();
7784 try {
7785 UiccCard uiccCard = phone.getUiccCard();
7786 if (uiccCard == null) {
7787 return false;
7788 }
7789 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7790 if (uiccProfile == null) {
7791 return false;
7792 }
7793 if (TelephonyManager.APPTYPE_SIM <= appType
7794 && appType <= TelephonyManager.APPTYPE_ISIM) {
7795 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7796 }
7797 return false;
7798 } finally {
7799 Binder.restoreCallingIdentity(identity);
7800 }
7801 }
7802
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007803 /**
chen xub4baa772019-04-03 10:23:41 -07007804 * Get whether making changes to modem configurations will trigger reboot.
7805 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007806 */
7807 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007808 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7809 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007810 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007811 mApp, subId, callingPackage, callingFeatureId,
7812 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007813 return false;
7814 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7818 } finally {
7819 Binder.restoreCallingIdentity(identity);
7820 }
7821 }
7822
Nathan Harold29f5f052019-02-15 13:41:57 -08007823 private void updateModemStateMetrics() {
7824 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7825 // TODO: check the state for each modem if the api is ready.
7826 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7827 }
7828
Pengquan Meng3889a572019-01-23 11:16:29 -08007829 @Override
7830 public int[] getSlotsMapping() {
7831 enforceReadPrivilegedPermission("getSlotsMapping");
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7836 // All logical slots should have a mapping to a physical slot.
7837 int[] logicalSlotsMapping = new int[phoneCount];
7838 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7839 for (int i = 0; i < slotInfos.length; i++) {
7840 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7841 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7842 }
7843 }
7844 return logicalSlotsMapping;
7845 } finally {
7846 Binder.restoreCallingIdentity(identity);
7847 }
7848 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007849
7850 /**
7851 * Get the IRadio HAL Version
7852 */
7853 @Override
7854 public int getRadioHalVersion() {
7855 Phone phone = getDefaultPhone();
7856 if (phone == null) return -1;
7857 HalVersion hv = phone.getHalVersion();
7858 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7859 return hv.major * 100 + hv.minor;
7860 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007861
7862 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007863 * Get the current calling package name.
7864 * @return the current calling package name
7865 */
7866 @Override
7867 public String getCurrentPackageName() {
7868 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
7869 }
7870
7871 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007872 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7873 * corresponding network requests on a subId.
7874 *
7875 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007876 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007877 * 2) APN is un-metered for this subscription, or
7878 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007879 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007880 *
7881 * @return whether data is allowed for a apn type.
7882 *
7883 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007884 */
7885 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007886 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007887 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7888 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007889
7890 // Now that all security checks passes, perform the operation as ourselves.
7891 final long identity = Binder.clearCallingIdentity();
7892 try {
7893 Phone phone = getPhone(subId);
7894 if (phone == null) return false;
7895
Jack Yu41407ee2019-05-13 16:54:09 -07007896 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007897 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
7900 }
7901 }
7902
7903 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007904 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007905 enforceReadPrivilegedPermission("isApnMetered");
7906
7907 // Now that all security checks passes, perform the operation as ourselves.
7908 final long identity = Binder.clearCallingIdentity();
7909 try {
7910 Phone phone = getPhone(subId);
7911 if (phone == null) return true; // By default return true.
7912
Jack Yu41407ee2019-05-13 16:54:09 -07007913 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
7917 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007918
7919 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007920 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7921 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7922 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7923 if (iccRecords == null) {
7924 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7925 return false;
7926 }
7927 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7928 }
7929
7930 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007931 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08007932 if (callingPackage == null) {
7933 callingPackage = getCurrentPackageName();
7934 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007935 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7936 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7937 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7938 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7939 }
7940 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7941 Intent intent = new Intent();
7942 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7943 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7944 // Bring up choose default SMS subscription dialog right now
7945 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7946 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7947 mApp.startActivity(intent);
7948 }
chen xud5ca2d52019-05-28 15:20:57 -07007949
7950 @Override
7951 public String getMmsUAProfUrl(int subId) {
7952 //TODO investigate if this API should require proper permission check in R b/133791609
7953 final long identity = Binder.clearCallingIdentity();
7954 try {
7955 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7956 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7957 } finally {
7958 Binder.restoreCallingIdentity(identity);
7959 }
7960 }
7961
7962 @Override
7963 public String getMmsUserAgent(int subId) {
7964 //TODO investigate if this API should require proper permission check in R b/133791609
7965 final long identity = Binder.clearCallingIdentity();
7966 try {
7967 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7968 .getString(com.android.internal.R.string.config_mms_user_agent);
7969 } finally {
7970 Binder.restoreCallingIdentity(identity);
7971 }
7972 }
Jack Yub07d4972019-05-28 16:12:25 -07007973
7974 @Override
7975 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7976 enforceModifyPermission();
7977
7978 // Now that all security checks passes, perform the operation as ourselves.
7979 final long identity = Binder.clearCallingIdentity();
7980 try {
7981 Phone phone = getPhone(subId);
7982 if (phone == null) return false;
7983
7984 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
7987 }
7988 }
7989
7990 @Override
7991 public boolean isDataAllowedInVoiceCall(int subId) {
7992 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7993
7994 // Now that all security checks passes, perform the operation as ourselves.
7995 final long identity = Binder.clearCallingIdentity();
7996 try {
7997 Phone phone = getPhone(subId);
7998 if (phone == null) return false;
7999
8000 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
8003 }
8004 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008005
changbettyd5c246e2019-12-24 15:40:37 +08008006 @Override
8007 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8008 enforceModifyPermission();
8009
8010 // Now that all security checks passes, perform the operation as ourselves.
8011 final long identity = Binder.clearCallingIdentity();
8012 try {
8013 Phone phone = getPhone(subId);
8014 if (phone == null) return false;
8015
8016 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 }
8021
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008022 /**
8023 * Updates whether conference event pacakge handling is enabled.
8024 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8025 * otherwise.
8026 */
8027 @Override
8028 public void setCepEnabled(boolean isCepEnabled) {
8029 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8030
8031 final long identity = Binder.clearCallingIdentity();
8032 try {
8033 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8034 for (Phone phone : PhoneFactory.getPhones()) {
8035 Phone defaultPhone = phone.getImsPhone();
8036 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8037 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8038 ImsPhoneCallTracker imsPhoneCallTracker =
8039 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8040 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8041 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8042 + imsPhone.getMsisdn());
8043 }
8044 }
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
allenwtsu46dcc572020-01-08 18:24:03 +08008049
8050 /**
8051 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8052 *
8053 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8054 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8055 * before being read.
8056 */
8057 @Override
8058 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8059 isCompressed) {
8060 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8061 mApp, subId, "notifyRcsAutoConfigurationReceived");
8062 try {
8063 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8064 if (configBinder == null) {
8065 Rlog.e(LOG_TAG, "null result for getImsConfig");
8066 } else {
8067 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8068 }
8069 } catch (RemoteException e) {
8070 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8071 }
8072 }
zoey chene02881a2019-12-30 16:11:23 +08008073
8074 @Override
8075 public boolean isIccLockEnabled(int subId) {
8076 enforceReadPrivilegedPermission("isIccLockEnabled");
8077
8078 // Now that all security checks passes, perform the operation as ourselves.
8079 final long identity = Binder.clearCallingIdentity();
8080 try {
8081 Phone phone = getPhone(subId);
8082 if (phone != null && phone.getIccCard() != null) {
8083 return phone.getIccCard().getIccLockEnabled();
8084 } else {
8085 return false;
8086 }
8087 } finally {
8088 Binder.restoreCallingIdentity(identity);
8089 }
8090 }
8091
8092 /**
8093 * Set the ICC pin lock enabled or disabled.
8094 *
8095 * @return an integer representing the status of IccLock enabled or disabled in the following
8096 * three cases:
8097 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8098 * successfully.
8099 * - Positive number and zero for remaining password attempts.
8100 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8101 *
8102 */
8103 @Override
8104 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8105 enforceModifyPermission();
8106
8107 Phone phone = getPhone(subId);
8108 if (phone == null) {
8109 return 0;
8110 }
8111 // Now that all security checks passes, perform the operation as ourselves.
8112 final long identity = Binder.clearCallingIdentity();
8113 try {
8114 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8115 new Pair<Boolean, String>(enabled, password), phone, null);
8116 return attemptsRemaining;
8117
8118 } catch (Exception e) {
8119 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8120 } finally {
8121 Binder.restoreCallingIdentity(identity);
8122 }
8123 return 0;
8124 }
8125
8126 /**
8127 * Change the ICC password used in ICC pin lock.
8128 *
8129 * @return an integer representing the status of IccLock changed in the following three cases:
8130 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8131 * - Positive number and zero for remaining password attempts.
8132 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8133 *
8134 */
8135 @Override
8136 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8137 enforceModifyPermission();
8138
8139 Phone phone = getPhone(subId);
8140 if (phone == null) {
8141 return 0;
8142 }
8143 // Now that all security checks passes, perform the operation as ourselves.
8144 final long identity = Binder.clearCallingIdentity();
8145 try {
8146 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8147 new Pair<String, String>(oldPassword, newPassword), phone, null);
8148 return attemptsRemaining;
8149
8150 } catch (Exception e) {
8151 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 return 0;
8156 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008157}