blob: d1d091a3b5c72f004d4626a5e9ee1b5a0b6f52d0 [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
3023 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003024 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3025 throws RemoteException {
3026 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3029 "IMS not available on device.");
3030 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 final long token = Binder.clearCallingIdentity();
3032 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003033 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003036 } catch (ImsException e) {
3037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 } finally {
3039 Binder.restoreCallingIdentity(token);
3040 }
3041 }
3042
3043 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003044 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3045 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003046 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3047 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3048 }
Meng Wangafbc5852019-09-19 17:37:13 -07003049 final long token = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3053 .removeRegistrationCallbackForSubscription(c, subId);
3054 } catch (ImsException e) {
3055 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3056 + "is inactive, ignoring unregister.");
3057 // If the subscription is no longer active, just return, since the callback
3058 // will already have been removed internally.
3059 } finally {
3060 Binder.restoreCallingIdentity(token);
3061 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 }
3063
Brad Ebingera34a6c22019-10-22 17:36:18 -07003064 /**
3065 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3066 */
3067 @Override
3068 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3069 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3070 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3071 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3072 "IMS not available on device.");
3073 }
3074 final long token = Binder.clearCallingIdentity();
3075 try {
3076 Phone phone = getPhone(subId);
3077 if (phone == null) {
3078 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3079 + subId + "'");
3080 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3081 }
3082 phone.getImsRegistrationState(regState -> {
3083 try {
3084 consumer.accept((regState == null)
3085 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3086 } catch (RemoteException e) {
3087 // Ignore if the remote process is no longer available to call back.
3088 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3089 }
3090 });
3091 } finally {
3092 Binder.restoreCallingIdentity(token);
3093 }
3094 }
3095
3096 /**
3097 * Get the transport type for the IMS service registration state.
3098 */
3099 @Override
3100 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3101 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3102 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3103 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3104 "IMS not available on device.");
3105 }
3106 final long token = Binder.clearCallingIdentity();
3107 try {
3108 Phone phone = getPhone(subId);
3109 if (phone == null) {
3110 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3111 + subId + "'");
3112 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3113 }
3114 phone.getImsRegistrationTech(regTech -> {
3115 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3116 int regTechConverted = (regTech == null)
3117 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3118 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3119 regTechConverted);
3120 try {
3121 consumer.accept(regTechConverted);
3122 } catch (RemoteException e) {
3123 // Ignore if the remote process is no longer available to call back.
3124 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3125 }
3126 });
3127 } finally {
3128 Binder.restoreCallingIdentity(token);
3129 }
3130 }
3131
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003133 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3134 throws RemoteException {
3135 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003136 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3137 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3138 "IMS not available on device.");
3139 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3141 final long token = Binder.clearCallingIdentity();
3142 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003144 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003145 } catch (ImsException e) {
3146 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(token);
3149 }
3150 }
3151
3152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003153 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3154 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003155 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3156 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3157 }
Meng Wangafbc5852019-09-19 17:37:13 -07003158
3159 final long token = Binder.clearCallingIdentity();
3160 try {
3161 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3162 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003163 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003164 } catch (ImsException e) {
3165 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3166 + "is inactive, ignoring unregister.");
3167 // If the subscription is no longer active, just return, since the callback
3168 // will already have been removed internally.
3169 } finally {
3170 Binder.restoreCallingIdentity(token);
3171 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003172 }
3173
3174 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003175 public boolean isCapable(int subId, int capability, int regTech) {
3176 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3178 final long token = Binder.clearCallingIdentity();
3179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003182 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3184 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003185 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003186 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3187 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 } finally {
3189 Binder.restoreCallingIdentity(token);
3190 }
3191 }
3192
3193 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003194 public boolean isAvailable(int subId, int capability, int regTech) {
3195 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003196 final long token = Binder.clearCallingIdentity();
3197 try {
3198 Phone phone = getPhone(subId);
3199 if (phone == null) return false;
3200 return phone.isImsCapabilityAvailable(capability, regTech);
3201 } finally {
3202 Binder.restoreCallingIdentity(token);
3203 }
3204 }
3205
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003206 /**
3207 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3208 * subscription.
3209 * @param subId The subscription to use to check the configuration.
3210 * @param callback The callback that will be used to send the result.
3211 * @param capability The MmTelFeature capability that will be used to send the result.
3212 * @param transportType The transport type of the MmTelFeature capability.
3213 */
3214 @Override
3215 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3216 int transportType) {
3217 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3218 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3219 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3220 "IMS not available on device.");
3221 }
3222 final long token = Binder.clearCallingIdentity();
3223 try {
3224 int slotId = getSlotIndex(subId);
3225 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3226 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3227 + subId + "'");
3228 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3229 }
3230 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3231 transportType, aBoolean -> {
3232 try {
3233 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3234 } catch (RemoteException e) {
3235 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3236 + "running. Ignore");
3237 }
3238 });
3239 } finally {
3240 Binder.restoreCallingIdentity(token);
3241 }
3242 }
3243
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 @Override
3245 public boolean isAdvancedCallingSettingEnabled(int subId) {
3246 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3247 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3248 final long token = Binder.clearCallingIdentity();
3249 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003250 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003252 } catch (ImsException e) {
3253 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003254 } finally {
3255 Binder.restoreCallingIdentity(token);
3256 }
3257 }
3258
3259 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003260 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003262 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003263 final long identity = Binder.clearCallingIdentity();
3264 try {
3265 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003266 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (ImsException e) {
3269 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 } finally {
3271 Binder.restoreCallingIdentity(identity);
3272 }
3273 }
3274
3275 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003276 public boolean isVtSettingEnabled(int subId) {
3277 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003281 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3282 } catch (ImsException e) {
3283 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003284 } finally {
3285 Binder.restoreCallingIdentity(identity);
3286 }
3287 }
3288
3289 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003290 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003292 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 final long identity = Binder.clearCallingIdentity();
3294 try {
3295 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003296 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003297 } catch (ImsException e) {
3298 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 } finally {
3300 Binder.restoreCallingIdentity(identity);
3301 }
3302 }
3303
3304 @Override
3305 public boolean isVoWiFiSettingEnabled(int subId) {
3306 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3307 final long identity = Binder.clearCallingIdentity();
3308 try {
3309 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003310 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003312 } catch (ImsException e) {
3313 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003314 } finally {
3315 Binder.restoreCallingIdentity(identity);
3316 }
3317 }
3318
3319 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003320 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003321 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003322 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003323 final long identity = Binder.clearCallingIdentity();
3324 try {
3325 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003326 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003327 } catch (ImsException e) {
3328 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 } finally {
3330 Binder.restoreCallingIdentity(identity);
3331 }
3332 }
3333
3334 @Override
3335 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3336 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3337 final long identity = Binder.clearCallingIdentity();
3338 try {
3339 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003340 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003341 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003342 } catch (ImsException e) {
3343 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
3347 }
3348
3349 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003350 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003352 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003356 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003357 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003358 } catch (ImsException e) {
3359 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003360 } finally {
3361 Binder.restoreCallingIdentity(identity);
3362 }
3363 }
3364
3365 @Override
3366 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3367 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3368 "setVoWiFiNonPersistent");
3369 final long identity = Binder.clearCallingIdentity();
3370 try {
3371 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003373 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003374 } catch (ImsException e) {
3375 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
3379 }
3380
3381 @Override
3382 public int getVoWiFiModeSetting(int subId) {
3383 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
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)).getWfcMode(false /*isRoaming*/);
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
3397 public void setVoWiFiModeSetting(int subId, int mode) {
3398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3399 "setVoWiFiModeSetting");
3400 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)).setWfcMode(mode, false /*isRoaming*/);
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 int getVoWiFiRoamingModeSetting(int subId) {
3414 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3415 final long identity = Binder.clearCallingIdentity();
3416 try {
3417 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003418 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003419 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003420 } catch (ImsException e) {
3421 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
3427 @Override
3428 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3430 "setVoWiFiRoamingModeSetting");
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003434 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003435 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003436 } catch (ImsException e) {
3437 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
3440 }
3441 }
3442
3443 @Override
3444 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3446 "setRttCapabilityEnabled");
3447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003450 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3451 } catch (ImsException e) {
3452 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 } finally {
3454 Binder.restoreCallingIdentity(identity);
3455 }
3456 }
3457
3458 @Override
3459 public boolean isTtyOverVolteEnabled(int subId) {
3460 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003465 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003466 } catch (ImsException e) {
3467 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003473 @Override
3474 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3475 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3476 final long identity = Binder.clearCallingIdentity();
3477 try {
Peter Wang44b186e2020-01-13 23:33:09 -08003478 if (isImsAvailableOnDevice()) {
3479 throw new ImsException("IMS not available on device.",
3480 ImsException.CODE_ERROR_UNSUPPORTED_OPERATION);
3481 }
3482
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003483 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003484 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003485 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003486 } catch (ImsException e) {
3487 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003488 } finally {
3489 Binder.restoreCallingIdentity(identity);
3490 }
3491 }
3492
3493 @Override
3494 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3495 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3496 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3498 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3499 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003500 try {
3501 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003502 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003503 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003504 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003505 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3506 + "is inactive, ignoring unregister.");
3507 // If the subscription is no longer active, just return, since the callback will already
3508 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
3512 }
3513
allenwtsu99c623b2020-01-03 18:24:23 +08003514
3515 private void checkModifyPhoneStatePermission(int subId, String message) {
3516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3517 message);
3518 }
3519
3520 private boolean isImsProvisioningRequired(int subId, int capability,
3521 boolean isMmtelCapability) {
3522 Phone phone = getPhone(subId);
3523 if (phone == null) {
3524 loge("phone instance null for subid " + subId);
3525 return false;
3526 }
3527 if (isMmtelCapability) {
3528 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3529 return false;
3530 }
3531 } else {
3532 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3533 return false;
3534 }
3535 }
3536 return true;
3537 }
3538
3539 @Override
3540 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3541 boolean isProvisioned) {
3542 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3543
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 if (!isImsProvisioningRequired(subId, capability, false)) {
3548 return;
3549 }
3550
3551 // this capability requires provisioning, route to the correct API.
3552 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3553 switch (capability) {
3554 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3555 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3556 ims.setEabProvisioned(isProvisioned);
3557 break;
3558 default: {
3559 throw new IllegalArgumentException("Tried to set provisioning for "
3560 + "rcs capability '" + capability + "', which does not require "
3561 + "provisioning.");
3562 }
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567
3568 }
3569
3570
3571 @Override
3572 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3573 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3574 final long identity = Binder.clearCallingIdentity();
3575 try {
3576 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3577 if (!isImsProvisioningRequired(subId, capability, false)) {
3578 return true;
3579 }
3580
3581 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3582 switch (capability) {
3583 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3584 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3585 return ims.isEabProvisionedOnDevice();
3586
3587 default: {
3588 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3589 + "capability '" + capability + "', which does not require "
3590 + "provisioning.");
3591 }
3592 }
3593
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
3596 }
3597 }
3598
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003599 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003600 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3601 boolean isProvisioned) {
3602 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3603 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3604 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3605 }
allenwtsu99c623b2020-01-03 18:24:23 +08003606 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003607 final long identity = Binder.clearCallingIdentity();
3608 try {
3609 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003610 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003611 return;
3612 }
3613
3614 // this capability requires provisioning, route to the correct API.
3615 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3616 switch (capability) {
3617 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3618 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3619 ims.setVolteProvisioned(isProvisioned);
3620 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3621 ims.setWfcProvisioned(isProvisioned);
3622 }
3623 break;
3624 }
3625 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3626 // There is currently no difference in VT provisioning type.
3627 ims.setVtProvisioned(isProvisioned);
3628 break;
3629 }
3630 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3631 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3632 // change the capability of the feature instead if needed.
3633 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3634 == isProvisioned) {
3635 // No change in provisioning.
3636 return;
3637 }
3638 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3639 try {
3640 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003641 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003642 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3643 + ", Exception" + e.getMessage());
3644 }
3645 break;
3646 }
3647 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003648 throw new IllegalArgumentException("Tried to set provisioning for "
3649 + "MmTel capability '" + capability + "', which does not require "
3650 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003651 }
3652 }
3653
3654 } finally {
3655 Binder.restoreCallingIdentity(identity);
3656 }
3657 }
3658
3659 @Override
3660 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3661 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3662 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3663 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3664 }
3665 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003669 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003670 return true;
3671 }
3672
3673 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3674 switch (capability) {
3675 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3676 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3677 return ims.isVolteProvisionedOnDevice();
3678 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3679 return ims.isWfcProvisionedOnDevice();
3680 }
3681 // This should never happen, since we are checking tech above to make sure it
3682 // is either LTE or IWLAN.
3683 throw new IllegalArgumentException("Invalid radio technology for voice "
3684 + "capability.");
3685 }
3686 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3687 // There is currently no difference in VT provisioning type.
3688 return ims.isVtProvisionedOnDevice();
3689 }
3690 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3691 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3692 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3693 }
3694 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003695 throw new IllegalArgumentException(
3696 "Tried to get provisioning for MmTel capability '" + capability
3697 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 }
3699 }
3700
3701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
3707 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3708 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3709 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3710 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3711 }
3712 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3713 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3714 return (provisionedBits & capability) > 0;
3715 }
3716
3717 @Override
3718 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3719 boolean isProvisioned) {
3720 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3721 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3722 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3723 }
3724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3725 "setProvisioningStatusForCapability");
3726 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3727 // If the current provisioning status for capability already matches isProvisioned,
3728 // do nothing.
3729 if (((provisionedBits & capability) > 0) == isProvisioned) {
3730 return;
3731 }
3732 if (isProvisioned) {
3733 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3734 } else {
3735 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3736 }
3737 }
3738
3739 /**
3740 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3741 * technology. The bitfield should mirror the bitfield defined by
3742 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3743 */
3744 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3745 String key = getMmTelProvisioningKey(subId, tech);
3746 // Default is no capabilities are provisioned.
3747 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3748 }
3749
3750 /**
3751 * Sets the MmTel capability provisioning bitfield (defined by
3752 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3753 * technology specified.
3754 *
3755 * Note: This is a synchronous command and should not be called on UI thread.
3756 */
3757 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3758 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3759 String key = getMmTelProvisioningKey(subId, tech);
3760 editor.putInt(key, newField);
3761 editor.commit();
3762 }
3763
3764 private static String getMmTelProvisioningKey(int subId, int tech) {
3765 // resulting key is provision_ims_mmtel_{subId}_{tech}
3766 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3767 }
3768
3769 /**
3770 * Query CarrierConfig to see if the specified capability requires provisioning for the
3771 * carrier associated with the subscription id.
3772 */
3773 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3774 int capability) {
3775 CarrierConfigManager configManager = new CarrierConfigManager(context);
3776 PersistableBundle c = configManager.getConfigForSubId(subId);
3777 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003778 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003779 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3780 false);
3781 boolean requireVoiceVtProvisioning = c.getBoolean(
3782 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3783
3784 // First check to make sure that the capability requires provisioning.
3785 switch (capability) {
3786 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3787 // intentional fallthrough
3788 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3789 if (requireVoiceVtProvisioning) {
3790 // Voice and Video requires provisioning
3791 return true;
3792 }
3793 break;
3794 }
3795 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3796 if (requireUtProvisioning) {
3797 // UT requires provisioning
3798 return true;
3799 }
3800 break;
3801 }
3802 }
3803 return false;
3804 }
3805
allenwtsu99c623b2020-01-03 18:24:23 +08003806 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
3807 int capability) {
3808 CarrierConfigManager configManager = new CarrierConfigManager(context);
3809 PersistableBundle c = configManager.getConfigForSubId(subId);
3810
3811 boolean requireRcsProvisioning = c.getBoolean(
3812 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
3813
3814 // First check to make sure that the capability requires provisioning.
3815 switch (capability) {
3816 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3817 // intentional fallthrough
3818 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
3819 if (requireRcsProvisioning) {
3820 // OPTION or PRESENCE requires provisioning
3821 return true;
3822 }
3823 break;
3824 }
3825 }
3826 return false;
3827 }
3828
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003829 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003830 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003831 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3832 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3833 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003834 enforceReadPrivilegedPermission("getImsProvisioningInt");
3835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003838 int slotId = getSlotIndex(subId);
3839 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3840 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3841 + subId + "' for key:" + key);
3842 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3843 }
3844 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003845 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003846 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3847 + subId + "' for key:" + key);
3848 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003849 } finally {
3850 Binder.restoreCallingIdentity(identity);
3851 }
3852 }
3853
3854 @Override
3855 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3857 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3858 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003859 enforceReadPrivilegedPermission("getImsProvisioningString");
3860 final long identity = Binder.clearCallingIdentity();
3861 try {
3862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003863 int slotId = getSlotIndex(subId);
3864 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3865 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3866 + subId + "' for key:" + key);
3867 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3868 }
3869 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003871 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3872 + subId + "' for key:" + key);
3873 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003874 } finally {
3875 Binder.restoreCallingIdentity(identity);
3876 }
3877 }
3878
3879 @Override
3880 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003881 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3882 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3883 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003884 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3885 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 int slotId = getSlotIndex(subId);
3890 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3891 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3892 + subId + "' for key:" + key);
3893 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3894 }
3895 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003896 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003897 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3898 + "' for key:" + key);
3899 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
3903 }
3904
3905 @Override
3906 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3908 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3909 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3911 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003912 final long identity = Binder.clearCallingIdentity();
3913 try {
3914 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003915 int slotId = getSlotIndex(subId);
3916 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3917 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3918 + subId + "' for key:" + key);
3919 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3920 }
3921 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003922 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003923 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3924 + "' for key:" + key);
3925 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003926 } finally {
3927 Binder.restoreCallingIdentity(identity);
3928 }
3929 }
3930
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003931 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003932 int slotId = SubscriptionManager.getSlotIndex(subId);
3933 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003934 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3935 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 }
3937 return slotId;
3938 }
3939
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003940 private int getSlotIndex(int subId) {
3941 int slotId = SubscriptionManager.getSlotIndex(subId);
3942 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3943 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3944 }
3945 return slotId;
3946 }
3947
Wink Saville36469e72014-06-11 15:17:00 -07003948 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003949 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003950 */
3951 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003952 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3953 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003954 final int targetSdk = getTargetSdk(callingPackage);
3955 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003956 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003957 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003958 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003959 mApp, subId, callingPackage, callingFeatureId,
3960 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003961 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3962 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 final Phone phone = getPhone(subId);
3967 if (phone != null) {
3968 return phone.getServiceState().getDataNetworkType();
3969 } else {
3970 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3971 }
3972 } finally {
3973 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003974 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003975 }
3976
3977 /**
3978 * Returns the data network type
3979 */
3980 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003981 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3982 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3983 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003984 }
3985
3986 /**
3987 * Returns the data network type for a subId
3988 */
3989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003990 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3991 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003993 mApp, subId, callingPackage, callingFeatureId,
3994 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003995 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3996 }
3997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 final Phone phone = getPhone(subId);
4001 if (phone != null) {
4002 return phone.getServiceState().getDataNetworkType();
4003 } else {
4004 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4005 }
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004009 }
4010
4011 /**
Wink Saville36469e72014-06-11 15:17:00 -07004012 * Returns the Voice network type for a subId
4013 */
4014 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004015 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4016 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004018 mApp, subId, callingPackage, callingFeatureId,
4019 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004020 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4021 }
4022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023 final long identity = Binder.clearCallingIdentity();
4024 try {
4025 final Phone phone = getPhone(subId);
4026 if (phone != null) {
4027 return phone.getServiceState().getVoiceNetworkType();
4028 } else {
4029 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4030 }
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004034 }
4035
4036 /**
4037 * @return true if a ICC card is present
4038 */
4039 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004040 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004041 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4042 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004043 }
4044
4045 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004046 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004047 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004048 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004049 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 final Phone phone = PhoneFactory.getPhone(slotIndex);
4053 if (phone != null) {
4054 return phone.getIccCard().hasIccCard();
4055 } else {
4056 return false;
4057 }
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004060 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004061 }
4062
4063 /**
4064 * Return if the current radio is LTE on CDMA. This
4065 * is a tri-state return value as for a period of time
4066 * the mode may be unknown.
4067 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004068 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004069 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004070 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004071 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004072 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004073 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4074 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4075 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004076 }
4077
Sanket Padawe356d7632015-06-22 14:03:32 -07004078 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004079 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4080 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004082 mApp, subId, callingPackage, callingFeatureId,
4083 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004084 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4085 }
4086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004087 final long identity = Binder.clearCallingIdentity();
4088 try {
4089 final Phone phone = getPhone(subId);
4090 if (phone == null) {
4091 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4092 } else {
4093 return phone.getLteOnCdmaMode();
4094 }
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004097 }
Wink Saville36469e72014-06-11 15:17:00 -07004098 }
4099
Wink Saville36469e72014-06-11 15:17:00 -07004100 /**
4101 * {@hide}
4102 * Returns Default subId, 0 in the case of single standby.
4103 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004104 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004105 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004106 }
4107
Shishir Agrawala9f32182016-04-12 12:00:16 -07004108 private int getSlotForDefaultSubscription() {
4109 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4110 }
4111
Wink Savilleb564aae2014-10-23 10:18:09 -07004112 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004113 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004114 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004115
Pengquan Menge92a50d2018-09-21 15:54:48 -07004116 private boolean isActiveSubscription(int subId) {
4117 return mSubscriptionController.isActiveSubId(subId);
4118 }
4119
Ihab Awadf2177b72013-11-25 13:33:23 -08004120 /**
4121 * @see android.telephony.TelephonyManager.WifiCallingChoices
4122 */
4123 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 final long identity = Binder.clearCallingIdentity();
4125 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004126 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4128 getWhenToMakeWifiCallsDefaultPreference());
4129 } finally {
4130 Binder.restoreCallingIdentity(identity);
4131 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004132 }
4133
4134 /**
4135 * @see android.telephony.TelephonyManager.WifiCallingChoices
4136 */
4137 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
4140 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004141 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004142 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004146 }
4147
Sailesh Nepald1e68152013-12-12 19:08:02 -08004148 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004149 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004150 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004151 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004152
Jordan Liu4c733742019-02-28 12:03:40 -08004153 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4154 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4155 if (phoneId == -1) {
4156 throw new IllegalArgumentException("Given slot index: " + slotIndex
4157 + " does not correspond to an active phone");
4158 }
4159 return PhoneFactory.getPhone(phoneId);
4160 }
4161
Shishir Agrawal566b7612013-10-28 14:41:00 -07004162 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004163 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4164 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4166 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004167 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004168 if (DBG) {
4169 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4170 }
4171 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4172 p2);
4173 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004174
Jordan Liu4c733742019-02-28 12:03:40 -08004175
4176 @Override
4177 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4178 int slotIndex, String callingPackage, String aid, int p2) {
4179 enforceModifyPermission();
4180 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4181 if (DBG) {
4182 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4183 }
4184 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4185 callingPackage, aid, p2);
4186 }
4187
4188 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4189 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004190 final long identity = Binder.clearCallingIdentity();
4191 try {
4192 if (TextUtils.equals(ISDR_AID, aid)) {
4193 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004194 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4195 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004196 if (bestComponent == null
4197 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4198 loge("The calling package is not allowed to access ISD-R.");
4199 throw new SecurityException(
4200 "The calling package is not allowed to access ISD-R.");
4201 }
Derek Tan740e1672017-06-27 14:56:27 -07004202 }
Derek Tan740e1672017-06-27 14:56:27 -07004203
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004204 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004205 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4206 null /* workSource */);
4207 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 return response;
4209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004212 }
4213
4214 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004215 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004216 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4217 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004218 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4219 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4220 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004221
Jordan Liu4c733742019-02-28 12:03:40 -08004222 @Override
4223 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4224 enforceModifyPermission();
4225 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4226 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4227 channel);
4228 }
4229
4230 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231 final long identity = Binder.clearCallingIdentity();
4232 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233 if (channel < 0) {
4234 return false;
4235 }
Jordan Liu4c733742019-02-28 12:03:40 -08004236 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4237 null /* workSource */);
4238 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239 return success;
4240 } finally {
4241 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004242 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004243 }
4244
4245 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004246 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004247 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004248 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4249 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004250 if (DBG) {
4251 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4252 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4253 + p3 + " data=" + data);
4254 }
4255 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4256 command, p1, p2, p3, data);
4257 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004258
Jordan Liu4c733742019-02-28 12:03:40 -08004259 @Override
4260 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4261 int command, int p1, int p2, int p3, String data) {
4262 enforceModifyPermission();
4263 if (DBG) {
4264 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4265 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4266 + p3 + " data=" + data);
4267 }
4268 return iccTransmitApduLogicalChannelWithPermission(
4269 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4270 data);
4271 }
4272
4273 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4274 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275 final long identity = Binder.clearCallingIdentity();
4276 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004277 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004278 return "";
4279 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004282 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4283 null /* workSource */);
4284 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004285
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 // Append the returned status code to the end of the response payload.
4287 String s = Integer.toHexString(
4288 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4289 if (response.payload != null) {
4290 s = IccUtils.bytesToHexString(response.payload) + s;
4291 }
4292 return s;
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004295 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004296 }
Jake Hambye994d462014-02-03 13:10:13 -08004297
Evan Charltonc66da362014-05-16 14:06:40 -07004298 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004299 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4300 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004301 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4302 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004304 if (DBG) {
4305 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4306 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4307 }
4308 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4309 cla, command, p1, p2, p3, data);
4310 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004311
Jordan Liu4c733742019-02-28 12:03:40 -08004312 @Override
4313 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4314 int command, int p1, int p2, int p3, String data) {
4315 enforceModifyPermission();
4316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4317 if (DBG) {
4318 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4319 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4320 + " data=" + data);
4321 }
4322
4323 return iccTransmitApduBasicChannelWithPermission(
4324 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4325 p2, p3, data);
4326 }
4327
4328 // open APDU basic channel assuming the caller has sufficient permissions
4329 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4330 int cla, 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 {
4333 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4334 && TextUtils.equals(ISDR_AID, data)) {
4335 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004336 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4337 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 if (bestComponent == null
4339 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4340 loge("The calling package is not allowed to select ISD-R.");
4341 throw new SecurityException(
4342 "The calling package is not allowed to select ISD-R.");
4343 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004344 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004347 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4348 null /* workSource */);
4349 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004351 // Append the returned status code to the end of the response payload.
4352 String s = Integer.toHexString(
4353 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4354 if (response.payload != null) {
4355 s = IccUtils.bytesToHexString(response.payload) + s;
4356 }
4357 return s;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004360 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004361 }
4362
4363 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004364 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004365 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4367 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004369 final long identity = Binder.clearCallingIdentity();
4370 try {
4371 if (DBG) {
4372 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4373 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4374 }
4375
4376 IccIoResult response =
4377 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4378 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4379 subId);
4380
4381 if (DBG) {
4382 log("Exchange SIM_IO [R]" + response);
4383 }
4384
4385 byte[] result = null;
4386 int length = 2;
4387 if (response.payload != null) {
4388 length = 2 + response.payload.length;
4389 result = new byte[length];
4390 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4391 } else {
4392 result = new byte[length];
4393 }
4394
4395 result[length - 1] = (byte) response.sw2;
4396 result[length - 2] = (byte) response.sw1;
4397 return result;
4398 } finally {
4399 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004400 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004401 }
4402
Nathan Haroldb3014052017-01-25 15:57:32 -08004403 /**
4404 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4405 * on a particular subscription
4406 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004407 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4408 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004410 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004411 return null;
4412 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413
4414 final long identity = Binder.clearCallingIdentity();
4415 try {
4416 if (appType != TelephonyManager.APPTYPE_USIM
4417 && appType != TelephonyManager.APPTYPE_SIM) {
4418 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4419 return null;
4420 }
4421 Object response = sendRequest(
4422 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4423 if (response instanceof String[]) {
4424 return (String[]) response;
4425 }
yincheng zhao2737e882019-09-06 17:06:54 -07004426 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004428 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429 } finally {
4430 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004431 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004432 }
4433
yincheng zhao2737e882019-09-06 17:06:54 -07004434 /**
4435 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4436 * subscription.
4437 *
4438 * @param subId the id of the subscription.
4439 * @param appType the uicc app type, must be USIM or SIM.
4440 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4441 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004442 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004443 * @return number of fplmns that is successfully written to the SIM.
4444 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004445 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4446 String callingFeatureId) {
4447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4448 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004449 if (DBG) logv("no permissions for setForbiddenplmns");
4450 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4451 }
4452 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4453 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4454 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4455 }
4456 if (fplmns == null) {
4457 throw new IllegalArgumentException("Fplmn List provided is null");
4458 }
4459 for (String fplmn : fplmns) {
4460 if (!CellIdentity.isValidPlmn(fplmn)) {
4461 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4462 }
4463 }
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 Object response = sendRequest(
4467 CMD_SET_FORBIDDEN_PLMNS,
4468 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4469 subId);
4470 return (int) response;
4471 } finally {
4472 Binder.restoreCallingIdentity(identity);
4473 }
4474 }
4475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004476 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004477 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4479 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4484 if (response.payload == null) {
4485 return "";
4486 }
Evan Charltonc66da362014-05-16 14:06:40 -07004487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 // Append the returned status code to the end of the response payload.
4489 String s = Integer.toHexString(
4490 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4491 s = IccUtils.bytesToHexString(response.payload) + s;
4492 return s;
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
Evan Charltonc66da362014-05-16 14:06:40 -07004496 }
4497
Jake Hambye994d462014-02-03 13:10:13 -08004498 /**
4499 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4500 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4501 *
4502 * @param itemID the ID of the item to read
4503 * @return the NV item as a String, or null on error.
4504 */
4505 @Override
4506 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004507 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4509 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004510
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004514 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4516 return value;
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Jake Hambye994d462014-02-03 13:10:13 -08004520 }
4521
4522 /**
4523 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4524 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4525 *
4526 * @param itemID the ID of the item to read
4527 * @param itemValue the value to write, as a String
4528 * @return true on success; false on any failure
4529 */
4530 @Override
4531 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004532 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004533 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4534 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004535
4536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4539 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004540 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4542 return success;
4543 } finally {
4544 Binder.restoreCallingIdentity(identity);
4545 }
Jake Hambye994d462014-02-03 13:10:13 -08004546 }
4547
4548 /**
4549 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4550 * Used for device configuration by some CDMA operators.
4551 *
4552 * @param preferredRoamingList byte array containing the new PRL
4553 * @return true on success; false on any failure
4554 */
4555 @Override
4556 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4558 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559
4560 final long identity = Binder.clearCallingIdentity();
4561 try {
4562 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4563 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4564 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4565 return success;
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
Jake Hambye994d462014-02-03 13:10:13 -08004569 }
4570
4571 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004572 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004573 * Used for device configuration by some CDMA operators.
4574 *
chen xu6dac5ab2018-10-26 17:39:23 -07004575 * @param slotIndex - device slot.
4576 *
Jake Hambye994d462014-02-03 13:10:13 -08004577 * @return true on success; false on any failure
4578 */
4579 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004580 public boolean resetModemConfig(int slotIndex) {
4581 Phone phone = PhoneFactory.getPhone(slotIndex);
4582 if (phone != null) {
4583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4584 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585
chen xu6dac5ab2018-10-26 17:39:23 -07004586 final long identity = Binder.clearCallingIdentity();
4587 try {
4588 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4589 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4590 return success;
4591 } finally {
4592 Binder.restoreCallingIdentity(identity);
4593 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 }
chen xu6dac5ab2018-10-26 17:39:23 -07004595 return false;
4596 }
4597
4598 /**
4599 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4600 *
4601 * @param slotIndex - device slot.
4602 *
4603 * @return true on success; false on any failure
4604 */
4605 @Override
4606 public boolean rebootModem(int slotIndex) {
4607 Phone phone = PhoneFactory.getPhone(slotIndex);
4608 if (phone != null) {
4609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4610 mApp, phone.getSubId(), "rebootModem");
4611
4612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4615 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4616 return success;
4617 } finally {
4618 Binder.restoreCallingIdentity(identity);
4619 }
4620 }
4621 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004622 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004623
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004624 public String[] getPcscfAddress(String apnType, String callingPackage,
4625 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004626 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4628 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004629 return new String[0];
4630 }
4631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 final long identity = Binder.clearCallingIdentity();
4633 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004634 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
Wink Saville36469e72014-06-11 15:17:00 -07004638 }
4639
Brad Ebinger51f743a2017-01-23 13:50:20 -08004640 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004641 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4642 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004643 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004644 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646
4647 final long identity = Binder.clearCallingIdentity();
4648 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004649 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004650 // may happen if the device does not support IMS.
4651 return;
4652 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004653 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 } finally {
4655 Binder.restoreCallingIdentity(identity);
4656 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004657 }
4658
4659 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004660 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4661 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004662 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004663 public void disableIms(int slotId) {
4664 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665
4666 final long identity = Binder.clearCallingIdentity();
4667 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004668 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004669 // may happen if the device does not support IMS.
4670 return;
4671 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004672 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 } finally {
4674 Binder.restoreCallingIdentity(identity);
4675 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004676 }
4677
4678 /**
4679 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4680 * feature or {@link null} if the service is not available. If the feature is available, the
4681 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4682 */
4683 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004684 IImsServiceFeatureCallback callback) {
4685 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004686
4687 final long identity = Binder.clearCallingIdentity();
4688 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004689 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004690 // may happen if the device does not support IMS.
4691 return null;
4692 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004693 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 } finally {
4695 Binder.restoreCallingIdentity(identity);
4696 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004697 }
4698
4699 /**
4700 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4701 * feature during emergency calling or {@link null} if the service is not available. If the
4702 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4703 * listener for feature updates.
4704 */
4705 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4706 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004710 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004711 // may happen if the device does not support IMS.
4712 return null;
4713 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004714 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004718 }
4719
Brad Ebinger5f64b052017-12-14 14:26:15 -08004720 /**
4721 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004722 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004723 */
4724 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4725 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004726
4727 final long identity = Binder.clearCallingIdentity();
4728 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004729 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004730 // may happen if the device does not support IMS.
4731 return null;
4732 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004733 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 } finally {
4735 Binder.restoreCallingIdentity(identity);
4736 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004737 }
4738
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004739 /**
4740 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004741 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004742 */
4743 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4744 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745
4746 final long identity = Binder.clearCallingIdentity();
4747 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004748 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004749 // may happen if the device does not support IMS.
4750 return null;
4751 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004752 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 } finally {
4754 Binder.restoreCallingIdentity(identity);
4755 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004756 }
4757
Brad Ebinger884c07b2018-02-15 16:17:40 -08004758 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004759 * Sets the ImsService Package Name that Telephony will bind to.
4760 *
Brad Ebinger24c29992019-12-05 13:03:21 -08004761 * @param slotIndex the slot ID that the ImsService should bind for.
4762 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004763 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08004764 * @param featureTypes An integer array of feature types associated with a packageName.
4765 * @param packageName The name of the package that the current configuration will be replaced
4766 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004767 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004768 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004769 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4770 int[] featureTypes, String packageName) {
4771 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4774 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08004775 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 final long identity = Binder.clearCallingIdentity();
4778 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004779 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004780 // may happen if the device does not support IMS.
4781 return false;
4782 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004783 Map<Integer, String> featureConfig = new HashMap<>();
4784 for (int featureType : featureTypes) {
4785 featureConfig.put(featureType, packageName);
4786 }
4787 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4788 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 } finally {
4790 Binder.restoreCallingIdentity(identity);
4791 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004792 }
4793
4794 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08004795 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004796 *
4797 * @param slotId The slot that the ImsService is associated with.
4798 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4799 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08004800 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004801 * @return the package name of the ImsService configuration.
4802 */
Brad Ebinger24c29992019-12-05 13:03:21 -08004803 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4804 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004805 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08004806 TelephonyPermissions
4807 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4808 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4809 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811 final long identity = Binder.clearCallingIdentity();
4812 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004813 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004814 // may happen if the device does not support IMS.
4815 return "";
4816 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004817 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08004818 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4819 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004823 }
4824
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004825 /**
4826 * Get the MmTelFeature state associated with the requested subscription id.
4827 * @param subId The subscription that the MmTelFeature is associated with.
4828 * @param callback A callback with an integer containing the
4829 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4830 */
4831 @Override
4832 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4833 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4834 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4835 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4836 "IMS not available on device.");
4837 }
4838 final long token = Binder.clearCallingIdentity();
4839 try {
4840 int slotId = getSlotIndex(subId);
4841 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4842 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4843 + subId + "'");
4844 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4845 }
4846 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4847 try {
4848 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4849 } catch (RemoteException e) {
4850 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4851 + "Ignore");
4852 }
4853 });
4854 } finally {
4855 Binder.restoreCallingIdentity(token);
4856 }
4857 }
4858
Wink Saville36469e72014-06-11 15:17:00 -07004859 public void setImsRegistrationState(boolean registered) {
4860 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004864 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
Wink Saville36469e72014-06-11 15:17:00 -07004868 }
4869
4870 /**
Stuart Scott54788802015-03-30 13:18:01 -07004871 * Set the network selection mode to automatic.
4872 *
4873 */
4874 @Override
4875 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4877 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878
Pengquan Menge92a50d2018-09-21 15:54:48 -07004879 if (!isActiveSubscription(subId)) {
4880 return;
4881 }
4882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4886 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4887 } finally {
4888 Binder.restoreCallingIdentity(identity);
4889 }
Stuart Scott54788802015-03-30 13:18:01 -07004890 }
4891
Pengquan Mengea84e042018-09-20 14:57:26 -07004892 /**
4893 * Ask the radio to connect to the input network and change selection mode to manual.
4894 *
4895 * @param subId the id of the subscription.
4896 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4897 * the operator to attach to.
4898 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4899 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4900 * normal network selection next time.
4901 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004902 */
4903 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004904 public boolean setNetworkSelectionModeManual(
4905 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4907 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004908
4909 if (!isActiveSubscription(subId)) {
4910 return false;
4911 }
4912
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004913 final long identity = Binder.clearCallingIdentity();
4914 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004915 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004917 if (DBG) {
4918 log("setNetworkSelectionModeManual: subId: " + subId
4919 + " operator: " + operatorInfo);
4920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4922 } finally {
4923 Binder.restoreCallingIdentity(identity);
4924 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004925 }
4926
4927 /**
4928 * Scans for available networks.
4929 */
4930 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004931 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4932 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4934 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004935 LocationAccessPolicy.LocationPermissionResult locationResult =
4936 LocationAccessPolicy.checkLocationPermission(mApp,
4937 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4938 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004939 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004940 .setCallingPid(Binder.getCallingPid())
4941 .setCallingUid(Binder.getCallingUid())
4942 .setMethod("getCellNetworkScanResults")
4943 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4944 .build());
4945 switch (locationResult) {
4946 case DENIED_HARD:
4947 throw new SecurityException("Not allowed to access scan results -- location");
4948 case DENIED_SOFT:
4949 return null;
4950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951
Pengquan Menga1bb6272018-09-06 09:59:22 -07004952 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004953 try {
4954 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004955 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 } finally {
4958 Binder.restoreCallingIdentity(identity);
4959 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004960 }
4961
4962 /**
yinxub1bed742017-04-17 11:45:04 -07004963 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004964 *
yinxub1bed742017-04-17 11:45:04 -07004965 * @param subId id of the subscription
4966 * @param request contains the radio access networks with bands/channels to scan
4967 * @param messenger callback messenger for scan results or errors
4968 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004969 * @return the id of the requested scan which can be used to stop the scan.
4970 */
4971 @Override
4972 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004973 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4975 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004976 LocationAccessPolicy.LocationPermissionResult locationResult =
4977 LocationAccessPolicy.checkLocationPermission(mApp,
4978 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4979 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07004980 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004981 .setCallingPid(Binder.getCallingPid())
4982 .setCallingUid(Binder.getCallingUid())
4983 .setMethod("requestNetworkScan")
4984 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4985 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004986 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004987 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004988 if (e != null) {
4989 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4990 throw e;
4991 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004992 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004993 return TelephonyScanManager.INVALID_SCAN_ID;
4994 }
4995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 }
Hall Liu912dfd32019-04-25 14:02:26 -07004997 int callingUid = Binder.getCallingUid();
4998 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 return mNetworkScanRequestTracker.startNetworkScan(
5002 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005003 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
yinxu504e1392017-04-12 16:03:22 -07005007 }
5008
Hall Liub2ac8ef2019-02-28 15:56:23 -08005009 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005010 NetworkScanRequest request, int subId) {
5011 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5012 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5013 boolean hasNetworkScanPermission =
5014 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5015 == PERMISSION_GRANTED;
5016
5017 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5018 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5019 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005020 }
5021
5022 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5023 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005024 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5025 return new SecurityException("Specific channels must not be"
5026 + " scanned without location access.");
5027 }
5028 }
5029 }
5030
Hall Liub2ac8ef2019-02-28 15:56:23 -08005031 return null;
5032 }
5033
yinxu504e1392017-04-12 16:03:22 -07005034 /**
5035 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005036 *
5037 * @param subId id of the subscription
5038 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005039 */
5040 @Override
5041 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044
Hall Liu912dfd32019-04-25 14:02:26 -07005045 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005048 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
yinxu504e1392017-04-12 16:03:22 -07005052 }
5053
5054 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005055 * Get the calculated preferred network type.
5056 * Used for debugging incorrect network type.
5057 *
5058 * @return the preferred network type, defined in RILConstants.java.
5059 */
5060 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005061 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005062 final Phone defaultPhone = getDefaultPhone();
5063 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005064 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005065 return RILConstants.PREFERRED_NETWORK_MODE;
5066 }
5067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005071 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 } finally {
5073 Binder.restoreCallingIdentity(identity);
5074 }
Junda Liu84d15a22014-07-02 11:21:04 -07005075 }
5076
5077 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005078 * Get the preferred network type.
5079 * Used for device configuration by some CDMA operators.
5080 *
5081 * @return the preferred network type, defined in RILConstants.java.
5082 */
5083 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005084 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005085 TelephonyPermissions
5086 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5087 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088
5089 final long identity = Binder.clearCallingIdentity();
5090 try {
5091 if (DBG) log("getPreferredNetworkType");
5092 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5093 int networkType = (result != null ? result[0] : -1);
5094 if (DBG) log("getPreferredNetworkType: " + networkType);
5095 return networkType;
5096 } finally {
5097 Binder.restoreCallingIdentity(identity);
5098 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005099 }
5100
5101 /**
5102 * Set the preferred network type.
5103 * Used for device configuration by some CDMA operators.
5104 *
5105 * @param networkType the preferred network type, defined in RILConstants.java.
5106 * @return true on success; false on any failure.
5107 */
5108 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005109 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5111 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
5116 Boolean success = (Boolean) sendRequest(
5117 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5118 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5119 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005120 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5122 }
5123 return success;
5124 } finally {
5125 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005126 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005127 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005128
5129 /**
Miaoa84611c2019-03-15 09:21:10 +08005130 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005131 *
Miaoa84611c2019-03-15 09:21:10 +08005132 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005133 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005134 * @hide
5135 */
5136 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005137 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005140 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 try {
Miaoa84611c2019-03-15 09:21:10 +08005142 if (phone != null) {
5143 return phone.hasMatchedTetherApnSetting();
5144 } else {
5145 return false;
5146 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 } finally {
5148 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005149 }
Junda Liu475951f2014-11-07 16:45:03 -08005150 }
5151
5152 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005153 * Set mobile data enabled
5154 * Used by the user through settings etc to turn on/off mobile data
5155 *
5156 * @param enable {@code true} turn turn data on, else {@code false}
5157 */
5158 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005159 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5161 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162
5163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 int phoneId = mSubscriptionController.getPhoneId(subId);
5166 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5167 Phone phone = PhoneFactory.getPhone(phoneId);
5168 if (phone != null) {
5169 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005170 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005171 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005172 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005173 }
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005176 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005177 }
5178
5179 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005180 * Get the user enabled state of Mobile Data.
5181 *
5182 * TODO: remove and use isUserDataEnabled.
5183 * This can't be removed now because some vendor codes
5184 * calls through ITelephony directly while they should
5185 * use TelephonyManager.
5186 *
5187 * @return true on enabled
5188 */
5189 @Override
5190 public boolean getDataEnabled(int subId) {
5191 return isUserDataEnabled(subId);
5192 }
5193
5194 /**
5195 * Get whether mobile data is enabled per user setting.
5196 *
5197 * There are other factors deciding whether mobile data is actually enabled, but they are
5198 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005199 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005200 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005201 *
5202 * @return {@code true} if data is enabled else {@code false}
5203 */
5204 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005205 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005206 try {
5207 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5208 null);
5209 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005210 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5211 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005213
5214 final long identity = Binder.clearCallingIdentity();
5215 try {
5216 int phoneId = mSubscriptionController.getPhoneId(subId);
5217 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5218 Phone phone = PhoneFactory.getPhone(phoneId);
5219 if (phone != null) {
5220 boolean retVal = phone.isUserDataEnabled();
5221 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5222 return retVal;
5223 } else {
5224 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5225 return false;
5226 }
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005229 }
5230 }
5231
5232 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005233 * Checks if the device is capable of mobile data by considering whether whether the
5234 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5235 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005236 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005237 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005238 */
5239 @Override
5240 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005241 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242
5243 final long identity = Binder.clearCallingIdentity();
5244 try {
5245 int phoneId = mSubscriptionController.getPhoneId(subId);
5246 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5247 Phone phone = PhoneFactory.getPhone(phoneId);
5248 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005249 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5251 return retVal;
5252 } else {
5253 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5254 return false;
5255 }
5256 } finally {
5257 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005258 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005259 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005260
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005261 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5262 Phone phone) {
5263 //load access rules from carrier configs, and check those as well: b/139133814
5264 SubscriptionController subController = SubscriptionController.getInstance();
5265 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5266 || subController == null) return privilegeFromSim;
5267
5268 int uid = Binder.getCallingUid();
5269 PackageManager pkgMgr = phone.getContext().getPackageManager();
5270 String[] packages = pkgMgr.getPackagesForUid(uid);
5271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5275 SubscriptionManager subManager = (SubscriptionManager)
5276 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5277 for (String pkg : packages) {
5278 if (subManager.canManageSubscription(subInfo, pkg)) {
5279 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5280 }
5281 }
5282 return privilegeFromSim;
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
5287
5288 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5289 String pkgName) {
5290 //load access rules from carrier configs, and check those as well: b/139133814
5291 SubscriptionController subController = SubscriptionController.getInstance();
5292 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5293 || subController == null) return privilegeFromSim;
5294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5298 SubscriptionManager subManager = (SubscriptionManager)
5299 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5300 return subManager.canManageSubscription(subInfo, pkgName)
5301 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
5305 }
5306
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005307 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005308 public int getCarrierPrivilegeStatus(int subId) {
5309 final Phone phone = getPhone(subId);
5310 if (phone == null) {
5311 loge("getCarrierPrivilegeStatus: Invalid subId");
5312 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5313 }
5314 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005315 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005316 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005317 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5318 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005319
5320 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5321 card.getCarrierPrivilegeStatusForCurrentTransaction(
5322 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005323 }
Junda Liu29340342014-07-10 15:23:27 -07005324
5325 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005326 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005327 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005328 final Phone phone = getPhone(subId);
5329 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005330 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5332 }
5333 UiccProfile profile =
5334 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5335 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005336 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005337 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5338 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005339 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005340 profile.getCarrierPrivilegeStatusForUid(
5341 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005342 }
5343
5344 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005345 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5346 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005347 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005348 }
5349
5350 int phoneId = SubscriptionManager.getPhoneId(subId);
5351 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005352 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005353 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005354 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5355 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005356 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5357 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5358 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005359 }
5360
5361 @Override
5362 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005363 if (TextUtils.isEmpty(pkgName))
5364 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005365 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5366 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5367 UiccCard card = UiccController.getInstance().getUiccCard(i);
5368 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005369 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005370 continue;
5371 }
5372
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005373 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5374 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5375 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005376 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5377 break;
5378 }
5379 }
5380
5381 return result;
Junda Liu29340342014-07-10 15:23:27 -07005382 }
Derek Tan89e89d42014-07-08 17:00:10 -07005383
5384 @Override
Junda Liue64de782015-04-16 17:19:16 -07005385 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5386 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5387 loge("phoneId " + phoneId + " is not valid.");
5388 return null;
5389 }
5390 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005391 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005392 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005393 return null ;
5394 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005395 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005396 }
5397
Amith Yamasani6e118872016-02-19 12:53:51 -08005398 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005399 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005400 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005401 List<String> privilegedPackages = new ArrayList<>();
5402 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005403 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5404 // has UICC in that slot.
5405 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005406 if (card.hasCarrierPrivilegeRules()) {
5407 if (packages == null) {
5408 // Only check packages in user 0 for now
5409 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005410 PackageManager.MATCH_DISABLED_COMPONENTS
5411 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005412 | PackageManager.GET_SIGNING_CERTIFICATES,
5413 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005414 }
5415 for (int p = packages.size() - 1; p >= 0; p--) {
5416 PackageInfo pkgInfo = packages.get(p);
5417 if (pkgInfo != null && pkgInfo.packageName != null
5418 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005419 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005420 privilegedPackages.add(pkgInfo.packageName);
5421 }
5422 }
5423 }
5424 }
5425 return privilegedPackages;
5426 }
5427
chen xuf7e9fe82019-05-09 19:31:02 -07005428 @Override
5429 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005430 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5431
5432 final long identity = Binder.clearCallingIdentity();
5433
chen xuf7e9fe82019-05-09 19:31:02 -07005434 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005435 try {
5436 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5437 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5438 }
5439 } finally {
5440 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005441 }
5442 return privilegedPackages;
5443 }
5444
Wink Savilleb564aae2014-10-23 10:18:09 -07005445 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005446 final Phone phone = getPhone(subId);
5447 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005448 if (card == null) {
5449 loge("getIccId: No UICC");
5450 return null;
5451 }
5452 String iccId = card.getIccId();
5453 if (TextUtils.isEmpty(iccId)) {
5454 loge("getIccId: ICC ID is null or empty.");
5455 return null;
5456 }
5457 return iccId;
5458 }
5459
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005460 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005461 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5462 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005463 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005464 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 final String iccId = getIccId(subId);
5469 final Phone phone = getPhone(subId);
5470 if (phone == null) {
5471 return false;
5472 }
5473 final String subscriberId = phone.getSubscriberId();
5474
5475 if (DBG_MERGE) {
5476 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5477 + subscriberId + " to " + number);
5478 }
5479
5480 if (TextUtils.isEmpty(iccId)) {
5481 return false;
5482 }
5483
5484 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5485
5486 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5487 if (alphaTag == null) {
5488 editor.remove(alphaTagPrefKey);
5489 } else {
5490 editor.putString(alphaTagPrefKey, alphaTag);
5491 }
5492
5493 // Record both the line number and IMSI for this ICCID, since we need to
5494 // track all merged IMSIs based on line number
5495 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5496 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5497 if (number == null) {
5498 editor.remove(numberPrefKey);
5499 editor.remove(subscriberPrefKey);
5500 } else {
5501 editor.putString(numberPrefKey, number);
5502 editor.putString(subscriberPrefKey, subscriberId);
5503 }
5504
5505 editor.commit();
5506 return true;
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005509 }
Derek Tan7226c842014-07-02 17:42:23 -07005510 }
5511
5512 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005513 public String getLine1NumberForDisplay(int subId, String callingPackage,
5514 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005515 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005516 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005517 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005518 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005519 return null;
5520 }
Derek Tan97ebb422014-09-05 16:55:38 -07005521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522 final long identity = Binder.clearCallingIdentity();
5523 try {
5524 String iccId = getIccId(subId);
5525 if (iccId != null) {
5526 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5527 if (DBG_MERGE) {
5528 log("getLine1NumberForDisplay returning "
5529 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5530 }
5531 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5534 return null;
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005537 }
Derek Tan7226c842014-07-02 17:42:23 -07005538 }
5539
5540 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005541 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5542 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005544 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005545 return null;
5546 }
Derek Tan97ebb422014-09-05 16:55:38 -07005547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 final long identity = Binder.clearCallingIdentity();
5549 try {
5550 String iccId = getIccId(subId);
5551 if (iccId != null) {
5552 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5553 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5554 }
5555 return null;
5556 } finally {
5557 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005558 }
Derek Tan7226c842014-07-02 17:42:23 -07005559 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005560
5561 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005562 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5563 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005564 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5565 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005567 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005568 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005569 return null;
5570 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005571
Jordan Liub49b04b2019-05-06 14:45:15 -07005572 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5573 // the process, where TelephonyManager was instantiated.
5574 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005575 final long identity = Binder.clearCallingIdentity();
5576 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005577 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005578 final TelephonyManager tele = TelephonyManager.from(context);
5579 final SubscriptionManager sub = SubscriptionManager.from(context);
5580
5581 // Figure out what subscribers are currently active
5582 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005583
Jordan Liub49b04b2019-05-06 14:45:15 -07005584 // Only consider subs which match the current subId
5585 // This logic can be simplified. See b/131189269 for progress.
5586 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005587 activeSubscriberIds.add(tele.getSubscriberId(subId));
5588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589
5590 // First pass, find a number override for an active subscriber
5591 String mergeNumber = null;
5592 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5593 for (String key : prefs.keySet()) {
5594 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5595 final String subscriberId = (String) prefs.get(key);
5596 if (activeSubscriberIds.contains(subscriberId)) {
5597 final String iccId = key.substring(
5598 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5599 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5600 mergeNumber = (String) prefs.get(numberKey);
5601 if (DBG_MERGE) {
5602 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5603 + " for active subscriber " + subscriberId);
5604 }
5605 if (!TextUtils.isEmpty(mergeNumber)) {
5606 break;
5607 }
5608 }
5609 }
5610 }
5611
5612 // Shortcut when no active merged subscribers
5613 if (TextUtils.isEmpty(mergeNumber)) {
5614 return null;
5615 }
5616
5617 // Second pass, find all subscribers under that line override
5618 final ArraySet<String> result = new ArraySet<>();
5619 for (String key : prefs.keySet()) {
5620 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5621 final String number = (String) prefs.get(key);
5622 if (mergeNumber.equals(number)) {
5623 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5624 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5625 final String subscriberId = (String) prefs.get(subscriberKey);
5626 if (!TextUtils.isEmpty(subscriberId)) {
5627 result.add(subscriberId);
5628 }
5629 }
5630 }
5631 }
5632
5633 final String[] resultArray = result.toArray(new String[result.size()]);
5634 Arrays.sort(resultArray);
5635 if (DBG_MERGE) {
5636 Slog.d(LOG_TAG,
5637 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5638 }
5639 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005640 } finally {
5641 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005642 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005643 }
5644
5645 @Override
zoey chen38003472019-12-13 17:16:31 +08005646 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
5647 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07005648
5649 final long identity = Binder.clearCallingIdentity();
5650 try {
5651 final TelephonyManager telephonyManager = mApp.getSystemService(
5652 TelephonyManager.class);
5653 String subscriberId = telephonyManager.getSubscriberId(subId);
5654 if (subscriberId == null) {
5655 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08005656 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07005657 + subId);
5658 }
5659 return null;
5660 }
5661
5662 final SubscriptionInfo info = SubscriptionController.getInstance()
5663 .getSubscriptionInfo(subId);
5664 final ParcelUuid groupUuid = info.getGroupUuid();
5665 // If it doesn't belong to any group, return just subscriberId of itself.
5666 if (groupUuid == null) {
5667 return new String[]{subscriberId};
5668 }
5669
5670 // Get all subscriberIds from the group.
5671 final List<String> mergedSubscriberIds = new ArrayList<>();
5672 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005673 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5674 mApp.getFeatureId());
Malcolm Chen6ca97372019-07-01 16:28:21 -07005675 for (SubscriptionInfo subInfo : groupInfos) {
5676 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5677 if (subscriberId != null) {
5678 mergedSubscriberIds.add(subscriberId);
5679 }
5680 }
5681
5682 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685
5686 }
5687 }
5688
5689 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005690 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005691 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005692 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 final Phone phone = getPhone(subId);
5697 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005701 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005702
5703 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005704 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005705 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5706 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005707 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5708 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
5711 try {
5712 final Phone phone = getPhone(subId);
5713 if (phone == null) {
5714 return false;
5715 }
5716 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5717 cdmaNonRoamingList);
5718 } finally {
5719 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005720 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005721 }
5722
5723 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005724 @Deprecated
5725 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5726 enforceModifyPermission();
5727
5728 int returnValue = 0;
5729 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005730 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005731 if(result.exception == null) {
5732 if (result.result != null) {
5733 byte[] responseData = (byte[])(result.result);
5734 if(responseData.length > oemResp.length) {
5735 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5736 responseData.length + "bytes. Buffer Size is " +
5737 oemResp.length + "bytes.");
5738 }
5739 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5740 returnValue = responseData.length;
5741 }
5742 } else {
5743 CommandException ex = (CommandException) result.exception;
5744 returnValue = ex.getCommandError().ordinal();
5745 if(returnValue > 0) returnValue *= -1;
5746 }
5747 } catch (RuntimeException e) {
5748 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5749 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5750 if(returnValue > 0) returnValue *= -1;
5751 }
5752
5753 return returnValue;
5754 }
5755
5756 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005757 public void setRadioCapability(RadioAccessFamily[] rafs) {
5758 try {
5759 ProxyController.getInstance().setRadioCapability(rafs);
5760 } catch (RuntimeException e) {
5761 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5762 }
5763 }
5764
5765 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005766 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005767 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005768 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005769 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005770 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 final long identity = Binder.clearCallingIdentity();
5773 try {
chen xub97461a2018-10-26 14:17:57 -07005774 TelephonyPermissions
5775 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5776 mApp, phone.getSubId(), "getRadioAccessFamily");
5777 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
chen xub97461a2018-10-26 14:17:57 -07005781 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005782 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005783
5784 @Override
5785 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005786 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005787 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005788
5789 final long identity = Binder.clearCallingIdentity();
5790 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005791 ImsManager.getInstance(defaultPhone.getContext(),
5792 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 } finally {
5794 Binder.restoreCallingIdentity(identity);
5795 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005796 }
5797
5798 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005799 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005800 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005801 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5802 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005803 return false;
5804 }
Svet Ganovb320e182015-04-16 12:30:10 -07005805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 // Check the user preference and the system-level IMS setting. Even if the user has
5809 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5810 // In the long run, we may instead need to check if there exists a connection service
5811 // which can support video calling.
5812 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005813 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 return imsManager.isVtEnabledByPlatform()
5815 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5816 && imsManager.isVtEnabledByUser();
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
5819 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005820 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005821
Andrew Leea1239f22015-03-02 17:44:07 -08005822 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005823 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5824 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005825 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005826 mApp, subId, callingPackage, callingFeatureId,
5827 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828 return false;
5829 }
5830
5831 final long identity = Binder.clearCallingIdentity();
5832 try {
5833 CarrierConfigManager configManager =
5834 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005835 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005836 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
5839 }
Andrew Leea1239f22015-03-02 17:44:07 -08005840 }
5841
5842 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005843 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005845 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 return false;
5847 }
5848
5849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 CarrierConfigManager configManager =
5852 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005853 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5855 } finally {
5856 Binder.restoreCallingIdentity(identity);
5857 }
Andrew Leea1239f22015-03-02 17:44:07 -08005858 }
5859
Andrew Lee9431b832015-03-09 18:46:45 -07005860 @Override
5861 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07005862 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005863 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005864 }
5865
5866 @Override
5867 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 final long identity = Binder.clearCallingIdentity();
5869 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005870 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 } finally {
5872 Binder.restoreCallingIdentity(identity);
5873 }
Andrew Lee9431b832015-03-09 18:46:45 -07005874 }
5875
Hall Liuf6668912018-10-31 17:05:23 -07005876 /**
5877 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5878 * support for the feature and device firmware support.
5879 *
5880 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5881 */
5882 @Override
5883 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005885 final Phone phone = getPhone(subscriptionId);
5886 if (phone == null) {
5887 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5888 return false;
5889 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005891 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5893 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005894 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 return isCarrierSupported && isDeviceSupported;
5896 } finally {
5897 Binder.restoreCallingIdentity(identity);
5898 }
Hall Liu98187582018-01-22 19:15:32 -08005899 }
5900
Hall Liuf6668912018-10-31 17:05:23 -07005901 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005902 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5903 * RTT setting, will return true if the device and carrier both support RTT.
5904 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005905 */
5906 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005907 final long identity = Binder.clearCallingIdentity();
5908 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00005909 boolean isRttSupported = isRttSupported(subscriptionId);
5910 boolean isUserRttSettingOn = Settings.Secure.getInt(
5911 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
5912 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5913 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5914 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
5917 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005918 }
5919
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005920 @Deprecated
5921 @Override
5922 public String getDeviceId(String callingPackage) {
5923 return getDeviceIdWithFeature(callingPackage, null);
5924 }
5925
Sanket Padawe7310cc72015-01-14 09:53:20 -08005926 /**
5927 * Returns the unique device ID of phone, for example, the IMEI for
5928 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5929 *
5930 * <p>Requires Permission:
5931 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5932 */
5933 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005934 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005935 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005936 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005937 return null;
5938 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005939 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005940 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005941 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005942 return null;
5943 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944
5945 final long identity = Binder.clearCallingIdentity();
5946 try {
5947 return phone.getDeviceId();
5948 } finally {
5949 Binder.restoreCallingIdentity(identity);
5950 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005951 }
5952
Ping Sunc67b7c22016-03-02 19:16:45 +08005953 /**
5954 * {@hide}
5955 * Returns the IMS Registration Status on a particular subid
5956 *
5957 * @param subId
5958 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005959 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005960 Phone phone = getPhone(subId);
5961 if (phone != null) {
5962 return phone.isImsRegistered();
5963 } else {
5964 return false;
5965 }
5966 }
5967
Santos Cordon7a1885b2015-02-03 11:15:19 -08005968 @Override
5969 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005970 final long identity = Binder.clearCallingIdentity();
5971 try {
5972 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5973 } finally {
5974 Binder.restoreCallingIdentity(identity);
5975 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005976 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005977
Tyler Gunnf70ed162019-04-03 15:28:53 -07005978 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07005979 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005980 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005982 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07005983 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5984 }
5985 final long identity = Binder.clearCallingIdentity();
5986 try {
5987 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
5991 }
5992
5993 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005994 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 Phone phone = getPhone(subscriptionId);
5998 if (phone == null) {
5999 return null;
6000 }
6001 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
6005 }
6006
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006007 /**
6008 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006009 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006010 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 final long identity = Binder.clearCallingIdentity();
6012 try {
6013 Phone phone = getPhone(subId);
6014 if (phone != null) {
6015 return phone.isWifiCallingEnabled();
6016 } else {
6017 return false;
6018 }
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006021 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006022 }
6023
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006024 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006025 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006026 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006027 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 final long identity = Binder.clearCallingIdentity();
6029 try {
6030 Phone phone = getPhone(subId);
6031 if (phone != null) {
6032 return phone.isVideoEnabled();
6033 } else {
6034 return false;
6035 }
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006038 }
6039 }
6040
6041 /**
6042 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6043 * defined in {@link ImsRegistrationImplBase}.
6044 */
6045 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046 final long identity = Binder.clearCallingIdentity();
6047 try {
6048 Phone phone = getPhone(subId);
6049 if (phone != null) {
6050 return phone.getImsRegistrationTech();
6051 } else {
6052 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6053 }
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006056 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006057 }
6058
Stuart Scott8eef64f2015-04-08 15:13:54 -07006059 @Override
6060 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006061 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006062 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6063 return;
6064 }
6065
Svet Ganovcc087f82015-05-12 20:35:54 -07006066 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006067
Svet Ganovcc087f82015-05-12 20:35:54 -07006068 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006069 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6070 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006071 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006072 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006073 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006074 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6075 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006076 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006077 // There has been issues when Sms raw table somehow stores orphan
6078 // fragments. They lead to garbled message when new fragments come
6079 // in and combined with those stale ones. In case this happens again,
6080 // user can reset all network settings which will clean up this table.
6081 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006082 // Clean up IMS settings as well here.
6083 int slotId = getSlotIndex(subId);
6084 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6085 ImsManager.getInstance(mApp, slotId).factoryReset();
6086 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006087
6088 // Erase modem config if erase modem on network setting is enabled.
6089 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6090 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6091 if (configValue != null && Boolean.parseBoolean(configValue)) {
6092 sendEraseModemConfig(getDefaultPhone());
6093 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006094 } finally {
6095 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006096 }
6097 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006098
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006099 private void cleanUpSmsRawTable(Context context) {
6100 ContentResolver resolver = context.getContentResolver();
6101 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6102 resolver.delete(uri, null, null);
6103 }
6104
Narayan Kamath1c496c22015-04-16 14:40:19 +01006105 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006106 public String getSimLocaleForSubscriber(int subId) {
6107 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6108 final Phone phone = getPhone(subId);
6109 if (phone == null) {
6110 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006111 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 final long identity = Binder.clearCallingIdentity();
6114 try {
chen xu5d3637b2019-01-21 23:31:38 -08006115 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006116 phone.getContext().getOpPackageName(), phone.getContext().getFeatureId());
chen xu6291c472019-02-04 12:55:53 -08006117 if (info == null) {
6118 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6119 return null;
6120 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 // Try and fetch the locale from the carrier properties or from the SIM language
6122 // preferences (EF-PL and EF-LI)...
6123 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006124 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006125 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6126 if (localeFromDefaultSim != null) {
6127 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6128 if (DBG) log("Using locale from subId: " + subId + " locale: "
6129 + localeFromDefaultSim);
6130 return localeFromDefaultSim.toLanguageTag();
6131 } else {
6132 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 }
6134 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 // The SIM language preferences only store a language (e.g. fr = French), not an
6137 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6138 // the SIM and carrier preferences does not include a country we add the country
6139 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006140 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006142 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 return mccLocale.toLanguageTag();
6144 }
6145
6146 if (DBG) log("No locale found - returning null");
6147 return null;
6148 } finally {
6149 Binder.restoreCallingIdentity(identity);
6150 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006151 }
6152
6153 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006154 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6155 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006156 }
6157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 /**
6159 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6160 */
6161 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006162 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6163 mApp.getFeatureId());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006164 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006165
Chenjie Yu1ba97252018-01-11 18:16:20 -08006166 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006167 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006168
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006169 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006170 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6171 * representing the state of the modem.
6172 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006173 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6174 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006175 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006176 */
6177 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006178 public void requestModemActivityInfo(ResultReceiver result) {
6179 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006180 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181
6182 final long identity = Binder.clearCallingIdentity();
6183 try {
6184 ModemActivityInfo ret = null;
6185 synchronized (mLastModemActivityInfo) {
6186 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6187 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006188 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006189 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07006191 int[] txTimeMs = info.getTransmitTimeMillis();
6192 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07006194 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 }
6196 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006197 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6198 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 mLastModemActivityInfo.setIdleTimeMillis(
6200 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07006201 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6202 mLastModemActivityInfo.setReceiveTimeMillis(
6203 info.getReceiveTimeMillis() + mLastModemActivityInfo
6204 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006205 }
Chen Xud78231e2019-09-10 18:49:52 -07006206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6208 mLastModemActivityInfo.getSleepTimeMillis(),
6209 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07006210 mLastModemActivityInfo.getTransmitTimeMillis(),
6211 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006212 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 Bundle bundle = new Bundle();
6214 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6215 result.send(0, bundle);
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006218 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006219 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006220
Siddharth Rayb8114062018-06-17 15:02:38 -07006221 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6222 // less than total activity duration.
6223 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6224 if (info == null) {
6225 return false;
6226 }
6227 int activityDurationMs =
6228 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6229 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006230 int[] txTimeMs = info.getTransmitTimeMillis();
6231 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6232 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006233 }
6234 return (info.isValid()
6235 && (info.getSleepTimeMillis() <= activityDurationMs)
6236 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006237 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006238 && (totalTxTimeMs <= activityDurationMs));
6239 }
6240
Jack Yu85bd38a2015-11-09 11:34:32 -08006241 /**
6242 * {@hide}
6243 * Returns the service state information on specified subscription.
6244 */
6245 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006246 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6247 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006248 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006249 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006250 return null;
6251 }
6252
Hall Liuf19c44f2018-11-27 14:38:17 -08006253 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6254 LocationAccessPolicy.checkLocationPermission(mApp,
6255 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6256 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006257 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006258 .setCallingPid(Binder.getCallingPid())
6259 .setCallingUid(Binder.getCallingUid())
6260 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006261 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006262 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6263 .build());
6264
6265 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6266 LocationAccessPolicy.checkLocationPermission(mApp,
6267 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6268 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006269 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006270 .setCallingPid(Binder.getCallingPid())
6271 .setCallingUid(Binder.getCallingUid())
6272 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006273 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006274 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6275 .build());
6276 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6277 boolean hasFinePermission =
6278 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6279 boolean hasCoarsePermission =
6280 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6281
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 final Phone phone = getPhone(subId);
6285 if (phone == null) {
6286 return null;
6287 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006288
Hall Liuf19c44f2018-11-27 14:38:17 -08006289 ServiceState ss = phone.getServiceState();
6290
6291 // Scrub out the location info in ServiceState depending on what level of access
6292 // the caller has.
6293 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006294 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6295 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296 } finally {
6297 Binder.restoreCallingIdentity(identity);
6298 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006299 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006300
6301 /**
6302 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6303 *
6304 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6305 * voicemail ringtone.
6306 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6307 * PhoneAccount.
6308 */
6309 @Override
6310 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6314 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006315 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006316 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006322 }
6323
6324 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006325 * Sets the per-account voicemail ringtone.
6326 *
6327 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6328 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6329 *
6330 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6331 * voicemail ringtone.
6332 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6333 * PhoneAccount.
6334 */
6335 @Override
6336 public void setVoicemailRingtoneUri(String callingPackage,
6337 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006338 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006339 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006340 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6341 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6343 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6344 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6350 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006351 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 }
6353 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6354 } finally {
6355 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006356 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006357 }
6358
6359 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006360 * Returns whether vibration is set for voicemail notification in Phone settings.
6361 *
6362 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6363 * voicemail vibration setting.
6364 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6365 */
6366 @Override
6367 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 final long identity = Binder.clearCallingIdentity();
6369 try {
6370 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6371 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006372 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006374
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006379 }
6380
Youhan Wange64578a2016-05-02 15:32:42 -07006381 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006382 * Sets the per-account voicemail vibration.
6383 *
6384 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6385 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6386 *
6387 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6388 * voicemail vibration setting.
6389 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6390 * specific PhoneAccount.
6391 */
6392 @Override
6393 public void setVoicemailVibrationEnabled(String callingPackage,
6394 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006395 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006396 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006397 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6398 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6400 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6401 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006402 }
6403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6407 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006408 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 }
6410 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006413 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006414 }
6415
6416 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006417 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6418 *
6419 * @throws SecurityException if the caller does not have the required permission
6420 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006421 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006423 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006424 }
6425
6426 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006427 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6428 * permission.
6429 *
6430 * @throws SecurityException if the caller does not have the required permission
6431 */
6432 private void enforceSendSmsPermission() {
6433 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6434 }
6435
6436 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006437 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006438 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006439 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006440 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006441 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
6444 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006445 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 if (componentName == null) {
6447 throw new SecurityException(
6448 "Caller not current active visual voicemail package[null]");
6449 }
6450 String vvmPackage = componentName.getPackageName();
6451 if (!callingPackage.equals(vvmPackage)) {
6452 throw new SecurityException("Caller not current active visual voicemail package["
6453 + vvmPackage + "]");
6454 }
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006457 }
6458 }
6459
6460 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006461 * Return the application ID for the app type.
6462 *
6463 * @param subId the subscription ID that this request applies to.
6464 * @param appType the uicc app type.
6465 * @return Application ID for specificied app type, or null if no uicc.
6466 */
6467 @Override
6468 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006469 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006470 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006471
6472 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006473 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006474 if (phone == null) {
6475 return null;
6476 }
6477 String aid = null;
6478 try {
6479 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6480 .getApplicationByType(appType).getAid();
6481 } catch (Exception e) {
6482 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6483 }
6484 return aid;
6485 } finally {
6486 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006487 }
Youhan Wange64578a2016-05-02 15:32:42 -07006488 }
6489
Youhan Wang4001d252016-05-11 10:29:41 -07006490 /**
6491 * Return the Electronic Serial Number.
6492 *
6493 * @param subId the subscription ID that this request applies to.
6494 * @return ESN or null if error.
6495 */
6496 @Override
6497 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006498 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006499 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500
6501 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006502 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 if (phone == null) {
6504 return null;
6505 }
6506 String esn = null;
6507 try {
6508 esn = phone.getEsn();
6509 } catch (Exception e) {
6510 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6511 }
6512 return esn;
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006515 }
Youhan Wang4001d252016-05-11 10:29:41 -07006516 }
6517
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006518 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006519 * Return the Preferred Roaming List Version.
6520 *
6521 * @param subId the subscription ID that this request applies to.
6522 * @return PRLVersion or null if error.
6523 */
6524 @Override
6525 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006526 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006527 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528
6529 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006530 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 if (phone == null) {
6532 return null;
6533 }
6534 String cdmaPrlVersion = null;
6535 try {
6536 cdmaPrlVersion = phone.getCdmaPrlVersion();
6537 } catch (Exception e) {
6538 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6539 }
6540 return cdmaPrlVersion;
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006543 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006544 }
6545
6546 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006547 * Get snapshot of Telephony histograms
6548 * @return List of Telephony histograms
6549 * @hide
6550 */
6551 @Override
6552 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6554 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555
6556 final long identity = Binder.clearCallingIdentity();
6557 try {
6558 return RIL.getTelephonyRILTimingHistograms();
6559 } finally {
6560 Binder.restoreCallingIdentity(identity);
6561 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006562 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006563
6564 /**
6565 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006566 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6567 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006568 * Require system privileges. In the future we may add this to carrier APIs.
6569 *
Michele Berionne482f8202018-11-27 18:57:59 -08006570 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006571 */
6572 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006573 @TelephonyManager.SetCarrierRestrictionResult
6574 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006575 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006576 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006577
Michele Berionne482f8202018-11-27 18:57:59 -08006578 if (carrierRestrictionRules == null) {
6579 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006580 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006581
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006582 final long identity = Binder.clearCallingIdentity();
6583 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006584 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006585 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006589 }
6590
6591 /**
6592 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006593 * Get the allowed carrier list and the excluded carrier list, including the priority between
6594 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006595 * Require system privileges. In the future we may add this to carrier APIs.
6596 *
Michele Berionne482f8202018-11-27 18:57:59 -08006597 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006598 */
6599 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006600 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006601 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006602 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603
6604 final long identity = Binder.clearCallingIdentity();
6605 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006606 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6607 if (response instanceof CarrierRestrictionRules) {
6608 return (CarrierRestrictionRules) response;
6609 }
6610 // Response is an Exception of some kind,
6611 // which is signalled to the user as a NULL retval
6612 return null;
6613 } catch (Exception e) {
6614 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6615 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616 } finally {
6617 Binder.restoreCallingIdentity(identity);
6618 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006619 }
6620
fionaxu59545b42016-05-25 15:53:37 -07006621 /**
6622 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6623 * @param subId the subscription ID that this action applies to.
6624 * @param enabled control enable or disable metered apns.
6625 * {@hide}
6626 */
6627 @Override
6628 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6629 enforceModifyPermission();
6630 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006631
6632 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006633 if (phone == null) {
6634 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6635 return;
6636 }
6637 try {
6638 phone.carrierActionSetMeteredApnsEnabled(enabled);
6639 } catch (Exception e) {
6640 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006641 } finally {
6642 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006643 }
6644 }
6645
6646 /**
6647 * Action set from carrier signalling broadcast receivers to enable/disable radio
6648 * @param subId the subscription ID that this action applies to.
6649 * @param enabled control enable or disable radio.
6650 * {@hide}
6651 */
6652 @Override
6653 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6654 enforceModifyPermission();
6655 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006658 if (phone == null) {
6659 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6660 return;
6661 }
6662 try {
6663 phone.carrierActionSetRadioEnabled(enabled);
6664 } catch (Exception e) {
6665 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006666 } finally {
6667 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006668 }
6669 }
6670
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006671 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006672 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6673 * network status based on which carrier apps could apply actions accordingly,
6674 * enable/disable default url handler for example.
6675 *
6676 * @param subId the subscription ID that this action applies to.
6677 * @param report control start/stop reporting the default network status.
6678 * {@hide}
6679 */
6680 @Override
6681 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6682 enforceModifyPermission();
6683 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684
6685 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006686 if (phone == null) {
6687 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6688 return;
6689 }
6690 try {
6691 phone.carrierActionReportDefaultNetworkStatus(report);
6692 } catch (Exception e) {
6693 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 } finally {
6695 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006696 }
6697 }
6698
6699 /**
fionaxud9622282017-07-17 17:51:30 -07006700 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6701 * @param subId the subscription ID that this action applies to.
6702 * {@hide}
6703 */
6704 @Override
6705 public void carrierActionResetAll(int subId) {
6706 enforceModifyPermission();
6707 final Phone phone = getPhone(subId);
6708 if (phone == null) {
6709 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6710 return;
6711 }
6712 try {
6713 phone.carrierActionResetAll();
6714 } catch (Exception e) {
6715 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6716 }
6717 }
6718
6719 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006720 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6721 * bug report is being generated.
6722 */
6723 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006724 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006725 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6726 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006727 writer.println("Permission Denial: can't dump Phone from pid="
6728 + Binder.getCallingPid()
6729 + ", uid=" + Binder.getCallingUid()
6730 + "without permission "
6731 + android.Manifest.permission.DUMP);
6732 return;
6733 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006735 }
Jack Yueb89b242016-06-22 13:27:47 -07006736
Brad Ebingerdac2f002018-04-03 15:17:52 -07006737 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08006738 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
6739 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
6740 @NonNull String[] args) {
6741 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
6742 this, in.getFileDescriptor(), out.getFileDescriptor(),
6743 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006744 }
6745
Jack Yueb89b242016-06-22 13:27:47 -07006746 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006747 * Get aggregated video call data usage since boot.
6748 *
6749 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6750 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006751 * {@hide}
6752 */
6753 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006754 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006755 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6756 null);
6757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 // NetworkStatsService keeps tracking the active network interface and identity. It
6761 // records the delta with the corresponding network identity.
6762 // We just return the total video call data usage snapshot since boot.
6763 Phone phone = getPhone(subId);
6764 if (phone != null) {
6765 return phone.getVtDataUsage(perUidStats);
6766 }
6767 return null;
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006770 }
Jack Yueb89b242016-06-22 13:27:47 -07006771 }
Jack Yu75ab2952016-07-08 14:29:33 -07006772
6773 /**
6774 * Policy control of data connection. Usually used when data limit is passed.
6775 * @param enabled True if enabling the data, otherwise disabling.
6776 * @param subId Subscription index
6777 * {@hide}
6778 */
6779 @Override
6780 public void setPolicyDataEnabled(boolean enabled, int subId) {
6781 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782
6783 final long identity = Binder.clearCallingIdentity();
6784 try {
6785 Phone phone = getPhone(subId);
6786 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006787 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006788 }
6789 } finally {
6790 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006791 }
6792 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006793
6794 /**
6795 * Get Client request stats
6796 * @return List of Client Request Stats
6797 * @hide
6798 */
6799 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006800 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6801 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006803 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006804 return null;
6805 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006806 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 if (phone != null) {
6811 return phone.getClientRequestStats();
6812 }
6813
6814 return null;
6815 } finally {
6816 Binder.restoreCallingIdentity(identity);
6817 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006818 }
6819
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006820 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006821 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006822 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006823 }
Jack Yueb4124c2017-02-16 15:32:43 -08006824
6825 /**
Grace Chen70990072017-03-24 17:21:30 -07006826 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006827 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006828 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006829 * @param state State of SIM (power down, power up, pass through)
6830 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6831 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6832 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006833 *
6834 **/
6835 @Override
Grace Chen70990072017-03-24 17:21:30 -07006836 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006837 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006838 Phone phone = PhoneFactory.getPhone(slotIndex);
6839
vagdeviaf9a5b92018-08-15 16:01:53 -07006840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 final long identity = Binder.clearCallingIdentity();
6843 try {
6844 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006845 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846 }
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006849 }
6850 }
Shuo Qiandd210312017-04-12 22:11:33 +00006851
Tyler Gunn65d45c22017-06-05 11:22:26 -07006852 private boolean isUssdApiAllowed(int subId) {
6853 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006854 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006855 if (configManager == null) {
6856 return false;
6857 }
6858 PersistableBundle pb = configManager.getConfigForSubId(subId);
6859 if (pb == null) {
6860 return false;
6861 }
6862 return pb.getBoolean(
6863 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6864 }
6865
Shuo Qiandd210312017-04-12 22:11:33 +00006866 /**
6867 * Check if phone is in emergency callback mode
6868 * @return true if phone is in emergency callback mode
6869 * @param subId sub id
6870 */
goneil9c5f4872017-12-05 14:07:56 -08006871 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006872 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006873 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006874 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 if (phone != null) {
6879 return phone.isInEcm();
6880 } else {
6881 return false;
6882 }
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006885 }
6886 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006887
6888 /**
6889 * Get the current signal strength information for the given subscription.
6890 * Because this information is not updated when the device is in a low power state
6891 * it should not be relied-upon to be current.
6892 * @param subId Subscription index
6893 * @return the most recent cached signal strength info from the modem
6894 */
6895 @Override
6896 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 final long identity = Binder.clearCallingIdentity();
6898 try {
6899 Phone p = getPhone(subId);
6900 if (p == null) {
6901 return null;
6902 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 return p.getSignalStrength();
6905 } finally {
6906 Binder.restoreCallingIdentity(identity);
6907 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006908 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006909
Pengquan Meng77b7f132018-08-22 14:49:57 -07006910 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006911 * Get the current modem radio state for the given slot.
6912 * @param slotIndex slot index.
6913 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006914 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006915 * @return the current radio power state from the modem
6916 */
6917 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006918 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006919 Phone phone = PhoneFactory.getPhone(slotIndex);
6920 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6922 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006923 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6924 }
6925
6926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 return phone.getRadioPowerState();
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
6932 }
6933 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6934 }
6935
6936 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006937 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6938 *
6939 * <p>Requires one of the following permissions:
6940 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6941 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6942 * privileges.
6943 *
6944 * @param subId subscription id
6945 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6946 * {@code false}.
6947 */
6948 @Override
6949 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006950 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6951 null /* message */);
6952
Pengquan Menga1bb6272018-09-06 09:59:22 -07006953 boolean isEnabled = false;
6954 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006955 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006956 Phone phone = getPhone(subId);
6957 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006958 } catch (Exception e) {
6959 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6960 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006961 } finally {
6962 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006963 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006964 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006965 }
6966
6967
6968 /**
6969 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6970 *
6971 * <p> Requires permission:
6972 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6973 * privileges.
6974 *
6975 * @param subId subscription id
6976 * @param isEnabled {@code true} means enable, {@code false} means disable.
6977 */
6978 @Override
6979 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006980 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6981 mApp, subId, "setDataRoamingEnabled");
6982
Pengquan Menga1bb6272018-09-06 09:59:22 -07006983 final long identity = Binder.clearCallingIdentity();
6984 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006985 Phone phone = getPhone(subId);
6986 if (phone != null) {
6987 phone.setDataRoamingEnabled(isEnabled);
6988 }
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006991 }
6992 }
6993
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006994 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006995 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006996 TelephonyPermissions
6997 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006998 mApp, subId, "isManualNetworkSelectionAllowed");
6999
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007000 boolean isAllowed = true;
7001 final long identity = Binder.clearCallingIdentity();
7002 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007003 Phone phone = getPhone(subId);
7004 if (phone != null) {
7005 isAllowed = phone.isCspPlmnEnabled();
7006 }
7007 } finally {
7008 Binder.restoreCallingIdentity(identity);
7009 }
7010 return isAllowed;
7011 }
7012
7013 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007014 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007015 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007016 try {
7017 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007018 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007019 } catch (SecurityException e) {
7020 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7021 // has carrier privileges on an active UICC
7022 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7023 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007024 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007025 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007026 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007027
7028 final long identity = Binder.clearCallingIdentity();
7029 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007030 UiccController uiccController = UiccController.getInstance();
7031 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007032 if (hasReadPermission) {
7033 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007034 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007035
7036 // Remove private info if the caller doesn't have access
7037 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7038 for (UiccCardInfo cardInfo : cardInfos) {
7039 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7040 // is available
7041 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7042 if (card == null || card.getUiccProfile() == null) {
7043 // assume no access if the card or profile is unavailable
7044 filteredInfos.add(cardInfo.getUnprivileged());
7045 continue;
7046 }
7047 UiccProfile profile = card.getUiccProfile();
7048 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7049 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7050 filteredInfos.add(cardInfo);
7051 } else {
7052 filteredInfos.add(cardInfo.getUnprivileged());
7053 }
7054 }
7055 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007056 } finally {
7057 Binder.restoreCallingIdentity(identity);
7058 }
7059 }
7060
7061 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007062 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007063 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 final long identity = Binder.clearCallingIdentity();
7066 try {
7067 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7068 if (slots == null) {
7069 Rlog.i(LOG_TAG, "slots is null.");
7070 return null;
7071 }
7072
7073 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7074 for (int i = 0; i < slots.length; i++) {
7075 UiccSlot slot = slots[i];
7076 if (slot == null) {
7077 continue;
7078 }
7079
Jordan Liu7be7e652019-05-06 18:55:02 +00007080 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 UiccCard card = slot.getUiccCard();
7082 if (card != null) {
7083 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007084 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007085 cardId = slot.getEid();
7086 if (TextUtils.isEmpty(cardId)) {
7087 cardId = slot.getIccId();
7088 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007089 }
7090
Jordan Liu857451f2019-05-09 16:35:35 -07007091 if (cardId != null) {
7092 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7093 // if cardId is an EID, it's all digits so this is fine
7094 cardId = IccUtils.stripTrailingFs(cardId);
7095 }
7096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007097 int cardState = 0;
7098 switch (slot.getCardState()) {
7099 case CARDSTATE_ABSENT:
7100 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7101 break;
7102 case CARDSTATE_PRESENT:
7103 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7104 break;
7105 case CARDSTATE_ERROR:
7106 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7107 break;
7108 case CARDSTATE_RESTRICTED:
7109 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7110 break;
7111 default:
7112 break;
7113
7114 }
7115
7116 infos[i] = new UiccSlotInfo(
7117 slot.isActive(),
7118 slot.isEuicc(),
7119 cardId,
7120 cardState,
7121 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007122 slot.isExtendedApduSupported(),
7123 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124 }
7125 return infos;
7126 } finally {
7127 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007128 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007129 }
7130
7131 @Override
7132 public boolean switchSlots(int[] physicalSlots) {
7133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134
7135 final long identity = Binder.clearCallingIdentity();
7136 try {
7137 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7138 } finally {
7139 Binder.restoreCallingIdentity(identity);
7140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007141 }
Jack Yu4c988042018-02-27 15:30:01 -08007142
7143 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007144 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007145 final long identity = Binder.clearCallingIdentity();
7146 try {
7147 return UiccController.getInstance().getCardIdForDefaultEuicc();
7148 } finally {
7149 Binder.restoreCallingIdentity(identity);
7150 }
7151 }
7152
7153 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007154 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7155 enforceModifyPermission();
7156 final Phone phone = getPhone(subId);
7157 if (phone == null) {
7158 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7159 return;
7160 }
7161
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 phone.setRadioIndicationUpdateMode(filters, mode);
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
Jack Yu4c988042018-02-27 15:30:01 -08007168 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007169
7170 /**
goneil47ffb6e2018-04-06 15:40:58 -07007171 * A test API to reload the UICC profile.
7172 *
7173 * <p>Requires that the calling app has permission
7174 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7175 * @hide
7176 */
7177 @Override
7178 public void refreshUiccProfile(int subId) {
7179 enforceModifyPermission();
7180
7181 final long identity = Binder.clearCallingIdentity();
7182 try {
7183 Phone phone = getPhone(subId);
7184 if (phone == null) {
7185 return;
7186 }
7187 UiccCard uiccCard = phone.getUiccCard();
7188 if (uiccCard == null) {
7189 return;
7190 }
7191 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7192 if (uiccProfile == null) {
7193 return;
7194 }
7195 uiccProfile.refresh();
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
7198 }
7199 }
7200
7201 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007202 * Returns false if the mobile data is disabled by default, otherwise return true.
7203 */
7204 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007205 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007206 }
7207
7208 /**
7209 * Returns true if the data roaming is enabled by default, i.e the system property
7210 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7211 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7212 */
7213 private boolean getDefaultDataRoamingEnabled(int subId) {
7214 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007215 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007216 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007217 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7218 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7219 return isDataRoamingEnabled;
7220 }
7221
7222 /**
7223 * Returns the default network type for the given {@code subId}, if the default network type is
7224 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7225 */
7226 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007227 List<Integer> list = TelephonyProperties.default_network();
7228 int phoneId = mSubscriptionController.getPhoneId(subId);
7229 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7230 return list.get(phoneId);
7231 }
7232 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007233 }
fionaxua13278b2018-03-21 00:08:13 -07007234
7235 @Override
7236 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007237 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 final Phone phone = getPhone(subId);
7243 if (phone == null) {
7244 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7245 return;
7246 }
chen xueaba88a2019-03-15 13:15:10 -07007247 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7248 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007249 } finally {
7250 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007251 }
fionaxua13278b2018-03-21 00:08:13 -07007252 }
7253
7254 @Override
7255 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007256 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257
7258 final long identity = Binder.clearCallingIdentity();
7259 try {
7260 final Phone phone = getPhone(subId);
7261 if (phone == null) {
7262 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7263 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7264 }
7265 return phone.getCarrierIdListVersion();
7266 } finally {
7267 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007268 }
fionaxua13278b2018-03-21 00:08:13 -07007269 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007270
7271 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007272 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7273 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007275 mApp, subId, callingPackage, callingFeatureId,
7276 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007277 return -1;
7278 }
7279
7280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
7285 }
7286 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007287
7288 @Override
7289 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007290 TelephonyPermissions
7291 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007292 mApp, subId, "getCdmaRoamingMode");
7293
7294 final long identity = Binder.clearCallingIdentity();
7295 try {
7296 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
7299 }
7300 }
7301
7302 @Override
7303 public boolean setCdmaRoamingMode(int subId, int mode) {
7304 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7305 mApp, subId, "setCdmaRoamingMode");
7306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7310 } finally {
7311 Binder.restoreCallingIdentity(identity);
7312 }
7313 }
7314
7315 @Override
7316 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7318 mApp, subId, "setCdmaSubscriptionMode");
7319
7320 final long identity = Binder.clearCallingIdentity();
7321 try {
7322 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007327
sqianc5eccab2018-10-19 18:46:41 -07007328 @Override
sqian8c685422019-02-22 15:55:18 -08007329 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007330 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007332 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7333 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007334 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7335 }
7336 final long identity = Binder.clearCallingIdentity();
7337 try {
sqian854d44b2018-12-12 16:48:18 -08007338 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7339 for (Phone phone: PhoneFactory.getPhones()) {
7340 if (phone.getEmergencyNumberTracker() != null
7341 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7342 emergencyNumberListInternal.put(
7343 phone.getSubId(),
7344 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7345 }
sqian11b7a0e2018-12-05 18:48:28 -08007346 }
sqian854d44b2018-12-12 16:48:18 -08007347 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007348 } finally {
7349 Binder.restoreCallingIdentity(identity);
7350 }
sqianc5eccab2018-10-19 18:46:41 -07007351 }
7352
7353 @Override
sqian8c685422019-02-22 15:55:18 -08007354 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007355 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007356 if (!exactMatch) {
7357 TelephonyPermissions
7358 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007359 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007360 }
7361 final long identity = Binder.clearCallingIdentity();
7362 try {
sqian854d44b2018-12-12 16:48:18 -08007363 for (Phone phone: PhoneFactory.getPhones()) {
7364 if (phone.getEmergencyNumberTracker() != null
7365 && phone.getEmergencyNumberTracker() != null) {
7366 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7367 number, exactMatch)) {
7368 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007369 }
7370 }
sqian11b7a0e2018-12-05 18:48:28 -08007371 }
7372 return false;
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
7376 }
7377
sqianf4ca7ed2019-01-15 18:32:07 -08007378 /**
7379 * Update emergency number list for test mode.
7380 */
7381 @Override
7382 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7383 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7384 "updateEmergencyNumberListTestMode");
7385
7386 final long identity = Binder.clearCallingIdentity();
7387 try {
7388 for (Phone phone: PhoneFactory.getPhones()) {
7389 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7390 if (tracker != null) {
7391 tracker.executeEmergencyNumberTestModeCommand(action, num);
7392 }
7393 }
7394 } finally {
7395 Binder.restoreCallingIdentity(identity);
7396 }
7397 }
7398
7399 /**
7400 * Get the full emergency number list for test mode.
7401 */
7402 @Override
7403 public List<String> getEmergencyNumberListTestMode() {
7404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7405 "getEmergencyNumberListTestMode");
7406
7407 final long identity = Binder.clearCallingIdentity();
7408 try {
7409 Set<String> emergencyNumbers = new HashSet<>();
7410 for (Phone phone: PhoneFactory.getPhones()) {
7411 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7412 if (tracker != null) {
7413 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7414 emergencyNumbers.add(num.getNumber());
7415 }
7416 }
7417 }
7418 return new ArrayList<>(emergencyNumbers);
7419 } finally {
7420 Binder.restoreCallingIdentity(identity);
7421 }
7422 }
7423
chen xud6b45bd2018-10-30 22:27:10 -07007424 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007425 public int getEmergencyNumberDbVersion(int subId) {
7426 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7427
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
7430 final Phone phone = getPhone(subId);
7431 if (phone == null) {
7432 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7433 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7434 }
7435 return phone.getEmergencyNumberDbVersion();
7436 } finally {
7437 Binder.restoreCallingIdentity(identity);
7438 }
7439 }
7440
7441 @Override
7442 public void notifyOtaEmergencyNumberDbInstalled() {
7443 enforceModifyPermission();
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 for (Phone phone: PhoneFactory.getPhones()) {
7448 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7449 if (tracker != null) {
7450 tracker.updateOtaEmergencyNumberDatabase();
7451 }
7452 }
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
7456 }
7457
7458 @Override
7459 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7460 enforceActiveEmergencySessionPermission();
7461
7462 final long identity = Binder.clearCallingIdentity();
7463 try {
7464 for (Phone phone: PhoneFactory.getPhones()) {
7465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7466 if (tracker != null) {
7467 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7468 }
7469 }
7470 } finally {
7471 Binder.restoreCallingIdentity(identity);
7472 }
7473 }
7474
7475 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007476 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7477 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7478 Phone phone = getPhone(subId);
7479 if (phone == null) {
7480 return null;
7481 }
7482 final long identity = Binder.clearCallingIdentity();
7483 try {
7484 UiccProfile profile = UiccController.getInstance()
7485 .getUiccProfileForPhone(phone.getPhoneId());
7486 if (profile != null) {
7487 return profile.getCertsFromCarrierPrivilegeAccessRules();
7488 }
7489 } finally {
7490 Binder.restoreCallingIdentity(identity);
7491 }
7492 return null;
7493 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007494
7495 /**
7496 * Enable or disable a modem stack.
7497 */
7498 @Override
7499 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7500 enforceModifyPermission();
7501
7502 final long identity = Binder.clearCallingIdentity();
7503 try {
7504 Phone phone = PhoneFactory.getPhone(slotIndex);
7505 if (phone == null) {
7506 return false;
7507 } else {
7508 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7509 }
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
7512 }
7513 }
Michelecea4cf22018-12-21 15:00:11 -08007514
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007515 /**
7516 * Whether a modem stack is enabled or not.
7517 */
7518 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007519 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7520 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007521 Phone phone = PhoneFactory.getPhone(slotIndex);
7522 if (phone == null) return false;
7523
7524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007525 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7526 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007527 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7528 }
7529
7530 final long identity = Binder.clearCallingIdentity();
7531 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007532 try {
7533 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7534 } catch (NoSuchElementException ex) {
7535 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7536 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007537 } finally {
7538 Binder.restoreCallingIdentity(identity);
7539 }
7540 }
7541
Michelecea4cf22018-12-21 15:00:11 -08007542 @Override
Michele0ea7d782019-03-19 14:58:42 -07007543 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007544 enforceModifyPermission();
7545
7546 final long identity = Binder.clearCallingIdentity();
7547 try {
7548 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007549 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007550 .commit();
7551 } finally {
7552 Binder.restoreCallingIdentity(identity);
7553 }
7554 }
7555
7556 @Override
Michele0ea7d782019-03-19 14:58:42 -07007557 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007558 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007560 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7561 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007562 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007563 }
Michelecea4cf22018-12-21 15:00:11 -08007564
7565 final long identity = Binder.clearCallingIdentity();
7566 try {
Michele0ea7d782019-03-19 14:58:42 -07007567 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007568 } finally {
7569 Binder.restoreCallingIdentity(identity);
7570 }
7571 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007572
Michele0ea7d782019-03-19 14:58:42 -07007573 @TelephonyManager.IsMultiSimSupportedResult
7574 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007575 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7576 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7577 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007578 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7579 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007580 }
7581 // Check if the hardware supports multisim functionality. If usage of multisim is not
7582 // supported by the modem, indicate that it is restricted.
7583 PhoneCapability staticCapability =
7584 mPhoneConfigurationManager.getStaticPhoneCapability();
7585 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007586 loge("isMultiSimSupportedInternal: no static configuration available");
7587 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007588 }
7589 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007590 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7591 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007592 }
7593 // Check if support of multiple SIMs is restricted by carrier
7594 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007595 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007596 }
7597
Michele0ea7d782019-03-19 14:58:42 -07007598 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007599 }
7600
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007601 /**
7602 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007603 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7604 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7605 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007606 * @param numOfSims number of active sims we want to switch to
7607 */
7608 @Override
7609 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007610 if (numOfSims == 1) {
7611 enforceModifyPermission();
7612 } else {
7613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7614 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7615 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007616 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007617
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007618 try {
Michele30b57b22019-03-01 12:01:14 -08007619 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007620 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007621 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7622 return;
7623 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007624 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7625 } finally {
7626 Binder.restoreCallingIdentity(identity);
7627 }
7628 }
7629
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007630 @Override
7631 public boolean isApplicationOnUicc(int subId, int appType) {
7632 enforceReadPrivilegedPermission("isApplicationOnUicc");
7633 Phone phone = getPhone(subId);
7634 if (phone == null) {
7635 return false;
7636 }
7637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 UiccCard uiccCard = phone.getUiccCard();
7640 if (uiccCard == null) {
7641 return false;
7642 }
7643 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7644 if (uiccProfile == null) {
7645 return false;
7646 }
7647 if (TelephonyManager.APPTYPE_SIM <= appType
7648 && appType <= TelephonyManager.APPTYPE_ISIM) {
7649 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7650 }
7651 return false;
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
7655 }
7656
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007657 /**
chen xub4baa772019-04-03 10:23:41 -07007658 * Get whether making changes to modem configurations will trigger reboot.
7659 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007660 */
7661 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007662 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7663 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007664 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007665 mApp, subId, callingPackage, callingFeatureId,
7666 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007667 return false;
7668 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
7675 }
7676
Nathan Harold29f5f052019-02-15 13:41:57 -08007677 private void updateModemStateMetrics() {
7678 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7679 // TODO: check the state for each modem if the api is ready.
7680 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7681 }
7682
Pengquan Meng3889a572019-01-23 11:16:29 -08007683 @Override
7684 public int[] getSlotsMapping() {
7685 enforceReadPrivilegedPermission("getSlotsMapping");
7686
7687 final long identity = Binder.clearCallingIdentity();
7688 try {
7689 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7690 // All logical slots should have a mapping to a physical slot.
7691 int[] logicalSlotsMapping = new int[phoneCount];
7692 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7693 for (int i = 0; i < slotInfos.length; i++) {
7694 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7695 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7696 }
7697 }
7698 return logicalSlotsMapping;
7699 } finally {
7700 Binder.restoreCallingIdentity(identity);
7701 }
7702 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007703
7704 /**
7705 * Get the IRadio HAL Version
7706 */
7707 @Override
7708 public int getRadioHalVersion() {
7709 Phone phone = getDefaultPhone();
7710 if (phone == null) return -1;
7711 HalVersion hv = phone.getHalVersion();
7712 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7713 return hv.major * 100 + hv.minor;
7714 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007715
7716 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007717 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7718 * corresponding network requests on a subId.
7719 *
7720 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007721 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007722 * 2) APN is un-metered for this subscription, or
7723 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08007724 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07007725 *
7726 * @return whether data is allowed for a apn type.
7727 *
7728 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007729 */
7730 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007731 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007732 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7733 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007734
7735 // Now that all security checks passes, perform the operation as ourselves.
7736 final long identity = Binder.clearCallingIdentity();
7737 try {
7738 Phone phone = getPhone(subId);
7739 if (phone == null) return false;
7740
Jack Yu41407ee2019-05-13 16:54:09 -07007741 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007742 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7743 } finally {
7744 Binder.restoreCallingIdentity(identity);
7745 }
7746 }
7747
7748 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007749 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007750 enforceReadPrivilegedPermission("isApnMetered");
7751
7752 // Now that all security checks passes, perform the operation as ourselves.
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 Phone phone = getPhone(subId);
7756 if (phone == null) return true; // By default return true.
7757
Jack Yu41407ee2019-05-13 16:54:09 -07007758 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007759 } finally {
7760 Binder.restoreCallingIdentity(identity);
7761 }
7762 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007763
7764 @Override
changbetty7157e9e2019-12-06 18:16:37 +08007765 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
7766 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
7767 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
7768 if (iccRecords == null) {
7769 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
7770 return false;
7771 }
7772 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
7773 }
7774
7775 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07007776 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7777 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7778 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7779 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7780 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7781 }
7782 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7783 Intent intent = new Intent();
7784 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7785 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7786 // Bring up choose default SMS subscription dialog right now
7787 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7788 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7789 mApp.startActivity(intent);
7790 }
chen xud5ca2d52019-05-28 15:20:57 -07007791
7792 @Override
7793 public String getMmsUAProfUrl(int subId) {
7794 //TODO investigate if this API should require proper permission check in R b/133791609
7795 final long identity = Binder.clearCallingIdentity();
7796 try {
7797 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7798 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7799 } finally {
7800 Binder.restoreCallingIdentity(identity);
7801 }
7802 }
7803
7804 @Override
7805 public String getMmsUserAgent(int subId) {
7806 //TODO investigate if this API should require proper permission check in R b/133791609
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
7809 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7810 .getString(com.android.internal.R.string.config_mms_user_agent);
7811 } finally {
7812 Binder.restoreCallingIdentity(identity);
7813 }
7814 }
Jack Yub07d4972019-05-28 16:12:25 -07007815
7816 @Override
7817 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7818 enforceModifyPermission();
7819
7820 // Now that all security checks passes, perform the operation as ourselves.
7821 final long identity = Binder.clearCallingIdentity();
7822 try {
7823 Phone phone = getPhone(subId);
7824 if (phone == null) return false;
7825
7826 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7827 } finally {
7828 Binder.restoreCallingIdentity(identity);
7829 }
7830 }
7831
7832 @Override
7833 public boolean isDataAllowedInVoiceCall(int subId) {
7834 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7835
7836 // Now that all security checks passes, perform the operation as ourselves.
7837 final long identity = Binder.clearCallingIdentity();
7838 try {
7839 Phone phone = getPhone(subId);
7840 if (phone == null) return false;
7841
7842 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7843 } finally {
7844 Binder.restoreCallingIdentity(identity);
7845 }
7846 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007847
changbettyd5c246e2019-12-24 15:40:37 +08007848 @Override
7849 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
7850 enforceModifyPermission();
7851
7852 // Now that all security checks passes, perform the operation as ourselves.
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 Phone phone = getPhone(subId);
7856 if (phone == null) return false;
7857
7858 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
7859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
7862 }
7863
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007864 /**
7865 * Updates whether conference event pacakge handling is enabled.
7866 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7867 * otherwise.
7868 */
7869 @Override
7870 public void setCepEnabled(boolean isCepEnabled) {
7871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7872
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7876 for (Phone phone : PhoneFactory.getPhones()) {
7877 Phone defaultPhone = phone.getImsPhone();
7878 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7879 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7880 ImsPhoneCallTracker imsPhoneCallTracker =
7881 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7882 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7883 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7884 + imsPhone.getMsisdn());
7885 }
7886 }
7887 } finally {
7888 Binder.restoreCallingIdentity(identity);
7889 }
7890 }
allenwtsu46dcc572020-01-08 18:24:03 +08007891
7892 /**
7893 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
7894 *
7895 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
7896 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
7897 * before being read.
7898 */
7899 @Override
7900 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
7901 isCompressed) {
7902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7903 mApp, subId, "notifyRcsAutoConfigurationReceived");
7904 try {
7905 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
7906 if (configBinder == null) {
7907 Rlog.e(LOG_TAG, "null result for getImsConfig");
7908 } else {
7909 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
7910 }
7911 } catch (RemoteException e) {
7912 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
7913 }
7914 }
zoey chene02881a2019-12-30 16:11:23 +08007915
7916 @Override
7917 public boolean isIccLockEnabled(int subId) {
7918 enforceReadPrivilegedPermission("isIccLockEnabled");
7919
7920 // Now that all security checks passes, perform the operation as ourselves.
7921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 Phone phone = getPhone(subId);
7924 if (phone != null && phone.getIccCard() != null) {
7925 return phone.getIccCard().getIccLockEnabled();
7926 } else {
7927 return false;
7928 }
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
7932 }
7933
7934 /**
7935 * Set the ICC pin lock enabled or disabled.
7936 *
7937 * @return an integer representing the status of IccLock enabled or disabled in the following
7938 * three cases:
7939 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
7940 * successfully.
7941 * - Positive number and zero for remaining password attempts.
7942 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
7943 *
7944 */
7945 @Override
7946 public int setIccLockEnabled(int subId, boolean enabled, String password) {
7947 enforceModifyPermission();
7948
7949 Phone phone = getPhone(subId);
7950 if (phone == null) {
7951 return 0;
7952 }
7953 // Now that all security checks passes, perform the operation as ourselves.
7954 final long identity = Binder.clearCallingIdentity();
7955 try {
7956 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
7957 new Pair<Boolean, String>(enabled, password), phone, null);
7958 return attemptsRemaining;
7959
7960 } catch (Exception e) {
7961 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
7962 } finally {
7963 Binder.restoreCallingIdentity(identity);
7964 }
7965 return 0;
7966 }
7967
7968 /**
7969 * Change the ICC password used in ICC pin lock.
7970 *
7971 * @return an integer representing the status of IccLock changed in the following three cases:
7972 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
7973 * - Positive number and zero for remaining password attempts.
7974 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
7975 *
7976 */
7977 @Override
7978 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
7979 enforceModifyPermission();
7980
7981 Phone phone = getPhone(subId);
7982 if (phone == null) {
7983 return 0;
7984 }
7985 // Now that all security checks passes, perform the operation as ourselves.
7986 final long identity = Binder.clearCallingIdentity();
7987 try {
7988 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
7989 new Pair<String, String>(oldPassword, newPassword), phone, null);
7990 return attemptsRemaining;
7991
7992 } catch (Exception e) {
7993 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
7994 } finally {
7995 Binder.restoreCallingIdentity(identity);
7996 }
7997 return 0;
7998 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007999}