blob: 9f422e9acc4948528fb37af4370bcb91bd0c18b6 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-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 Kim8d298d42018-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 Xuc7b18ec2019-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 zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070070import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070071import android.telephony.CellInfoGsm;
72import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070073import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070074import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070075import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070076import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080077import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070078import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080079import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070080import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080081import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080082import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070083import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080084import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.Rlog;
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;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070090import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080092import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080093import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000094import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070095import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -0700100import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
113import 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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800167import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700168import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800169import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700170import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700171import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800172import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700173import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700174import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800175
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700176import java.io.FileDescriptor;
177import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800180import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800182import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100183import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700185import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187
188/**
189 * Implementation of the ITelephony interface.
190 */
Santos Cordon117fee72014-05-16 17:56:12 -0700191public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192 private static final String LOG_TAG = "PhoneInterfaceManager";
193 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
194 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800195 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197 // Message codes used with mMainThreadHandler
198 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700199 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
200 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700201 private static final int CMD_OPEN_CHANNEL = 9;
202 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
203 private static final int CMD_CLOSE_CHANNEL = 11;
204 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800205 private static final int CMD_NV_READ_ITEM = 13;
206 private static final int EVENT_NV_READ_ITEM_DONE = 14;
207 private static final int CMD_NV_WRITE_ITEM = 15;
208 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
209 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
210 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700211 private static final int CMD_RESET_MODEM_CONFIG = 19;
212 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800213 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
214 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
215 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
216 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800217 private static final int CMD_SEND_ENVELOPE = 25;
218 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000219 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
220 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700221 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
222 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
223 private static final int CMD_EXCHANGE_SIM_IO = 31;
224 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800225 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
226 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700227 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700229 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
230 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700231 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
232 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
233 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
234 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700235 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
236 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
237 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
238 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700239 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800240 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
241 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000242 private static final int CMD_SWITCH_SLOTS = 50;
243 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700244 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
245 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
246 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
247 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
248 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
249 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
250 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
251 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700252 private static final int CMD_GET_ALL_CELL_INFO = 60;
253 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
254 private static final int CMD_GET_CELL_LOCATION = 62;
255 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700256 private static final int CMD_MODEM_REBOOT = 64;
257 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700258 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
259 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800260 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
261 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700262 private static final int CMD_GET_MODEM_STATUS = 70;
263 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700264 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
265 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700266 private static final int CMD_ERASE_MODEM_CONFIG = 74;
267 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800269 // Parameters of select command.
270 private static final int SELECT_COMMAND = 0xA4;
271 private static final int SELECT_P1 = 0x04;
272 private static final int SELECT_P2 = 0;
273 private static final int SELECT_P3 = 0x10;
274
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700275 /** The singleton instance. */
276 private static PhoneInterfaceManager sInstance;
277
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800280 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700305 * Experiment flag to enable erase modem config on reset network, default value is false
306 */
307 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
308 "reset_network_erase_modem_config_enabled";
309
310 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700311 * A request object to use for transmitting data to an ICC.
312 */
313 private static final class IccAPDUArgument {
314 public int channel, cla, command, p1, p2, p3;
315 public String data;
316
317 public IccAPDUArgument(int channel, int cla, int command,
318 int p1, int p2, int p3, String data) {
319 this.channel = channel;
320 this.cla = cla;
321 this.command = command;
322 this.p1 = p1;
323 this.p2 = p2;
324 this.p3 = p3;
325 this.data = data;
326 }
327 }
328
329 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700330 * A request object to use for transmitting data to an ICC.
331 */
332 private static final class ManualNetworkSelectionArgument {
333 public OperatorInfo operatorInfo;
334 public boolean persistSelection;
335
336 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
337 this.operatorInfo = operatorInfo;
338 this.persistSelection = persistSelection;
339 }
340 }
341
342 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
344 * request after sending. The main thread will notify the request when it is complete.
345 */
346 private static final class MainThreadRequest {
347 /** The argument to use for the request */
348 public Object argument;
349 /** The result of the request that is run on the main thread */
350 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800351 // The subscriber id that this request applies to. Defaults to
352 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
353 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354
Nathan Harold92bed182018-10-12 18:16:49 -0700355 // In cases where subId is unavailable, the caller needs to specify the phone.
356 public Phone phone;
357
vagdeviaf9a5b92018-08-15 16:01:53 -0700358 public WorkSource workSource;
359
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700360 public MainThreadRequest(Object argument) {
361 this.argument = argument;
362 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800363
Nathan Harold92bed182018-10-12 18:16:49 -0700364 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
365 this.argument = argument;
366 if (phone != null) {
367 this.phone = phone;
368 }
369 this.workSource = workSource;
370 }
371
vagdeviaf9a5b92018-08-15 16:01:53 -0700372 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800373 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 if (subId != null) {
375 this.subId = subId;
376 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700377 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800378 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700379 }
380
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800381 private static final class IncomingThirdPartyCallArgs {
382 public final ComponentName component;
383 public final String callId;
384 public final String callerDisplayName;
385
386 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
387 String callerDisplayName) {
388 this.component = component;
389 this.callId = callId;
390 this.callerDisplayName = callerDisplayName;
391 }
392 }
393
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700394 /**
395 * A handler that processes messages on the main thread in the phone process. Since many
396 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
397 * inbound binder threads to the main thread in the phone process. The Binder thread
398 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
399 * on, which will be notified when the operation completes and will contain the result of the
400 * request.
401 *
402 * <p>If a MainThreadRequest object is provided in the msg.obj field,
403 * note that request.result must be set to something non-null for the calling thread to
404 * unblock.
405 */
406 private final class MainThreadHandler extends Handler {
407 @Override
408 public void handleMessage(Message msg) {
409 MainThreadRequest request;
410 Message onCompleted;
411 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800412 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700413 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800414 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415
416 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700417 case CMD_HANDLE_USSD_REQUEST: {
418 request = (MainThreadRequest) msg.obj;
419 final Phone phone = getPhoneFromRequest(request);
420 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
421 String ussdRequest = ussdObject.first;
422 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 if (!isUssdApiAllowed(request.subId)) {
425 // Carrier does not support use of this API, return failure.
426 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
427 UssdResponse response = new UssdResponse(ussdRequest, null);
428 Bundle returnData = new Bundle();
429 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
430 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700431
Pengquan Menga1bb6272018-09-06 09:59:22 -0700432 request.result = true;
433 notifyRequester(request);
434 return;
435 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700436
Pengquan Menga1bb6272018-09-06 09:59:22 -0700437 try {
438 request.result = phone != null
439 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
440 } catch (CallStateException cse) {
441 request.result = false;
442 }
443 // Wake up the requesting thread
444 notifyRequester(request);
445 break;
pkanwar32d516d2016-10-14 19:37:38 -0700446 }
447
Yorke Lee716f67e2015-06-17 15:39:16 -0700448 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700450 final Phone phone = getPhoneFromRequest(request);
451 request.result = phone != null ?
452 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
453 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700454 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700456 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700458
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700461 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800462 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 if (uiccCard == null) {
464 loge("iccTransmitApduLogicalChannel: No UICC");
465 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700467 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
469 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700470 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 iccArgument.channel, iccArgument.cla, iccArgument.command,
472 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700473 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700474 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 break;
476
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 ar = (AsyncResult) msg.obj;
479 request = (MainThreadRequest) ar.userObj;
480 if (ar.exception == null && ar.result != null) {
481 request.result = ar.result;
482 } else {
483 request.result = new IccIoResult(0x6F, 0, (byte[])null);
484 if (ar.result == null) {
485 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800486 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700487 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800488 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 } else {
490 loge("iccTransmitApduLogicalChannel: Unknown exception");
491 }
492 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 break;
495
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
497 request = (MainThreadRequest) msg.obj;
498 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800499 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 if (uiccCard == null) {
501 loge("iccTransmitApduBasicChannel: No UICC");
502 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 } else {
505 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
506 request);
507 uiccCard.iccTransmitApduBasicChannel(
508 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
509 iccArgument.p3, iccArgument.data, onCompleted);
510 }
511 break;
512
513 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
514 ar = (AsyncResult) msg.obj;
515 request = (MainThreadRequest) ar.userObj;
516 if (ar.exception == null && ar.result != null) {
517 request.result = ar.result;
518 } else {
519 request.result = new IccIoResult(0x6F, 0, (byte[])null);
520 if (ar.result == null) {
521 loge("iccTransmitApduBasicChannel: Empty response");
522 } else if (ar.exception instanceof CommandException) {
523 loge("iccTransmitApduBasicChannel: CommandException: " +
524 ar.exception);
525 } else {
526 loge("iccTransmitApduBasicChannel: Unknown exception");
527 }
528 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 break;
531
532 case CMD_EXCHANGE_SIM_IO:
533 request = (MainThreadRequest) msg.obj;
534 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 if (uiccCard == null) {
537 loge("iccExchangeSimIO: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
542 request);
543 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
544 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
545 iccArgument.data, onCompleted);
546 }
547 break;
548
549 case EVENT_EXCHANGE_SIM_IO_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
554 } else {
555 request.result = new IccIoResult(0x6f, 0, (byte[])null);
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 case CMD_SEND_ENVELOPE:
561 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800562 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700563 if (uiccCard == null) {
564 loge("sendEnvelopeWithStatus: No UICC");
565 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700566 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700567 } else {
568 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
569 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
570 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800571 break;
572
573 case EVENT_SEND_ENVELOPE_DONE:
574 ar = (AsyncResult) msg.obj;
575 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700576 if (ar.exception == null && ar.result != null) {
577 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700579 request.result = new IccIoResult(0x6F, 0, (byte[])null);
580 if (ar.result == null) {
581 loge("sendEnvelopeWithStatus: Empty response");
582 } else if (ar.exception instanceof CommandException) {
583 loge("sendEnvelopeWithStatus: CommandException: " +
584 ar.exception);
585 } else {
586 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
587 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 break;
591
Shishir Agrawal566b7612013-10-28 14:41:00 -0700592 case CMD_OPEN_CHANNEL:
593 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800594 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800595 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700596 if (uiccCard == null) {
597 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800598 request.result = new IccOpenLogicalChannelResponse(-1,
599 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700600 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700601 } else {
602 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800603 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
604 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 break;
607
608 case EVENT_OPEN_CHANNEL_DONE:
609 ar = (AsyncResult) msg.obj;
610 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700611 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 int[] result = (int[]) ar.result;
614 int channelId = result[0];
615 byte[] selectResponse = null;
616 if (result.length > 1) {
617 selectResponse = new byte[result.length - 1];
618 for (int i = 1; i < result.length; ++i) {
619 selectResponse[i - 1] = (byte) result[i];
620 }
621 }
622 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700623 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 if (ar.result == null) {
626 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700627 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 if (ar.exception != null) {
629 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
630 }
631
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700632 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700633 if (ar.exception instanceof CommandException) {
634 CommandException.Error error =
635 ((CommandException) (ar.exception)).getCommandError();
636 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700637 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700638 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700640 }
641 }
642 openChannelResp = new IccOpenLogicalChannelResponse(
643 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700644 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700645 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700646 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case CMD_CLOSE_CHANNEL:
650 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800651 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900654 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
658 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
659 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 break;
661
662 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800663 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
664 break;
665
666 case CMD_NV_READ_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 ar = (AsyncResult) msg.obj;
675 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800676 if (ar.exception == null && ar.result != null) {
677 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800679 request.result = "";
680 if (ar.result == null) {
681 loge("nvReadItem: Empty response");
682 } else if (ar.exception instanceof CommandException) {
683 loge("nvReadItem: CommandException: " +
684 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700685 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800686 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700687 }
688 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700689 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
Jake Hambye994d462014-02-03 13:10:13 -0800692 case CMD_NV_WRITE_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
695 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700697 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
700 case EVENT_NV_WRITE_ITEM_DONE:
701 handleNullReturnEvent(msg, "nvWriteItem");
702 break;
703
704 case CMD_NV_WRITE_CDMA_PRL:
705 request = (MainThreadRequest) msg.obj;
706 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800707 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800708 break;
709
710 case EVENT_NV_WRITE_CDMA_PRL_DONE:
711 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800715 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700716 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800717 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800718 break;
719
chen xu6dac5ab2018-10-26 17:39:23 -0700720 case EVENT_RESET_MODEM_CONFIG_DONE:
721 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800722 break;
723
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 case CMD_GET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
731 ar = (AsyncResult) msg.obj;
732 request = (MainThreadRequest) ar.userObj;
733 if (ar.exception == null && ar.result != null) {
734 request.result = ar.result; // Integer
735 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800736 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800737 if (ar.result == null) {
738 loge("getPreferredNetworkType: Empty response");
739 } else if (ar.exception instanceof CommandException) {
740 loge("getPreferredNetworkType: CommandException: " +
741 ar.exception);
742 } else {
743 loge("getPreferredNetworkType: Unknown exception");
744 }
745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 break;
748
749 case CMD_SET_PREFERRED_NETWORK_TYPE:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
752 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
757 handleNullReturnEvent(msg, "setPreferredNetworkType");
758 break;
759
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
761 request = (MainThreadRequest)msg.obj;
762 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000764 break;
765
766 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
767 ar = (AsyncResult)msg.obj;
768 request = (MainThreadRequest)ar.userObj;
769 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000771 break;
772
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 case CMD_SET_VOICEMAIL_NUMBER:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
776 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800777 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
778 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800779 break;
780
781 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
782 handleNullReturnEvent(msg, "setVoicemailNumber");
783 break;
784
Stuart Scott54788802015-03-30 13:18:01 -0700785 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
788 request);
789 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
790 break;
791
792 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
793 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
794 break;
795
Shishir Agrawal302c8692015-06-19 13:49:39 -0700796 case CMD_PERFORM_NETWORK_SCAN:
797 request = (MainThreadRequest) msg.obj;
798 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
799 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
800 break;
801
802 case EVENT_PERFORM_NETWORK_SCAN_DONE:
803 ar = (AsyncResult) msg.obj;
804 request = (MainThreadRequest) ar.userObj;
805 CellNetworkScanResult cellScanResult;
806 if (ar.exception == null && ar.result != null) {
807 cellScanResult = new CellNetworkScanResult(
808 CellNetworkScanResult.STATUS_SUCCESS,
809 (List<OperatorInfo>) ar.result);
810 } else {
811 if (ar.result == null) {
812 loge("getCellNetworkScanResults: Empty response");
813 }
814 if (ar.exception != null) {
815 loge("getCellNetworkScanResults: Exception: " + ar.exception);
816 }
817 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
818 if (ar.exception instanceof CommandException) {
819 CommandException.Error error =
820 ((CommandException) (ar.exception)).getCommandError();
821 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
822 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
823 } else if (error == CommandException.Error.GENERIC_FAILURE) {
824 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
825 }
826 }
827 cellScanResult = new CellNetworkScanResult(errorCode, null);
828 }
829 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700830 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 break;
832
833 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
834 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700835 ManualNetworkSelectionArgument selArg =
836 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700837 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
838 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700839 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
840 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
843 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700844 ar = (AsyncResult) msg.obj;
845 request = (MainThreadRequest) ar.userObj;
846 if (ar.exception == null) {
847 request.result = true;
848 } else {
849 request.result = false;
850 loge("setNetworkSelectionModeManual " + ar.exception);
851 }
852 notifyRequester(request);
853 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700854 break;
855
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 case CMD_GET_MODEM_ACTIVITY_INFO:
857 request = (MainThreadRequest) msg.obj;
858 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700859 if (defaultPhone != null) {
860 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
861 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700862 break;
863
864 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
865 ar = (AsyncResult) msg.obj;
866 request = (MainThreadRequest) ar.userObj;
867 if (ar.exception == null && ar.result != null) {
868 request.result = ar.result;
869 } else {
870 if (ar.result == null) {
871 loge("queryModemActivityInfo: Empty response");
872 } else if (ar.exception instanceof CommandException) {
873 loge("queryModemActivityInfo: CommandException: " +
874 ar.exception);
875 } else {
876 loge("queryModemActivityInfo: Unknown exception");
877 }
878 }
Amit Mahajand4766222016-01-28 15:28:28 -0800879 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
880 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700881 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800882 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700883 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700884 break;
885
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 case CMD_SET_ALLOWED_CARRIERS:
887 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800888 CarrierRestrictionRules argument =
889 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800891 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_SET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800900 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
901 if (ar.exception instanceof CommandException) {
902 loge("setAllowedCarriers: CommandException: " + ar.exception);
903 CommandException.Error error =
904 ((CommandException) (ar.exception)).getCommandError();
905 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
906 request.result =
907 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
908 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 } else {
910 loge("setAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case CMD_GET_ALLOWED_CARRIERS:
917 request = (MainThreadRequest) msg.obj;
918 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800919 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700920 break;
921
922 case EVENT_GET_ALLOWED_CARRIERS_DONE:
923 ar = (AsyncResult) msg.obj;
924 request = (MainThreadRequest) ar.userObj;
925 if (ar.exception == null && ar.result != null) {
926 request.result = ar.result;
927 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800928 request.result = new IllegalStateException(
929 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700930 if (ar.result == null) {
931 loge("getAllowedCarriers: Empty response");
932 } else if (ar.exception instanceof CommandException) {
933 loge("getAllowedCarriers: CommandException: " +
934 ar.exception);
935 } else {
936 loge("getAllowedCarriers: Unknown exception");
937 }
938 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700939 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700940 break;
941
Nathan Haroldb3014052017-01-25 15:57:32 -0800942 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
943 ar = (AsyncResult) msg.obj;
944 request = (MainThreadRequest) ar.userObj;
945 if (ar.exception == null && ar.result != null) {
946 request.result = ar.result;
947 } else {
948 request.result = new IllegalArgumentException(
949 "Failed to retrieve Forbidden Plmns");
950 if (ar.result == null) {
951 loge("getForbiddenPlmns: Empty response");
952 } else {
953 loge("getForbiddenPlmns: Unknown exception");
954 }
955 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700956 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800957 break;
958
959 case CMD_GET_FORBIDDEN_PLMNS:
960 request = (MainThreadRequest) msg.obj;
961 uiccCard = getUiccCardFromRequest(request);
962 if (uiccCard == null) {
963 loge("getForbiddenPlmns() UiccCard is null");
964 request.result = new IllegalArgumentException(
965 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700966 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800967 break;
968 }
969 Integer appType = (Integer) request.argument;
970 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
971 if (uiccApp == null) {
972 loge("getForbiddenPlmns() no app with specified type -- "
973 + appType);
974 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700975 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800976 break;
977 } else {
978 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
979 + " specified type -- " + appType);
980 }
981 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
982 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
983 onCompleted);
984 break;
985
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000986 case CMD_SWITCH_SLOTS:
987 request = (MainThreadRequest) msg.obj;
988 int[] physicalSlots = (int[]) request.argument;
989 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
990 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
991 break;
992
993 case EVENT_SWITCH_SLOTS_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
998 break;
999 case CMD_GET_NETWORK_SELECTION_MODE:
1000 request = (MainThreadRequest) msg.obj;
1001 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1002 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1003 break;
1004
1005 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1006 ar = (AsyncResult) msg.obj;
1007 request = (MainThreadRequest) ar.userObj;
1008 if (ar.exception != null) {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1010 } else {
1011 int mode = ((int[]) ar.result)[0];
1012 if (mode == 0) {
1013 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1014 } else {
1015 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1016 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001017 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001018 notifyRequester(request);
1019 break;
1020 case CMD_GET_CDMA_ROAMING_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1023 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1024 break;
1025 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 if (ar.exception != null) {
1029 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1030 } else {
1031 request.result = ((int[]) ar.result)[0];
1032 }
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_ROAMING_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1038 int mode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
1046 break;
1047 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1048 request = (MainThreadRequest) msg.obj;
1049 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1050 int subscriptionMode = (int) request.argument;
1051 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1052 break;
1053 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 request.result = ar.exception == null;
1057 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001058 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 case CMD_GET_ALL_CELL_INFO:
1060 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001061 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001062 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 case EVENT_GET_ALL_CELL_INFO_DONE:
1065 ar = (AsyncResult) msg.obj;
1066 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001067 // If a timeout occurs, the response will be null
1068 request.result = (ar.exception == null && ar.result != null)
1069 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001070 synchronized (request) {
1071 request.notifyAll();
1072 }
1073 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 case CMD_REQUEST_CELL_INFO_UPDATE:
1075 request = (MainThreadRequest) msg.obj;
1076 request.phone.requestCellInfoUpdate(request.workSource,
1077 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1078 break;
1079 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1083 try {
1084 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001086 cb.onError(
1087 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1088 ar.exception.getClass().getName(),
1089 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001091 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001092 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 } else {
1094 // use the result as returned
1095 cb.onCellInfo((List<CellInfo>) ar.result);
1096 }
1097 } catch (RemoteException re) {
1098 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1099 }
1100 break;
1101 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 request = (MainThreadRequest) msg.obj;
1103 WorkSource ws = (WorkSource) request.argument;
1104 Phone phone = getPhoneFromRequest(request);
1105 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1106 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 if (ar.exception == null) {
1111 request.result = ar.result;
1112 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001113 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001114 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1115 ? new CdmaCellLocation() : new GsmCellLocation();
1116 }
1117
1118 synchronized (request) {
1119 request.notifyAll();
1120 }
1121 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001122 case CMD_MODEM_REBOOT:
1123 request = (MainThreadRequest) msg.obj;
1124 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001125 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001126 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001127 case EVENT_CMD_MODEM_REBOOT_DONE:
1128 handleNullReturnEvent(msg, "rebootModem");
1129 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001130 case CMD_REQUEST_ENABLE_MODEM:
1131 request = (MainThreadRequest) msg.obj;
1132 boolean enable = (boolean) request.argument;
1133 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001134 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001135 PhoneConfigurationManager.getInstance()
1136 .enablePhone(request.phone, enable, onCompleted);
1137 break;
1138 case EVENT_ENABLE_MODEM_DONE:
1139 ar = (AsyncResult) msg.obj;
1140 request = (MainThreadRequest) ar.userObj;
1141 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001142 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001143 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001144 if ((boolean) request.result) {
1145 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1146 updateModemStateMetrics();
1147 } else {
1148 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1149 + ar.exception);
1150 }
1151 notifyRequester(request);
1152 break;
1153 case CMD_GET_MODEM_STATUS:
1154 request = (MainThreadRequest) msg.obj;
1155 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1156 PhoneConfigurationManager.getInstance()
1157 .getPhoneStatusFromModem(request.phone, onCompleted);
1158 break;
1159 case EVENT_GET_MODEM_STATUS_DONE:
1160 ar = (AsyncResult) msg.obj;
1161 request = (MainThreadRequest) ar.userObj;
1162 int id = request.phone.getPhoneId();
1163 if (ar.exception == null && ar.result != null) {
1164 request.result = ar.result;
1165 //update the cache as modem status has changed
1166 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1167 (boolean) request.result);
1168 } else {
1169 // Return true if modem status cannot be retrieved. For most cases,
1170 // modem status is on. And for older version modems, GET_MODEM_STATUS
1171 // and disable modem are not supported. Modem is always on.
1172 // TODO: this should be fixed in R to support a third
1173 // status UNKNOWN b/131631629
1174 request.result = true;
1175 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1176 + ar.exception);
1177 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001178 notifyRequester(request);
1179 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001180 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1181 ar = (AsyncResult) msg.obj;
1182 request = (MainThreadRequest) ar.userObj;
1183 if (ar.exception == null && ar.result != null) {
1184 request.result = ar.result;
1185 } else {
1186 request.result = -1;
1187 loge("Failed to set Forbidden Plmns");
1188 if (ar.result == null) {
1189 loge("setForbidenPlmns: Empty response");
1190 } else if (ar.exception != null) {
1191 loge("setForbiddenPlmns: Exception: " + ar.exception);
1192 request.result = -1;
1193 } else {
1194 loge("setForbiddenPlmns: Unknown exception");
1195 }
1196 }
1197 notifyRequester(request);
1198 break;
1199 case CMD_SET_FORBIDDEN_PLMNS:
1200 request = (MainThreadRequest) msg.obj;
1201 uiccCard = getUiccCardFromRequest(request);
1202 if (uiccCard == null) {
1203 loge("setForbiddenPlmns: UiccCard is null");
1204 request.result = -1;
1205 notifyRequester(request);
1206 break;
1207 }
1208 Pair<Integer, List<String>> setFplmnsArgs =
1209 (Pair<Integer, List<String>>) request.argument;
1210 appType = setFplmnsArgs.first;
1211 List<String> fplmns = setFplmnsArgs.second;
1212 uiccApp = uiccCard.getApplicationByType(appType);
1213 if (uiccApp == null) {
1214 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1215 request.result = -1;
1216 loge("Failed to get UICC App");
1217 notifyRequester(request);
1218 } else {
1219 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1220 ((SIMRecords) uiccApp.getIccRecords())
1221 .setForbiddenPlmns(onCompleted, fplmns);
1222 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001223 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001224 case CMD_ERASE_MODEM_CONFIG:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1227 defaultPhone.eraseModemConfig(onCompleted);
1228 break;
1229 case EVENT_ERASE_MODEM_CONFIG_DONE:
1230 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001231 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001232 default:
1233 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1234 break;
1235 }
1236 }
Jake Hambye994d462014-02-03 13:10:13 -08001237
Pengquan Menga1bb6272018-09-06 09:59:22 -07001238 private void notifyRequester(MainThreadRequest request) {
1239 synchronized (request) {
1240 request.notifyAll();
1241 }
1242 }
1243
Jake Hambye994d462014-02-03 13:10:13 -08001244 private void handleNullReturnEvent(Message msg, String command) {
1245 AsyncResult ar = (AsyncResult) msg.obj;
1246 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1247 if (ar.exception == null) {
1248 request.result = true;
1249 } else {
1250 request.result = false;
1251 if (ar.exception instanceof CommandException) {
1252 loge(command + ": CommandException: " + ar.exception);
1253 } else {
1254 loge(command + ": Unknown exception");
1255 }
1256 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001257 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001259 }
1260
1261 /**
1262 * Posts the specified command to be executed on the main thread,
1263 * waits for the request to complete, and returns the result.
1264 * @see #sendRequestAsync
1265 */
1266 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001267 return sendRequest(
1268 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001269 }
1270
1271 /**
1272 * Posts the specified command to be executed on the main thread,
1273 * waits for the request to complete, and returns the result.
1274 * @see #sendRequestAsync
1275 */
1276 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1277 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001278 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001279 }
1280
1281 /**
1282 * Posts the specified command to be executed on the main thread,
1283 * waits for the request to complete, and returns the result.
1284 * @see #sendRequestAsync
1285 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001286 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001287 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001288 }
1289
1290 /**
1291 * Posts the specified command to be executed on the main thread,
1292 * waits for the request to complete, and returns the result.
1293 * @see #sendRequestAsync
1294 */
Nathan Harold92bed182018-10-12 18:16:49 -07001295 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1296 return sendRequest(command, argument, subId, null, workSource);
1297 }
1298
1299 /**
1300 * Posts the specified command to be executed on the main thread,
1301 * waits for the request to complete, and returns the result.
1302 * @see #sendRequestAsync
1303 */
1304 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1305 return sendRequest(
1306 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1307 }
1308
1309 /**
1310 * Posts the specified command to be executed on the main thread,
1311 * waits for the request to complete, and returns the result.
1312 * @see #sendRequestAsync
1313 */
1314 private Object sendRequest(
1315 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1317 throw new RuntimeException("This method will deadlock if called from the main thread.");
1318 }
1319
Nathan Harold92bed182018-10-12 18:16:49 -07001320 MainThreadRequest request = null;
1321 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1322 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1323 } else if (phone != null) {
1324 request = new MainThreadRequest(argument, phone, workSource);
1325 } else {
1326 request = new MainThreadRequest(argument, subId, workSource);
1327 }
1328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 Message msg = mMainThreadHandler.obtainMessage(command, request);
1330 msg.sendToTarget();
1331
1332 // Wait for the request to complete
1333 synchronized (request) {
1334 while (request.result == null) {
1335 try {
1336 request.wait();
1337 } catch (InterruptedException e) {
1338 // Do nothing, go back and wait until the request is complete
1339 }
1340 }
1341 }
1342 return request.result;
1343 }
1344
1345 /**
1346 * Asynchronous ("fire and forget") version of sendRequest():
1347 * Posts the specified command to be executed on the main thread, and
1348 * returns immediately.
1349 * @see #sendRequest
1350 */
1351 private void sendRequestAsync(int command) {
1352 mMainThreadHandler.sendEmptyMessage(command);
1353 }
1354
1355 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001357 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001358 */
1359 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001360 sendRequestAsync(command, argument, null, null);
1361 }
1362
1363 /**
1364 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1365 * @see {@link #sendRequest(int,Object)}
1366 */
1367 private void sendRequestAsync(
1368 int command, Object argument, Phone phone, WorkSource workSource) {
1369 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001370 Message msg = mMainThreadHandler.obtainMessage(command, request);
1371 msg.sendToTarget();
1372 }
1373
1374 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001375 * Initialize the singleton PhoneInterfaceManager instance.
1376 * This is only done once, at startup, from PhoneApp.onCreate().
1377 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001378 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 synchronized (PhoneInterfaceManager.class) {
1380 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001381 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 } else {
1383 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1384 }
1385 return sInstance;
1386 }
1387 }
1388
1389 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001390 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001393 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001394 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001395 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1396 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001397 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001398 mTelephonySharedPreferences =
1399 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001400 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001401 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001402
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 publish();
1404 }
1405
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001406 private Phone getDefaultPhone() {
1407 Phone thePhone = getPhone(getDefaultSubscription());
1408 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1409 }
1410
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 private void publish() {
1412 if (DBG) log("publish: " + this);
1413
1414 ServiceManager.addService("phone", this);
1415 }
1416
Stuart Scott584921c2015-01-15 17:10:34 -08001417 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001418 if (request.phone != null) {
1419 return request.phone;
1420 } else {
1421 return getPhoneFromSubId(request.subId);
1422 }
1423 }
1424
1425 private Phone getPhoneFromSubId(int subId) {
1426 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1427 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001428 }
1429
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001430 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1431 Phone phone = getPhoneFromRequest(request);
1432 return phone == null ? null :
1433 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1434 }
1435
Wink Saville36469e72014-06-11 15:17:00 -07001436 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001437 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001438 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001441 private void sendEraseModemConfig(Phone phone) {
1442 if (phone != null) {
1443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1444 mApp, phone.getSubId(), "eraseModemConfig");
1445 final long identity = Binder.clearCallingIdentity();
1446 try {
1447 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1448 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1449 } finally {
1450 Binder.restoreCallingIdentity(identity);
1451 }
1452 }
1453 }
1454
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001455 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("dial: " + number);
1461 // No permission check needed here: This is just a wrapper around the
1462 // ACTION_DIAL intent, which is available to any app since it puts up
1463 // the UI before it does anything.
1464
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001465 final long identity = Binder.clearCallingIdentity();
1466 try {
1467 String url = createTelUrl(number);
1468 if (url == null) {
1469 return;
1470 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 // PENDING: should we just silently fail if phone is offhook or ringing?
1473 PhoneConstants.State state = mCM.getState(subId);
1474 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1475 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1476 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1477 mApp.startActivity(intent);
1478 }
1479 } finally {
1480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001481 }
1482 }
1483
1484 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001485 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001486 }
1487
Wink Savilleb564aae2014-10-23 10:18:09 -07001488 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 if (DBG) log("call: " + number);
1490
1491 // This is just a wrapper around the ACTION_CALL intent, but we still
1492 // need to do a permission check since we're calling startActivity()
1493 // from the context of the phone app.
1494 enforceCallPermission();
1495
Jordan Liu1617b712019-07-10 15:06:26 -07001496 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 != AppOpsManager.MODE_ALLOWED) {
1498 return;
1499 }
1500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001501 final long identity = Binder.clearCallingIdentity();
1502 try {
1503 String url = createTelUrl(number);
1504 if (url == null) {
1505 return;
1506 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001508 boolean isValid = false;
1509 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1510 if (slist != null) {
1511 for (SubscriptionInfo subInfoRecord : slist) {
1512 if (subInfoRecord.getSubscriptionId() == subId) {
1513 isValid = true;
1514 break;
1515 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001516 }
Wink Saville08874612014-08-31 19:19:58 -07001517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001518 if (!isValid) {
1519 return;
1520 }
Wink Saville08874612014-08-31 19:19:58 -07001521
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001522 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1523 intent.putExtra(SUBSCRIPTION_KEY, subId);
1524 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1525 mApp.startActivity(intent);
1526 } finally {
1527 Binder.restoreCallingIdentity(identity);
1528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001529 }
1530
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001531 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001532 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001533 }
1534
Wink Savilleb564aae2014-10-23 10:18:09 -07001535 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001536 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001537 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1538 }
1539
1540 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001541 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
Wink Savilleb564aae2014-10-23 10:18:09 -07001544 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001546 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1547 }
1548
1549 /** {@hide} */
1550 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001551 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001552 }
1553
Wink Savilleb564aae2014-10-23 10:18:09 -07001554 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001556
1557 final long identity = Binder.clearCallingIdentity();
1558 try {
1559 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1560 checkSimPin.start();
1561 return checkSimPin.unlockSim(null, pin);
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
1564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Wink Saville9de0f752013-10-22 19:04:03 -07001567 /** {@hide} */
1568 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001569 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Wink Savilleb564aae2014-10-23 10:18:09 -07001572 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001574
1575 final long identity = Binder.clearCallingIdentity();
1576 try {
1577 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1578 checkSimPuk.start();
1579 return checkSimPuk.unlockSim(puk, pin);
1580 } finally {
1581 Binder.restoreCallingIdentity(identity);
1582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001583 }
1584
1585 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001586 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 * a synchronous one.
1588 */
1589 private static class UnlockSim extends Thread {
1590
1591 private final IccCard mSimCard;
1592
1593 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001594 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1595 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596
1597 // For replies from SimCard interface
1598 private Handler mHandler;
1599
1600 // For async handler to identify request type
1601 private static final int SUPPLY_PIN_COMPLETE = 100;
1602
1603 public UnlockSim(IccCard simCard) {
1604 mSimCard = simCard;
1605 }
1606
1607 @Override
1608 public void run() {
1609 Looper.prepare();
1610 synchronized (UnlockSim.this) {
1611 mHandler = new Handler() {
1612 @Override
1613 public void handleMessage(Message msg) {
1614 AsyncResult ar = (AsyncResult) msg.obj;
1615 switch (msg.what) {
1616 case SUPPLY_PIN_COMPLETE:
1617 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1618 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001619 mRetryCount = msg.arg1;
1620 if (ar.exception != null) {
1621 if (ar.exception instanceof CommandException &&
1622 ((CommandException)(ar.exception)).getCommandError()
1623 == CommandException.Error.PASSWORD_INCORRECT) {
1624 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1625 } else {
1626 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1627 }
1628 } else {
1629 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 mDone = true;
1632 UnlockSim.this.notifyAll();
1633 }
1634 break;
1635 }
1636 }
1637 };
1638 UnlockSim.this.notifyAll();
1639 }
1640 Looper.loop();
1641 }
1642
1643 /*
1644 * Use PIN or PUK to unlock SIM card
1645 *
1646 * If PUK is null, unlock SIM card with PIN
1647 *
1648 * If PUK is not null, unlock SIM card with PUK and set PIN code
1649 */
Wink Saville9de0f752013-10-22 19:04:03 -07001650 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651
1652 while (mHandler == null) {
1653 try {
1654 wait();
1655 } catch (InterruptedException e) {
1656 Thread.currentThread().interrupt();
1657 }
1658 }
1659 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1660
1661 if (puk == null) {
1662 mSimCard.supplyPin(pin, callback);
1663 } else {
1664 mSimCard.supplyPuk(puk, pin, callback);
1665 }
1666
1667 while (!mDone) {
1668 try {
1669 Log.d(LOG_TAG, "wait for done");
1670 wait();
1671 } catch (InterruptedException e) {
1672 // Restore the interrupted status
1673 Thread.currentThread().interrupt();
1674 }
1675 }
1676 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001677 int[] resultArray = new int[2];
1678 resultArray[0] = mResult;
1679 resultArray[1] = mRetryCount;
1680 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 }
1682 }
1683
1684 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001685 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001686
1687 }
1688
Wink Savilleb564aae2014-10-23 10:18:09 -07001689 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001690 // No permission check needed here: this call is harmless, and it's
1691 // needed for the ServiceState.requestStateUpdate() call (which is
1692 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693 final long identity = Binder.clearCallingIdentity();
1694 try {
1695 final Phone phone = getPhone(subId);
1696 if (phone != null) {
1697 phone.updateServiceLocation();
1698 }
1699 } finally {
1700 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001701 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 }
1703
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001704 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001705 @Override
1706 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001707 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
1709
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001710 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001711 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1712 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1713 callingFeatureId);
1714 }
1715
1716 @Deprecated
1717 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001718 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001719 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1720 }
1721
1722 @Override
1723 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1724 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001726 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001727 return false;
1728 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729
1730 final long identity = Binder.clearCallingIdentity();
1731 try {
1732 return isRadioOnForSubscriber(subId);
1733 } finally {
1734 Binder.restoreCallingIdentity(identity);
1735 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001736 }
1737
1738 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
1743 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1744 } else {
1745 return false;
1746 }
1747 } finally {
1748 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 }
1751
1752 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001753 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
Wink Saville36469e72014-06-11 15:17:00 -07001755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 final Phone phone = getPhone(subId);
1762 if (phone != null) {
1763 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Wink Saville36469e72014-06-11 15:17:00 -07001768 }
1769
1770 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001771 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
Wink Savilleb564aae2014-10-23 10:18:09 -07001774 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 final Phone phone = getPhone(subId);
1780 if (phone == null) {
1781 return false;
1782 }
1783 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1784 toggleRadioOnOffForSubscriber(subId);
1785 }
1786 return true;
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
Wink Saville36469e72014-06-11 15:17:00 -07001791
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001792 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001793 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001794 /*
1795 * If any of the Radios are available, it will need to be
1796 * shutdown. So return true if any Radio is available.
1797 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1801 Phone phone = PhoneFactory.getPhone(i);
1802 if (phone != null && phone.isRadioAvailable()) return true;
1803 }
1804 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1805 return false;
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001809 }
1810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001811 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001812 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 enforceModifyPermission();
1814
1815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1818 logv("Shutting down Phone " + i);
1819 shutdownRadioUsingPhoneId(i);
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001823 }
1824 }
1825
1826 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001827 Phone phone = PhoneFactory.getPhone(phoneId);
1828 if (phone != null && phone.isRadioAvailable()) {
1829 phone.shutdownRadio();
1830 }
1831 }
1832
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1839 if (defaultPhone != null) {
1840 defaultPhone.setRadioPower(turnOn);
1841 return true;
1842 } else {
1843 loge("There's no default phone.");
1844 return false;
1845 }
1846 } finally {
1847 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001848 }
Wink Saville36469e72014-06-11 15:17:00 -07001849 }
1850
Wink Savilleb564aae2014-10-23 10:18:09 -07001851 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001852 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001853
1854 final long identity = Binder.clearCallingIdentity();
1855 try {
1856 final Phone phone = getPhone(subId);
1857 if (phone != null) {
1858 phone.setRadioPower(turnOn);
1859 return true;
1860 } else {
1861 return false;
1862 }
1863 } finally {
1864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
1867
Wink Saville36469e72014-06-11 15:17:00 -07001868 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001869 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001870 public boolean enableDataConnectivity() {
1871 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001872
1873 final long identity = Binder.clearCallingIdentity();
1874 try {
1875 int subId = mSubscriptionController.getDefaultDataSubId();
1876 final Phone phone = getPhone(subId);
1877 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001878 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001879 return true;
1880 } else {
1881 return false;
1882 }
1883 } finally {
1884 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001885 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001886 }
1887
Wink Saville36469e72014-06-11 15:17:00 -07001888 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001889 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001890 public boolean disableDataConnectivity() {
1891 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001892
1893 final long identity = Binder.clearCallingIdentity();
1894 try {
1895 int subId = mSubscriptionController.getDefaultDataSubId();
1896 final Phone phone = getPhone(subId);
1897 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001898 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001899 return true;
1900 } else {
1901 return false;
1902 }
1903 } finally {
1904 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001905 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 }
1907
Sanket Padawe356d7632015-06-22 14:03:32 -07001908 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001909 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001910 final long identity = Binder.clearCallingIdentity();
1911 try {
1912 final Phone phone = getPhone(subId);
1913 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001914 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001915 } else {
1916 return false;
1917 }
1918 } finally {
1919 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001921 }
1922
1923 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001924 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001925 }
1926
pkanwarae03a6b2016-11-06 20:37:09 -08001927 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001928 enforceCallPermission();
1929
1930 final long identity = Binder.clearCallingIdentity();
1931 try {
1932 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1933 return;
1934 }
1935 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1936 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1937 } finally {
1938 Binder.restoreCallingIdentity(identity);
1939 }
pkanwar32d516d2016-10-14 19:37:38 -07001940 };
1941
Wink Savilleb564aae2014-10-23 10:18:09 -07001942 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944
1945 final long identity = Binder.clearCallingIdentity();
1946 try {
1947 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1948 return false;
1949 }
1950 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1951 } finally {
1952 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001953 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 }
1955
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001957 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001958 }
1959
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001960 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 Phone phone = PhoneFactory.getPhone(slotIndex);
1964 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1965 PhoneConstantConversions.convertCallState(phone.getState());
1966 } finally {
1967 Binder.restoreCallingIdentity(identity);
1968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 }
1970
Sanket Padawe356d7632015-06-22 14:03:32 -07001971 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001972 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001973 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1974 }
1975
1976 @Override
1977 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978 final long identity = Binder.clearCallingIdentity();
1979 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001980 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 if (phone != null) {
1982 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1983 } else {
1984 return PhoneConstantConversions.convertDataState(
1985 PhoneConstants.DataState.DISCONNECTED);
1986 }
1987 } finally {
1988 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 }
1991
Sanket Padawe356d7632015-06-22 14:03:32 -07001992 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001993 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001994 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1995 }
1996
1997 @Override
1998 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999 final long identity = Binder.clearCallingIdentity();
2000 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002001 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002 if (phone != null) {
2003 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2004 } else {
2005 return TelephonyManager.DATA_ACTIVITY_NONE;
2006 }
2007 } finally {
2008 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010 }
2011
2012 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002013 public Bundle getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002014 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002015 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002016
2017 LocationAccessPolicy.LocationPermissionResult locationResult =
2018 LocationAccessPolicy.checkLocationPermission(mApp,
2019 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2020 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002021 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002022 .setCallingPid(Binder.getCallingPid())
2023 .setCallingUid(Binder.getCallingUid())
2024 .setMethod("getCellLocation")
2025 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2026 .build());
2027 switch (locationResult) {
2028 case DENIED_HARD:
2029 throw new SecurityException("Not allowed to access cell location");
2030 case DENIED_SOFT:
2031 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 if (DBG_LOC) log("getCellLocation: is active user");
2038 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07002039 int subId = mSubscriptionController.getDefaultDataSubId();
2040 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
2041 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 return data;
2043 } finally {
2044 Binder.restoreCallingIdentity(identity);
2045 }
Svetoslav64fad262015-04-14 14:35:21 -07002046 }
2047
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002049 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2050 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002051 if (!TextUtils.isEmpty(callingPackage)) {
2052 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2054 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002055 return "";
2056 }
2057 }
2058
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002059 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2060 // registered cell info, so return a NULL country instead.
2061 final long identity = Binder.clearCallingIdentity();
2062 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002063 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2064 // Get default phone in this case.
2065 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2066 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002067 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002068 // Todo: fix this when we can get the actual cellular network info when the device
2069 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002071 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2072 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002073 return "";
2074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075 Phone phone = PhoneFactory.getPhone(phoneId);
2076 if (phone != null) {
2077 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002078 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079 if (sst != null) {
2080 LocaleTracker lt = sst.getLocaleTracker();
2081 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002082 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2083 return lt.getCurrentCountry();
2084 } else if (emergencyNumberTracker != null) {
2085 return emergencyNumberTracker.getEmergencyCountryIso();
2086 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002087 }
2088 }
2089 }
2090 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002091 } finally {
2092 Binder.restoreCallingIdentity(identity);
2093 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002094 }
2095
2096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002098 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002099 }
2100
Sanket Padawe356d7632015-06-22 14:03:32 -07002101 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002102 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 mApp.enforceCallingOrSelfPermission(
2104 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002105
2106 final long identity = Binder.clearCallingIdentity();
2107 try {
2108 final Phone phone = getPhone(subId);
2109 if (phone != null) {
2110 phone.enableLocationUpdates();
2111 }
2112 } finally {
2113 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002114 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
2117 @Override
2118 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002119 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002120 }
2121
Sanket Padawe356d7632015-06-22 14:03:32 -07002122 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002123 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 mApp.enforceCallingOrSelfPermission(
2125 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002126
2127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 final Phone phone = getPhone(subId);
2130 if (phone != null) {
2131 phone.disableLocationUpdates();
2132 }
2133 } finally {
2134 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
2137
Nathan Harold31d7ff32018-10-15 20:20:30 -07002138 /**
2139 * Returns the target SDK version number for a given package name.
2140 *
Nathan Haroldec184742019-07-10 17:04:16 -07002141 * This call MUST be invoked before clearing the calling UID.
2142 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002143 * @return target SDK if the package is found or INT_MAX.
2144 */
2145 private int getTargetSdk(String packageName) {
2146 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002147 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002148 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002149 if (ai != null) return ai.targetSdkVersion;
2150 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002151 loge("Failed to get package info for pkg="
2152 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002153 }
2154 return Integer.MAX_VALUE;
2155 }
2156
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002157 @Override
2158 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002159 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2160 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002161 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002162 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2163 throw new SecurityException(
2164 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2165 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002166
Jordan Liu1617b712019-07-10 15:06:26 -07002167 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2169 return null;
2170 }
Svetoslav64fad262015-04-14 14:35:21 -07002171
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002172 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002174 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002175 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176
Nathan Haroldf180aac2018-06-01 18:43:55 -07002177 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2178 for (CellInfo ci : info) {
2179 if (ci instanceof CellInfoGsm) {
2180 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2181 } else if (ci instanceof CellInfoWcdma) {
2182 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002185 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002188 private List<CellInfo> getCachedCellInfo() {
2189 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2190 for (Phone phone : PhoneFactory.getPhones()) {
2191 List<CellInfo> info = phone.getAllCellInfo();
2192 if (info != null) cellInfos.addAll(info);
2193 }
2194 return cellInfos;
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196
2197 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002198 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002199 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002200 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002201
2202 LocationAccessPolicy.LocationPermissionResult locationResult =
2203 LocationAccessPolicy.checkLocationPermission(mApp,
2204 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2205 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002206 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002207 .setCallingPid(Binder.getCallingPid())
2208 .setCallingUid(Binder.getCallingUid())
2209 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002210 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002211 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2212 .build());
2213 switch (locationResult) {
2214 case DENIED_HARD:
2215 throw new SecurityException("Not allowed to access cell info");
2216 case DENIED_SOFT:
2217 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002220 final int targetSdk = getTargetSdk(callingPackage);
2221 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2222 return getCachedCellInfo();
2223 }
2224
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002225 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002226 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2230 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002231 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002232 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002233 if (info != null) cellInfos.addAll(info);
2234 }
2235 return cellInfos;
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239 }
2240
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002241 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002242 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2243 String callingFeatureId) {
2244 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2245 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002246 }
2247
2248 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002249 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2250 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002251 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002252 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002253 }
2254
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002255 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2256 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002257 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002258 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002259
2260 LocationAccessPolicy.LocationPermissionResult locationResult =
2261 LocationAccessPolicy.checkLocationPermission(mApp,
2262 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2263 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002264 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002265 .setCallingPid(Binder.getCallingPid())
2266 .setCallingUid(Binder.getCallingUid())
2267 .setMethod("requestCellInfoUpdate")
2268 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2269 .build());
2270 switch (locationResult) {
2271 case DENIED_HARD:
2272 throw new SecurityException("Not allowed to access cell info");
2273 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002274 try {
2275 cb.onCellInfo(new ArrayList<CellInfo>());
2276 } catch (RemoteException re) {
2277 // Drop without consequences
2278 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002279 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002280 }
2281
Nathan Harolda939a962019-05-09 10:13:47 -07002282
2283 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002284 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2285
2286 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2287 }
2288
2289 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002291 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002292 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293
2294 final long identity = Binder.clearCallingIdentity();
2295 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002296 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002297 } finally {
2298 Binder.restoreCallingIdentity(identity);
2299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
Shishir Agrawala9f32182016-04-12 12:00:16 -07002302 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002303 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002304 Phone phone = PhoneFactory.getPhone(slotIndex);
2305 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002306 return null;
2307 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002309 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002310 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002311 return null;
2312 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002313
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
2316 return phone.getImei();
2317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002320 }
2321
2322 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002323 public String getTypeAllocationCodeForSlot(int slotIndex) {
2324 Phone phone = PhoneFactory.getPhone(slotIndex);
2325 String tac = null;
2326 if (phone != null) {
2327 String imei = phone.getImei();
2328 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2329 }
2330 return tac;
2331 }
2332
2333 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002334 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002335 Phone phone = PhoneFactory.getPhone(slotIndex);
2336 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002337 return null;
2338 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002339
Jeff Davidson913390f2018-02-23 17:11:49 -08002340 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002341 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002342 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 return null;
2344 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002345
2346 final long identity = Binder.clearCallingIdentity();
2347 try {
2348 return phone.getMeid();
2349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Jack Yu2af8d712017-03-15 17:14:14 -07002352 }
2353
2354 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002355 public String getManufacturerCodeForSlot(int slotIndex) {
2356 Phone phone = PhoneFactory.getPhone(slotIndex);
2357 String manufacturerCode = null;
2358 if (phone != null) {
2359 String meid = phone.getMeid();
2360 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2361 }
2362 return manufacturerCode;
2363 }
2364
2365 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002366 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2367 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002368 Phone phone = PhoneFactory.getPhone(slotIndex);
2369 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002370 return null;
2371 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002372 int subId = phone.getSubId();
2373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002374 mApp, subId, callingPackage, callingFeatureId,
2375 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002376 return null;
2377 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 return phone.getDeviceSvn();
2382 } finally {
2383 Binder.restoreCallingIdentity(identity);
2384 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002385 }
2386
fionaxu43304da2017-11-27 22:51:16 -08002387 @Override
2388 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002389 final long identity = Binder.clearCallingIdentity();
2390 try {
2391 final Phone phone = getPhone(subId);
2392 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
2395 }
fionaxu43304da2017-11-27 22:51:16 -08002396 }
2397
2398 @Override
2399 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002400 final long identity = Binder.clearCallingIdentity();
2401 try {
2402 final Phone phone = getPhone(subId);
2403 return phone == null ? null : phone.getCarrierName();
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
2406 }
fionaxu43304da2017-11-27 22:51:16 -08002407 }
2408
calvinpanffe225e2018-11-01 19:43:06 +08002409 @Override
chen xu0026ca62019-03-06 15:28:50 -08002410 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 final Phone phone = getPhone(subId);
2414 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002415 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002416 } finally {
2417 Binder.restoreCallingIdentity(identity);
2418 }
2419 }
2420
2421 @Override
chen xu0026ca62019-03-06 15:28:50 -08002422 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002423 final long identity = Binder.clearCallingIdentity();
2424 try {
2425 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002426 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002427 } finally {
2428 Binder.restoreCallingIdentity(identity);
2429 }
2430 }
2431
chen xu651eec72018-11-11 19:03:44 -08002432 @Override
chen xu864e11c2018-12-06 22:10:03 -08002433 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2434 if (!isSubscriptionMccMnc) {
2435 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2436 }
chen xu651eec72018-11-11 19:03:44 -08002437 final Phone phone = PhoneFactory.getPhone(slotIndex);
2438 if (phone == null) {
2439 return TelephonyManager.UNKNOWN_CARRIER_ID;
2440 }
2441 final long identity = Binder.clearCallingIdentity();
2442 try {
2443 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
2446 }
2447 }
2448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 //
2450 // Internal helper methods.
2451 //
2452
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002453 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2455 *
2456 * @throws SecurityException if the caller does not have the required permission
2457 */
2458 private void enforceModifyPermission() {
2459 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2460 }
2461
Shuo Qianf2b2df42019-11-13 17:43:31 -08002462 private void enforceActiveEmergencySessionPermission() {
2463 mApp.enforceCallingOrSelfPermission(
2464 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2465 }
2466
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 /**
2468 * Make sure the caller has the CALL_PHONE permission.
2469 *
2470 * @throws SecurityException if the caller does not have the required permission
2471 */
2472 private void enforceCallPermission() {
2473 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2474 }
2475
paulhu423b5f22019-08-23 19:17:33 +08002476 private void enforceSettingsPermission() {
2477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002478 }
2479
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 private String createTelUrl(String number) {
2481 if (TextUtils.isEmpty(number)) {
2482 return null;
2483 }
2484
Jake Hambye994d462014-02-03 13:10:13 -08002485 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 }
2487
Ihab Awadf9e92732013-12-05 18:02:52 -08002488 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2490 }
2491
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002492 private static void logv(String msg) {
2493 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2494 }
2495
Ihab Awadf9e92732013-12-05 18:02:52 -08002496 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2498 }
2499
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002500 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002501 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002502 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002506 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 final Phone phone = PhoneFactory.getPhone(slotIndex);
2510 if (phone == null) {
2511 return PhoneConstants.PHONE_TYPE_NONE;
2512 } else {
2513 return phone.getPhoneType();
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002518 }
2519
2520 /**
2521 * Returns the CDMA ERI icon index to display
2522 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002523 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002524 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2525 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2526 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002530 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2531 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002533 mApp, subId, callingPackage, callingFeatureId,
2534 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002535 return -1;
2536 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537
2538 final long identity = Binder.clearCallingIdentity();
2539 try {
2540 final Phone phone = getPhone(subId);
2541 if (phone != null) {
2542 return phone.getCdmaEriIconIndex();
2543 } else {
2544 return -1;
2545 }
2546 } finally {
2547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002549 }
2550
2551 /**
2552 * Returns the CDMA ERI icon mode,
2553 * 0 - ON
2554 * 1 - FLASHING
2555 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002556 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002557 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2558 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2559 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002560 }
2561
Sanket Padawe356d7632015-06-22 14:03:32 -07002562 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002563 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2564 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002565 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002566 mApp, subId, callingPackage, callingFeatureId,
2567 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002568 return -1;
2569 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone phone = getPhone(subId);
2574 if (phone != null) {
2575 return phone.getCdmaEriIconMode();
2576 } else {
2577 return -1;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
2584 /**
2585 * Returns the CDMA ERI text,
2586 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002587 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002588 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2589 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2590 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002591 }
2592
Sanket Padawe356d7632015-06-22 14:03:32 -07002593 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002594 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2595 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002597 mApp, subId, callingPackage, callingFeatureId,
2598 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002599 return null;
2600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 final Phone phone = getPhone(subId);
2605 if (phone != null) {
2606 return phone.getCdmaEriText();
2607 } else {
2608 return null;
2609 }
2610 } finally {
2611 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002612 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002613 }
2614
2615 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 * Returns the CDMA MDN.
2617 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002618 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002619 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2621 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 return phone.getLine1Number();
2628 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002629 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630 return null;
2631 }
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002634 }
2635 }
2636
2637 /**
2638 * Returns the CDMA MIN.
2639 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002640 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002641 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2643 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2649 return phone.getCdmaMin();
2650 } else {
2651 return null;
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002655 }
2656 }
2657
Hall Liud892bec2018-11-30 14:51:45 -08002658 @Override
2659 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2660 INumberVerificationCallback callback, String callingPackage) {
2661 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2662 != PERMISSION_GRANTED) {
2663 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2664 }
2665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2666
2667 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2668 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2669 throw new SecurityException("Calling package must be configured in the device config");
2670 }
2671
2672 if (range == null) {
2673 throw new NullPointerException("Range must be non-null");
2674 }
2675
2676 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002677 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002678
2679 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2680 }
2681
Junda Liuca05d5d2014-08-14 22:36:34 -07002682 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002683 * Returns true if CDMA provisioning needs to run.
2684 */
2685 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002688 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002689 } finally {
2690 Binder.restoreCallingIdentity(identity);
2691 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 }
2693
2694 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002695 * Sets the voice mail number of a given subId.
2696 */
2697 @Override
2698 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002699 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002700
2701 final long identity = Binder.clearCallingIdentity();
2702 try {
2703 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2704 new Pair<String, String>(alphaTag, number), new Integer(subId));
2705 return success;
2706 } finally {
2707 Binder.restoreCallingIdentity(identity);
2708 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002709 }
2710
Ta-wei Yen87c49842016-05-13 21:19:52 -07002711 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002712 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002714 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2715 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002716 if (!TextUtils.equals(callingPackage, systemDialer)) {
2717 throw new SecurityException("caller must be system dialer");
2718 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719
2720 final long identity = Binder.clearCallingIdentity();
2721 try {
2722 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2723 if (phoneAccountHandle == null) {
2724 return null;
2725 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002726 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002729 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002730 }
2731
2732 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002733 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2734 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002735 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002737 mApp, subId, callingPackage, callingFeatureId,
2738 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002739 return null;
2740 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002741
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 final long identity = Binder.clearCallingIdentity();
2743 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002744 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002745 } finally {
2746 Binder.restoreCallingIdentity(identity);
2747 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002748 }
2749
2750 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002751 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2752 VisualVoicemailSmsFilterSettings settings) {
2753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002754
2755 final long identity = Binder.clearCallingIdentity();
2756 try {
2757 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002758 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 } finally {
2760 Binder.restoreCallingIdentity(identity);
2761 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002762 }
2763
2764 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002765 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767
2768 final long identity = Binder.clearCallingIdentity();
2769 try {
2770 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002771 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 } finally {
2773 Binder.restoreCallingIdentity(identity);
2774 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002775 }
2776
2777 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002778 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2779 String callingPackage, int subId) {
2780 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781
2782 final long identity = Binder.clearCallingIdentity();
2783 try {
2784 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002785 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 } finally {
2787 Binder.restoreCallingIdentity(identity);
2788 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002789 }
2790
2791 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002792 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002793 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
2795 final long identity = Binder.clearCallingIdentity();
2796 try {
2797 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002798 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 } finally {
2800 Binder.restoreCallingIdentity(identity);
2801 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002802 }
2803
2804 @Override
2805 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2806 String number, int port, String text, PendingIntent sentIntent) {
2807 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002808 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002809 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002810 SmsController smsController = PhoneFactory.getSmsController();
2811 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2812 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002813 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002814
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002815 /**
fionaxu0152e512016-11-14 13:36:14 -08002816 * Sets the voice activation state of a given subId.
2817 */
2818 @Override
2819 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2821 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002822
2823 final long identity = Binder.clearCallingIdentity();
2824 try {
2825 final Phone phone = getPhone(subId);
2826 if (phone != null) {
2827 phone.setVoiceActivationState(activationState);
2828 } else {
2829 loge("setVoiceActivationState fails with invalid subId: " + subId);
2830 }
2831 } finally {
2832 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002833 }
2834 }
2835
2836 /**
2837 * Sets the data activation state of a given subId.
2838 */
2839 @Override
2840 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2842 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002843
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 final Phone phone = getPhone(subId);
2847 if (phone != null) {
2848 phone.setDataActivationState(activationState);
2849 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002850 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002851 }
2852 } finally {
2853 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002854 }
2855 }
2856
2857 /**
2858 * Returns the voice activation state of a given subId.
2859 */
2860 @Override
2861 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002862 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002863
fionaxu0152e512016-11-14 13:36:14 -08002864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 if (phone != null) {
2868 return phone.getVoiceActivationState();
2869 } else {
2870 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2871 }
2872 } finally {
2873 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002874 }
2875 }
2876
2877 /**
2878 * Returns the data activation state of a given subId.
2879 */
2880 @Override
2881 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883
fionaxu0152e512016-11-14 13:36:14 -08002884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 final long identity = Binder.clearCallingIdentity();
2886 try {
2887 if (phone != null) {
2888 return phone.getDataActivationState();
2889 } else {
2890 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2891 }
2892 } finally {
2893 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002894 }
2895 }
2896
2897 /**
Wink Saville36469e72014-06-11 15:17:00 -07002898 * Returns the unread count of voicemails for a subId
2899 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002900 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002901 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2902 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002904 mApp, subId, callingPackage, callingFeatureId,
2905 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002906 return 0;
2907 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null) {
2912 return phone.getVoiceMessageCount();
2913 } else {
2914 return 0;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002919 }
2920
2921 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002922 * returns true, if the device is in a state where both voice and data
2923 * are supported simultaneously. This can change based on location or network condition.
2924 */
2925 @Override
2926 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002927 final long identity = Binder.clearCallingIdentity();
2928 try {
2929 final Phone phone = getPhone(subId);
2930 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2931 } finally {
2932 Binder.restoreCallingIdentity(identity);
2933 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002934 }
2935
2936 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002937 * Send the dialer code if called from the current default dialer or the caller has
2938 * carrier privilege.
2939 * @param inputCode The dialer code to send
2940 */
2941 @Override
2942 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002943 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002945 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2946 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002947 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002948 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2949 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002950 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002954 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu235cc5e2017-03-06 22:25:57 -08002958 }
2959
Pengquan Menga1bb6272018-09-06 09:59:22 -07002960 @Override
2961 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002962 if (!isActiveSubscription(subId)) {
2963 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2964 }
2965
Pengquan Menga1bb6272018-09-06 09:59:22 -07002966 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2967 }
2968
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002970 public boolean isInEmergencySmsMode() {
2971 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 for (Phone phone : PhoneFactory.getPhones()) {
2975 if (phone.isInEmergencySmsMode()) {
2976 return true;
2977 }
2978 }
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 return false;
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2987 throws RemoteException {
2988 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002989 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2990 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2991 "IMS not available on device.");
2992 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 final long token = Binder.clearCallingIdentity();
2994 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002996 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002998 } catch (ImsException e) {
2999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 } finally {
3001 Binder.restoreCallingIdentity(token);
3002 }
3003 }
3004
3005 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003006 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3007 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003008 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3009 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3010 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003011 final long token = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3015 .removeRegistrationCallbackForSubscription(c, subId);
3016 } catch (ImsException e) {
3017 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3018 + "is inactive, ignoring unregister.");
3019 // If the subscription is no longer active, just return, since the callback
3020 // will already have been removed internally.
3021 } finally {
3022 Binder.restoreCallingIdentity(token);
3023 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 }
3025
Brad Ebinger774ba362019-10-22 17:36:18 -07003026 /**
3027 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3028 */
3029 @Override
3030 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3031 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3032 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3033 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3034 "IMS not available on device.");
3035 }
3036 final long token = Binder.clearCallingIdentity();
3037 try {
3038 Phone phone = getPhone(subId);
3039 if (phone == null) {
3040 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3041 + subId + "'");
3042 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3043 }
3044 phone.getImsRegistrationState(regState -> {
3045 try {
3046 consumer.accept((regState == null)
3047 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3048 } catch (RemoteException e) {
3049 // Ignore if the remote process is no longer available to call back.
3050 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3051 }
3052 });
3053 } finally {
3054 Binder.restoreCallingIdentity(token);
3055 }
3056 }
3057
3058 /**
3059 * Get the transport type for the IMS service registration state.
3060 */
3061 @Override
3062 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3063 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3064 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3065 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3066 "IMS not available on device.");
3067 }
3068 final long token = Binder.clearCallingIdentity();
3069 try {
3070 Phone phone = getPhone(subId);
3071 if (phone == null) {
3072 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3073 + subId + "'");
3074 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3075 }
3076 phone.getImsRegistrationTech(regTech -> {
3077 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3078 int regTechConverted = (regTech == null)
3079 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3080 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3081 regTechConverted);
3082 try {
3083 consumer.accept(regTechConverted);
3084 } catch (RemoteException e) {
3085 // Ignore if the remote process is no longer available to call back.
3086 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3087 }
3088 });
3089 } finally {
3090 Binder.restoreCallingIdentity(token);
3091 }
3092 }
3093
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003095 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3096 throws RemoteException {
3097 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003098 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3099 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3100 "IMS not available on device.");
3101 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3103 final long token = Binder.clearCallingIdentity();
3104 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(token);
3111 }
3112 }
3113
3114 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003115 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3116 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003117 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3118 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3119 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003120
3121 final long token = Binder.clearCallingIdentity();
3122 try {
3123 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3124 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003125 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003126 } catch (ImsException e) {
3127 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3128 + "is inactive, ignoring unregister.");
3129 // If the subscription is no longer active, just return, since the callback
3130 // will already have been removed internally.
3131 } finally {
3132 Binder.restoreCallingIdentity(token);
3133 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003134 }
3135
3136 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003137 public boolean isCapable(int subId, int capability, int regTech) {
3138 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3140 final long token = Binder.clearCallingIdentity();
3141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003142 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3146 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003147 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003148 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3149 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003150 } finally {
3151 Binder.restoreCallingIdentity(token);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003156 public boolean isAvailable(int subId, int capability, int regTech) {
3157 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 final long token = Binder.clearCallingIdentity();
3159 try {
3160 Phone phone = getPhone(subId);
3161 if (phone == null) return false;
3162 return phone.isImsCapabilityAvailable(capability, regTech);
3163 } finally {
3164 Binder.restoreCallingIdentity(token);
3165 }
3166 }
3167
Brad Ebinger77b832e2019-10-17 17:03:22 -07003168 /**
3169 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3170 * subscription.
3171 * @param subId The subscription to use to check the configuration.
3172 * @param callback The callback that will be used to send the result.
3173 * @param capability The MmTelFeature capability that will be used to send the result.
3174 * @param transportType The transport type of the MmTelFeature capability.
3175 */
3176 @Override
3177 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3178 int transportType) {
3179 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3180 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3181 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3182 "IMS not available on device.");
3183 }
3184 final long token = Binder.clearCallingIdentity();
3185 try {
3186 int slotId = getSlotIndex(subId);
3187 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3188 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3189 + subId + "'");
3190 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3191 }
3192 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3193 transportType, aBoolean -> {
3194 try {
3195 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3196 } catch (RemoteException e) {
3197 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3198 + "running. Ignore");
3199 }
3200 });
3201 } finally {
3202 Binder.restoreCallingIdentity(token);
3203 }
3204 }
3205
Brad Ebinger35c841c2018-10-01 10:40:55 -07003206 @Override
3207 public boolean isAdvancedCallingSettingEnabled(int subId) {
3208 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3210 final long token = Binder.clearCallingIdentity();
3211 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003212 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003214 } catch (ImsException e) {
3215 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003216 } finally {
3217 Binder.restoreCallingIdentity(token);
3218 }
3219 }
3220
3221 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003222 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003224 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003228 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003230 } catch (ImsException e) {
3231 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 } finally {
3233 Binder.restoreCallingIdentity(identity);
3234 }
3235 }
3236
3237 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003238 public boolean isVtSettingEnabled(int subId) {
3239 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003243 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3244 } catch (ImsException e) {
3245 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003246 } finally {
3247 Binder.restoreCallingIdentity(identity);
3248 }
3249 }
3250
3251 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003252 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003254 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 final long identity = Binder.clearCallingIdentity();
3256 try {
3257 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003258 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003259 } catch (ImsException e) {
3260 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003261 } finally {
3262 Binder.restoreCallingIdentity(identity);
3263 }
3264 }
3265
3266 @Override
3267 public boolean isVoWiFiSettingEnabled(int subId) {
3268 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3269 final long identity = Binder.clearCallingIdentity();
3270 try {
3271 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003272 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (ImsException e) {
3275 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 } finally {
3277 Binder.restoreCallingIdentity(identity);
3278 }
3279 }
3280
3281 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003282 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003283 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003284 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 final long identity = Binder.clearCallingIdentity();
3286 try {
3287 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003288 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003289 } catch (ImsException e) {
3290 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 } finally {
3292 Binder.restoreCallingIdentity(identity);
3293 }
3294 }
3295
3296 @Override
3297 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3298 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3299 final long identity = Binder.clearCallingIdentity();
3300 try {
3301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003302 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003304 } catch (ImsException e) {
3305 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003306 } finally {
3307 Binder.restoreCallingIdentity(identity);
3308 }
3309 }
3310
3311 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003312 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003314 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003315 final long identity = Binder.clearCallingIdentity();
3316 try {
3317 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003318 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003320 } catch (ImsException e) {
3321 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
3325 }
3326
3327 @Override
3328 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3330 "setVoWiFiNonPersistent");
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003335 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003336 } catch (ImsException e) {
3337 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003338 } finally {
3339 Binder.restoreCallingIdentity(identity);
3340 }
3341 }
3342
3343 @Override
3344 public int getVoWiFiModeSetting(int subId) {
3345 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3346 final long identity = Binder.clearCallingIdentity();
3347 try {
3348 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003349 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003351 } catch (ImsException e) {
3352 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
3356 }
3357
3358 @Override
3359 public void setVoWiFiModeSetting(int subId, int mode) {
3360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3361 "setVoWiFiModeSetting");
3362 final long identity = Binder.clearCallingIdentity();
3363 try {
3364 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003365 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003367 } catch (ImsException e) {
3368 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
3372 }
3373
3374 @Override
3375 public int getVoWiFiRoamingModeSetting(int subId) {
3376 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003380 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003382 } catch (ImsException e) {
3383 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 } finally {
3385 Binder.restoreCallingIdentity(identity);
3386 }
3387 }
3388
3389 @Override
3390 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3392 "setVoWiFiRoamingModeSetting");
3393 final long identity = Binder.clearCallingIdentity();
3394 try {
3395 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003396 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003398 } catch (ImsException e) {
3399 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 } finally {
3401 Binder.restoreCallingIdentity(identity);
3402 }
3403 }
3404
3405 @Override
3406 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3408 "setRttCapabilityEnabled");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003412 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3413 } catch (ImsException e) {
3414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 } finally {
3416 Binder.restoreCallingIdentity(identity);
3417 }
3418 }
3419
3420 @Override
3421 public boolean isTtyOverVolteEnabled(int subId) {
3422 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003426 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003428 } catch (ImsException e) {
3429 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003430 } finally {
3431 Binder.restoreCallingIdentity(identity);
3432 }
3433 }
3434
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003435 @Override
3436 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3437 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3438 final long identity = Binder.clearCallingIdentity();
3439 try {
3440 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003441 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003442 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003443 } catch (ImsException e) {
3444 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
3450 @Override
3451 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3452 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3453 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003454 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3455 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3456 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 try {
3458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003459 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003460 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003462 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3463 + "is inactive, ignoring unregister.");
3464 // If the subscription is no longer active, just return, since the callback will already
3465 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470
3471 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3473 boolean isProvisioned) {
3474 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3475 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3476 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3477 }
3478 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3479 "setProvisioningStatusForCapability");
3480 final long identity = Binder.clearCallingIdentity();
3481 try {
3482 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3483 Phone phone = getPhone(subId);
3484 if (phone == null) {
3485 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3486 + subId);
3487 return;
3488 }
3489 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3490 return;
3491 }
3492
3493 // this capability requires provisioning, route to the correct API.
3494 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3495 switch (capability) {
3496 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3497 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3498 ims.setVolteProvisioned(isProvisioned);
3499 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3500 ims.setWfcProvisioned(isProvisioned);
3501 }
3502 break;
3503 }
3504 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3505 // There is currently no difference in VT provisioning type.
3506 ims.setVtProvisioned(isProvisioned);
3507 break;
3508 }
3509 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3510 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3511 // change the capability of the feature instead if needed.
3512 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3513 == isProvisioned) {
3514 // No change in provisioning.
3515 return;
3516 }
3517 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3518 try {
3519 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003521 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3522 + ", Exception" + e.getMessage());
3523 }
3524 break;
3525 }
3526 default: {
3527 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3528 + capability + "', which does not require provisioning.");
3529 }
3530 }
3531
3532 } finally {
3533 Binder.restoreCallingIdentity(identity);
3534 }
3535 }
3536
3537 @Override
3538 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3539 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3540 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3541 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3542 }
3543 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3544 final long identity = Binder.clearCallingIdentity();
3545 try {
3546 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3547 Phone phone = getPhone(subId);
3548 if (phone == null) {
3549 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3550 + subId);
3551 // We will fail with "true" as the provisioning status because this is the default
3552 // if we do not require provisioning.
3553 return true;
3554 }
3555
3556 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3557 return true;
3558 }
3559
3560 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3561 switch (capability) {
3562 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3563 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3564 return ims.isVolteProvisionedOnDevice();
3565 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3566 return ims.isWfcProvisionedOnDevice();
3567 }
3568 // This should never happen, since we are checking tech above to make sure it
3569 // is either LTE or IWLAN.
3570 throw new IllegalArgumentException("Invalid radio technology for voice "
3571 + "capability.");
3572 }
3573 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3574 // There is currently no difference in VT provisioning type.
3575 return ims.isVtProvisionedOnDevice();
3576 }
3577 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3578 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3579 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3580 }
3581 default: {
3582 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3583 + capability + "', which does not require provisioning.");
3584 }
3585 }
3586
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
3592 @Override
3593 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3594 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3595 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3596 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3597 }
3598 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3599 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3600 return (provisionedBits & capability) > 0;
3601 }
3602
3603 @Override
3604 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3605 boolean isProvisioned) {
3606 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3607 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3608 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3609 }
3610 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3611 "setProvisioningStatusForCapability");
3612 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3613 // If the current provisioning status for capability already matches isProvisioned,
3614 // do nothing.
3615 if (((provisionedBits & capability) > 0) == isProvisioned) {
3616 return;
3617 }
3618 if (isProvisioned) {
3619 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3620 } else {
3621 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3622 }
3623 }
3624
3625 /**
3626 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3627 * technology. The bitfield should mirror the bitfield defined by
3628 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3629 */
3630 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3631 String key = getMmTelProvisioningKey(subId, tech);
3632 // Default is no capabilities are provisioned.
3633 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3634 }
3635
3636 /**
3637 * Sets the MmTel capability provisioning bitfield (defined by
3638 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3639 * technology specified.
3640 *
3641 * Note: This is a synchronous command and should not be called on UI thread.
3642 */
3643 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3644 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3645 String key = getMmTelProvisioningKey(subId, tech);
3646 editor.putInt(key, newField);
3647 editor.commit();
3648 }
3649
3650 private static String getMmTelProvisioningKey(int subId, int tech) {
3651 // resulting key is provision_ims_mmtel_{subId}_{tech}
3652 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3653 }
3654
3655 /**
3656 * Query CarrierConfig to see if the specified capability requires provisioning for the
3657 * carrier associated with the subscription id.
3658 */
3659 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3660 int capability) {
3661 CarrierConfigManager configManager = new CarrierConfigManager(context);
3662 PersistableBundle c = configManager.getConfigForSubId(subId);
3663 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003664 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003665 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3666 false);
3667 boolean requireVoiceVtProvisioning = c.getBoolean(
3668 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3669
3670 // First check to make sure that the capability requires provisioning.
3671 switch (capability) {
3672 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3673 // intentional fallthrough
3674 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3675 if (requireVoiceVtProvisioning) {
3676 // Voice and Video requires provisioning
3677 return true;
3678 }
3679 break;
3680 }
3681 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3682 if (requireUtProvisioning) {
3683 // UT requires provisioning
3684 return true;
3685 }
3686 break;
3687 }
3688 }
3689 return false;
3690 }
3691
3692 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003693 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003694 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3695 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3696 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003697 enforceReadPrivilegedPermission("getImsProvisioningInt");
3698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003701 int slotId = getSlotIndex(subId);
3702 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3703 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3704 + subId + "' for key:" + key);
3705 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3706 }
3707 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003709 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3710 + subId + "' for key:" + key);
3711 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3720 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3721 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003722 enforceReadPrivilegedPermission("getImsProvisioningString");
3723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003726 int slotId = getSlotIndex(subId);
3727 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3728 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3729 + subId + "' for key:" + key);
3730 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3731 }
3732 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003733 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003734 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3735 + subId + "' for key:" + key);
3736 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003737 } finally {
3738 Binder.restoreCallingIdentity(identity);
3739 }
3740 }
3741
3742 @Override
3743 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003744 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3745 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3746 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003747 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3748 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003752 int slotId = getSlotIndex(subId);
3753 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3754 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3755 + subId + "' for key:" + key);
3756 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3757 }
3758 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003760 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3761 + "' for key:" + key);
3762 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 } finally {
3764 Binder.restoreCallingIdentity(identity);
3765 }
3766 }
3767
3768 @Override
3769 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003770 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3771 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3772 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3774 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003775 final long identity = Binder.clearCallingIdentity();
3776 try {
3777 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003778 int slotId = getSlotIndex(subId);
3779 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3780 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3781 + subId + "' for key:" + key);
3782 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3783 }
3784 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003785 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003786 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3787 + "' for key:" + key);
3788 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 } finally {
3790 Binder.restoreCallingIdentity(identity);
3791 }
3792 }
3793
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003795 int slotId = SubscriptionManager.getSlotIndex(subId);
3796 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3798 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003799 }
3800 return slotId;
3801 }
3802
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003803 private int getSlotIndex(int subId) {
3804 int slotId = SubscriptionManager.getSlotIndex(subId);
3805 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3806 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3807 }
3808 return slotId;
3809 }
3810
Wink Saville36469e72014-06-11 15:17:00 -07003811 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003812 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003813 */
3814 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003815 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3816 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003817 final int targetSdk = getTargetSdk(callingPackage);
3818 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003819 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003820 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003821 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003822 mApp, subId, callingPackage, callingFeatureId,
3823 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003824 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3825 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 final Phone phone = getPhone(subId);
3830 if (phone != null) {
3831 return phone.getServiceState().getDataNetworkType();
3832 } else {
3833 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3834 }
3835 } finally {
3836 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003837 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003838 }
3839
3840 /**
3841 * Returns the data network type
3842 */
3843 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003844 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3845 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3846 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003847 }
3848
3849 /**
3850 * Returns the data network type for a subId
3851 */
3852 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003853 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003856 mApp, subId, callingPackage, callingFeatureId,
3857 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003858 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3859 }
3860
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 final Phone phone = getPhone(subId);
3864 if (phone != null) {
3865 return phone.getServiceState().getDataNetworkType();
3866 } else {
3867 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3868 }
3869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003872 }
3873
3874 /**
Wink Saville36469e72014-06-11 15:17:00 -07003875 * Returns the Voice network type for a subId
3876 */
3877 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003878 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3879 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003880 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003881 mApp, subId, callingPackage, callingFeatureId,
3882 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003883 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3884 }
3885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 final Phone phone = getPhone(subId);
3889 if (phone != null) {
3890 return phone.getServiceState().getVoiceNetworkType();
3891 } else {
3892 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3893 }
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003897 }
3898
3899 /**
3900 * @return true if a ICC card is present
3901 */
3902 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003903 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003904 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3905 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003906 }
3907
3908 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003910 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003911 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003912 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003913 final long identity = Binder.clearCallingIdentity();
3914 try {
3915 final Phone phone = PhoneFactory.getPhone(slotIndex);
3916 if (phone != null) {
3917 return phone.getIccCard().hasIccCard();
3918 } else {
3919 return false;
3920 }
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003923 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003924 }
3925
3926 /**
3927 * Return if the current radio is LTE on CDMA. This
3928 * is a tri-state return value as for a period of time
3929 * the mode may be unknown.
3930 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003931 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003932 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003933 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003934 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003935 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003936 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3937 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3938 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003939 }
3940
Sanket Padawe356d7632015-06-22 14:03:32 -07003941 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003942 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3943 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003944 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003945 mApp, subId, callingPackage, callingFeatureId,
3946 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003947 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3948 }
3949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003950 final long identity = Binder.clearCallingIdentity();
3951 try {
3952 final Phone phone = getPhone(subId);
3953 if (phone == null) {
3954 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3955 } else {
3956 return phone.getLteOnCdmaMode();
3957 }
3958 } finally {
3959 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003960 }
Wink Saville36469e72014-06-11 15:17:00 -07003961 }
3962
Wink Saville36469e72014-06-11 15:17:00 -07003963 /**
3964 * {@hide}
3965 * Returns Default subId, 0 in the case of single standby.
3966 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003967 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003968 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003969 }
3970
Shishir Agrawala9f32182016-04-12 12:00:16 -07003971 private int getSlotForDefaultSubscription() {
3972 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3973 }
3974
Wink Savilleb564aae2014-10-23 10:18:09 -07003975 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003976 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003977 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003978
Pengquan Menge92a50d2018-09-21 15:54:48 -07003979 private boolean isActiveSubscription(int subId) {
3980 return mSubscriptionController.isActiveSubId(subId);
3981 }
3982
Ihab Awadf2177b72013-11-25 13:33:23 -08003983 /**
3984 * @see android.telephony.TelephonyManager.WifiCallingChoices
3985 */
3986 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 final long identity = Binder.clearCallingIdentity();
3988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003989 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3991 getWhenToMakeWifiCallsDefaultPreference());
3992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003995 }
3996
3997 /**
3998 * @see android.telephony.TelephonyManager.WifiCallingChoices
3999 */
4000 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4006 } finally {
4007 Binder.restoreCallingIdentity(identity);
4008 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004009 }
4010
Sailesh Nepald1e68152013-12-12 19:08:02 -08004011 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004012 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004013 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004014 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004015
Jordan Liu4c733742019-02-28 12:03:40 -08004016 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4017 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4018 if (phoneId == -1) {
4019 throw new IllegalArgumentException("Given slot index: " + slotIndex
4020 + " does not correspond to an active phone");
4021 }
4022 return PhoneFactory.getPhone(phoneId);
4023 }
4024
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004026 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4027 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4029 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004031 if (DBG) {
4032 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4033 }
4034 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4035 p2);
4036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004037
Jordan Liu4c733742019-02-28 12:03:40 -08004038
4039 @Override
4040 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4041 int slotIndex, String callingPackage, String aid, int p2) {
4042 enforceModifyPermission();
4043 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4044 if (DBG) {
4045 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4046 }
4047 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4048 callingPackage, aid, p2);
4049 }
4050
4051 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4052 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 if (TextUtils.equals(ISDR_AID, aid)) {
4056 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4058 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 if (bestComponent == null
4060 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4061 loge("The calling package is not allowed to access ISD-R.");
4062 throw new SecurityException(
4063 "The calling package is not allowed to access ISD-R.");
4064 }
Derek Tan740e1672017-06-27 14:56:27 -07004065 }
Derek Tan740e1672017-06-27 14:56:27 -07004066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004067 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004068 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4069 null /* workSource */);
4070 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004071 return response;
4072 } finally {
4073 Binder.restoreCallingIdentity(identity);
4074 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004075 }
4076
4077 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004078 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004079 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4080 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004081 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4082 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4083 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004084
Jordan Liu4c733742019-02-28 12:03:40 -08004085 @Override
4086 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4087 enforceModifyPermission();
4088 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4089 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4090 channel);
4091 }
4092
4093 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004094 final long identity = Binder.clearCallingIdentity();
4095 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004096 if (channel < 0) {
4097 return false;
4098 }
Jordan Liu4c733742019-02-28 12:03:40 -08004099 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4100 null /* workSource */);
4101 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004102 return success;
4103 } finally {
4104 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004105 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004106 }
4107
4108 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004109 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004110 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4112 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004113 if (DBG) {
4114 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4115 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4116 + p3 + " data=" + data);
4117 }
4118 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4119 command, p1, p2, p3, data);
4120 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004121
Jordan Liu4c733742019-02-28 12:03:40 -08004122 @Override
4123 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4124 int command, int p1, int p2, int p3, String data) {
4125 enforceModifyPermission();
4126 if (DBG) {
4127 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4128 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4129 + p3 + " data=" + data);
4130 }
4131 return iccTransmitApduLogicalChannelWithPermission(
4132 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4133 data);
4134 }
4135
4136 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4137 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 final long identity = Binder.clearCallingIdentity();
4139 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004140 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 return "";
4142 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004145 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4146 null /* workSource */);
4147 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 // Append the returned status code to the end of the response payload.
4150 String s = Integer.toHexString(
4151 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4152 if (response.payload != null) {
4153 s = IccUtils.bytesToHexString(response.payload) + s;
4154 }
4155 return s;
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004158 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004159 }
Jake Hambye994d462014-02-03 13:10:13 -08004160
Evan Charltonc66da362014-05-16 14:06:40 -07004161 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004162 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4163 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4165 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004167 if (DBG) {
4168 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4169 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4170 }
4171 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4172 cla, command, p1, p2, p3, data);
4173 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004174
Jordan Liu4c733742019-02-28 12:03:40 -08004175 @Override
4176 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4177 int command, int p1, int p2, int p3, String data) {
4178 enforceModifyPermission();
4179 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4180 if (DBG) {
4181 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4182 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4183 + " data=" + data);
4184 }
4185
4186 return iccTransmitApduBasicChannelWithPermission(
4187 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4188 p2, p3, data);
4189 }
4190
4191 // open APDU basic channel assuming the caller has sufficient permissions
4192 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4193 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4197 && TextUtils.equals(ISDR_AID, data)) {
4198 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4200 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004201 if (bestComponent == null
4202 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4203 loge("The calling package is not allowed to select ISD-R.");
4204 throw new SecurityException(
4205 "The calling package is not allowed to select ISD-R.");
4206 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004207 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004208
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004210 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4211 null /* workSource */);
4212 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 // Append the returned status code to the end of the response payload.
4215 String s = Integer.toHexString(
4216 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4217 if (response.payload != null) {
4218 s = IccUtils.bytesToHexString(response.payload) + s;
4219 }
4220 return s;
4221 } finally {
4222 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004223 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004224 }
4225
4226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004227 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004228 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4230 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 final long identity = Binder.clearCallingIdentity();
4233 try {
4234 if (DBG) {
4235 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4236 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4237 }
4238
4239 IccIoResult response =
4240 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4241 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4242 subId);
4243
4244 if (DBG) {
4245 log("Exchange SIM_IO [R]" + response);
4246 }
4247
4248 byte[] result = null;
4249 int length = 2;
4250 if (response.payload != null) {
4251 length = 2 + response.payload.length;
4252 result = new byte[length];
4253 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4254 } else {
4255 result = new byte[length];
4256 }
4257
4258 result[length - 1] = (byte) response.sw2;
4259 result[length - 2] = (byte) response.sw1;
4260 return result;
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004263 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004264 }
4265
Nathan Haroldb3014052017-01-25 15:57:32 -08004266 /**
4267 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4268 * on a particular subscription
4269 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004270 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4271 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004272 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004273 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004274 return null;
4275 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276
4277 final long identity = Binder.clearCallingIdentity();
4278 try {
4279 if (appType != TelephonyManager.APPTYPE_USIM
4280 && appType != TelephonyManager.APPTYPE_SIM) {
4281 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4282 return null;
4283 }
4284 Object response = sendRequest(
4285 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4286 if (response instanceof String[]) {
4287 return (String[]) response;
4288 }
yincheng zhaod698b842019-09-06 17:06:54 -07004289 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004291 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004294 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004295 }
4296
yincheng zhaod698b842019-09-06 17:06:54 -07004297 /**
4298 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4299 * subscription.
4300 *
4301 * @param subId the id of the subscription.
4302 * @param appType the uicc app type, must be USIM or SIM.
4303 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4304 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004305 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004306 * @return number of fplmns that is successfully written to the SIM.
4307 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004308 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4309 String callingFeatureId) {
4310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4311 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004312 if (DBG) logv("no permissions for setForbiddenplmns");
4313 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4314 }
4315 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4316 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4317 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4318 }
4319 if (fplmns == null) {
4320 throw new IllegalArgumentException("Fplmn List provided is null");
4321 }
4322 for (String fplmn : fplmns) {
4323 if (!CellIdentity.isValidPlmn(fplmn)) {
4324 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4325 }
4326 }
4327 final long identity = Binder.clearCallingIdentity();
4328 try {
4329 Object response = sendRequest(
4330 CMD_SET_FORBIDDEN_PLMNS,
4331 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4332 subId);
4333 return (int) response;
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004339 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004340 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004341 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4342 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 final long identity = Binder.clearCallingIdentity();
4345 try {
4346 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4347 if (response.payload == null) {
4348 return "";
4349 }
Evan Charltonc66da362014-05-16 14:06:40 -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 s = IccUtils.bytesToHexString(response.payload) + s;
4355 return s;
4356 } finally {
4357 Binder.restoreCallingIdentity(identity);
4358 }
Evan Charltonc66da362014-05-16 14:06:40 -07004359 }
4360
Jake Hambye994d462014-02-03 13:10:13 -08004361 /**
4362 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4363 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4364 *
4365 * @param itemID the ID of the item to read
4366 * @return the NV item as a String, or null on error.
4367 */
4368 @Override
4369 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004370 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4372 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373
4374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004377 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4379 return value;
4380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Jake Hambye994d462014-02-03 13:10:13 -08004383 }
4384
4385 /**
4386 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4387 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4388 *
4389 * @param itemID the ID of the item to read
4390 * @param itemValue the value to write, as a String
4391 * @return true on success; false on any failure
4392 */
4393 @Override
4394 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004395 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
4399 final long identity = Binder.clearCallingIdentity();
4400 try {
4401 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4402 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004403 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
4408 }
Jake Hambye994d462014-02-03 13:10:13 -08004409 }
4410
4411 /**
4412 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4413 * Used for device configuration by some CDMA operators.
4414 *
4415 * @param preferredRoamingList byte array containing the new PRL
4416 * @return true on success; false on any failure
4417 */
4418 @Override
4419 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4421 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422
4423 final long identity = Binder.clearCallingIdentity();
4424 try {
4425 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4426 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4427 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4428 return success;
4429 } finally {
4430 Binder.restoreCallingIdentity(identity);
4431 }
Jake Hambye994d462014-02-03 13:10:13 -08004432 }
4433
4434 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004435 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004436 * Used for device configuration by some CDMA operators.
4437 *
chen xu6dac5ab2018-10-26 17:39:23 -07004438 * @param slotIndex - device slot.
4439 *
Jake Hambye994d462014-02-03 13:10:13 -08004440 * @return true on success; false on any failure
4441 */
4442 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004443 public boolean resetModemConfig(int slotIndex) {
4444 Phone phone = PhoneFactory.getPhone(slotIndex);
4445 if (phone != null) {
4446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4447 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448
chen xu6dac5ab2018-10-26 17:39:23 -07004449 final long identity = Binder.clearCallingIdentity();
4450 try {
4451 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4452 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4453 return success;
4454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 }
chen xu6dac5ab2018-10-26 17:39:23 -07004458 return false;
4459 }
4460
4461 /**
4462 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4463 *
4464 * @param slotIndex - device slot.
4465 *
4466 * @return true on success; false on any failure
4467 */
4468 @Override
4469 public boolean rebootModem(int slotIndex) {
4470 Phone phone = PhoneFactory.getPhone(slotIndex);
4471 if (phone != null) {
4472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4473 mApp, phone.getSubId(), "rebootModem");
4474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4478 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4479 return success;
4480 } finally {
4481 Binder.restoreCallingIdentity(identity);
4482 }
4483 }
4484 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004485 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004486
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004487 public String[] getPcscfAddress(String apnType, String callingPackage,
4488 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004489 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004490 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4491 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004492 return new String[0];
4493 }
4494
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 final long identity = Binder.clearCallingIdentity();
4496 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004497 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Wink Saville36469e72014-06-11 15:17:00 -07004501 }
4502
Brad Ebinger51f743a2017-01-23 13:50:20 -08004503 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004504 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4505 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004506 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004507 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004512 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004513 // may happen if the device does not support IMS.
4514 return;
4515 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004516 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004520 }
4521
4522 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4524 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004525 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004526 public void disableIms(int slotId) {
4527 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004531 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 // may happen if the device does not support IMS.
4533 return;
4534 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004535 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004539 }
4540
4541 /**
4542 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4543 * feature or {@link null} if the service is not available. If the feature is available, the
4544 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4545 */
4546 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004547 IImsServiceFeatureCallback callback) {
4548 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549
4550 final long identity = Binder.clearCallingIdentity();
4551 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004552 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004553 // may happen if the device does not support IMS.
4554 return null;
4555 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004556 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004557 } finally {
4558 Binder.restoreCallingIdentity(identity);
4559 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004560 }
4561
4562 /**
4563 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4564 * feature during emergency calling or {@link null} if the service is not available. If the
4565 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4566 * listener for feature updates.
4567 */
4568 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004573 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004574 // may happen if the device does not support IMS.
4575 return null;
4576 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004577 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004578 } finally {
4579 Binder.restoreCallingIdentity(identity);
4580 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004581 }
4582
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 /**
4584 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004585 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004586 */
4587 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4588 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004593 // may happen if the device does not support IMS.
4594 return null;
4595 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004596 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004600 }
4601
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 /**
4603 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004604 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004605 */
4606 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4607 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608
4609 final long identity = Binder.clearCallingIdentity();
4610 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004611 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004612 // may happen if the device does not support IMS.
4613 return null;
4614 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004615 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 } finally {
4617 Binder.restoreCallingIdentity(identity);
4618 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004619 }
4620
Brad Ebinger884c07b2018-02-15 16:17:40 -08004621 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004622 * Sets the ImsService Package Name that Telephony will bind to.
4623 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004624 * @param slotIndex the slot ID that the ImsService should bind for.
4625 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004626 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004627 * @param featureTypes An integer array of feature types associated with a packageName.
4628 * @param packageName The name of the package that the current configuration will be replaced
4629 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004630 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004631 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004632 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4633 int[] featureTypes, String packageName) {
4634 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4635 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004636 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4637 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004638 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 final long identity = Binder.clearCallingIdentity();
4641 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004642 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004643 // may happen if the device does not support IMS.
4644 return false;
4645 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004646 Map<Integer, String> featureConfig = new HashMap<>();
4647 for (int featureType : featureTypes) {
4648 featureConfig.put(featureType, packageName);
4649 }
4650 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4651 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004652 } finally {
4653 Binder.restoreCallingIdentity(identity);
4654 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004655 }
4656
4657 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004658 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004659 *
4660 * @param slotId The slot that the ImsService is associated with.
4661 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4662 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004663 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004664 * @return the package name of the ImsService configuration.
4665 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004666 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4667 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004668 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004669 TelephonyPermissions
4670 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4671 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4672 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 final long identity = Binder.clearCallingIdentity();
4675 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004676 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004677 // may happen if the device does not support IMS.
4678 return "";
4679 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004680 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004681 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4682 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004683 } finally {
4684 Binder.restoreCallingIdentity(identity);
4685 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004686 }
4687
Brad Ebinger77b832e2019-10-17 17:03:22 -07004688 /**
4689 * Get the MmTelFeature state associated with the requested subscription id.
4690 * @param subId The subscription that the MmTelFeature is associated with.
4691 * @param callback A callback with an integer containing the
4692 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4693 */
4694 @Override
4695 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4696 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4697 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4698 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4699 "IMS not available on device.");
4700 }
4701 final long token = Binder.clearCallingIdentity();
4702 try {
4703 int slotId = getSlotIndex(subId);
4704 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4705 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4706 + subId + "'");
4707 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4708 }
4709 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4710 try {
4711 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4712 } catch (RemoteException e) {
4713 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4714 + "Ignore");
4715 }
4716 });
4717 } finally {
4718 Binder.restoreCallingIdentity(token);
4719 }
4720 }
4721
Wink Saville36469e72014-06-11 15:17:00 -07004722 public void setImsRegistrationState(boolean registered) {
4723 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724
4725 final long identity = Binder.clearCallingIdentity();
4726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004727 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728 } finally {
4729 Binder.restoreCallingIdentity(identity);
4730 }
Wink Saville36469e72014-06-11 15:17:00 -07004731 }
4732
4733 /**
Stuart Scott54788802015-03-30 13:18:01 -07004734 * Set the network selection mode to automatic.
4735 *
4736 */
4737 @Override
4738 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004739 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4740 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004741
Pengquan Menge92a50d2018-09-21 15:54:48 -07004742 if (!isActiveSubscription(subId)) {
4743 return;
4744 }
4745
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746 final long identity = Binder.clearCallingIdentity();
4747 try {
4748 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4749 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
4752 }
Stuart Scott54788802015-03-30 13:18:01 -07004753 }
4754
Pengquan Mengea84e042018-09-20 14:57:26 -07004755 /**
4756 * Ask the radio to connect to the input network and change selection mode to manual.
4757 *
4758 * @param subId the id of the subscription.
4759 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4760 * the operator to attach to.
4761 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4762 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4763 * normal network selection next time.
4764 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004765 */
4766 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004767 public boolean setNetworkSelectionModeManual(
4768 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4770 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004771
4772 if (!isActiveSubscription(subId)) {
4773 return false;
4774 }
4775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004778 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004780 if (DBG) {
4781 log("setNetworkSelectionModeManual: subId: " + subId
4782 + " operator: " + operatorInfo);
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4785 } finally {
4786 Binder.restoreCallingIdentity(identity);
4787 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004788 }
4789
4790 /**
4791 * Scans for available networks.
4792 */
4793 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004794 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4795 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004796 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4797 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004798 LocationAccessPolicy.LocationPermissionResult locationResult =
4799 LocationAccessPolicy.checkLocationPermission(mApp,
4800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4801 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004802 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004803 .setCallingPid(Binder.getCallingPid())
4804 .setCallingUid(Binder.getCallingUid())
4805 .setMethod("getCellNetworkScanResults")
4806 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4807 .build());
4808 switch (locationResult) {
4809 case DENIED_HARD:
4810 throw new SecurityException("Not allowed to access scan results -- location");
4811 case DENIED_SOFT:
4812 return null;
4813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004814
Pengquan Menga1bb6272018-09-06 09:59:22 -07004815 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 try {
4817 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004818 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004823 }
4824
4825 /**
yinxub1bed742017-04-17 11:45:04 -07004826 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004827 *
yinxub1bed742017-04-17 11:45:04 -07004828 * @param subId id of the subscription
4829 * @param request contains the radio access networks with bands/channels to scan
4830 * @param messenger callback messenger for scan results or errors
4831 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004832 * @return the id of the requested scan which can be used to stop the scan.
4833 */
4834 @Override
4835 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004836 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004837 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4838 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004839 LocationAccessPolicy.LocationPermissionResult locationResult =
4840 LocationAccessPolicy.checkLocationPermission(mApp,
4841 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4842 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004843 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004844 .setCallingPid(Binder.getCallingPid())
4845 .setCallingUid(Binder.getCallingUid())
4846 .setMethod("requestNetworkScan")
4847 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4848 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004849 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004850 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004851 if (e != null) {
4852 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4853 throw e;
4854 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004855 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004856 return TelephonyScanManager.INVALID_SCAN_ID;
4857 }
4858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 }
Hall Liu912dfd32019-04-25 14:02:26 -07004860 int callingUid = Binder.getCallingUid();
4861 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 return mNetworkScanRequestTracker.startNetworkScan(
4865 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004866 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004867 } finally {
4868 Binder.restoreCallingIdentity(identity);
4869 }
yinxu504e1392017-04-12 16:03:22 -07004870 }
4871
Hall Liub2ac8ef2019-02-28 15:56:23 -08004872 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004873 NetworkScanRequest request, int subId) {
4874 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4875 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4876 boolean hasNetworkScanPermission =
4877 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4878 == PERMISSION_GRANTED;
4879
4880 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4881 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4882 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004883 }
4884
4885 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4886 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004887 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4888 return new SecurityException("Specific channels must not be"
4889 + " scanned without location access.");
4890 }
4891 }
4892 }
4893
Hall Liub2ac8ef2019-02-28 15:56:23 -08004894 return null;
4895 }
4896
yinxu504e1392017-04-12 16:03:22 -07004897 /**
4898 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004899 *
4900 * @param subId id of the subscription
4901 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004902 */
4903 @Override
4904 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4906 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004907
Hall Liu912dfd32019-04-25 14:02:26 -07004908 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 final long identity = Binder.clearCallingIdentity();
4910 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004911 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
yinxu504e1392017-04-12 16:03:22 -07004915 }
4916
4917 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004918 * Get the calculated preferred network type.
4919 * Used for debugging incorrect network type.
4920 *
4921 * @return the preferred network type, defined in RILConstants.java.
4922 */
4923 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004924 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004925 final Phone defaultPhone = getDefaultPhone();
4926 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004927 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004928 return RILConstants.PREFERRED_NETWORK_MODE;
4929 }
4930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935 } finally {
4936 Binder.restoreCallingIdentity(identity);
4937 }
Junda Liu84d15a22014-07-02 11:21:04 -07004938 }
4939
4940 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004941 * Get the preferred network type.
4942 * Used for device configuration by some CDMA operators.
4943 *
4944 * @return the preferred network type, defined in RILConstants.java.
4945 */
4946 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004947 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004948 TelephonyPermissions
4949 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4950 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951
4952 final long identity = Binder.clearCallingIdentity();
4953 try {
4954 if (DBG) log("getPreferredNetworkType");
4955 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4956 int networkType = (result != null ? result[0] : -1);
4957 if (DBG) log("getPreferredNetworkType: " + networkType);
4958 return networkType;
4959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004962 }
4963
4964 /**
4965 * Set the preferred network type.
4966 * Used for device configuration by some CDMA operators.
4967 *
4968 * @param networkType the preferred network type, defined in RILConstants.java.
4969 * @return true on success; false on any failure.
4970 */
4971 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004972 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4974 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4979 Boolean success = (Boolean) sendRequest(
4980 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4981 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4982 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004983 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4985 }
4986 return success;
4987 } finally {
4988 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004989 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004990 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004991
4992 /**
Miaoa84611c2019-03-15 09:21:10 +08004993 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004994 *
Miaoa84611c2019-03-15 09:21:10 +08004995 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004996 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004997 * @hide
4998 */
4999 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005000 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005003 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 try {
Miaoa84611c2019-03-15 09:21:10 +08005005 if (phone != null) {
5006 return phone.hasMatchedTetherApnSetting();
5007 } else {
5008 return false;
5009 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005012 }
Junda Liu475951f2014-11-07 16:45:03 -08005013 }
5014
5015 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005016 * Set mobile data enabled
5017 * Used by the user through settings etc to turn on/off mobile data
5018 *
5019 * @param enable {@code true} turn turn data on, else {@code false}
5020 */
5021 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005022 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5024 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025
5026 final long identity = Binder.clearCallingIdentity();
5027 try {
5028 int phoneId = mSubscriptionController.getPhoneId(subId);
5029 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5030 Phone phone = PhoneFactory.getPhone(phoneId);
5031 if (phone != null) {
5032 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005033 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005034 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005035 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005036 }
5037 } finally {
5038 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005039 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005040 }
5041
5042 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005043 * Get the user enabled state of Mobile Data.
5044 *
5045 * TODO: remove and use isUserDataEnabled.
5046 * This can't be removed now because some vendor codes
5047 * calls through ITelephony directly while they should
5048 * use TelephonyManager.
5049 *
5050 * @return true on enabled
5051 */
5052 @Override
5053 public boolean getDataEnabled(int subId) {
5054 return isUserDataEnabled(subId);
5055 }
5056
5057 /**
5058 * Get whether mobile data is enabled per user setting.
5059 *
5060 * There are other factors deciding whether mobile data is actually enabled, but they are
5061 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005062 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005063 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005064 *
5065 * @return {@code true} if data is enabled else {@code false}
5066 */
5067 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005068 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005069 try {
5070 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5071 null);
5072 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5074 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005075 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 int phoneId = mSubscriptionController.getPhoneId(subId);
5080 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5081 Phone phone = PhoneFactory.getPhone(phoneId);
5082 if (phone != null) {
5083 boolean retVal = phone.isUserDataEnabled();
5084 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5085 return retVal;
5086 } else {
5087 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5088 return false;
5089 }
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005092 }
5093 }
5094
5095 /**
5096 * Get whether mobile data is enabled.
5097 *
5098 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5099 * whether mobile data is actually enabled.
5100 *
5101 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5102 *
5103 * @return {@code true} if data is enabled else {@code false}
5104 */
5105 @Override
5106 public boolean isDataEnabled(int subId) {
5107 try {
5108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5109 null);
5110 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005111 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5112 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005113 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005114
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 int phoneId = mSubscriptionController.getPhoneId(subId);
5118 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5119 Phone phone = PhoneFactory.getPhone(phoneId);
5120 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005121 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5123 return retVal;
5124 } else {
5125 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5126 return false;
5127 }
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005130 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005131 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005132
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005133 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5134 Phone phone) {
5135 //load access rules from carrier configs, and check those as well: b/139133814
5136 SubscriptionController subController = SubscriptionController.getInstance();
5137 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5138 || subController == null) return privilegeFromSim;
5139
5140 int uid = Binder.getCallingUid();
5141 PackageManager pkgMgr = phone.getContext().getPackageManager();
5142 String[] packages = pkgMgr.getPackagesForUid(uid);
5143
5144 final long identity = Binder.clearCallingIdentity();
5145 try {
5146 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5147 SubscriptionManager subManager = (SubscriptionManager)
5148 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5149 for (String pkg : packages) {
5150 if (subManager.canManageSubscription(subInfo, pkg)) {
5151 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5152 }
5153 }
5154 return privilegeFromSim;
5155 } finally {
5156 Binder.restoreCallingIdentity(identity);
5157 }
5158 }
5159
5160 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5161 String pkgName) {
5162 //load access rules from carrier configs, and check those as well: b/139133814
5163 SubscriptionController subController = SubscriptionController.getInstance();
5164 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5165 || subController == null) return privilegeFromSim;
5166
5167 final long identity = Binder.clearCallingIdentity();
5168 try {
5169 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5170 SubscriptionManager subManager = (SubscriptionManager)
5171 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5172 return subManager.canManageSubscription(subInfo, pkgName)
5173 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5174 } finally {
5175 Binder.restoreCallingIdentity(identity);
5176 }
5177 }
5178
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005179 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005180 public int getCarrierPrivilegeStatus(int subId) {
5181 final Phone phone = getPhone(subId);
5182 if (phone == null) {
5183 loge("getCarrierPrivilegeStatus: Invalid subId");
5184 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5185 }
5186 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005187 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005188 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005189 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5190 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005191
5192 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5193 card.getCarrierPrivilegeStatusForCurrentTransaction(
5194 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005195 }
Junda Liu29340342014-07-10 15:23:27 -07005196
5197 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005198 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5199 final Phone phone = getPhone(subId);
5200 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005201 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5203 }
5204 UiccProfile profile =
5205 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5206 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005207 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5209 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005210 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5211 profile.getCarrierPrivilegeStatusForUid(
5212 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 }
5214
5215 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005216 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5217 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005218 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005219 }
5220
5221 int phoneId = SubscriptionManager.getPhoneId(subId);
5222 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005223 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005224 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005225 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5226 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005227 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5228 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5229 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005230 }
5231
5232 @Override
5233 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005234 if (TextUtils.isEmpty(pkgName))
5235 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005236 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5237 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5238 UiccCard card = UiccController.getInstance().getUiccCard(i);
5239 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005240 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005241 continue;
5242 }
5243
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005244 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5245 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5246 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005247 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5248 break;
5249 }
5250 }
5251
5252 return result;
Junda Liu29340342014-07-10 15:23:27 -07005253 }
Derek Tan89e89d42014-07-08 17:00:10 -07005254
5255 @Override
Junda Liue64de782015-04-16 17:19:16 -07005256 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5257 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5258 loge("phoneId " + phoneId + " is not valid.");
5259 return null;
5260 }
5261 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005262 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005263 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005264 return null ;
5265 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005266 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005267 }
5268
Amith Yamasani6e118872016-02-19 12:53:51 -08005269 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005270 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005272 List<String> privilegedPackages = new ArrayList<>();
5273 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005274 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5275 // has UICC in that slot.
5276 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005277 if (card.hasCarrierPrivilegeRules()) {
5278 if (packages == null) {
5279 // Only check packages in user 0 for now
5280 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005281 PackageManager.MATCH_DISABLED_COMPONENTS
5282 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005283 | PackageManager.GET_SIGNING_CERTIFICATES,
5284 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005285 }
5286 for (int p = packages.size() - 1; p >= 0; p--) {
5287 PackageInfo pkgInfo = packages.get(p);
5288 if (pkgInfo != null && pkgInfo.packageName != null
5289 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005290 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005291 privilegedPackages.add(pkgInfo.packageName);
5292 }
5293 }
5294 }
5295 }
5296 return privilegedPackages;
5297 }
5298
chen xuf7e9fe82019-05-09 19:31:02 -07005299 @Override
5300 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005301 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5302
5303 final long identity = Binder.clearCallingIdentity();
5304
chen xuf7e9fe82019-05-09 19:31:02 -07005305 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005306 try {
5307 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5308 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5309 }
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005312 }
5313 return privilegedPackages;
5314 }
5315
Wink Savilleb564aae2014-10-23 10:18:09 -07005316 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005317 final Phone phone = getPhone(subId);
5318 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005319 if (card == null) {
5320 loge("getIccId: No UICC");
5321 return null;
5322 }
5323 String iccId = card.getIccId();
5324 if (TextUtils.isEmpty(iccId)) {
5325 loge("getIccId: ICC ID is null or empty.");
5326 return null;
5327 }
5328 return iccId;
5329 }
5330
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005331 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005332 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5333 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5335 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337 final long identity = Binder.clearCallingIdentity();
5338 try {
5339 final String iccId = getIccId(subId);
5340 final Phone phone = getPhone(subId);
5341 if (phone == null) {
5342 return false;
5343 }
5344 final String subscriberId = phone.getSubscriberId();
5345
5346 if (DBG_MERGE) {
5347 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5348 + subscriberId + " to " + number);
5349 }
5350
5351 if (TextUtils.isEmpty(iccId)) {
5352 return false;
5353 }
5354
5355 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5356
5357 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5358 if (alphaTag == null) {
5359 editor.remove(alphaTagPrefKey);
5360 } else {
5361 editor.putString(alphaTagPrefKey, alphaTag);
5362 }
5363
5364 // Record both the line number and IMSI for this ICCID, since we need to
5365 // track all merged IMSIs based on line number
5366 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5367 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5368 if (number == null) {
5369 editor.remove(numberPrefKey);
5370 editor.remove(subscriberPrefKey);
5371 } else {
5372 editor.putString(numberPrefKey, number);
5373 editor.putString(subscriberPrefKey, subscriberId);
5374 }
5375
5376 editor.commit();
5377 return true;
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005380 }
Derek Tan7226c842014-07-02 17:42:23 -07005381 }
5382
5383 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005384 public String getLine1NumberForDisplay(int subId, String callingPackage,
5385 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005386 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005388 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005389 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005390 return null;
5391 }
Derek Tan97ebb422014-09-05 16:55:38 -07005392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 String iccId = getIccId(subId);
5396 if (iccId != null) {
5397 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5398 if (DBG_MERGE) {
5399 log("getLine1NumberForDisplay returning "
5400 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5401 }
5402 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5405 return null;
5406 } finally {
5407 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005408 }
Derek Tan7226c842014-07-02 17:42:23 -07005409 }
5410
5411 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005412 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5413 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005415 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005416 return null;
5417 }
Derek Tan97ebb422014-09-05 16:55:38 -07005418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 String iccId = getIccId(subId);
5422 if (iccId != null) {
5423 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5424 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5425 }
5426 return null;
5427 } finally {
5428 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005429 }
Derek Tan7226c842014-07-02 17:42:23 -07005430 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005431
5432 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005433 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5434 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005435 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5436 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005437 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005438 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005439 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005440 return null;
5441 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005442
Jordan Liub49b04b2019-05-06 14:45:15 -07005443 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5444 // the process, where TelephonyManager was instantiated.
5445 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005446 final long identity = Binder.clearCallingIdentity();
5447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005448 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 final TelephonyManager tele = TelephonyManager.from(context);
5450 final SubscriptionManager sub = SubscriptionManager.from(context);
5451
5452 // Figure out what subscribers are currently active
5453 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
Jordan Liub49b04b2019-05-06 14:45:15 -07005455 // Only consider subs which match the current subId
5456 // This logic can be simplified. See b/131189269 for progress.
5457 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005458 activeSubscriberIds.add(tele.getSubscriberId(subId));
5459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460
5461 // First pass, find a number override for an active subscriber
5462 String mergeNumber = null;
5463 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5464 for (String key : prefs.keySet()) {
5465 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5466 final String subscriberId = (String) prefs.get(key);
5467 if (activeSubscriberIds.contains(subscriberId)) {
5468 final String iccId = key.substring(
5469 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5470 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5471 mergeNumber = (String) prefs.get(numberKey);
5472 if (DBG_MERGE) {
5473 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5474 + " for active subscriber " + subscriberId);
5475 }
5476 if (!TextUtils.isEmpty(mergeNumber)) {
5477 break;
5478 }
5479 }
5480 }
5481 }
5482
5483 // Shortcut when no active merged subscribers
5484 if (TextUtils.isEmpty(mergeNumber)) {
5485 return null;
5486 }
5487
5488 // Second pass, find all subscribers under that line override
5489 final ArraySet<String> result = new ArraySet<>();
5490 for (String key : prefs.keySet()) {
5491 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5492 final String number = (String) prefs.get(key);
5493 if (mergeNumber.equals(number)) {
5494 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5495 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5496 final String subscriberId = (String) prefs.get(subscriberKey);
5497 if (!TextUtils.isEmpty(subscriberId)) {
5498 result.add(subscriberId);
5499 }
5500 }
5501 }
5502 }
5503
5504 final String[] resultArray = result.toArray(new String[result.size()]);
5505 Arrays.sort(resultArray);
5506 if (DBG_MERGE) {
5507 Slog.d(LOG_TAG,
5508 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5509 }
5510 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005511 } finally {
5512 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005513 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005514 }
5515
5516 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005517 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5518 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5519
5520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 final TelephonyManager telephonyManager = mApp.getSystemService(
5523 TelephonyManager.class);
5524 String subscriberId = telephonyManager.getSubscriberId(subId);
5525 if (subscriberId == null) {
5526 if (DBG) {
5527 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5528 + subId);
5529 }
5530 return null;
5531 }
5532
5533 final SubscriptionInfo info = SubscriptionController.getInstance()
5534 .getSubscriptionInfo(subId);
5535 final ParcelUuid groupUuid = info.getGroupUuid();
5536 // If it doesn't belong to any group, return just subscriberId of itself.
5537 if (groupUuid == null) {
5538 return new String[]{subscriberId};
5539 }
5540
5541 // Get all subscriberIds from the group.
5542 final List<String> mergedSubscriberIds = new ArrayList<>();
5543 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005544 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5545 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005546 for (SubscriptionInfo subInfo : groupInfos) {
5547 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5548 if (subscriberId != null) {
5549 mergedSubscriberIds.add(subscriberId);
5550 }
5551 }
5552
5553 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556
5557 }
5558 }
5559
5560 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005561 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005562 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5563 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 final Phone phone = getPhone(subId);
5568 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005572 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005573
5574 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005575 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005576 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5577 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005578 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579
5580 final long identity = Binder.clearCallingIdentity();
5581 try {
5582 final Phone phone = getPhone(subId);
5583 if (phone == null) {
5584 return false;
5585 }
5586 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5587 cdmaNonRoamingList);
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005590 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005591 }
5592
5593 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005594 @Deprecated
5595 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5596 enforceModifyPermission();
5597
5598 int returnValue = 0;
5599 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005600 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005601 if(result.exception == null) {
5602 if (result.result != null) {
5603 byte[] responseData = (byte[])(result.result);
5604 if(responseData.length > oemResp.length) {
5605 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5606 responseData.length + "bytes. Buffer Size is " +
5607 oemResp.length + "bytes.");
5608 }
5609 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5610 returnValue = responseData.length;
5611 }
5612 } else {
5613 CommandException ex = (CommandException) result.exception;
5614 returnValue = ex.getCommandError().ordinal();
5615 if(returnValue > 0) returnValue *= -1;
5616 }
5617 } catch (RuntimeException e) {
5618 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5619 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5620 if(returnValue > 0) returnValue *= -1;
5621 }
5622
5623 return returnValue;
5624 }
5625
5626 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005627 public void setRadioCapability(RadioAccessFamily[] rafs) {
5628 try {
5629 ProxyController.getInstance().setRadioCapability(rafs);
5630 } catch (RuntimeException e) {
5631 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5632 }
5633 }
5634
5635 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005636 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005637 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005638 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005639 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005640 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005641 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
chen xub97461a2018-10-26 14:17:57 -07005644 TelephonyPermissions
5645 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5646 mApp, phone.getSubId(), "getRadioAccessFamily");
5647 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
chen xub97461a2018-10-26 14:17:57 -07005651 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005652 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005653
5654 @Override
5655 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005656 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005661 ImsManager.getInstance(defaultPhone.getContext(),
5662 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005666 }
5667
5668 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005669 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005670 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005671 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5672 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005673 return false;
5674 }
Svet Ganovb320e182015-04-16 12:30:10 -07005675
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 final long identity = Binder.clearCallingIdentity();
5677 try {
5678 // Check the user preference and the system-level IMS setting. Even if the user has
5679 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5680 // In the long run, we may instead need to check if there exists a connection service
5681 // which can support video calling.
5682 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005683 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 return imsManager.isVtEnabledByPlatform()
5685 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5686 && imsManager.isVtEnabledByUser();
5687 } finally {
5688 Binder.restoreCallingIdentity(identity);
5689 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005690 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005691
Andrew Leea1239f22015-03-02 17:44:07 -08005692 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005693 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5694 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005696 mApp, subId, callingPackage, callingFeatureId,
5697 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 return false;
5699 }
5700
5701 final long identity = Binder.clearCallingIdentity();
5702 try {
5703 CarrierConfigManager configManager =
5704 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
5709 }
Andrew Leea1239f22015-03-02 17:44:07 -08005710 }
5711
5712 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005713 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005715 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005716 return false;
5717 }
5718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 CarrierConfigManager configManager =
5722 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5725 } finally {
5726 Binder.restoreCallingIdentity(identity);
5727 }
Andrew Leea1239f22015-03-02 17:44:07 -08005728 }
5729
Andrew Lee9431b832015-03-09 18:46:45 -07005730 @Override
5731 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005732 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005733 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005734 }
5735
5736 @Override
5737 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 final long identity = Binder.clearCallingIdentity();
5739 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005740 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
Andrew Lee9431b832015-03-09 18:46:45 -07005744 }
5745
Hall Liuf6668912018-10-31 17:05:23 -07005746 /**
5747 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5748 * support for the feature and device firmware support.
5749 *
5750 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5751 */
5752 @Override
5753 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005755 final Phone phone = getPhone(subscriptionId);
5756 if (phone == null) {
5757 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5758 return false;
5759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005761 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5763 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005764 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005765 return isCarrierSupported && isDeviceSupported;
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
Hall Liu98187582018-01-22 19:15:32 -08005769 }
5770
Hall Liuf6668912018-10-31 17:05:23 -07005771 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005772 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5773 * RTT setting, will return true if the device and carrier both support RTT.
5774 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005775 */
5776 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 final long identity = Binder.clearCallingIdentity();
5778 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005779 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005783 }
5784
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005785 @Deprecated
5786 @Override
5787 public String getDeviceId(String callingPackage) {
5788 return getDeviceIdWithFeature(callingPackage, null);
5789 }
5790
Sanket Padawe7310cc72015-01-14 09:53:20 -08005791 /**
5792 * Returns the unique device ID of phone, for example, the IMEI for
5793 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5794 *
5795 * <p>Requires Permission:
5796 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5797 */
5798 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005799 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005800 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005801 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005802 return null;
5803 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005804 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005805 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005806 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005807 return null;
5808 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809
5810 final long identity = Binder.clearCallingIdentity();
5811 try {
5812 return phone.getDeviceId();
5813 } finally {
5814 Binder.restoreCallingIdentity(identity);
5815 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005816 }
5817
Ping Sunc67b7c22016-03-02 19:16:45 +08005818 /**
5819 * {@hide}
5820 * Returns the IMS Registration Status on a particular subid
5821 *
5822 * @param subId
5823 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005824 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005825 Phone phone = getPhone(subId);
5826 if (phone != null) {
5827 return phone.isImsRegistered();
5828 } else {
5829 return false;
5830 }
5831 }
5832
Santos Cordon7a1885b2015-02-03 11:15:19 -08005833 @Override
5834 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
5840 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005841 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005842
Tyler Gunnf70ed162019-04-03 15:28:53 -07005843 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005844 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005845 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005846 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005847 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005848 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5849 }
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5853 } finally {
5854 Binder.restoreCallingIdentity(identity);
5855 }
5856 }
5857
5858 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005859 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 Phone phone = getPhone(subscriptionId);
5863 if (phone == null) {
5864 return null;
5865 }
5866 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005872 /**
5873 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005874 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005875 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 final long identity = Binder.clearCallingIdentity();
5877 try {
5878 Phone phone = getPhone(subId);
5879 if (phone != null) {
5880 return phone.isWifiCallingEnabled();
5881 } else {
5882 return false;
5883 }
5884 } finally {
5885 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005886 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005887 }
5888
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005889 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005890 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005891 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005892 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005893 final long identity = Binder.clearCallingIdentity();
5894 try {
5895 Phone phone = getPhone(subId);
5896 if (phone != null) {
5897 return phone.isVideoEnabled();
5898 } else {
5899 return false;
5900 }
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005903 }
5904 }
5905
5906 /**
5907 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5908 * defined in {@link ImsRegistrationImplBase}.
5909 */
5910 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005911 final long identity = Binder.clearCallingIdentity();
5912 try {
5913 Phone phone = getPhone(subId);
5914 if (phone != null) {
5915 return phone.getImsRegistrationTech();
5916 } else {
5917 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5918 }
5919 } finally {
5920 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005921 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005922 }
5923
Stuart Scott8eef64f2015-04-08 15:13:54 -07005924 @Override
5925 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005926 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005927 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5928 return;
5929 }
5930
Svet Ganovcc087f82015-05-12 20:35:54 -07005931 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005932
Svet Ganovcc087f82015-05-12 20:35:54 -07005933 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005934 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5935 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005936 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005937 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005938 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005939 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5940 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005941 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005942 // There has been issues when Sms raw table somehow stores orphan
5943 // fragments. They lead to garbled message when new fragments come
5944 // in and combined with those stale ones. In case this happens again,
5945 // user can reset all network settings which will clean up this table.
5946 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005947 // Clean up IMS settings as well here.
5948 int slotId = getSlotIndex(subId);
5949 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5950 ImsManager.getInstance(mApp, slotId).factoryReset();
5951 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005952
5953 // Erase modem config if erase modem on network setting is enabled.
5954 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5955 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5956 if (configValue != null && Boolean.parseBoolean(configValue)) {
5957 sendEraseModemConfig(getDefaultPhone());
5958 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005959 } finally {
5960 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005961 }
5962 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005963
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005964 private void cleanUpSmsRawTable(Context context) {
5965 ContentResolver resolver = context.getContentResolver();
5966 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5967 resolver.delete(uri, null, null);
5968 }
5969
Narayan Kamath1c496c22015-04-16 14:40:19 +01005970 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005971 public String getSimLocaleForSubscriber(int subId) {
5972 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5973 final Phone phone = getPhone(subId);
5974 if (phone == null) {
5975 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005976 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005977 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 final long identity = Binder.clearCallingIdentity();
5979 try {
chen xu5d3637b2019-01-21 23:31:38 -08005980 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005981 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08005982 if (info == null) {
5983 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5984 return null;
5985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 // Try and fetch the locale from the carrier properties or from the SIM language
5987 // preferences (EF-PL and EF-LI)...
5988 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005989 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005990 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5991 if (localeFromDefaultSim != null) {
5992 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5993 if (DBG) log("Using locale from subId: " + subId + " locale: "
5994 + localeFromDefaultSim);
5995 return localeFromDefaultSim.toLanguageTag();
5996 } else {
5997 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 }
5999 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006000
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006001 // The SIM language preferences only store a language (e.g. fr = French), not an
6002 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6003 // the SIM and carrier preferences does not include a country we add the country
6004 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006005 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006007 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 return mccLocale.toLanguageTag();
6009 }
6010
6011 if (DBG) log("No locale found - returning null");
6012 return null;
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
6015 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006016 }
6017
6018 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006019 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6020 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006021 }
6022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006023 /**
6024 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6025 */
6026 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006027 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6028 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006029 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006030
Chenjie Yu1ba97252018-01-11 18:16:20 -08006031 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006032 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006033
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006034 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006035 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6036 * representing the state of the modem.
6037 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006038 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6039 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006040 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006041 */
6042 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006043 public void requestModemActivityInfo(ResultReceiver result) {
6044 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006045 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006046
6047 final long identity = Binder.clearCallingIdentity();
6048 try {
6049 ModemActivityInfo ret = null;
6050 synchronized (mLastModemActivityInfo) {
6051 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6052 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006053 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006054 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006056 int[] txTimeMs = info.getTransmitTimeMillis();
6057 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006058 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006059 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 }
6061 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006062 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6063 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 mLastModemActivityInfo.setIdleTimeMillis(
6065 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006066 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6067 mLastModemActivityInfo.setReceiveTimeMillis(
6068 info.getReceiveTimeMillis() + mLastModemActivityInfo
6069 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006070 }
Chen Xu13851032019-09-10 18:49:52 -07006071
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6073 mLastModemActivityInfo.getSleepTimeMillis(),
6074 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006075 mLastModemActivityInfo.getTransmitTimeMillis(),
6076 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006077 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 Bundle bundle = new Bundle();
6079 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6080 result.send(0, bundle);
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006083 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006084 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006085
Siddharth Rayb8114062018-06-17 15:02:38 -07006086 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6087 // less than total activity duration.
6088 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6089 if (info == null) {
6090 return false;
6091 }
6092 int activityDurationMs =
6093 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6094 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006095 int[] txTimeMs = info.getTransmitTimeMillis();
6096 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6097 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006098 }
6099 return (info.isValid()
6100 && (info.getSleepTimeMillis() <= activityDurationMs)
6101 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006102 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006103 && (totalTxTimeMs <= activityDurationMs));
6104 }
6105
Jack Yu85bd38a2015-11-09 11:34:32 -08006106 /**
6107 * {@hide}
6108 * Returns the service state information on specified subscription.
6109 */
6110 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006111 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6112 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006113 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006114 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006115 return null;
6116 }
6117
Hall Liuf19c44f2018-11-27 14:38:17 -08006118 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6119 LocationAccessPolicy.checkLocationPermission(mApp,
6120 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6121 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006122 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006123 .setCallingPid(Binder.getCallingPid())
6124 .setCallingUid(Binder.getCallingUid())
6125 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006126 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006127 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6128 .build());
6129
6130 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6131 LocationAccessPolicy.checkLocationPermission(mApp,
6132 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6133 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006134 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006135 .setCallingPid(Binder.getCallingPid())
6136 .setCallingUid(Binder.getCallingUid())
6137 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006138 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006139 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6140 .build());
6141 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6142 boolean hasFinePermission =
6143 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6144 boolean hasCoarsePermission =
6145 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 final Phone phone = getPhone(subId);
6150 if (phone == null) {
6151 return null;
6152 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006153
Hall Liuf19c44f2018-11-27 14:38:17 -08006154 ServiceState ss = phone.getServiceState();
6155
6156 // Scrub out the location info in ServiceState depending on what level of access
6157 // the caller has.
6158 if (hasFinePermission) return ss;
6159 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6160 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006161 } finally {
6162 Binder.restoreCallingIdentity(identity);
6163 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006164 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006165
6166 /**
6167 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6168 *
6169 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6170 * voicemail ringtone.
6171 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6172 * PhoneAccount.
6173 */
6174 @Override
6175 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6179 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006180 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006187 }
6188
6189 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006190 * Sets the per-account voicemail ringtone.
6191 *
6192 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6193 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6194 *
6195 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6196 * voicemail ringtone.
6197 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6198 * PhoneAccount.
6199 */
6200 @Override
6201 public void setVoicemailRingtoneUri(String callingPackage,
6202 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006204 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006205 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6206 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6208 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6209 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211
6212 final long identity = Binder.clearCallingIdentity();
6213 try {
6214 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6215 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006216 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 }
6218 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006221 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006222 }
6223
6224 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006225 * Returns whether vibration is set for voicemail notification in Phone settings.
6226 *
6227 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6228 * voicemail vibration setting.
6229 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6230 */
6231 @Override
6232 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6236 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006237 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6241 } finally {
6242 Binder.restoreCallingIdentity(identity);
6243 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006244 }
6245
Youhan Wange64578a2016-05-02 15:32:42 -07006246 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006247 * Sets the per-account voicemail vibration.
6248 *
6249 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6250 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6251 *
6252 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6253 * voicemail vibration setting.
6254 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6255 * specific PhoneAccount.
6256 */
6257 @Override
6258 public void setVoicemailVibrationEnabled(String callingPackage,
6259 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006260 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006261 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006262 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6263 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006264 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6265 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6266 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006267 }
6268
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6272 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006273 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 }
6275 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6276 } finally {
6277 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006278 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006279 }
6280
6281 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006282 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6283 *
6284 * @throws SecurityException if the caller does not have the required permission
6285 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006286 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006287 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006288 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006289 }
6290
6291 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006292 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6293 * permission.
6294 *
6295 * @throws SecurityException if the caller does not have the required permission
6296 */
6297 private void enforceSendSmsPermission() {
6298 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6299 }
6300
6301 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006302 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006303 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006304 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006305 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006306 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 final long identity = Binder.clearCallingIdentity();
6308 try {
6309 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006310 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 if (componentName == null) {
6312 throw new SecurityException(
6313 "Caller not current active visual voicemail package[null]");
6314 }
6315 String vvmPackage = componentName.getPackageName();
6316 if (!callingPackage.equals(vvmPackage)) {
6317 throw new SecurityException("Caller not current active visual voicemail package["
6318 + vvmPackage + "]");
6319 }
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006322 }
6323 }
6324
6325 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006326 * Return the application ID for the app type.
6327 *
6328 * @param subId the subscription ID that this request applies to.
6329 * @param appType the uicc app type.
6330 * @return Application ID for specificied app type, or null if no uicc.
6331 */
6332 @Override
6333 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006334 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006335 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336
6337 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006338 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006339 if (phone == null) {
6340 return null;
6341 }
6342 String aid = null;
6343 try {
6344 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6345 .getApplicationByType(appType).getAid();
6346 } catch (Exception e) {
6347 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6348 }
6349 return aid;
6350 } finally {
6351 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006352 }
Youhan Wange64578a2016-05-02 15:32:42 -07006353 }
6354
Youhan Wang4001d252016-05-11 10:29:41 -07006355 /**
6356 * Return the Electronic Serial Number.
6357 *
6358 * @param subId the subscription ID that this request applies to.
6359 * @return ESN or null if error.
6360 */
6361 @Override
6362 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006363 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006364 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365
6366 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006367 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 if (phone == null) {
6369 return null;
6370 }
6371 String esn = null;
6372 try {
6373 esn = phone.getEsn();
6374 } catch (Exception e) {
6375 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6376 }
6377 return esn;
6378 } finally {
6379 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006380 }
Youhan Wang4001d252016-05-11 10:29:41 -07006381 }
6382
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006383 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006384 * Return the Preferred Roaming List Version.
6385 *
6386 * @param subId the subscription ID that this request applies to.
6387 * @return PRLVersion or null if error.
6388 */
6389 @Override
6390 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006391 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006392 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393
6394 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006395 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006396 if (phone == null) {
6397 return null;
6398 }
6399 String cdmaPrlVersion = null;
6400 try {
6401 cdmaPrlVersion = phone.getCdmaPrlVersion();
6402 } catch (Exception e) {
6403 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6404 }
6405 return cdmaPrlVersion;
6406 } finally {
6407 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006408 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006409 }
6410
6411 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006412 * Get snapshot of Telephony histograms
6413 * @return List of Telephony histograms
6414 * @hide
6415 */
6416 @Override
6417 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6419 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420
6421 final long identity = Binder.clearCallingIdentity();
6422 try {
6423 return RIL.getTelephonyRILTimingHistograms();
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006427 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006428
6429 /**
6430 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006431 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6432 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006433 * Require system privileges. In the future we may add this to carrier APIs.
6434 *
Michele Berionne482f8202018-11-27 18:57:59 -08006435 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006436 */
6437 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006438 @TelephonyManager.SetCarrierRestrictionResult
6439 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006440 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006441 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006442
Michele Berionne482f8202018-11-27 18:57:59 -08006443 if (carrierRestrictionRules == null) {
6444 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006445 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 final long identity = Binder.clearCallingIdentity();
6448 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006449 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006450 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006451 } finally {
6452 Binder.restoreCallingIdentity(identity);
6453 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006454 }
6455
6456 /**
6457 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006458 * Get the allowed carrier list and the excluded carrier list, including the priority between
6459 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006460 * Require system privileges. In the future we may add this to carrier APIs.
6461 *
Michele Berionne482f8202018-11-27 18:57:59 -08006462 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006463 */
6464 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006465 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006466 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006467 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006468
6469 final long identity = Binder.clearCallingIdentity();
6470 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006471 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6472 if (response instanceof CarrierRestrictionRules) {
6473 return (CarrierRestrictionRules) response;
6474 }
6475 // Response is an Exception of some kind,
6476 // which is signalled to the user as a NULL retval
6477 return null;
6478 } catch (Exception e) {
6479 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6480 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006484 }
6485
fionaxu59545b42016-05-25 15:53:37 -07006486 /**
6487 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6488 * @param subId the subscription ID that this action applies to.
6489 * @param enabled control enable or disable metered apns.
6490 * {@hide}
6491 */
6492 @Override
6493 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6494 enforceModifyPermission();
6495 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496
6497 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006498 if (phone == null) {
6499 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6500 return;
6501 }
6502 try {
6503 phone.carrierActionSetMeteredApnsEnabled(enabled);
6504 } catch (Exception e) {
6505 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 } finally {
6507 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006508 }
6509 }
6510
6511 /**
6512 * Action set from carrier signalling broadcast receivers to enable/disable radio
6513 * @param subId the subscription ID that this action applies to.
6514 * @param enabled control enable or disable radio.
6515 * {@hide}
6516 */
6517 @Override
6518 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6519 enforceModifyPermission();
6520 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006521
6522 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006523 if (phone == null) {
6524 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6525 return;
6526 }
6527 try {
6528 phone.carrierActionSetRadioEnabled(enabled);
6529 } catch (Exception e) {
6530 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006533 }
6534 }
6535
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006536 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006537 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6538 * network status based on which carrier apps could apply actions accordingly,
6539 * enable/disable default url handler for example.
6540 *
6541 * @param subId the subscription ID that this action applies to.
6542 * @param report control start/stop reporting the default network status.
6543 * {@hide}
6544 */
6545 @Override
6546 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6547 enforceModifyPermission();
6548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006549
6550 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006551 if (phone == null) {
6552 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6553 return;
6554 }
6555 try {
6556 phone.carrierActionReportDefaultNetworkStatus(report);
6557 } catch (Exception e) {
6558 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 } finally {
6560 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006561 }
6562 }
6563
6564 /**
fionaxud9622282017-07-17 17:51:30 -07006565 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6566 * @param subId the subscription ID that this action applies to.
6567 * {@hide}
6568 */
6569 @Override
6570 public void carrierActionResetAll(int subId) {
6571 enforceModifyPermission();
6572 final Phone phone = getPhone(subId);
6573 if (phone == null) {
6574 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6575 return;
6576 }
6577 try {
6578 phone.carrierActionResetAll();
6579 } catch (Exception e) {
6580 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6581 }
6582 }
6583
6584 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006585 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6586 * bug report is being generated.
6587 */
6588 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006589 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006590 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6591 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006592 writer.println("Permission Denial: can't dump Phone from pid="
6593 + Binder.getCallingPid()
6594 + ", uid=" + Binder.getCallingUid()
6595 + "without permission "
6596 + android.Manifest.permission.DUMP);
6597 return;
6598 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006599 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006600 }
Jack Yueb89b242016-06-22 13:27:47 -07006601
Brad Ebingerdac2f002018-04-03 15:17:52 -07006602 @Override
6603 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6604 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6605 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006606 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6607 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006608 }
6609
Jack Yueb89b242016-06-22 13:27:47 -07006610 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006611 * Get aggregated video call data usage since boot.
6612 *
6613 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6614 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006615 * {@hide}
6616 */
6617 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006618 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006619 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6620 null);
6621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 // NetworkStatsService keeps tracking the active network interface and identity. It
6625 // records the delta with the corresponding network identity.
6626 // We just return the total video call data usage snapshot since boot.
6627 Phone phone = getPhone(subId);
6628 if (phone != null) {
6629 return phone.getVtDataUsage(perUidStats);
6630 }
6631 return null;
6632 } finally {
6633 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006634 }
Jack Yueb89b242016-06-22 13:27:47 -07006635 }
Jack Yu75ab2952016-07-08 14:29:33 -07006636
6637 /**
6638 * Policy control of data connection. Usually used when data limit is passed.
6639 * @param enabled True if enabling the data, otherwise disabling.
6640 * @param subId Subscription index
6641 * {@hide}
6642 */
6643 @Override
6644 public void setPolicyDataEnabled(boolean enabled, int subId) {
6645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006646
6647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 Phone phone = getPhone(subId);
6650 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006651 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006655 }
6656 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006657
6658 /**
6659 * Get Client request stats
6660 * @return List of Client Request Stats
6661 * @hide
6662 */
6663 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006664 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6665 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006666 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006667 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006668 return null;
6669 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006670 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006671
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 final long identity = Binder.clearCallingIdentity();
6673 try {
6674 if (phone != null) {
6675 return phone.getClientRequestStats();
6676 }
6677
6678 return null;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006682 }
6683
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006684 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006685 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006686 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006687 }
Jack Yueb4124c2017-02-16 15:32:43 -08006688
6689 /**
Grace Chen70990072017-03-24 17:21:30 -07006690 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006691 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006692 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006693 * @param state State of SIM (power down, power up, pass through)
6694 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6695 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6696 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006697 *
6698 **/
6699 @Override
Grace Chen70990072017-03-24 17:21:30 -07006700 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006701 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006702 Phone phone = PhoneFactory.getPhone(slotIndex);
6703
vagdeviaf9a5b92018-08-15 16:01:53 -07006704 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006709 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 }
6711 } finally {
6712 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006713 }
6714 }
Shuo Qiandd210312017-04-12 22:11:33 +00006715
Tyler Gunn65d45c22017-06-05 11:22:26 -07006716 private boolean isUssdApiAllowed(int subId) {
6717 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006718 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006719 if (configManager == null) {
6720 return false;
6721 }
6722 PersistableBundle pb = configManager.getConfigForSubId(subId);
6723 if (pb == null) {
6724 return false;
6725 }
6726 return pb.getBoolean(
6727 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6728 }
6729
Shuo Qiandd210312017-04-12 22:11:33 +00006730 /**
6731 * Check if phone is in emergency callback mode
6732 * @return true if phone is in emergency callback mode
6733 * @param subId sub id
6734 */
goneil9c5f4872017-12-05 14:07:56 -08006735 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006736 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006737 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006739
6740 final long identity = Binder.clearCallingIdentity();
6741 try {
6742 if (phone != null) {
6743 return phone.isInEcm();
6744 } else {
6745 return false;
6746 }
6747 } finally {
6748 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006749 }
6750 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006751
6752 /**
6753 * Get the current signal strength information for the given subscription.
6754 * Because this information is not updated when the device is in a low power state
6755 * it should not be relied-upon to be current.
6756 * @param subId Subscription index
6757 * @return the most recent cached signal strength info from the modem
6758 */
6759 @Override
6760 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 Phone p = getPhone(subId);
6764 if (p == null) {
6765 return null;
6766 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006767
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768 return p.getSignalStrength();
6769 } finally {
6770 Binder.restoreCallingIdentity(identity);
6771 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006772 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006773
Pengquan Meng77b7f132018-08-22 14:49:57 -07006774 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006775 * Get the current modem radio state for the given slot.
6776 * @param slotIndex slot index.
6777 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006778 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006779 * @return the current radio power state from the modem
6780 */
6781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006782 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006783 Phone phone = PhoneFactory.getPhone(slotIndex);
6784 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6786 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006787 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6788 }
6789
6790 final long identity = Binder.clearCallingIdentity();
6791 try {
6792 return phone.getRadioPowerState();
6793 } finally {
6794 Binder.restoreCallingIdentity(identity);
6795 }
6796 }
6797 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6798 }
6799
6800 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006801 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6802 *
6803 * <p>Requires one of the following permissions:
6804 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6805 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6806 * privileges.
6807 *
6808 * @param subId subscription id
6809 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6810 * {@code false}.
6811 */
6812 @Override
6813 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006814 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6815 null /* message */);
6816
Pengquan Menga1bb6272018-09-06 09:59:22 -07006817 boolean isEnabled = false;
6818 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006819 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006820 Phone phone = getPhone(subId);
6821 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006822 } catch (Exception e) {
6823 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6824 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006825 } finally {
6826 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006827 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006828 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006829 }
6830
6831
6832 /**
6833 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6834 *
6835 * <p> Requires permission:
6836 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6837 * privileges.
6838 *
6839 * @param subId subscription id
6840 * @param isEnabled {@code true} means enable, {@code false} means disable.
6841 */
6842 @Override
6843 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006844 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6845 mApp, subId, "setDataRoamingEnabled");
6846
Pengquan Menga1bb6272018-09-06 09:59:22 -07006847 final long identity = Binder.clearCallingIdentity();
6848 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006849 Phone phone = getPhone(subId);
6850 if (phone != null) {
6851 phone.setDataRoamingEnabled(isEnabled);
6852 }
6853 } finally {
6854 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006855 }
6856 }
6857
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006858 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006859 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006860 TelephonyPermissions
6861 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006862 mApp, subId, "isManualNetworkSelectionAllowed");
6863
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006864 boolean isAllowed = true;
6865 final long identity = Binder.clearCallingIdentity();
6866 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006867 Phone phone = getPhone(subId);
6868 if (phone != null) {
6869 isAllowed = phone.isCspPlmnEnabled();
6870 }
6871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
6874 return isAllowed;
6875 }
6876
6877 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006878 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006879 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006880 try {
6881 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006882 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006883 } catch (SecurityException e) {
6884 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6885 // has carrier privileges on an active UICC
6886 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6887 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006888 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006889 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006890 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006894 UiccController uiccController = UiccController.getInstance();
6895 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006896 if (hasReadPermission) {
6897 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006898 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006899
6900 // Remove private info if the caller doesn't have access
6901 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6902 for (UiccCardInfo cardInfo : cardInfos) {
6903 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6904 // is available
6905 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6906 if (card == null || card.getUiccProfile() == null) {
6907 // assume no access if the card or profile is unavailable
6908 filteredInfos.add(cardInfo.getUnprivileged());
6909 continue;
6910 }
6911 UiccProfile profile = card.getUiccProfile();
6912 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6913 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6914 filteredInfos.add(cardInfo);
6915 } else {
6916 filteredInfos.add(cardInfo.getUnprivileged());
6917 }
6918 }
6919 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006920 } finally {
6921 Binder.restoreCallingIdentity(identity);
6922 }
6923 }
6924
6925 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006926 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006927 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6932 if (slots == null) {
6933 Rlog.i(LOG_TAG, "slots is null.");
6934 return null;
6935 }
6936
6937 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6938 for (int i = 0; i < slots.length; i++) {
6939 UiccSlot slot = slots[i];
6940 if (slot == null) {
6941 continue;
6942 }
6943
Jordan Liu7be7e652019-05-06 18:55:02 +00006944 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 UiccCard card = slot.getUiccCard();
6946 if (card != null) {
6947 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006948 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006949 cardId = slot.getEid();
6950 if (TextUtils.isEmpty(cardId)) {
6951 cardId = slot.getIccId();
6952 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006953 }
6954
Jordan Liu857451f2019-05-09 16:35:35 -07006955 if (cardId != null) {
6956 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6957 // if cardId is an EID, it's all digits so this is fine
6958 cardId = IccUtils.stripTrailingFs(cardId);
6959 }
6960
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 int cardState = 0;
6962 switch (slot.getCardState()) {
6963 case CARDSTATE_ABSENT:
6964 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6965 break;
6966 case CARDSTATE_PRESENT:
6967 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6968 break;
6969 case CARDSTATE_ERROR:
6970 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6971 break;
6972 case CARDSTATE_RESTRICTED:
6973 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6974 break;
6975 default:
6976 break;
6977
6978 }
6979
6980 infos[i] = new UiccSlotInfo(
6981 slot.isActive(),
6982 slot.isEuicc(),
6983 cardId,
6984 cardState,
6985 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006986 slot.isExtendedApduSupported(),
6987 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 }
6989 return infos;
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006993 }
6994
6995 @Override
6996 public boolean switchSlots(int[] physicalSlots) {
6997 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998
6999 final long identity = Binder.clearCallingIdentity();
7000 try {
7001 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007005 }
Jack Yu4c988042018-02-27 15:30:01 -08007006
7007 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007008 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007009 final long identity = Binder.clearCallingIdentity();
7010 try {
7011 return UiccController.getInstance().getCardIdForDefaultEuicc();
7012 } finally {
7013 Binder.restoreCallingIdentity(identity);
7014 }
7015 }
7016
7017 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007018 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7019 enforceModifyPermission();
7020 final Phone phone = getPhone(subId);
7021 if (phone == null) {
7022 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7023 return;
7024 }
7025
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 final long identity = Binder.clearCallingIdentity();
7027 try {
7028 phone.setRadioIndicationUpdateMode(filters, mode);
7029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Jack Yu4c988042018-02-27 15:30:01 -08007032 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007033
7034 /**
goneil47ffb6e2018-04-06 15:40:58 -07007035 * A test API to reload the UICC profile.
7036 *
7037 * <p>Requires that the calling app has permission
7038 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7039 * @hide
7040 */
7041 @Override
7042 public void refreshUiccProfile(int subId) {
7043 enforceModifyPermission();
7044
7045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 Phone phone = getPhone(subId);
7048 if (phone == null) {
7049 return;
7050 }
7051 UiccCard uiccCard = phone.getUiccCard();
7052 if (uiccCard == null) {
7053 return;
7054 }
7055 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7056 if (uiccProfile == null) {
7057 return;
7058 }
7059 uiccProfile.refresh();
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
7062 }
7063 }
7064
7065 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007066 * Returns false if the mobile data is disabled by default, otherwise return true.
7067 */
7068 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007069 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007070 }
7071
7072 /**
7073 * Returns true if the data roaming is enabled by default, i.e the system property
7074 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7075 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7076 */
7077 private boolean getDefaultDataRoamingEnabled(int subId) {
7078 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007079 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007080 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007081 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7082 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7083 return isDataRoamingEnabled;
7084 }
7085
7086 /**
7087 * Returns the default network type for the given {@code subId}, if the default network type is
7088 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7089 */
7090 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007091 List<Integer> list = TelephonyProperties.default_network();
7092 int phoneId = mSubscriptionController.getPhoneId(subId);
7093 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7094 return list.get(phoneId);
7095 }
7096 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007097 }
fionaxua13278b2018-03-21 00:08:13 -07007098
7099 @Override
7100 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007101 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007102 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
7106 final Phone phone = getPhone(subId);
7107 if (phone == null) {
7108 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7109 return;
7110 }
chen xueaba88a2019-03-15 13:15:10 -07007111 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7112 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113 } finally {
7114 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007115 }
fionaxua13278b2018-03-21 00:08:13 -07007116 }
7117
7118 @Override
7119 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007120 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 final Phone phone = getPhone(subId);
7125 if (phone == null) {
7126 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7127 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7128 }
7129 return phone.getCarrierIdListVersion();
7130 } finally {
7131 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007132 }
fionaxua13278b2018-03-21 00:08:13 -07007133 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007134
7135 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007136 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7137 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007138 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007139 mApp, subId, callingPackage, callingFeatureId,
7140 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007141 return -1;
7142 }
7143
7144 final long identity = Binder.clearCallingIdentity();
7145 try {
7146 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
7150 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007151
7152 @Override
7153 public int getCdmaRoamingMode(int subId) {
7154 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7155 mApp, subId, "getCdmaRoamingMode");
7156
7157 final long identity = Binder.clearCallingIdentity();
7158 try {
7159 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
7163 }
7164
7165 @Override
7166 public boolean setCdmaRoamingMode(int subId, int mode) {
7167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7168 mApp, subId, "setCdmaRoamingMode");
7169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7173 } finally {
7174 Binder.restoreCallingIdentity(identity);
7175 }
7176 }
7177
7178 @Override
7179 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7180 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7181 mApp, subId, "setCdmaSubscriptionMode");
7182
7183 final long identity = Binder.clearCallingIdentity();
7184 try {
7185 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
7189 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007190
sqianc5eccab2018-10-19 18:46:41 -07007191 @Override
sqian8c685422019-02-22 15:55:18 -08007192 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007193 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007195 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7196 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007197 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7198 }
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
sqian854d44b2018-12-12 16:48:18 -08007201 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7202 for (Phone phone: PhoneFactory.getPhones()) {
7203 if (phone.getEmergencyNumberTracker() != null
7204 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7205 emergencyNumberListInternal.put(
7206 phone.getSubId(),
7207 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7208 }
sqian11b7a0e2018-12-05 18:48:28 -08007209 }
sqian854d44b2018-12-12 16:48:18 -08007210 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007211 } finally {
7212 Binder.restoreCallingIdentity(identity);
7213 }
sqianc5eccab2018-10-19 18:46:41 -07007214 }
7215
7216 @Override
sqian8c685422019-02-22 15:55:18 -08007217 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007218 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007219 if (!exactMatch) {
7220 TelephonyPermissions
7221 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007222 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007223 }
7224 final long identity = Binder.clearCallingIdentity();
7225 try {
sqian854d44b2018-12-12 16:48:18 -08007226 for (Phone phone: PhoneFactory.getPhones()) {
7227 if (phone.getEmergencyNumberTracker() != null
7228 && phone.getEmergencyNumberTracker() != null) {
7229 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7230 number, exactMatch)) {
7231 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007232 }
7233 }
sqian11b7a0e2018-12-05 18:48:28 -08007234 }
7235 return false;
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
7238 }
7239 }
7240
sqianf4ca7ed2019-01-15 18:32:07 -08007241 /**
7242 * Update emergency number list for test mode.
7243 */
7244 @Override
7245 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7246 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7247 "updateEmergencyNumberListTestMode");
7248
7249 final long identity = Binder.clearCallingIdentity();
7250 try {
7251 for (Phone phone: PhoneFactory.getPhones()) {
7252 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7253 if (tracker != null) {
7254 tracker.executeEmergencyNumberTestModeCommand(action, num);
7255 }
7256 }
7257 } finally {
7258 Binder.restoreCallingIdentity(identity);
7259 }
7260 }
7261
7262 /**
7263 * Get the full emergency number list for test mode.
7264 */
7265 @Override
7266 public List<String> getEmergencyNumberListTestMode() {
7267 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7268 "getEmergencyNumberListTestMode");
7269
7270 final long identity = Binder.clearCallingIdentity();
7271 try {
7272 Set<String> emergencyNumbers = new HashSet<>();
7273 for (Phone phone: PhoneFactory.getPhones()) {
7274 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7275 if (tracker != null) {
7276 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7277 emergencyNumbers.add(num.getNumber());
7278 }
7279 }
7280 }
7281 return new ArrayList<>(emergencyNumbers);
7282 } finally {
7283 Binder.restoreCallingIdentity(identity);
7284 }
7285 }
7286
chen xud6b45bd2018-10-30 22:27:10 -07007287 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007288 public int getEmergencyNumberDbVersion(int subId) {
7289 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7290
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 final Phone phone = getPhone(subId);
7294 if (phone == null) {
7295 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7296 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7297 }
7298 return phone.getEmergencyNumberDbVersion();
7299 } finally {
7300 Binder.restoreCallingIdentity(identity);
7301 }
7302 }
7303
7304 @Override
7305 public void notifyOtaEmergencyNumberDbInstalled() {
7306 enforceModifyPermission();
7307
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 for (Phone phone: PhoneFactory.getPhones()) {
7311 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7312 if (tracker != null) {
7313 tracker.updateOtaEmergencyNumberDatabase();
7314 }
7315 }
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
7318 }
7319 }
7320
7321 @Override
7322 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7323 enforceActiveEmergencySessionPermission();
7324
7325 final long identity = Binder.clearCallingIdentity();
7326 try {
7327 for (Phone phone: PhoneFactory.getPhones()) {
7328 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7329 if (tracker != null) {
7330 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7331 }
7332 }
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
7336 }
7337
7338 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007339 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7340 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7341 Phone phone = getPhone(subId);
7342 if (phone == null) {
7343 return null;
7344 }
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 UiccProfile profile = UiccController.getInstance()
7348 .getUiccProfileForPhone(phone.getPhoneId());
7349 if (profile != null) {
7350 return profile.getCertsFromCarrierPrivilegeAccessRules();
7351 }
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
7355 return null;
7356 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007357
7358 /**
7359 * Enable or disable a modem stack.
7360 */
7361 @Override
7362 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7363 enforceModifyPermission();
7364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = PhoneFactory.getPhone(slotIndex);
7368 if (phone == null) {
7369 return false;
7370 } else {
7371 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7372 }
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
7376 }
Michelecea4cf22018-12-21 15:00:11 -08007377
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007378 /**
7379 * Whether a modem stack is enabled or not.
7380 */
7381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007382 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7383 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007384 Phone phone = PhoneFactory.getPhone(slotIndex);
7385 if (phone == null) return false;
7386
7387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007388 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7389 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007390 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7391 }
7392
7393 final long identity = Binder.clearCallingIdentity();
7394 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007395 try {
7396 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7397 } catch (NoSuchElementException ex) {
7398 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7399 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007400 } finally {
7401 Binder.restoreCallingIdentity(identity);
7402 }
7403 }
7404
Michelecea4cf22018-12-21 15:00:11 -08007405 @Override
Michele0ea7d782019-03-19 14:58:42 -07007406 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007407 enforceModifyPermission();
7408
7409 final long identity = Binder.clearCallingIdentity();
7410 try {
7411 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007412 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007413 .commit();
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
7417 }
7418
7419 @Override
Michele0ea7d782019-03-19 14:58:42 -07007420 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007421 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007423 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7424 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007425 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007426 }
Michelecea4cf22018-12-21 15:00:11 -08007427
7428 final long identity = Binder.clearCallingIdentity();
7429 try {
Michele0ea7d782019-03-19 14:58:42 -07007430 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007431 } finally {
7432 Binder.restoreCallingIdentity(identity);
7433 }
7434 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007435
Michele0ea7d782019-03-19 14:58:42 -07007436 @TelephonyManager.IsMultiSimSupportedResult
7437 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007438 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7439 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7440 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007441 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7442 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007443 }
7444 // Check if the hardware supports multisim functionality. If usage of multisim is not
7445 // supported by the modem, indicate that it is restricted.
7446 PhoneCapability staticCapability =
7447 mPhoneConfigurationManager.getStaticPhoneCapability();
7448 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007449 loge("isMultiSimSupportedInternal: no static configuration available");
7450 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007451 }
7452 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007453 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7454 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007455 }
7456 // Check if support of multiple SIMs is restricted by carrier
7457 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007458 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007459 }
7460
Michele0ea7d782019-03-19 14:58:42 -07007461 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007462 }
7463
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007464 /**
7465 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007466 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7467 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7468 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007469 * @param numOfSims number of active sims we want to switch to
7470 */
7471 @Override
7472 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007473 if (numOfSims == 1) {
7474 enforceModifyPermission();
7475 } else {
7476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7477 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7478 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007479 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007480
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007481 try {
Michele30b57b22019-03-01 12:01:14 -08007482 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007483 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007484 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7485 return;
7486 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007487 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7488 } finally {
7489 Binder.restoreCallingIdentity(identity);
7490 }
7491 }
7492
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007493 @Override
7494 public boolean isApplicationOnUicc(int subId, int appType) {
7495 enforceReadPrivilegedPermission("isApplicationOnUicc");
7496 Phone phone = getPhone(subId);
7497 if (phone == null) {
7498 return false;
7499 }
7500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 UiccCard uiccCard = phone.getUiccCard();
7503 if (uiccCard == null) {
7504 return false;
7505 }
7506 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7507 if (uiccProfile == null) {
7508 return false;
7509 }
7510 if (TelephonyManager.APPTYPE_SIM <= appType
7511 && appType <= TelephonyManager.APPTYPE_ISIM) {
7512 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7513 }
7514 return false;
7515 } finally {
7516 Binder.restoreCallingIdentity(identity);
7517 }
7518 }
7519
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007520 /**
chen xub4baa772019-04-03 10:23:41 -07007521 * Get whether making changes to modem configurations will trigger reboot.
7522 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007523 */
7524 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007525 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7526 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007528 mApp, subId, callingPackage, callingFeatureId,
7529 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007530 return false;
7531 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007532 final long identity = Binder.clearCallingIdentity();
7533 try {
7534 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7535 } finally {
7536 Binder.restoreCallingIdentity(identity);
7537 }
7538 }
7539
Nathan Harold29f5f052019-02-15 13:41:57 -08007540 private void updateModemStateMetrics() {
7541 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7542 // TODO: check the state for each modem if the api is ready.
7543 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7544 }
7545
Pengquan Meng3889a572019-01-23 11:16:29 -08007546 @Override
7547 public int[] getSlotsMapping() {
7548 enforceReadPrivilegedPermission("getSlotsMapping");
7549
7550 final long identity = Binder.clearCallingIdentity();
7551 try {
7552 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7553 // All logical slots should have a mapping to a physical slot.
7554 int[] logicalSlotsMapping = new int[phoneCount];
7555 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7556 for (int i = 0; i < slotInfos.length; i++) {
7557 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7558 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7559 }
7560 }
7561 return logicalSlotsMapping;
7562 } finally {
7563 Binder.restoreCallingIdentity(identity);
7564 }
7565 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007566
7567 /**
7568 * Get the IRadio HAL Version
7569 */
7570 @Override
7571 public int getRadioHalVersion() {
7572 Phone phone = getDefaultPhone();
7573 if (phone == null) return -1;
7574 HalVersion hv = phone.getHalVersion();
7575 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7576 return hv.major * 100 + hv.minor;
7577 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007578
7579 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007580 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7581 * corresponding network requests on a subId.
7582 *
7583 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007584 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007585 * 2) APN is un-metered for this subscription, or
7586 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7587 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7588 *
7589 * @return whether data is allowed for a apn type.
7590 *
7591 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007592 */
7593 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007594 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007595 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7596 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007597
7598 // Now that all security checks passes, perform the operation as ourselves.
7599 final long identity = Binder.clearCallingIdentity();
7600 try {
7601 Phone phone = getPhone(subId);
7602 if (phone == null) return false;
7603
Jack Yu41407ee2019-05-13 16:54:09 -07007604 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007605 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7606 } finally {
7607 Binder.restoreCallingIdentity(identity);
7608 }
7609 }
7610
7611 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007612 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007613 enforceReadPrivilegedPermission("isApnMetered");
7614
7615 // Now that all security checks passes, perform the operation as ourselves.
7616 final long identity = Binder.clearCallingIdentity();
7617 try {
7618 Phone phone = getPhone(subId);
7619 if (phone == null) return true; // By default return true.
7620
Jack Yu41407ee2019-05-13 16:54:09 -07007621 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007622 } finally {
7623 Binder.restoreCallingIdentity(identity);
7624 }
7625 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007626
7627 @Override
7628 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7629 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7630 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7631 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7632 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7633 }
7634 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7635 Intent intent = new Intent();
7636 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7637 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7638 // Bring up choose default SMS subscription dialog right now
7639 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7640 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7641 mApp.startActivity(intent);
7642 }
chen xud5ca2d52019-05-28 15:20:57 -07007643
7644 @Override
7645 public String getMmsUAProfUrl(int subId) {
7646 //TODO investigate if this API should require proper permission check in R b/133791609
7647 final long identity = Binder.clearCallingIdentity();
7648 try {
7649 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7650 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
7653 }
7654 }
7655
7656 @Override
7657 public String getMmsUserAgent(int subId) {
7658 //TODO investigate if this API should require proper permission check in R b/133791609
7659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7662 .getString(com.android.internal.R.string.config_mms_user_agent);
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
7666 }
Jack Yub07d4972019-05-28 16:12:25 -07007667
7668 @Override
7669 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7670 enforceModifyPermission();
7671
7672 // Now that all security checks passes, perform the operation as ourselves.
7673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 Phone phone = getPhone(subId);
7676 if (phone == null) return false;
7677
7678 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
7681 }
7682 }
7683
7684 @Override
7685 public boolean isDataAllowedInVoiceCall(int subId) {
7686 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7687
7688 // Now that all security checks passes, perform the operation as ourselves.
7689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone == null) return false;
7693
7694 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
7697 }
7698 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007699
7700 /**
7701 * Updates whether conference event pacakge handling is enabled.
7702 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7703 * otherwise.
7704 */
7705 @Override
7706 public void setCepEnabled(boolean isCepEnabled) {
7707 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7708
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7712 for (Phone phone : PhoneFactory.getPhones()) {
7713 Phone defaultPhone = phone.getImsPhone();
7714 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7715 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7716 ImsPhoneCallTracker imsPhoneCallTracker =
7717 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7718 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7719 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7720 + imsPhone.getMsisdn());
7721 }
7722 }
7723 } finally {
7724 Binder.restoreCallingIdentity(identity);
7725 }
7726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007727}