blob: d149f7b10ca854b7d229b2bd7ace5989bea3fcb9 [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
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070047import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070064import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080065import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070067import android.telephony.CellInfoGsm;
68import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070069import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070071import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070072import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080073import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070074import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070076import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080077import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080078import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070079import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080080import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070081import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080083import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080084import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070087import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080089import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000090import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070091import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070095import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070098import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700102import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsMmTelFeature;
104import android.telephony.ims.aidl.IImsRcsFeature;
105import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800107import android.telephony.ims.feature.MmTelFeature;
108import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800109import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Andrew Lee312e8172014-10-23 17:01:36 -0700116import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800117import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700119import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700120import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800121import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800125import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700126import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800127import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700130import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700132import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700133import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700135import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800136import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700137import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700138import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700139import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700140import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700141import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import com.android.internal.telephony.SmsApplication;
144import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800153import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700154import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.uicc.IccIoResult;
156import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700158import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800159import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800161import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000162import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700163import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800164import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800167import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700168import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700169import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800170
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700171import java.io.FileDescriptor;
172import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700175import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800176import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800177import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800178import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100179import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700181import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184/**
185 * Implementation of the ITelephony interface.
186 */
Santos Cordon117fee72014-05-16 17:56:12 -0700187public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private static final String LOG_TAG = "PhoneInterfaceManager";
189 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
190 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
193 // Message codes used with mMainThreadHandler
194 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700195 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
196 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197 private static final int CMD_OPEN_CHANNEL = 9;
198 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
199 private static final int CMD_CLOSE_CHANNEL = 11;
200 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800201 private static final int CMD_NV_READ_ITEM = 13;
202 private static final int EVENT_NV_READ_ITEM_DONE = 14;
203 private static final int CMD_NV_WRITE_ITEM = 15;
204 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
205 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
206 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700207 private static final int CMD_RESET_MODEM_CONFIG = 19;
208 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800209 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
210 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
211 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
212 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800213 private static final int CMD_SEND_ENVELOPE = 25;
214 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000215 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
216 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700217 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
218 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
219 private static final int CMD_EXCHANGE_SIM_IO = 31;
220 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800221 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
222 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700223 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
224 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700225 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
226 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700227 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
228 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
229 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700231 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
232 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
233 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
234 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700235 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800236 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
237 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000238 private static final int CMD_SWITCH_SLOTS = 50;
239 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700240 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
241 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
242 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
243 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
244 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
245 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
246 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
247 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700248 private static final int CMD_GET_ALL_CELL_INFO = 60;
249 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
250 private static final int CMD_GET_CELL_LOCATION = 62;
251 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_MODEM_REBOOT = 64;
253 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700254 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
255 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800256 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
257 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700258 private static final int CMD_GET_MODEM_STATUS = 70;
259 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800261 // Parameters of select command.
262 private static final int SELECT_COMMAND = 0xA4;
263 private static final int SELECT_P1 = 0x04;
264 private static final int SELECT_P2 = 0;
265 private static final int SELECT_P3 = 0x10;
266
Pengquan Meng85728fb2018-03-12 16:31:21 -0700267 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
268 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
269 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 /** The singleton instance. */
272 private static PhoneInterfaceManager sInstance;
273
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700276 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private AppOpsManager mAppOps;
278 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800279 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700281 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
Derek Tan97ebb422014-09-05 16:55:38 -0700283 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
284 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800285 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800286 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700287
Michelecea4cf22018-12-21 15:00:11 -0800288 // String to store multi SIM allowed
289 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
290
Derek Tan740e1672017-06-27 14:56:27 -0700291 // The AID of ISD-R.
292 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
293
yinxub1bed742017-04-17 11:45:04 -0700294 private NetworkScanRequestTracker mNetworkScanRequestTracker;
295
David Kelly5e06a7f2018-03-12 14:10:59 +0000296 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
297 private static final int MANUFACTURER_CODE_LENGTH = 8;
298
Derek Tan89e89d42014-07-08 17:00:10 -0700299 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700300 * A request object to use for transmitting data to an ICC.
301 */
302 private static final class IccAPDUArgument {
303 public int channel, cla, command, p1, p2, p3;
304 public String data;
305
306 public IccAPDUArgument(int channel, int cla, int command,
307 int p1, int p2, int p3, String data) {
308 this.channel = channel;
309 this.cla = cla;
310 this.command = command;
311 this.p1 = p1;
312 this.p2 = p2;
313 this.p3 = p3;
314 this.data = data;
315 }
316 }
317
318 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700319 * A request object to use for transmitting data to an ICC.
320 */
321 private static final class ManualNetworkSelectionArgument {
322 public OperatorInfo operatorInfo;
323 public boolean persistSelection;
324
325 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
326 this.operatorInfo = operatorInfo;
327 this.persistSelection = persistSelection;
328 }
329 }
330
331 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
333 * request after sending. The main thread will notify the request when it is complete.
334 */
335 private static final class MainThreadRequest {
336 /** The argument to use for the request */
337 public Object argument;
338 /** The result of the request that is run on the main thread */
339 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800340 // The subscriber id that this request applies to. Defaults to
341 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
342 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Nathan Harold92bed182018-10-12 18:16:49 -0700344 // In cases where subId is unavailable, the caller needs to specify the phone.
345 public Phone phone;
346
vagdeviaf9a5b92018-08-15 16:01:53 -0700347 public WorkSource workSource;
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 public MainThreadRequest(Object argument) {
350 this.argument = argument;
351 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800352
Nathan Harold92bed182018-10-12 18:16:49 -0700353 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
354 this.argument = argument;
355 if (phone != null) {
356 this.phone = phone;
357 }
358 this.workSource = workSource;
359 }
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800363 if (subId != null) {
364 this.subId = subId;
365 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 }
369
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800370 private static final class IncomingThirdPartyCallArgs {
371 public final ComponentName component;
372 public final String callId;
373 public final String callerDisplayName;
374
375 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
376 String callerDisplayName) {
377 this.component = component;
378 this.callId = callId;
379 this.callerDisplayName = callerDisplayName;
380 }
381 }
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 /**
384 * A handler that processes messages on the main thread in the phone process. Since many
385 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
386 * inbound binder threads to the main thread in the phone process. The Binder thread
387 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
388 * on, which will be notified when the operation completes and will contain the result of the
389 * request.
390 *
391 * <p>If a MainThreadRequest object is provided in the msg.obj field,
392 * note that request.result must be set to something non-null for the calling thread to
393 * unblock.
394 */
395 private final class MainThreadHandler extends Handler {
396 @Override
397 public void handleMessage(Message msg) {
398 MainThreadRequest request;
399 Message onCompleted;
400 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800401 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800403 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
405 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700406 case CMD_HANDLE_USSD_REQUEST: {
407 request = (MainThreadRequest) msg.obj;
408 final Phone phone = getPhoneFromRequest(request);
409 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
410 String ussdRequest = ussdObject.first;
411 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700412
Pengquan Menga1bb6272018-09-06 09:59:22 -0700413 if (!isUssdApiAllowed(request.subId)) {
414 // Carrier does not support use of this API, return failure.
415 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
416 UssdResponse response = new UssdResponse(ussdRequest, null);
417 Bundle returnData = new Bundle();
418 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
419 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700420
Pengquan Menga1bb6272018-09-06 09:59:22 -0700421 request.result = true;
422 notifyRequester(request);
423 return;
424 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 try {
427 request.result = phone != null
428 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
429 } catch (CallStateException cse) {
430 request.result = false;
431 }
432 // Wake up the requesting thread
433 notifyRequester(request);
434 break;
pkanwar32d516d2016-10-14 19:37:38 -0700435 }
436
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700439 final Phone phone = getPhoneFromRequest(request);
440 request.result = phone != null ?
441 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
442 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800451 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 if (uiccCard == null) {
453 loge("iccTransmitApduLogicalChannel: No UICC");
454 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
458 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument.channel, iccArgument.cla, iccArgument.command,
461 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 break;
465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 ar = (AsyncResult) msg.obj;
468 request = (MainThreadRequest) ar.userObj;
469 if (ar.exception == null && ar.result != null) {
470 request.result = ar.result;
471 } else {
472 request.result = new IccIoResult(0x6F, 0, (byte[])null);
473 if (ar.result == null) {
474 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800475 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800477 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 } else {
479 loge("iccTransmitApduLogicalChannel: Unknown exception");
480 }
481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 break;
484
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
486 request = (MainThreadRequest) msg.obj;
487 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800488 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 if (uiccCard == null) {
490 loge("iccTransmitApduBasicChannel: No UICC");
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 } else {
494 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
495 request);
496 uiccCard.iccTransmitApduBasicChannel(
497 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
498 iccArgument.p3, iccArgument.data, onCompleted);
499 }
500 break;
501
502 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
503 ar = (AsyncResult) msg.obj;
504 request = (MainThreadRequest) ar.userObj;
505 if (ar.exception == null && ar.result != null) {
506 request.result = ar.result;
507 } else {
508 request.result = new IccIoResult(0x6F, 0, (byte[])null);
509 if (ar.result == null) {
510 loge("iccTransmitApduBasicChannel: Empty response");
511 } else if (ar.exception instanceof CommandException) {
512 loge("iccTransmitApduBasicChannel: CommandException: " +
513 ar.exception);
514 } else {
515 loge("iccTransmitApduBasicChannel: Unknown exception");
516 }
517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 break;
520
521 case CMD_EXCHANGE_SIM_IO:
522 request = (MainThreadRequest) msg.obj;
523 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800524 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 if (uiccCard == null) {
526 loge("iccExchangeSimIO: No UICC");
527 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 } else {
530 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
531 request);
532 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
533 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
534 iccArgument.data, onCompleted);
535 }
536 break;
537
538 case EVENT_EXCHANGE_SIM_IO_DONE:
539 ar = (AsyncResult) msg.obj;
540 request = (MainThreadRequest) ar.userObj;
541 if (ar.exception == null && ar.result != null) {
542 request.result = ar.result;
543 } else {
544 request.result = new IccIoResult(0x6f, 0, (byte[])null);
545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 break;
548
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 case CMD_SEND_ENVELOPE:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("sendEnvelopeWithStatus: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
558 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 break;
561
562 case EVENT_SEND_ENVELOPE_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 if (ar.exception == null && ar.result != null) {
566 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 if (ar.result == null) {
570 loge("sendEnvelopeWithStatus: Empty response");
571 } else if (ar.exception instanceof CommandException) {
572 loge("sendEnvelopeWithStatus: CommandException: " +
573 ar.exception);
574 } else {
575 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
576 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 break;
580
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 case CMD_OPEN_CHANNEL:
582 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800584 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 if (uiccCard == null) {
586 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800587 request.result = new IccOpenLogicalChannelResponse(-1,
588 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 } else {
591 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800592 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
593 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 break;
596
597 case EVENT_OPEN_CHANNEL_DONE:
598 ar = (AsyncResult) msg.obj;
599 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 int[] result = (int[]) ar.result;
603 int channelId = result[0];
604 byte[] selectResponse = null;
605 if (result.length > 1) {
606 selectResponse = new byte[result.length - 1];
607 for (int i = 1; i < result.length; ++i) {
608 selectResponse[i - 1] = (byte) result[i];
609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.result == null) {
615 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 if (ar.exception != null) {
618 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
619 }
620
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700622 if (ar.exception instanceof CommandException) {
623 CommandException.Error error =
624 ((CommandException) (ar.exception)).getCommandError();
625 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700627 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700628 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 }
630 }
631 openChannelResp = new IccOpenLogicalChannelResponse(
632 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700634 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case CMD_CLOSE_CHANNEL:
639 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800640 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 if (uiccCard == null) {
642 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900643 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 } else {
646 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
647 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800652 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
653 break;
654
655 case CMD_NV_READ_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800658 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
659 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800660 break;
661
662 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800668 request.result = "";
669 if (ar.result == null) {
670 loge("nvReadItem: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("nvReadItem: CommandException: " +
673 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 }
677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
Jake Hambye994d462014-02-03 13:10:13 -0800681 case CMD_NV_WRITE_ITEM:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
684 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700686 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_WRITE_ITEM_DONE:
690 handleNullReturnEvent(msg, "nvWriteItem");
691 break;
692
693 case CMD_NV_WRITE_CDMA_PRL:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_CDMA_PRL_DONE:
700 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
701 break;
702
chen xu6dac5ab2018-10-26 17:39:23 -0700703 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800704 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700705 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
chen xu6dac5ab2018-10-26 17:39:23 -0700709 case EVENT_RESET_MODEM_CONFIG_DONE:
710 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 case CMD_GET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
720 ar = (AsyncResult) msg.obj;
721 request = (MainThreadRequest) ar.userObj;
722 if (ar.exception == null && ar.result != null) {
723 request.result = ar.result; // Integer
724 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800725 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 if (ar.result == null) {
727 loge("getPreferredNetworkType: Empty response");
728 } else if (ar.exception instanceof CommandException) {
729 loge("getPreferredNetworkType: CommandException: " +
730 ar.exception);
731 } else {
732 loge("getPreferredNetworkType: Unknown exception");
733 }
734 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 break;
737
738 case CMD_SET_PREFERRED_NETWORK_TYPE:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
741 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700742 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 break;
744
745 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
746 handleNullReturnEvent(msg, "setPreferredNetworkType");
747 break;
748
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
750 request = (MainThreadRequest)msg.obj;
751 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800752 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000753 break;
754
755 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
756 ar = (AsyncResult)msg.obj;
757 request = (MainThreadRequest)ar.userObj;
758 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 break;
761
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800762 case CMD_SET_VOICEMAIL_NUMBER:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
765 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800766 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
767 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800768 break;
769
770 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
771 handleNullReturnEvent(msg, "setVoicemailNumber");
772 break;
773
Stuart Scott54788802015-03-30 13:18:01 -0700774 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
777 request);
778 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
779 break;
780
781 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
782 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
783 break;
784
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 case CMD_PERFORM_NETWORK_SCAN:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
788 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
789 break;
790
791 case EVENT_PERFORM_NETWORK_SCAN_DONE:
792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
794 CellNetworkScanResult cellScanResult;
795 if (ar.exception == null && ar.result != null) {
796 cellScanResult = new CellNetworkScanResult(
797 CellNetworkScanResult.STATUS_SUCCESS,
798 (List<OperatorInfo>) ar.result);
799 } else {
800 if (ar.result == null) {
801 loge("getCellNetworkScanResults: Empty response");
802 }
803 if (ar.exception != null) {
804 loge("getCellNetworkScanResults: Exception: " + ar.exception);
805 }
806 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
807 if (ar.exception instanceof CommandException) {
808 CommandException.Error error =
809 ((CommandException) (ar.exception)).getCommandError();
810 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
812 } else if (error == CommandException.Error.GENERIC_FAILURE) {
813 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
814 }
815 }
816 cellScanResult = new CellNetworkScanResult(errorCode, null);
817 }
818 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700819 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 break;
821
822 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
823 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700824 ManualNetworkSelectionArgument selArg =
825 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
827 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
829 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null) {
836 request.result = true;
837 } else {
838 request.result = false;
839 loge("setNetworkSelectionModeManual " + ar.exception);
840 }
841 notifyRequester(request);
842 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 case CMD_GET_MODEM_ACTIVITY_INFO:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700848 if (defaultPhone != null) {
849 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
850 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
853 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("queryModemActivityInfo: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("queryModemActivityInfo: CommandException: " +
863 ar.exception);
864 } else {
865 loge("queryModemActivityInfo: Unknown exception");
866 }
867 }
Amit Mahajand4766222016-01-28 15:28:28 -0800868 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
869 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700870 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800871 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700872 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700873 break;
874
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 case CMD_SET_ALLOWED_CARRIERS:
876 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800877 CarrierRestrictionRules argument =
878 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800880 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case EVENT_SET_ALLOWED_CARRIERS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800889 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
890 if (ar.exception instanceof CommandException) {
891 loge("setAllowedCarriers: CommandException: " + ar.exception);
892 CommandException.Error error =
893 ((CommandException) (ar.exception)).getCommandError();
894 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
895 request.result =
896 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
897 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 } else {
899 loge("setAllowedCarriers: Unknown exception");
900 }
901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case CMD_GET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800908 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 break;
910
911 case EVENT_GET_ALLOWED_CARRIERS_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800917 request.result = new IllegalStateException(
918 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 if (ar.result == null) {
920 loge("getAllowedCarriers: Empty response");
921 } else if (ar.exception instanceof CommandException) {
922 loge("getAllowedCarriers: CommandException: " +
923 ar.exception);
924 } else {
925 loge("getAllowedCarriers: Unknown exception");
926 }
927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 break;
930
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 request.result = new IllegalArgumentException(
938 "Failed to retrieve Forbidden Plmns");
939 if (ar.result == null) {
940 loge("getForbiddenPlmns: Empty response");
941 } else {
942 loge("getForbiddenPlmns: Unknown exception");
943 }
944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800946 break;
947
948 case CMD_GET_FORBIDDEN_PLMNS:
949 request = (MainThreadRequest) msg.obj;
950 uiccCard = getUiccCardFromRequest(request);
951 if (uiccCard == null) {
952 loge("getForbiddenPlmns() UiccCard is null");
953 request.result = new IllegalArgumentException(
954 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957 }
958 Integer appType = (Integer) request.argument;
959 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
960 if (uiccApp == null) {
961 loge("getForbiddenPlmns() no app with specified type -- "
962 + appType);
963 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700964 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800965 break;
966 } else {
967 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
968 + " specified type -- " + appType);
969 }
970 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
971 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
972 onCompleted);
973 break;
974
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 case CMD_SWITCH_SLOTS:
976 request = (MainThreadRequest) msg.obj;
977 int[] physicalSlots = (int[]) request.argument;
978 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
979 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
980 break;
981
982 case EVENT_SWITCH_SLOTS_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700986 notifyRequester(request);
987 break;
988 case CMD_GET_NETWORK_SELECTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
991 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
992 break;
993
994 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception != null) {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
999 } else {
1000 int mode = ((int[]) ar.result)[0];
1001 if (mode == 0) {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1003 } else {
1004 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001006 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001007 notifyRequester(request);
1008 break;
1009 case CMD_GET_CDMA_ROAMING_MODE:
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1012 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1013 break;
1014 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception != null) {
1018 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1019 } else {
1020 request.result = ((int[]) ar.result)[0];
1021 }
1022 notifyRequester(request);
1023 break;
1024 case CMD_SET_CDMA_ROAMING_MODE:
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1027 int mode = (int) request.argument;
1028 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1029 break;
1030 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 request.result = ar.exception == null;
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1039 int subscriptionMode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001047 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 case CMD_GET_ALL_CELL_INFO:
1049 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001051 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case EVENT_GET_ALL_CELL_INFO_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001056 // If a timeout occurs, the response will be null
1057 request.result = (ar.exception == null && ar.result != null)
1058 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 synchronized (request) {
1060 request.notifyAll();
1061 }
1062 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 case CMD_REQUEST_CELL_INFO_UPDATE:
1064 request = (MainThreadRequest) msg.obj;
1065 request.phone.requestCellInfoUpdate(request.workSource,
1066 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1067 break;
1068 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
1071 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1072 try {
1073 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001075 cb.onError(
1076 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1077 ar.exception.getClass().getName(),
1078 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001081 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 } else {
1083 // use the result as returned
1084 cb.onCellInfo((List<CellInfo>) ar.result);
1085 }
1086 } catch (RemoteException re) {
1087 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1088 }
1089 break;
1090 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001091 request = (MainThreadRequest) msg.obj;
1092 WorkSource ws = (WorkSource) request.argument;
1093 Phone phone = getPhoneFromRequest(request);
1094 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1095 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001096 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null) {
1100 request.result = ar.result;
1101 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001102 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001103 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1104 ? new CdmaCellLocation() : new GsmCellLocation();
1105 }
1106
1107 synchronized (request) {
1108 request.notifyAll();
1109 }
1110 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001111 case CMD_MODEM_REBOOT:
1112 request = (MainThreadRequest) msg.obj;
1113 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001114 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case EVENT_CMD_MODEM_REBOOT_DONE:
1117 handleNullReturnEvent(msg, "rebootModem");
1118 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001119 case CMD_REQUEST_ENABLE_MODEM:
1120 request = (MainThreadRequest) msg.obj;
1121 boolean enable = (boolean) request.argument;
1122 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001123 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 PhoneConfigurationManager.getInstance()
1125 .enablePhone(request.phone, enable, onCompleted);
1126 break;
1127 case EVENT_ENABLE_MODEM_DONE:
1128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001131 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001132 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001133 if ((boolean) request.result) {
1134 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1135 updateModemStateMetrics();
1136 } else {
1137 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1138 + ar.exception);
1139 }
1140 notifyRequester(request);
1141 break;
1142 case CMD_GET_MODEM_STATUS:
1143 request = (MainThreadRequest) msg.obj;
1144 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1145 PhoneConfigurationManager.getInstance()
1146 .getPhoneStatusFromModem(request.phone, onCompleted);
1147 break;
1148 case EVENT_GET_MODEM_STATUS_DONE:
1149 ar = (AsyncResult) msg.obj;
1150 request = (MainThreadRequest) ar.userObj;
1151 int id = request.phone.getPhoneId();
1152 if (ar.exception == null && ar.result != null) {
1153 request.result = ar.result;
1154 //update the cache as modem status has changed
1155 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1156 (boolean) request.result);
1157 } else {
1158 // Return true if modem status cannot be retrieved. For most cases,
1159 // modem status is on. And for older version modems, GET_MODEM_STATUS
1160 // and disable modem are not supported. Modem is always on.
1161 // TODO: this should be fixed in R to support a third
1162 // status UNKNOWN b/131631629
1163 request.result = true;
1164 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1165 + ar.exception);
1166 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001167 notifyRequester(request);
1168 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001169 default:
1170 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1171 break;
1172 }
1173 }
Jake Hambye994d462014-02-03 13:10:13 -08001174
Pengquan Menga1bb6272018-09-06 09:59:22 -07001175 private void notifyRequester(MainThreadRequest request) {
1176 synchronized (request) {
1177 request.notifyAll();
1178 }
1179 }
1180
Jake Hambye994d462014-02-03 13:10:13 -08001181 private void handleNullReturnEvent(Message msg, String command) {
1182 AsyncResult ar = (AsyncResult) msg.obj;
1183 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1184 if (ar.exception == null) {
1185 request.result = true;
1186 } else {
1187 request.result = false;
1188 if (ar.exception instanceof CommandException) {
1189 loge(command + ": CommandException: " + ar.exception);
1190 } else {
1191 loge(command + ": Unknown exception");
1192 }
1193 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001194 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001196 }
1197
1198 /**
1199 * Posts the specified command to be executed on the main thread,
1200 * waits for the request to complete, and returns the result.
1201 * @see #sendRequestAsync
1202 */
1203 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001204 return sendRequest(
1205 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001206 }
1207
1208 /**
1209 * Posts the specified command to be executed on the main thread,
1210 * waits for the request to complete, and returns the result.
1211 * @see #sendRequestAsync
1212 */
1213 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1214 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001215 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001216 }
1217
1218 /**
1219 * Posts the specified command to be executed on the main thread,
1220 * waits for the request to complete, and returns the result.
1221 * @see #sendRequestAsync
1222 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001223 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001224 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001225 }
1226
1227 /**
1228 * Posts the specified command to be executed on the main thread,
1229 * waits for the request to complete, and returns the result.
1230 * @see #sendRequestAsync
1231 */
Nathan Harold92bed182018-10-12 18:16:49 -07001232 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1233 return sendRequest(command, argument, subId, null, workSource);
1234 }
1235
1236 /**
1237 * Posts the specified command to be executed on the main thread,
1238 * waits for the request to complete, and returns the result.
1239 * @see #sendRequestAsync
1240 */
1241 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1242 return sendRequest(
1243 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1244 }
1245
1246 /**
1247 * Posts the specified command to be executed on the main thread,
1248 * waits for the request to complete, and returns the result.
1249 * @see #sendRequestAsync
1250 */
1251 private Object sendRequest(
1252 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001253 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1254 throw new RuntimeException("This method will deadlock if called from the main thread.");
1255 }
1256
Nathan Harold92bed182018-10-12 18:16:49 -07001257 MainThreadRequest request = null;
1258 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1259 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1260 } else if (phone != null) {
1261 request = new MainThreadRequest(argument, phone, workSource);
1262 } else {
1263 request = new MainThreadRequest(argument, subId, workSource);
1264 }
1265
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001266 Message msg = mMainThreadHandler.obtainMessage(command, request);
1267 msg.sendToTarget();
1268
1269 // Wait for the request to complete
1270 synchronized (request) {
1271 while (request.result == null) {
1272 try {
1273 request.wait();
1274 } catch (InterruptedException e) {
1275 // Do nothing, go back and wait until the request is complete
1276 }
1277 }
1278 }
1279 return request.result;
1280 }
1281
1282 /**
1283 * Asynchronous ("fire and forget") version of sendRequest():
1284 * Posts the specified command to be executed on the main thread, and
1285 * returns immediately.
1286 * @see #sendRequest
1287 */
1288 private void sendRequestAsync(int command) {
1289 mMainThreadHandler.sendEmptyMessage(command);
1290 }
1291
1292 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001293 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001295 */
1296 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 sendRequestAsync(command, argument, null, null);
1298 }
1299
1300 /**
1301 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1302 * @see {@link #sendRequest(int,Object)}
1303 */
1304 private void sendRequestAsync(
1305 int command, Object argument, Phone phone, WorkSource workSource) {
1306 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001307 Message msg = mMainThreadHandler.obtainMessage(command, request);
1308 msg.sendToTarget();
1309 }
1310
1311 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 * Initialize the singleton PhoneInterfaceManager instance.
1313 * This is only done once, at startup, from PhoneApp.onCreate().
1314 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001315 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 synchronized (PhoneInterfaceManager.class) {
1317 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001318 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001319 } else {
1320 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1321 }
1322 return sInstance;
1323 }
1324 }
1325
1326 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001330 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1332 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001333 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001334 mTelephonySharedPreferences =
1335 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001336 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001337 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 publish();
1340 }
1341
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001342 private Phone getDefaultPhone() {
1343 Phone thePhone = getPhone(getDefaultSubscription());
1344 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1345 }
1346
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 private void publish() {
1348 if (DBG) log("publish: " + this);
1349
1350 ServiceManager.addService("phone", this);
1351 }
1352
Stuart Scott584921c2015-01-15 17:10:34 -08001353 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001354 if (request.phone != null) {
1355 return request.phone;
1356 } else {
1357 return getPhoneFromSubId(request.subId);
1358 }
1359 }
1360
1361 private Phone getPhoneFromSubId(int subId) {
1362 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1363 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001364 }
1365
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001366 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1367 Phone phone = getPhoneFromRequest(request);
1368 return phone == null ? null :
1369 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1370 }
1371
Wink Saville36469e72014-06-11 15:17:00 -07001372 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001373 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001374 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001376
1377 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001378 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001379 }
1380
Wink Savilleb564aae2014-10-23 10:18:09 -07001381 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382 if (DBG) log("dial: " + number);
1383 // No permission check needed here: This is just a wrapper around the
1384 // ACTION_DIAL intent, which is available to any app since it puts up
1385 // the UI before it does anything.
1386
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001387 final long identity = Binder.clearCallingIdentity();
1388 try {
1389 String url = createTelUrl(number);
1390 if (url == null) {
1391 return;
1392 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001394 // PENDING: should we just silently fail if phone is offhook or ringing?
1395 PhoneConstants.State state = mCM.getState(subId);
1396 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1397 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1398 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1399 mApp.startActivity(intent);
1400 }
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001403 }
1404 }
1405
1406 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001411 if (DBG) log("call: " + number);
1412
1413 // This is just a wrapper around the ACTION_CALL intent, but we still
1414 // need to do a permission check since we're calling startActivity()
1415 // from the context of the phone app.
1416 enforceCallPermission();
1417
Jordan Liu1617b712019-07-10 15:06:26 -07001418 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001419 != AppOpsManager.MODE_ALLOWED) {
1420 return;
1421 }
1422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001423 final long identity = Binder.clearCallingIdentity();
1424 try {
1425 String url = createTelUrl(number);
1426 if (url == null) {
1427 return;
1428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001429
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001430 boolean isValid = false;
1431 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1432 if (slist != null) {
1433 for (SubscriptionInfo subInfoRecord : slist) {
1434 if (subInfoRecord.getSubscriptionId() == subId) {
1435 isValid = true;
1436 break;
1437 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001438 }
Wink Saville08874612014-08-31 19:19:58 -07001439 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 if (!isValid) {
1441 return;
1442 }
Wink Saville08874612014-08-31 19:19:58 -07001443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001444 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1445 intent.putExtra(SUBSCRIPTION_KEY, subId);
1446 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1447 mApp.startActivity(intent);
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 }
1452
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001453 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001455 }
1456
Wink Savilleb564aae2014-10-23 10:18:09 -07001457 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001458 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001459 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1460 }
1461
1462 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001464 }
1465
Wink Savilleb564aae2014-10-23 10:18:09 -07001466 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001467 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001468 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1469 }
1470
1471 /** {@hide} */
1472 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001473 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001474 }
1475
Wink Savilleb564aae2014-10-23 10:18:09 -07001476 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001477 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001478
1479 final long identity = Binder.clearCallingIdentity();
1480 try {
1481 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1482 checkSimPin.start();
1483 return checkSimPin.unlockSim(null, pin);
1484 } finally {
1485 Binder.restoreCallingIdentity(identity);
1486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001487 }
1488
Wink Saville9de0f752013-10-22 19:04:03 -07001489 /** {@hide} */
1490 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001491 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001492 }
1493
Wink Savilleb564aae2014-10-23 10:18:09 -07001494 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001496
1497 final long identity = Binder.clearCallingIdentity();
1498 try {
1499 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1500 checkSimPuk.start();
1501 return checkSimPuk.unlockSim(puk, pin);
1502 } finally {
1503 Binder.restoreCallingIdentity(identity);
1504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 }
1506
1507 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001508 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509 * a synchronous one.
1510 */
1511 private static class UnlockSim extends Thread {
1512
1513 private final IccCard mSimCard;
1514
1515 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001516 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1517 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001518
1519 // For replies from SimCard interface
1520 private Handler mHandler;
1521
1522 // For async handler to identify request type
1523 private static final int SUPPLY_PIN_COMPLETE = 100;
1524
1525 public UnlockSim(IccCard simCard) {
1526 mSimCard = simCard;
1527 }
1528
1529 @Override
1530 public void run() {
1531 Looper.prepare();
1532 synchronized (UnlockSim.this) {
1533 mHandler = new Handler() {
1534 @Override
1535 public void handleMessage(Message msg) {
1536 AsyncResult ar = (AsyncResult) msg.obj;
1537 switch (msg.what) {
1538 case SUPPLY_PIN_COMPLETE:
1539 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1540 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001541 mRetryCount = msg.arg1;
1542 if (ar.exception != null) {
1543 if (ar.exception instanceof CommandException &&
1544 ((CommandException)(ar.exception)).getCommandError()
1545 == CommandException.Error.PASSWORD_INCORRECT) {
1546 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1547 } else {
1548 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1549 }
1550 } else {
1551 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 mDone = true;
1554 UnlockSim.this.notifyAll();
1555 }
1556 break;
1557 }
1558 }
1559 };
1560 UnlockSim.this.notifyAll();
1561 }
1562 Looper.loop();
1563 }
1564
1565 /*
1566 * Use PIN or PUK to unlock SIM card
1567 *
1568 * If PUK is null, unlock SIM card with PIN
1569 *
1570 * If PUK is not null, unlock SIM card with PUK and set PIN code
1571 */
Wink Saville9de0f752013-10-22 19:04:03 -07001572 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001573
1574 while (mHandler == null) {
1575 try {
1576 wait();
1577 } catch (InterruptedException e) {
1578 Thread.currentThread().interrupt();
1579 }
1580 }
1581 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1582
1583 if (puk == null) {
1584 mSimCard.supplyPin(pin, callback);
1585 } else {
1586 mSimCard.supplyPuk(puk, pin, callback);
1587 }
1588
1589 while (!mDone) {
1590 try {
1591 Log.d(LOG_TAG, "wait for done");
1592 wait();
1593 } catch (InterruptedException e) {
1594 // Restore the interrupted status
1595 Thread.currentThread().interrupt();
1596 }
1597 }
1598 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001599 int[] resultArray = new int[2];
1600 resultArray[0] = mResult;
1601 resultArray[1] = mRetryCount;
1602 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
1604 }
1605
1606 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001607 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001608
1609 }
1610
Wink Savilleb564aae2014-10-23 10:18:09 -07001611 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001612 // No permission check needed here: this call is harmless, and it's
1613 // needed for the ServiceState.requestStateUpdate() call (which is
1614 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001615 final long identity = Binder.clearCallingIdentity();
1616 try {
1617 final Phone phone = getPhone(subId);
1618 if (phone != null) {
1619 phone.updateServiceLocation();
1620 }
1621 } finally {
1622 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001623 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001624 }
1625
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001626 @Override
1627 public boolean isRadioOn(String callingPackage) {
1628 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 @Override
1632 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001634 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001635 return false;
1636 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 return isRadioOnForSubscriber(subId);
1641 } finally {
1642 Binder.restoreCallingIdentity(identity);
1643 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001644 }
1645
1646 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001647 final long identity = Binder.clearCallingIdentity();
1648 try {
1649 final Phone phone = getPhone(subId);
1650 if (phone != null) {
1651 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1652 } else {
1653 return false;
1654 }
1655 } finally {
1656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
1659
1660 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001661 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 }
Wink Saville36469e72014-06-11 15:17:00 -07001663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001666
1667 final long identity = Binder.clearCallingIdentity();
1668 try {
1669 final Phone phone = getPhone(subId);
1670 if (phone != null) {
1671 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1672 }
1673 } finally {
1674 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001675 }
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
1678 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001679 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001680 }
1681
Wink Savilleb564aae2014-10-23 10:18:09 -07001682 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001683 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001684
1685 final long identity = Binder.clearCallingIdentity();
1686 try {
1687 final Phone phone = getPhone(subId);
1688 if (phone == null) {
1689 return false;
1690 }
1691 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1692 toggleRadioOnOffForSubscriber(subId);
1693 }
1694 return true;
1695 } finally {
1696 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001697 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001698 }
Wink Saville36469e72014-06-11 15:17:00 -07001699
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001700 public boolean needMobileRadioShutdown() {
1701 /*
1702 * If any of the Radios are available, it will need to be
1703 * shutdown. So return true if any Radio is available.
1704 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001705 final long identity = Binder.clearCallingIdentity();
1706 try {
1707 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1708 Phone phone = PhoneFactory.getPhone(i);
1709 if (phone != null && phone.isRadioAvailable()) return true;
1710 }
1711 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1712 return false;
1713 } finally {
1714 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 }
1717
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001719 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001720 enforceModifyPermission();
1721
1722 final long identity = Binder.clearCallingIdentity();
1723 try {
1724 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1725 logv("Shutting down Phone " + i);
1726 shutdownRadioUsingPhoneId(i);
1727 }
1728 } finally {
1729 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 }
1731 }
1732
1733 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001734 Phone phone = PhoneFactory.getPhone(phoneId);
1735 if (phone != null && phone.isRadioAvailable()) {
1736 phone.shutdownRadio();
1737 }
1738 }
1739
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001741 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742
1743 final long identity = Binder.clearCallingIdentity();
1744 try {
1745 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1746 if (defaultPhone != null) {
1747 defaultPhone.setRadioPower(turnOn);
1748 return true;
1749 } else {
1750 loge("There's no default phone.");
1751 return false;
1752 }
1753 } finally {
1754 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001755 }
Wink Saville36469e72014-06-11 15:17:00 -07001756 }
1757
Wink Savilleb564aae2014-10-23 10:18:09 -07001758 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001759 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001760
1761 final long identity = Binder.clearCallingIdentity();
1762 try {
1763 final Phone phone = getPhone(subId);
1764 if (phone != null) {
1765 phone.setRadioPower(turnOn);
1766 return true;
1767 } else {
1768 return false;
1769 }
1770 } finally {
1771 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 }
1774
Wink Saville36469e72014-06-11 15:17:00 -07001775 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 public boolean enableDataConnectivity() {
1778 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001779
1780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 int subId = mSubscriptionController.getDefaultDataSubId();
1783 final Phone phone = getPhone(subId);
1784 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001785 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 return true;
1787 } else {
1788 return false;
1789 }
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Wink Saville36469e72014-06-11 15:17:00 -07001795 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 public boolean disableDataConnectivity() {
1798 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799
1800 final long identity = Binder.clearCallingIdentity();
1801 try {
1802 int subId = mSubscriptionController.getDefaultDataSubId();
1803 final Phone phone = getPhone(subId);
1804 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001805 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806 return true;
1807 } else {
1808 return false;
1809 }
1810 } finally {
1811 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001813 }
1814
Sanket Padawe356d7632015-06-22 14:03:32 -07001815 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001816 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001817 final long identity = Binder.clearCallingIdentity();
1818 try {
1819 final Phone phone = getPhone(subId);
1820 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001821 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822 } else {
1823 return false;
1824 }
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
1830 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001831 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001832 }
1833
pkanwarae03a6b2016-11-06 20:37:09 -08001834 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 enforceCallPermission();
1836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1840 return;
1841 }
1842 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1843 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
1846 }
pkanwar32d516d2016-10-14 19:37:38 -07001847 };
1848
Wink Savilleb564aae2014-10-23 10:18:09 -07001849 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001850 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001851
1852 final long identity = Binder.clearCallingIdentity();
1853 try {
1854 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1855 return false;
1856 }
1857 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1858 } finally {
1859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 }
1862
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001863 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001864 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001865 }
1866
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001867 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001868 final long identity = Binder.clearCallingIdentity();
1869 try {
1870 Phone phone = PhoneFactory.getPhone(slotIndex);
1871 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1872 PhoneConstantConversions.convertCallState(phone.getState());
1873 } finally {
1874 Binder.restoreCallingIdentity(identity);
1875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001876 }
1877
Sanket Padawe356d7632015-06-22 14:03:32 -07001878 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001879 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001880 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1881 }
1882
1883 @Override
1884 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 final long identity = Binder.clearCallingIdentity();
1886 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001887 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001888 if (phone != null) {
1889 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1890 } else {
1891 return PhoneConstantConversions.convertDataState(
1892 PhoneConstants.DataState.DISCONNECTED);
1893 }
1894 } finally {
1895 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 }
1898
Sanket Padawe356d7632015-06-22 14:03:32 -07001899 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001900 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001901 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1902 }
1903
1904 @Override
1905 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906 final long identity = Binder.clearCallingIdentity();
1907 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001908 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 if (phone != null) {
1910 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1911 } else {
1912 return TelephonyManager.DATA_ACTIVITY_NONE;
1913 }
1914 } finally {
1915 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001916 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917 }
1918
1919 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001920 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001921 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001922 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001923
1924 LocationAccessPolicy.LocationPermissionResult locationResult =
1925 LocationAccessPolicy.checkLocationPermission(mApp,
1926 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1927 .setCallingPackage(callingPackage)
1928 .setCallingPid(Binder.getCallingPid())
1929 .setCallingUid(Binder.getCallingUid())
1930 .setMethod("getCellLocation")
1931 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1932 .build());
1933 switch (locationResult) {
1934 case DENIED_HARD:
1935 throw new SecurityException("Not allowed to access cell location");
1936 case DENIED_SOFT:
1937 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 }
1939
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001940 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001941 final long identity = Binder.clearCallingIdentity();
1942 try {
1943 if (DBG_LOC) log("getCellLocation: is active user");
1944 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001945 int subId = mSubscriptionController.getDefaultDataSubId();
1946 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1947 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001948 return data;
1949 } finally {
1950 Binder.restoreCallingIdentity(identity);
1951 }
Svetoslav64fad262015-04-14 14:35:21 -07001952 }
1953
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001955 public String getNetworkCountryIsoForPhone(int phoneId) {
1956 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1957 // registered cell info, so return a NULL country instead.
1958 final long identity = Binder.clearCallingIdentity();
1959 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001960 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1961 // Get default phone in this case.
1962 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1963 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001965 // Todo: fix this when we can get the actual cellular network info when the device
1966 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001967 if (TelephonyManager.NETWORK_TYPE_IWLAN
1968 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1969 return "";
1970 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001971 Phone phone = PhoneFactory.getPhone(phoneId);
1972 if (phone != null) {
1973 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07001974 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 if (sst != null) {
1976 LocaleTracker lt = sst.getLocaleTracker();
1977 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07001978 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1979 return lt.getCurrentCountry();
1980 } else if (emergencyNumberTracker != null) {
1981 return emergencyNumberTracker.getEmergencyCountryIso();
1982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001983 }
1984 }
1985 }
1986 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001987 } finally {
1988 Binder.restoreCallingIdentity(identity);
1989 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001990 }
1991
1992 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001994 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001995 }
1996
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001998 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 mApp.enforceCallingOrSelfPermission(
2000 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 final Phone phone = getPhone(subId);
2005 if (phone != null) {
2006 phone.enableLocationUpdates();
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
2012
2013 @Override
2014 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002015 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002016 }
2017
Sanket Padawe356d7632015-06-22 14:03:32 -07002018 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 mApp.enforceCallingOrSelfPermission(
2021 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 final Phone phone = getPhone(subId);
2026 if (phone != null) {
2027 phone.disableLocationUpdates();
2028 }
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Nathan Harold31d7ff32018-10-15 20:20:30 -07002034 /**
2035 * Returns the target SDK version number for a given package name.
2036 *
Nathan Haroldec184742019-07-10 17:04:16 -07002037 * This call MUST be invoked before clearing the calling UID.
2038 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002039 * @return target SDK if the package is found or INT_MAX.
2040 */
2041 private int getTargetSdk(String packageName) {
2042 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002043 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002044 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002045 if (ai != null) return ai.targetSdkVersion;
2046 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002047 loge("Failed to get package info for pkg="
2048 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002049 }
2050 return Integer.MAX_VALUE;
2051 }
2052
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 @Override
2054 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002055 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2056 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002057 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2058 throw new SecurityException(
2059 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2060 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002061
Jordan Liu1617b712019-07-10 15:06:26 -07002062 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2064 return null;
2065 }
Svetoslav64fad262015-04-14 14:35:21 -07002066
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002067 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068
Nathan Haroldf180aac2018-06-01 18:43:55 -07002069 List<CellInfo> info = getAllCellInfo(callingPackage);
2070 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071
Nathan Haroldf180aac2018-06-01 18:43:55 -07002072 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2073 for (CellInfo ci : info) {
2074 if (ci instanceof CellInfoGsm) {
2075 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2076 } else if (ci instanceof CellInfoWcdma) {
2077 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2078 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002080 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002081 }
2082
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 private List<CellInfo> getCachedCellInfo() {
2084 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2085 for (Phone phone : PhoneFactory.getPhones()) {
2086 List<CellInfo> info = phone.getAllCellInfo();
2087 if (info != null) cellInfos.addAll(info);
2088 }
2089 return cellInfos;
2090 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091
2092 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002093 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002095 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002096
2097 LocationAccessPolicy.LocationPermissionResult locationResult =
2098 LocationAccessPolicy.checkLocationPermission(mApp,
2099 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2100 .setCallingPackage(callingPackage)
2101 .setCallingPid(Binder.getCallingPid())
2102 .setCallingUid(Binder.getCallingUid())
2103 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002104 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002105 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2106 .build());
2107 switch (locationResult) {
2108 case DENIED_HARD:
2109 throw new SecurityException("Not allowed to access cell info");
2110 case DENIED_SOFT:
2111 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002114 final int targetSdk = getTargetSdk(callingPackage);
2115 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2116 return getCachedCellInfo();
2117 }
2118
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002119 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002120 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2124 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002125 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002126 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127 if (info != null) cellInfos.addAll(info);
2128 }
2129 return cellInfos;
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 }
2133 }
2134
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002135 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002136 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2137 requestCellInfoUpdateInternal(
2138 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2139 }
2140
2141 @Override
2142 public void requestCellInfoUpdateWithWorkSource(
2143 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2144 enforceModifyPermission();
2145 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2146 }
2147
2148 private void requestCellInfoUpdateInternal(
2149 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002150 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002151 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002152
2153 LocationAccessPolicy.LocationPermissionResult locationResult =
2154 LocationAccessPolicy.checkLocationPermission(mApp,
2155 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2156 .setCallingPackage(callingPackage)
2157 .setCallingPid(Binder.getCallingPid())
2158 .setCallingUid(Binder.getCallingUid())
2159 .setMethod("requestCellInfoUpdate")
2160 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2161 .build());
2162 switch (locationResult) {
2163 case DENIED_HARD:
2164 throw new SecurityException("Not allowed to access cell info");
2165 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002166 try {
2167 cb.onCellInfo(new ArrayList<CellInfo>());
2168 } catch (RemoteException re) {
2169 // Drop without consequences
2170 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002171 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002172 }
2173
Nathan Harolda939a962019-05-09 10:13:47 -07002174
2175 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002176 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2177
2178 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2179 }
2180
2181 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002183 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002184 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002185
2186 final long identity = Binder.clearCallingIdentity();
2187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002188 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 } finally {
2190 Binder.restoreCallingIdentity(identity);
2191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002192 }
2193
Shishir Agrawala9f32182016-04-12 12:00:16 -07002194 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002195 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002196 Phone phone = PhoneFactory.getPhone(slotIndex);
2197 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002198 return null;
2199 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002200 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002201 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2202 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002203 return null;
2204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205
2206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 return phone.getImei();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002212 }
2213
2214 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002215 public String getTypeAllocationCodeForSlot(int slotIndex) {
2216 Phone phone = PhoneFactory.getPhone(slotIndex);
2217 String tac = null;
2218 if (phone != null) {
2219 String imei = phone.getImei();
2220 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2221 }
2222 return tac;
2223 }
2224
2225 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002226 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 Phone phone = PhoneFactory.getPhone(slotIndex);
2228 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002229 return null;
2230 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002231
Jeff Davidson913390f2018-02-23 17:11:49 -08002232 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002233 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2234 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002235 return null;
2236 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002237
2238 final long identity = Binder.clearCallingIdentity();
2239 try {
2240 return phone.getMeid();
2241 } finally {
2242 Binder.restoreCallingIdentity(identity);
2243 }
Jack Yu2af8d712017-03-15 17:14:14 -07002244 }
2245
2246 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002247 public String getManufacturerCodeForSlot(int slotIndex) {
2248 Phone phone = PhoneFactory.getPhone(slotIndex);
2249 String manufacturerCode = null;
2250 if (phone != null) {
2251 String meid = phone.getMeid();
2252 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2253 }
2254 return manufacturerCode;
2255 }
2256
2257 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002258 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002259 Phone phone = PhoneFactory.getPhone(slotIndex);
2260 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002261 return null;
2262 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002263 int subId = phone.getSubId();
2264 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2265 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2266 return null;
2267 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268
2269 final long identity = Binder.clearCallingIdentity();
2270 try {
2271 return phone.getDeviceSvn();
2272 } finally {
2273 Binder.restoreCallingIdentity(identity);
2274 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002275 }
2276
fionaxu43304da2017-11-27 22:51:16 -08002277 @Override
2278 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002279 final long identity = Binder.clearCallingIdentity();
2280 try {
2281 final Phone phone = getPhone(subId);
2282 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2283 } finally {
2284 Binder.restoreCallingIdentity(identity);
2285 }
fionaxu43304da2017-11-27 22:51:16 -08002286 }
2287
2288 @Override
2289 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
2292 final Phone phone = getPhone(subId);
2293 return phone == null ? null : phone.getCarrierName();
2294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
fionaxu43304da2017-11-27 22:51:16 -08002297 }
2298
calvinpanffe225e2018-11-01 19:43:06 +08002299 @Override
chen xu0026ca62019-03-06 15:28:50 -08002300 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002301 final long identity = Binder.clearCallingIdentity();
2302 try {
2303 final Phone phone = getPhone(subId);
2304 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002305 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002306 } finally {
2307 Binder.restoreCallingIdentity(identity);
2308 }
2309 }
2310
2311 @Override
chen xu0026ca62019-03-06 15:28:50 -08002312 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002313 final long identity = Binder.clearCallingIdentity();
2314 try {
2315 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002316 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002317 } finally {
2318 Binder.restoreCallingIdentity(identity);
2319 }
2320 }
2321
chen xu651eec72018-11-11 19:03:44 -08002322 @Override
chen xu864e11c2018-12-06 22:10:03 -08002323 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2324 if (!isSubscriptionMccMnc) {
2325 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2326 }
chen xu651eec72018-11-11 19:03:44 -08002327 final Phone phone = PhoneFactory.getPhone(slotIndex);
2328 if (phone == null) {
2329 return TelephonyManager.UNKNOWN_CARRIER_ID;
2330 }
2331 final long identity = Binder.clearCallingIdentity();
2332 try {
2333 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2334 } finally {
2335 Binder.restoreCallingIdentity(identity);
2336 }
2337 }
2338
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002339 //
2340 // Internal helper methods.
2341 //
2342
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002343 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2345 *
2346 * @throws SecurityException if the caller does not have the required permission
2347 */
2348 private void enforceModifyPermission() {
2349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2350 }
2351
2352 /**
2353 * Make sure the caller has the CALL_PHONE permission.
2354 *
2355 * @throws SecurityException if the caller does not have the required permission
2356 */
2357 private void enforceCallPermission() {
2358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2359 }
2360
Stuart Scott8eef64f2015-04-08 15:13:54 -07002361 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002362 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002363 "ConnectivityService");
2364 }
2365
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 private String createTelUrl(String number) {
2367 if (TextUtils.isEmpty(number)) {
2368 return null;
2369 }
2370
Jake Hambye994d462014-02-03 13:10:13 -08002371 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 }
2373
Ihab Awadf9e92732013-12-05 18:02:52 -08002374 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2376 }
2377
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002378 private static void logv(String msg) {
2379 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2380 }
2381
Ihab Awadf9e92732013-12-05 18:02:52 -08002382 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2384 }
2385
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002388 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002389 }
2390
Sanket Padawe356d7632015-06-22 14:03:32 -07002391 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002392 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002393 final long identity = Binder.clearCallingIdentity();
2394 try {
2395 final Phone phone = PhoneFactory.getPhone(slotIndex);
2396 if (phone == null) {
2397 return PhoneConstants.PHONE_TYPE_NONE;
2398 } else {
2399 return phone.getPhoneType();
2400 }
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002404 }
2405
2406 /**
2407 * Returns the CDMA ERI icon index to display
2408 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002409 @Override
2410 public int getCdmaEriIconIndex(String callingPackage) {
2411 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002412 }
2413
Sanket Padawe356d7632015-06-22 14:03:32 -07002414 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002417 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002418 return -1;
2419 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002420
2421 final long identity = Binder.clearCallingIdentity();
2422 try {
2423 final Phone phone = getPhone(subId);
2424 if (phone != null) {
2425 return phone.getCdmaEriIconIndex();
2426 } else {
2427 return -1;
2428 }
2429 } finally {
2430 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 }
2433
2434 /**
2435 * Returns the CDMA ERI icon mode,
2436 * 0 - ON
2437 * 1 - FLASHING
2438 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
2440 public int getCdmaEriIconMode(String callingPackage) {
2441 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002446 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002447 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002448 return -1;
2449 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null) {
2455 return phone.getCdmaEriIconMode();
2456 } else {
2457 return -1;
2458 }
2459 } finally {
2460 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002461 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002462 }
2463
2464 /**
2465 * Returns the CDMA ERI text,
2466 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002467 @Override
2468 public String getCdmaEriText(String callingPackage) {
2469 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002470 }
2471
Sanket Padawe356d7632015-06-22 14:03:32 -07002472 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002475 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002476 return null;
2477 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
2481 final Phone phone = getPhone(subId);
2482 if (phone != null) {
2483 return phone.getCdmaEriText();
2484 } else {
2485 return null;
2486 }
2487 } finally {
2488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002490 }
2491
2492 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002493 * Returns the CDMA MDN.
2494 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002496 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002497 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2498 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499
2500 final long identity = Binder.clearCallingIdentity();
2501 try {
2502 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002503 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 return phone.getLine1Number();
2505 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002506 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507 return null;
2508 }
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002511 }
2512 }
2513
2514 /**
2515 * Returns the CDMA MIN.
2516 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002517 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002518 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2520 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 final Phone phone = getPhone(subId);
2525 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2526 return phone.getCdmaMin();
2527 } else {
2528 return null;
2529 }
2530 } finally {
2531 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002532 }
2533 }
2534
Hall Liud892bec2018-11-30 14:51:45 -08002535 @Override
2536 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2537 INumberVerificationCallback callback, String callingPackage) {
2538 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2539 != PERMISSION_GRANTED) {
2540 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2541 }
2542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2543
2544 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2545 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2546 throw new SecurityException("Calling package must be configured in the device config");
2547 }
2548
2549 if (range == null) {
2550 throw new NullPointerException("Range must be non-null");
2551 }
2552
2553 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002554 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002555
2556 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2557 }
2558
Junda Liuca05d5d2014-08-14 22:36:34 -07002559 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002560 * Returns true if CDMA provisioning needs to run.
2561 */
2562 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 final long identity = Binder.clearCallingIdentity();
2564 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002565 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
2570
2571 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002572 * Sets the voice mail number of a given subId.
2573 */
2574 @Override
2575 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577
2578 final long identity = Binder.clearCallingIdentity();
2579 try {
2580 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2581 new Pair<String, String>(alphaTag, number), new Integer(subId));
2582 return success;
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
2585 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002586 }
2587
Ta-wei Yen87c49842016-05-13 21:19:52 -07002588 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002589 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2590 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002592 if (!TextUtils.equals(callingPackage, systemDialer)) {
2593 throw new SecurityException("caller must be system dialer");
2594 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2599 if (phoneAccountHandle == null) {
2600 return null;
2601 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002602 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002603 } finally {
2604 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002605 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002606 }
2607
2608 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002609 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002612 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002613 return null;
2614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002616 final long identity = Binder.clearCallingIdentity();
2617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002618 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002619 } finally {
2620 Binder.restoreCallingIdentity(identity);
2621 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002622 }
2623
2624 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002625 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2626 VisualVoicemailSmsFilterSettings settings) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002632 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002639 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2640 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002645 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002649 }
2650
2651 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002652 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2653 String callingPackage, int subId) {
2654 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002659 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002663 }
2664
2665 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002666 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002667 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668
2669 final long identity = Binder.clearCallingIdentity();
2670 try {
2671 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002672 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002676 }
2677
2678 @Override
2679 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2680 String number, int port, String text, PendingIntent sentIntent) {
2681 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002682 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002683 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002684 SmsController smsController = PhoneFactory.getSmsController();
2685 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2686 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002687 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002688
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002689 /**
fionaxu0152e512016-11-14 13:36:14 -08002690 * Sets the voice activation state of a given subId.
2691 */
2692 @Override
2693 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2695 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696
2697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 final Phone phone = getPhone(subId);
2700 if (phone != null) {
2701 phone.setVoiceActivationState(activationState);
2702 } else {
2703 loge("setVoiceActivationState fails with invalid subId: " + subId);
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
2711 * Sets the data activation state of a given subId.
2712 */
2713 @Override
2714 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2716 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717
2718 final long identity = Binder.clearCallingIdentity();
2719 try {
2720 final Phone phone = getPhone(subId);
2721 if (phone != null) {
2722 phone.setDataActivationState(activationState);
2723 } else {
2724 loge("setVoiceActivationState fails with invalid subId: " + subId);
2725 }
2726 } finally {
2727 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002728 }
2729 }
2730
2731 /**
2732 * Returns the voice activation state of a given subId.
2733 */
2734 @Override
2735 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002736 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737
fionaxu0152e512016-11-14 13:36:14 -08002738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 final long identity = Binder.clearCallingIdentity();
2740 try {
2741 if (phone != null) {
2742 return phone.getVoiceActivationState();
2743 } else {
2744 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2745 }
2746 } finally {
2747 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002748 }
2749 }
2750
2751 /**
2752 * Returns the data activation state of a given subId.
2753 */
2754 @Override
2755 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002756 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757
fionaxu0152e512016-11-14 13:36:14 -08002758 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002759 final long identity = Binder.clearCallingIdentity();
2760 try {
2761 if (phone != null) {
2762 return phone.getDataActivationState();
2763 } else {
2764 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2765 }
2766 } finally {
2767 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002768 }
2769 }
2770
2771 /**
Wink Saville36469e72014-06-11 15:17:00 -07002772 * Returns the unread count of voicemails for a subId
2773 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002774 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002775 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2776 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2777 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2778 return 0;
2779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002780 final long identity = Binder.clearCallingIdentity();
2781 try {
2782 final Phone phone = getPhone(subId);
2783 if (phone != null) {
2784 return phone.getVoiceMessageCount();
2785 } else {
2786 return 0;
2787 }
2788 } finally {
2789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002791 }
2792
2793 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002794 * returns true, if the device is in a state where both voice and data
2795 * are supported simultaneously. This can change based on location or network condition.
2796 */
2797 @Override
2798 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 final long identity = Binder.clearCallingIdentity();
2800 try {
2801 final Phone phone = getPhone(subId);
2802 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002806 }
2807
2808 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002809 * Send the dialer code if called from the current default dialer or the caller has
2810 * carrier privilege.
2811 * @param inputCode The dialer code to send
2812 */
2813 @Override
2814 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002816 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2818 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002819 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002820 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2821 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002826 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002827 } finally {
2828 Binder.restoreCallingIdentity(identity);
2829 }
fionaxu235cc5e2017-03-06 22:25:57 -08002830 }
2831
Pengquan Menga1bb6272018-09-06 09:59:22 -07002832 @Override
2833 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002834 if (!isActiveSubscription(subId)) {
2835 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2836 }
2837
Pengquan Menga1bb6272018-09-06 09:59:22 -07002838 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2839 }
2840
Brad Ebinger35c841c2018-10-01 10:40:55 -07002841 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002842 public boolean isInEmergencySmsMode() {
2843 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2844 final long identity = Binder.clearCallingIdentity();
2845 try {
2846 for (Phone phone : PhoneFactory.getPhones()) {
2847 if (phone.isInEmergencySmsMode()) {
2848 return true;
2849 }
2850 }
2851 } finally {
2852 Binder.restoreCallingIdentity(identity);
2853 }
2854 return false;
2855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2859 throws RemoteException {
2860 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002861 final long token = Binder.clearCallingIdentity();
2862 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002865 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002866 } catch (ImsException e) {
2867 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002868 } finally {
2869 Binder.restoreCallingIdentity(token);
2870 }
2871 }
2872
2873 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002874 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2875 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2877 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2878 }
Meng Wangafbc5852019-09-19 17:37:13 -07002879 final long token = Binder.clearCallingIdentity();
2880 try {
2881 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2882 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2883 .removeRegistrationCallbackForSubscription(c, subId);
2884 } catch (ImsException e) {
2885 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2886 + "is inactive, ignoring unregister.");
2887 // If the subscription is no longer active, just return, since the callback
2888 // will already have been removed internally.
2889 } finally {
2890 Binder.restoreCallingIdentity(token);
2891 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002892 }
2893
2894 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002895 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2896 throws RemoteException {
2897 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2899 final long token = Binder.clearCallingIdentity();
2900 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002901 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002902 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002903 } catch (ImsException e) {
2904 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002905 } finally {
2906 Binder.restoreCallingIdentity(token);
2907 }
2908 }
2909
2910 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002911 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2912 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002913 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2914 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2915 }
Meng Wangafbc5852019-09-19 17:37:13 -07002916
2917 final long token = Binder.clearCallingIdentity();
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2920 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002921 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002922 } catch (ImsException e) {
2923 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2924 + "is inactive, ignoring unregister.");
2925 // If the subscription is no longer active, just return, since the callback
2926 // will already have been removed internally.
2927 } finally {
2928 Binder.restoreCallingIdentity(token);
2929 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002930 }
2931
2932 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002933 public boolean isCapable(int subId, int capability, int regTech) {
2934 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2936 final long token = Binder.clearCallingIdentity();
2937 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002938 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002940 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002941 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2942 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002943 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002944 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2945 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002946 } finally {
2947 Binder.restoreCallingIdentity(token);
2948 }
2949 }
2950
2951 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002952 public boolean isAvailable(int subId, int capability, int regTech) {
2953 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002954 final long token = Binder.clearCallingIdentity();
2955 try {
2956 Phone phone = getPhone(subId);
2957 if (phone == null) return false;
2958 return phone.isImsCapabilityAvailable(capability, regTech);
2959 } finally {
2960 Binder.restoreCallingIdentity(token);
2961 }
2962 }
2963
2964 @Override
2965 public boolean isAdvancedCallingSettingEnabled(int subId) {
2966 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2967 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2968 final long token = Binder.clearCallingIdentity();
2969 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002970 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002972 } catch (ImsException e) {
2973 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002974 } finally {
2975 Binder.restoreCallingIdentity(token);
2976 }
2977 }
2978
2979 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002980 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002982 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002988 } catch (ImsException e) {
2989 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 }
2994
2995 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002996 public boolean isVtSettingEnabled(int subId) {
2997 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003001 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3002 } catch (ImsException e) {
3003 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003010 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003012 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003013 final long identity = Binder.clearCallingIdentity();
3014 try {
3015 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003016 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003017 } catch (ImsException e) {
3018 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public boolean isVoWiFiSettingEnabled(int subId) {
3026 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003032 } catch (ImsException e) {
3033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003040 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003042 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003046 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003047 } catch (ImsException e) {
3048 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3056 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003060 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003062 } catch (ImsException e) {
3063 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
3067 }
3068
3069 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003070 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003072 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003078 } catch (ImsException e) {
3079 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
3083 }
3084
3085 @Override
3086 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3088 "setVoWiFiNonPersistent");
3089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003092 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003093 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003094 } catch (ImsException e) {
3095 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 }
3100
3101 @Override
3102 public int getVoWiFiModeSetting(int subId) {
3103 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003107 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003108 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003109 } catch (ImsException e) {
3110 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
3117 public void setVoWiFiModeSetting(int subId, int mode) {
3118 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3119 "setVoWiFiModeSetting");
3120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003123 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003124 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003125 } catch (ImsException e) {
3126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
3133 public int getVoWiFiRoamingModeSetting(int subId) {
3134 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003138 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003139 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003140 } catch (ImsException e) {
3141 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 } finally {
3143 Binder.restoreCallingIdentity(identity);
3144 }
3145 }
3146
3147 @Override
3148 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3150 "setVoWiFiRoamingModeSetting");
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003154 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003156 } catch (ImsException e) {
3157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 } finally {
3159 Binder.restoreCallingIdentity(identity);
3160 }
3161 }
3162
3163 @Override
3164 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3166 "setRttCapabilityEnabled");
3167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003170 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3171 } catch (ImsException e) {
3172 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 } finally {
3174 Binder.restoreCallingIdentity(identity);
3175 }
3176 }
3177
3178 @Override
3179 public boolean isTtyOverVolteEnabled(int subId) {
3180 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3181 final long identity = Binder.clearCallingIdentity();
3182 try {
3183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003184 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003185 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003186 } catch (ImsException e) {
3187 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003193 @Override
3194 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3195 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3196 final long identity = Binder.clearCallingIdentity();
3197 try {
3198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003199 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003200 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003201 } catch (ImsException e) {
3202 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
3206 }
3207
3208 @Override
3209 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3210 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3211 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003212 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3213 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3214 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003215 try {
3216 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003218 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003219 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003220 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3221 + "is inactive, ignoring unregister.");
3222 // If the subscription is no longer active, just return, since the callback will already
3223 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003224 } finally {
3225 Binder.restoreCallingIdentity(identity);
3226 }
3227 }
3228
3229 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003230 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3231 boolean isProvisioned) {
3232 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3233 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3234 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3235 }
3236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3237 "setProvisioningStatusForCapability");
3238 final long identity = Binder.clearCallingIdentity();
3239 try {
3240 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3241 Phone phone = getPhone(subId);
3242 if (phone == null) {
3243 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3244 + subId);
3245 return;
3246 }
3247 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3248 return;
3249 }
3250
3251 // this capability requires provisioning, route to the correct API.
3252 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3253 switch (capability) {
3254 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3255 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3256 ims.setVolteProvisioned(isProvisioned);
3257 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3258 ims.setWfcProvisioned(isProvisioned);
3259 }
3260 break;
3261 }
3262 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3263 // There is currently no difference in VT provisioning type.
3264 ims.setVtProvisioned(isProvisioned);
3265 break;
3266 }
3267 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3268 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3269 // change the capability of the feature instead if needed.
3270 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3271 == isProvisioned) {
3272 // No change in provisioning.
3273 return;
3274 }
3275 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3276 try {
3277 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003278 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003279 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3280 + ", Exception" + e.getMessage());
3281 }
3282 break;
3283 }
3284 default: {
3285 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3286 + capability + "', which does not require provisioning.");
3287 }
3288 }
3289
3290 } finally {
3291 Binder.restoreCallingIdentity(identity);
3292 }
3293 }
3294
3295 @Override
3296 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3297 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3298 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3299 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3300 }
3301 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3302 final long identity = Binder.clearCallingIdentity();
3303 try {
3304 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3305 Phone phone = getPhone(subId);
3306 if (phone == null) {
3307 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3308 + subId);
3309 // We will fail with "true" as the provisioning status because this is the default
3310 // if we do not require provisioning.
3311 return true;
3312 }
3313
3314 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3315 return true;
3316 }
3317
3318 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3319 switch (capability) {
3320 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3321 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3322 return ims.isVolteProvisionedOnDevice();
3323 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3324 return ims.isWfcProvisionedOnDevice();
3325 }
3326 // This should never happen, since we are checking tech above to make sure it
3327 // is either LTE or IWLAN.
3328 throw new IllegalArgumentException("Invalid radio technology for voice "
3329 + "capability.");
3330 }
3331 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3332 // There is currently no difference in VT provisioning type.
3333 return ims.isVtProvisionedOnDevice();
3334 }
3335 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3336 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3337 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3338 }
3339 default: {
3340 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3341 + capability + "', which does not require provisioning.");
3342 }
3343 }
3344
3345 } finally {
3346 Binder.restoreCallingIdentity(identity);
3347 }
3348 }
3349
3350 @Override
3351 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3352 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3353 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3354 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3355 }
3356 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3357 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3358 return (provisionedBits & capability) > 0;
3359 }
3360
3361 @Override
3362 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3363 boolean isProvisioned) {
3364 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3365 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3366 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3367 }
3368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3369 "setProvisioningStatusForCapability");
3370 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3371 // If the current provisioning status for capability already matches isProvisioned,
3372 // do nothing.
3373 if (((provisionedBits & capability) > 0) == isProvisioned) {
3374 return;
3375 }
3376 if (isProvisioned) {
3377 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3378 } else {
3379 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3380 }
3381 }
3382
3383 /**
3384 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3385 * technology. The bitfield should mirror the bitfield defined by
3386 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3387 */
3388 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3389 String key = getMmTelProvisioningKey(subId, tech);
3390 // Default is no capabilities are provisioned.
3391 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3392 }
3393
3394 /**
3395 * Sets the MmTel capability provisioning bitfield (defined by
3396 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3397 * technology specified.
3398 *
3399 * Note: This is a synchronous command and should not be called on UI thread.
3400 */
3401 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3402 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3403 String key = getMmTelProvisioningKey(subId, tech);
3404 editor.putInt(key, newField);
3405 editor.commit();
3406 }
3407
3408 private static String getMmTelProvisioningKey(int subId, int tech) {
3409 // resulting key is provision_ims_mmtel_{subId}_{tech}
3410 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3411 }
3412
3413 /**
3414 * Query CarrierConfig to see if the specified capability requires provisioning for the
3415 * carrier associated with the subscription id.
3416 */
3417 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3418 int capability) {
3419 CarrierConfigManager configManager = new CarrierConfigManager(context);
3420 PersistableBundle c = configManager.getConfigForSubId(subId);
3421 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003422 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003423 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3424 false);
3425 boolean requireVoiceVtProvisioning = c.getBoolean(
3426 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3427
3428 // First check to make sure that the capability requires provisioning.
3429 switch (capability) {
3430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3431 // intentional fallthrough
3432 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3433 if (requireVoiceVtProvisioning) {
3434 // Voice and Video requires provisioning
3435 return true;
3436 }
3437 break;
3438 }
3439 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3440 if (requireUtProvisioning) {
3441 // UT requires provisioning
3442 return true;
3443 }
3444 break;
3445 }
3446 }
3447 return false;
3448 }
3449
3450 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3453 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3454 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003455 enforceReadPrivilegedPermission("getImsProvisioningInt");
3456 final long identity = Binder.clearCallingIdentity();
3457 try {
3458 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003459 int slotId = getSlotIndex(subId);
3460 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3461 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3462 + subId + "' for key:" + key);
3463 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3464 }
3465 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003466 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003467 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3468 + subId + "' for key:" + key);
3469 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
3473 }
3474
3475 @Override
3476 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003477 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3478 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3479 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003480 enforceReadPrivilegedPermission("getImsProvisioningString");
3481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003484 int slotId = getSlotIndex(subId);
3485 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3486 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3487 + subId + "' for key:" + key);
3488 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3489 }
3490 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003491 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003492 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3493 + subId + "' for key:" + key);
3494 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
3498 }
3499
3500 @Override
3501 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003502 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3503 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3504 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3506 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003510 int slotId = getSlotIndex(subId);
3511 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3512 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3513 + subId + "' for key:" + key);
3514 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3515 }
3516 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003517 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003518 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3519 + "' for key:" + key);
3520 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003521 } finally {
3522 Binder.restoreCallingIdentity(identity);
3523 }
3524 }
3525
3526 @Override
3527 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003528 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3529 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3530 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3532 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003536 int slotId = getSlotIndex(subId);
3537 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3538 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3539 + subId + "' for key:" + key);
3540 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3541 }
3542 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003543 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003544 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3545 + "' for key:" + key);
3546 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003547 } finally {
3548 Binder.restoreCallingIdentity(identity);
3549 }
3550 }
3551
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003552 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 int slotId = SubscriptionManager.getSlotIndex(subId);
3554 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003555 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3556 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 }
3558 return slotId;
3559 }
3560
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003561 private int getSlotIndex(int subId) {
3562 int slotId = SubscriptionManager.getSlotIndex(subId);
3563 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3564 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3565 }
3566 return slotId;
3567 }
3568
Wink Saville36469e72014-06-11 15:17:00 -07003569 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003570 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003571 */
3572 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003574 final int targetSdk = getTargetSdk(callingPackage);
3575 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3576 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3577 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003578 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3579 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003580 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3581 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003582
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 final Phone phone = getPhone(subId);
3586 if (phone != null) {
3587 return phone.getServiceState().getDataNetworkType();
3588 } else {
3589 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3590 }
3591 } finally {
3592 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 }
3595
3596 /**
3597 * Returns the data network type
3598 */
3599 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003600 public int getDataNetworkType(String callingPackage) {
3601 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003602 }
3603
3604 /**
3605 * Returns the data network type for a subId
3606 */
3607 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003610 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3612 }
3613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 final Phone phone = getPhone(subId);
3617 if (phone != null) {
3618 return phone.getServiceState().getDataNetworkType();
3619 } else {
3620 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3621 }
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 }
3626
3627 /**
Wink Saville36469e72014-06-11 15:17:00 -07003628 * Returns the Voice network type for a subId
3629 */
3630 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003631 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003633 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003634 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3635 }
3636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 final Phone phone = getPhone(subId);
3640 if (phone != null) {
3641 return phone.getServiceState().getVoiceNetworkType();
3642 } else {
3643 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3644 }
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003648 }
3649
3650 /**
3651 * @return true if a ICC card is present
3652 */
3653 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003654 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003655 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3656 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003657 }
3658
3659 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003660 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003661 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003662 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003663 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 final Phone phone = PhoneFactory.getPhone(slotIndex);
3667 if (phone != null) {
3668 return phone.getIccCard().hasIccCard();
3669 } else {
3670 return false;
3671 }
3672 } finally {
3673 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003674 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003675 }
3676
3677 /**
3678 * Return if the current radio is LTE on CDMA. This
3679 * is a tri-state return value as for a period of time
3680 * the mode may be unknown.
3681 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003682 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003684 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003685 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003686 @Override
3687 public int getLteOnCdmaMode(String callingPackage) {
3688 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003689 }
3690
Sanket Padawe356d7632015-06-22 14:03:32 -07003691 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003694 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003695 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3696 }
3697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 final Phone phone = getPhone(subId);
3701 if (phone == null) {
3702 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3703 } else {
3704 return phone.getLteOnCdmaMode();
3705 }
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003708 }
Wink Saville36469e72014-06-11 15:17:00 -07003709 }
3710
Wink Saville36469e72014-06-11 15:17:00 -07003711 /**
3712 * {@hide}
3713 * Returns Default subId, 0 in the case of single standby.
3714 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003715 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003716 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003717 }
3718
Shishir Agrawala9f32182016-04-12 12:00:16 -07003719 private int getSlotForDefaultSubscription() {
3720 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3721 }
3722
Wink Savilleb564aae2014-10-23 10:18:09 -07003723 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003724 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003725 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003726
Pengquan Menge92a50d2018-09-21 15:54:48 -07003727 private boolean isActiveSubscription(int subId) {
3728 return mSubscriptionController.isActiveSubId(subId);
3729 }
3730
Ihab Awadf2177b72013-11-25 13:33:23 -08003731 /**
3732 * @see android.telephony.TelephonyManager.WifiCallingChoices
3733 */
3734 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003735 final long identity = Binder.clearCallingIdentity();
3736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003737 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003738 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3739 getWhenToMakeWifiCallsDefaultPreference());
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
3742 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003743 }
3744
3745 /**
3746 * @see android.telephony.TelephonyManager.WifiCallingChoices
3747 */
3748 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 final long identity = Binder.clearCallingIdentity();
3750 try {
3751 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003752 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003753 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3754 } finally {
3755 Binder.restoreCallingIdentity(identity);
3756 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003757 }
3758
Sailesh Nepald1e68152013-12-12 19:08:02 -08003759 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003760 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003761 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003762 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003763
Jordan Liu4c733742019-02-28 12:03:40 -08003764 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3765 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3766 if (phoneId == -1) {
3767 throw new IllegalArgumentException("Given slot index: " + slotIndex
3768 + " does not correspond to an active phone");
3769 }
3770 return PhoneFactory.getPhone(phoneId);
3771 }
3772
Shishir Agrawal566b7612013-10-28 14:41:00 -07003773 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003774 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3775 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3777 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003779 if (DBG) {
3780 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3781 }
3782 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3783 p2);
3784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003785
Jordan Liu4c733742019-02-28 12:03:40 -08003786
3787 @Override
3788 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3789 int slotIndex, String callingPackage, String aid, int p2) {
3790 enforceModifyPermission();
3791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3792 if (DBG) {
3793 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3794 }
3795 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3796 callingPackage, aid, p2);
3797 }
3798
3799 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3800 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003801 final long identity = Binder.clearCallingIdentity();
3802 try {
3803 if (TextUtils.equals(ISDR_AID, aid)) {
3804 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003805 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3806 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 if (bestComponent == null
3808 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3809 loge("The calling package is not allowed to access ISD-R.");
3810 throw new SecurityException(
3811 "The calling package is not allowed to access ISD-R.");
3812 }
Derek Tan740e1672017-06-27 14:56:27 -07003813 }
Derek Tan740e1672017-06-27 14:56:27 -07003814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003816 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3817 null /* workSource */);
3818 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 return response;
3820 } finally {
3821 Binder.restoreCallingIdentity(identity);
3822 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003823 }
3824
3825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003826 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3828 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003829 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3830 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003832
Jordan Liu4c733742019-02-28 12:03:40 -08003833 @Override
3834 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3835 enforceModifyPermission();
3836 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3837 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3838 channel);
3839 }
3840
3841 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 final long identity = Binder.clearCallingIdentity();
3843 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003844 if (channel < 0) {
3845 return false;
3846 }
Jordan Liu4c733742019-02-28 12:03:40 -08003847 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3848 null /* workSource */);
3849 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 return success;
3851 } finally {
3852 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854 }
3855
3856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003857 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003858 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3860 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003861 if (DBG) {
3862 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3863 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3864 + p3 + " data=" + data);
3865 }
3866 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3867 command, p1, p2, p3, data);
3868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003869
Jordan Liu4c733742019-02-28 12:03:40 -08003870 @Override
3871 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3872 int command, int p1, int p2, int p3, String data) {
3873 enforceModifyPermission();
3874 if (DBG) {
3875 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3876 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3877 + p3 + " data=" + data);
3878 }
3879 return iccTransmitApduLogicalChannelWithPermission(
3880 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3881 data);
3882 }
3883
3884 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3885 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003888 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003889 return "";
3890 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003893 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3894 null /* workSource */);
3895 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 // Append the returned status code to the end of the response payload.
3898 String s = Integer.toHexString(
3899 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3900 if (response.payload != null) {
3901 s = IccUtils.bytesToHexString(response.payload) + s;
3902 }
3903 return s;
3904 } finally {
3905 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003906 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003907 }
Jake Hambye994d462014-02-03 13:10:13 -08003908
Evan Charltonc66da362014-05-16 14:06:40 -07003909 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003910 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3911 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3913 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003915 if (DBG) {
3916 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3917 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3918 }
3919 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3920 cla, command, p1, p2, p3, data);
3921 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003922
Jordan Liu4c733742019-02-28 12:03:40 -08003923 @Override
3924 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3925 int command, int p1, int p2, int p3, String data) {
3926 enforceModifyPermission();
3927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3928 if (DBG) {
3929 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3930 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3931 + " data=" + data);
3932 }
3933
3934 return iccTransmitApduBasicChannelWithPermission(
3935 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3936 p2, p3, data);
3937 }
3938
3939 // open APDU basic channel assuming the caller has sufficient permissions
3940 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3941 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3945 && TextUtils.equals(ISDR_AID, data)) {
3946 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003947 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3948 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 if (bestComponent == null
3950 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3951 loge("The calling package is not allowed to select ISD-R.");
3952 throw new SecurityException(
3953 "The calling package is not allowed to select ISD-R.");
3954 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003955 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003957 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003958 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3959 null /* workSource */);
3960 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003962 // Append the returned status code to the end of the response payload.
3963 String s = Integer.toHexString(
3964 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3965 if (response.payload != null) {
3966 s = IccUtils.bytesToHexString(response.payload) + s;
3967 }
3968 return s;
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003971 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003972 }
3973
3974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003975 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003976 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3978 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003980 final long identity = Binder.clearCallingIdentity();
3981 try {
3982 if (DBG) {
3983 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3984 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3985 }
3986
3987 IccIoResult response =
3988 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3989 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3990 subId);
3991
3992 if (DBG) {
3993 log("Exchange SIM_IO [R]" + response);
3994 }
3995
3996 byte[] result = null;
3997 int length = 2;
3998 if (response.payload != null) {
3999 length = 2 + response.payload.length;
4000 result = new byte[length];
4001 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4002 } else {
4003 result = new byte[length];
4004 }
4005
4006 result[length - 1] = (byte) response.sw2;
4007 result[length - 2] = (byte) response.sw1;
4008 return result;
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004011 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004012 }
4013
Nathan Haroldb3014052017-01-25 15:57:32 -08004014 /**
4015 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4016 * on a particular subscription
4017 */
sqianb6e41952018-03-12 14:54:01 -07004018 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4019 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4020 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4021 return null;
4022 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004023
4024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 if (appType != TelephonyManager.APPTYPE_USIM
4027 && appType != TelephonyManager.APPTYPE_SIM) {
4028 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4029 return null;
4030 }
4031 Object response = sendRequest(
4032 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4033 if (response instanceof String[]) {
4034 return (String[]) response;
4035 }
4036 // Response is an Exception of some kind,
4037 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004038 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 } finally {
4040 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004041 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004042 }
4043
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004044 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004045 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4047 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4052 if (response.payload == null) {
4053 return "";
4054 }
Evan Charltonc66da362014-05-16 14:06:40 -07004055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 // Append the returned status code to the end of the response payload.
4057 String s = Integer.toHexString(
4058 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4059 s = IccUtils.bytesToHexString(response.payload) + s;
4060 return s;
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Evan Charltonc66da362014-05-16 14:06:40 -07004064 }
4065
Jake Hambye994d462014-02-03 13:10:13 -08004066 /**
4067 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4068 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4069 *
4070 * @param itemID the ID of the item to read
4071 * @return the NV item as a String, or null on error.
4072 */
4073 @Override
4074 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004075 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4077 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004078
4079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004082 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004083 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4084 return value;
4085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
Jake Hambye994d462014-02-03 13:10:13 -08004088 }
4089
4090 /**
4091 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4092 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4093 *
4094 * @param itemID the ID of the item to read
4095 * @param itemValue the value to write, as a String
4096 * @return true on success; false on any failure
4097 */
4098 @Override
4099 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4107 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004108 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4110 return success;
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Jake Hambye994d462014-02-03 13:10:13 -08004114 }
4115
4116 /**
4117 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4118 * Used for device configuration by some CDMA operators.
4119 *
4120 * @param preferredRoamingList byte array containing the new PRL
4121 * @return true on success; false on any failure
4122 */
4123 @Override
4124 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4126 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004127
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4131 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4132 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4133 return success;
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
Jake Hambye994d462014-02-03 13:10:13 -08004137 }
4138
4139 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004140 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004141 * Used for device configuration by some CDMA operators.
4142 *
chen xu6dac5ab2018-10-26 17:39:23 -07004143 * @param slotIndex - device slot.
4144 *
Jake Hambye994d462014-02-03 13:10:13 -08004145 * @return true on success; false on any failure
4146 */
4147 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004148 public boolean resetModemConfig(int slotIndex) {
4149 Phone phone = PhoneFactory.getPhone(slotIndex);
4150 if (phone != null) {
4151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4152 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004153
chen xu6dac5ab2018-10-26 17:39:23 -07004154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4157 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4158 return success;
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004162 }
chen xu6dac5ab2018-10-26 17:39:23 -07004163 return false;
4164 }
4165
4166 /**
4167 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4168 *
4169 * @param slotIndex - device slot.
4170 *
4171 * @return true on success; false on any failure
4172 */
4173 @Override
4174 public boolean rebootModem(int slotIndex) {
4175 Phone phone = PhoneFactory.getPhone(slotIndex);
4176 if (phone != null) {
4177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4178 mApp, phone.getSubId(), "rebootModem");
4179
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
4182 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4183 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4184 return success;
4185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
4188 }
4189 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004190 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004191
Svet Ganovb320e182015-04-16 12:30:10 -07004192 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004194 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004195 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004196 return new String[0];
4197 }
4198
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199 final long identity = Binder.clearCallingIdentity();
4200 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004202 } finally {
4203 Binder.restoreCallingIdentity(identity);
4204 }
Wink Saville36469e72014-06-11 15:17:00 -07004205 }
4206
Brad Ebinger51f743a2017-01-23 13:50:20 -08004207 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004208 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4209 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004210 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004211 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004213
4214 final long identity = Binder.clearCallingIdentity();
4215 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004216 ImsResolver resolver = PhoneFactory.getImsResolver();
4217 if (resolver == null) {
4218 // may happen if the device does not support IMS.
4219 return;
4220 }
4221 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004225 }
4226
4227 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004228 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4229 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004230 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004231 public void disableIms(int slotId) {
4232 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004233
4234 final long identity = Binder.clearCallingIdentity();
4235 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004236 ImsResolver resolver = PhoneFactory.getImsResolver();
4237 if (resolver == null) {
4238 // may happen if the device does not support IMS.
4239 return;
4240 }
4241 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004242 } finally {
4243 Binder.restoreCallingIdentity(identity);
4244 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004245 }
4246
4247 /**
4248 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4249 * feature or {@link null} if the service is not available. If the feature is available, the
4250 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4251 */
4252 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004253 IImsServiceFeatureCallback callback) {
4254 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004255
4256 final long identity = Binder.clearCallingIdentity();
4257 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004258 ImsResolver resolver = PhoneFactory.getImsResolver();
4259 if (resolver == null) {
4260 // may happen if the device does not support IMS.
4261 return null;
4262 }
4263 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004267 }
4268
4269 /**
4270 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4271 * feature during emergency calling or {@link null} if the service is not available. If the
4272 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4273 * listener for feature updates.
4274 */
4275 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4276 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004280 ImsResolver resolver = PhoneFactory.getImsResolver();
4281 if (resolver == null) {
4282 // may happen if the device does not support IMS.
4283 return null;
4284 }
4285 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004289 }
4290
Brad Ebinger5f64b052017-12-14 14:26:15 -08004291 /**
4292 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004293 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004294 */
4295 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4296 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004297
4298 final long identity = Binder.clearCallingIdentity();
4299 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004300 ImsResolver resolver = PhoneFactory.getImsResolver();
4301 if (resolver == null) {
4302 // may happen if the device does not support IMS.
4303 return null;
4304 }
4305 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004309 }
4310
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004311 /**
4312 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004313 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004314 */
4315 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4316 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317
4318 final long identity = Binder.clearCallingIdentity();
4319 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004320 ImsResolver resolver = PhoneFactory.getImsResolver();
4321 if (resolver == null) {
4322 // may happen if the device does not support IMS.
4323 return null;
4324 }
4325 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 } finally {
4327 Binder.restoreCallingIdentity(identity);
4328 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004329 }
4330
Brad Ebinger884c07b2018-02-15 16:17:40 -08004331 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004332 * Sets the ImsService Package Name that Telephony will bind to.
4333 *
4334 * @param slotId the slot ID that the ImsService should bind for.
4335 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4336 * ImsService is the device default ImsService.
4337 * @param packageName The package name of the application that contains the ImsService to bind
4338 * to.
4339 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4340 * @hide
4341 */
4342 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004343 int[] subIds = SubscriptionManager.getSubId(slotId);
4344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4345 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4346 "setImsService");
4347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348 final long identity = Binder.clearCallingIdentity();
4349 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004350 ImsResolver resolver = PhoneFactory.getImsResolver();
4351 if (resolver == null) {
4352 // may happen if the device does not support IMS.
4353 return false;
4354 }
4355 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4356 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 } finally {
4358 Binder.restoreCallingIdentity(identity);
4359 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004360 }
4361
4362 /**
4363 * Return the ImsService configuration.
4364 *
4365 * @param slotId The slot that the ImsService is associated with.
4366 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4367 * the device default.
4368 * @return the package name of the ImsService configuration.
4369 */
4370 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004371 int[] subIds = SubscriptionManager.getSubId(slotId);
4372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4373 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4374 "getImsService");
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004378 ImsResolver resolver = PhoneFactory.getImsResolver();
4379 if (resolver == null) {
4380 // may happen if the device does not support IMS.
4381 return "";
4382 }
4383 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004384 } finally {
4385 Binder.restoreCallingIdentity(identity);
4386 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004387 }
4388
Wink Saville36469e72014-06-11 15:17:00 -07004389 public void setImsRegistrationState(boolean registered) {
4390 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004394 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395 } finally {
4396 Binder.restoreCallingIdentity(identity);
4397 }
Wink Saville36469e72014-06-11 15:17:00 -07004398 }
4399
4400 /**
Stuart Scott54788802015-03-30 13:18:01 -07004401 * Set the network selection mode to automatic.
4402 *
4403 */
4404 @Override
4405 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4407 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408
Pengquan Menge92a50d2018-09-21 15:54:48 -07004409 if (!isActiveSubscription(subId)) {
4410 return;
4411 }
4412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
4415 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4416 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
4419 }
Stuart Scott54788802015-03-30 13:18:01 -07004420 }
4421
Pengquan Mengea84e042018-09-20 14:57:26 -07004422 /**
4423 * Ask the radio to connect to the input network and change selection mode to manual.
4424 *
4425 * @param subId the id of the subscription.
4426 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4427 * the operator to attach to.
4428 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4429 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4430 * normal network selection next time.
4431 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004432 */
4433 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004434 public boolean setNetworkSelectionModeManual(
4435 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004436 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4437 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004438
4439 if (!isActiveSubscription(subId)) {
4440 return false;
4441 }
4442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 final long identity = Binder.clearCallingIdentity();
4444 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004445 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004447 if (DBG) {
4448 log("setNetworkSelectionModeManual: subId: " + subId
4449 + " operator: " + operatorInfo);
4450 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4452 } finally {
4453 Binder.restoreCallingIdentity(identity);
4454 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004455 }
4456
4457 /**
4458 * Scans for available networks.
4459 */
4460 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004461 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4463 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004464 LocationAccessPolicy.LocationPermissionResult locationResult =
4465 LocationAccessPolicy.checkLocationPermission(mApp,
4466 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4467 .setCallingPackage(callingPackage)
4468 .setCallingPid(Binder.getCallingPid())
4469 .setCallingUid(Binder.getCallingUid())
4470 .setMethod("getCellNetworkScanResults")
4471 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4472 .build());
4473 switch (locationResult) {
4474 case DENIED_HARD:
4475 throw new SecurityException("Not allowed to access scan results -- location");
4476 case DENIED_SOFT:
4477 return null;
4478 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479
Pengquan Menga1bb6272018-09-06 09:59:22 -07004480 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 try {
4482 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004483 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004488 }
4489
4490 /**
yinxub1bed742017-04-17 11:45:04 -07004491 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004492 *
yinxub1bed742017-04-17 11:45:04 -07004493 * @param subId id of the subscription
4494 * @param request contains the radio access networks with bands/channels to scan
4495 * @param messenger callback messenger for scan results or errors
4496 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004497 * @return the id of the requested scan which can be used to stop the scan.
4498 */
4499 @Override
4500 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004501 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4503 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004504 LocationAccessPolicy.LocationPermissionResult locationResult =
4505 LocationAccessPolicy.checkLocationPermission(mApp,
4506 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4507 .setCallingPackage(callingPackage)
4508 .setCallingPid(Binder.getCallingPid())
4509 .setCallingUid(Binder.getCallingUid())
4510 .setMethod("requestNetworkScan")
4511 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4512 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004514 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004515 if (e != null) {
4516 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4517 throw e;
4518 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004519 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004520 return TelephonyScanManager.INVALID_SCAN_ID;
4521 }
4522 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 }
Hall Liu912dfd32019-04-25 14:02:26 -07004524 int callingUid = Binder.getCallingUid();
4525 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 return mNetworkScanRequestTracker.startNetworkScan(
4529 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004530 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004531 } finally {
4532 Binder.restoreCallingIdentity(identity);
4533 }
yinxu504e1392017-04-12 16:03:22 -07004534 }
4535
Hall Liub2ac8ef2019-02-28 15:56:23 -08004536 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004537 NetworkScanRequest request, int subId) {
4538 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4539 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4540 boolean hasNetworkScanPermission =
4541 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4542 == PERMISSION_GRANTED;
4543
4544 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4545 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4546 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004547 }
4548
4549 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4550 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004551 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4552 return new SecurityException("Specific channels must not be"
4553 + " scanned without location access.");
4554 }
4555 }
4556 }
4557
Hall Liub2ac8ef2019-02-28 15:56:23 -08004558 return null;
4559 }
4560
yinxu504e1392017-04-12 16:03:22 -07004561 /**
4562 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004563 *
4564 * @param subId id of the subscription
4565 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004566 */
4567 @Override
4568 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004569 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4570 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571
Hall Liu912dfd32019-04-25 14:02:26 -07004572 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 final long identity = Binder.clearCallingIdentity();
4574 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004575 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
yinxu504e1392017-04-12 16:03:22 -07004579 }
4580
4581 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004582 * Get the calculated preferred network type.
4583 * Used for debugging incorrect network type.
4584 *
4585 * @return the preferred network type, defined in RILConstants.java.
4586 */
4587 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004588 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004589 final Phone defaultPhone = getDefaultPhone();
4590 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4591 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004592 return RILConstants.PREFERRED_NETWORK_MODE;
4593 }
4594
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004598 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004599 } finally {
4600 Binder.restoreCallingIdentity(identity);
4601 }
Junda Liu84d15a22014-07-02 11:21:04 -07004602 }
4603
4604 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004605 * Get the preferred network type.
4606 * Used for device configuration by some CDMA operators.
4607 *
4608 * @return the preferred network type, defined in RILConstants.java.
4609 */
4610 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004611 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004612 TelephonyPermissions
4613 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4614 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615
4616 final long identity = Binder.clearCallingIdentity();
4617 try {
4618 if (DBG) log("getPreferredNetworkType");
4619 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4620 int networkType = (result != null ? result[0] : -1);
4621 if (DBG) log("getPreferredNetworkType: " + networkType);
4622 return networkType;
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
4625 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004626 }
4627
4628 /**
4629 * Set the preferred network type.
4630 * Used for device configuration by some CDMA operators.
4631 *
4632 * @param networkType the preferred network type, defined in RILConstants.java.
4633 * @return true on success; false on any failure.
4634 */
4635 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004636 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4638 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639
4640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4643 Boolean success = (Boolean) sendRequest(
4644 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4645 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4646 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004647 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4649 }
4650 return success;
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004653 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004654 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004655
4656 /**
Miaoa84611c2019-03-15 09:21:10 +08004657 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004658 *
Miaoa84611c2019-03-15 09:21:10 +08004659 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004660 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004661 * @hide
4662 */
4663 @Override
Miaoa84611c2019-03-15 09:21:10 +08004664 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004665 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004667 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004668 try {
Miaoa84611c2019-03-15 09:21:10 +08004669 if (phone != null) {
4670 return phone.hasMatchedTetherApnSetting();
4671 } else {
4672 return false;
4673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 } finally {
4675 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004676 }
Junda Liu475951f2014-11-07 16:45:03 -08004677 }
4678
4679 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004680 * Set mobile data enabled
4681 * Used by the user through settings etc to turn on/off mobile data
4682 *
4683 * @param enable {@code true} turn turn data on, else {@code false}
4684 */
4685 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004686 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4688 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689
4690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 int phoneId = mSubscriptionController.getPhoneId(subId);
4693 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4694 Phone phone = PhoneFactory.getPhone(phoneId);
4695 if (phone != null) {
4696 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004697 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004699 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 }
4701 } finally {
4702 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004703 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004704 }
4705
4706 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004707 * Get the user enabled state of Mobile Data.
4708 *
4709 * TODO: remove and use isUserDataEnabled.
4710 * This can't be removed now because some vendor codes
4711 * calls through ITelephony directly while they should
4712 * use TelephonyManager.
4713 *
4714 * @return true on enabled
4715 */
4716 @Override
4717 public boolean getDataEnabled(int subId) {
4718 return isUserDataEnabled(subId);
4719 }
4720
4721 /**
4722 * Get whether mobile data is enabled per user setting.
4723 *
4724 * There are other factors deciding whether mobile data is actually enabled, but they are
4725 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004726 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004727 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004728 *
4729 * @return {@code true} if data is enabled else {@code false}
4730 */
4731 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004732 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004733 try {
4734 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4735 null);
4736 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004737 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4738 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740
4741 final long identity = Binder.clearCallingIdentity();
4742 try {
4743 int phoneId = mSubscriptionController.getPhoneId(subId);
4744 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4745 Phone phone = PhoneFactory.getPhone(phoneId);
4746 if (phone != null) {
4747 boolean retVal = phone.isUserDataEnabled();
4748 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4749 return retVal;
4750 } else {
4751 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4752 return false;
4753 }
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004756 }
4757 }
4758
4759 /**
4760 * Get whether mobile data is enabled.
4761 *
4762 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4763 * whether mobile data is actually enabled.
4764 *
4765 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4766 *
4767 * @return {@code true} if data is enabled else {@code false}
4768 */
4769 @Override
4770 public boolean isDataEnabled(int subId) {
4771 try {
4772 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4773 null);
4774 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4776 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778
4779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 int phoneId = mSubscriptionController.getPhoneId(subId);
4782 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4783 Phone phone = PhoneFactory.getPhone(phoneId);
4784 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004785 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4787 return retVal;
4788 } else {
4789 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4790 return false;
4791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004794 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004795 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004796
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004797 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4798 Phone phone) {
4799 //load access rules from carrier configs, and check those as well: b/139133814
4800 SubscriptionController subController = SubscriptionController.getInstance();
4801 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4802 || subController == null) return privilegeFromSim;
4803
4804 int uid = Binder.getCallingUid();
4805 PackageManager pkgMgr = phone.getContext().getPackageManager();
4806 String[] packages = pkgMgr.getPackagesForUid(uid);
4807
4808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4811 SubscriptionManager subManager = (SubscriptionManager)
4812 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4813 for (String pkg : packages) {
4814 if (subManager.canManageSubscription(subInfo, pkg)) {
4815 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4816 }
4817 }
4818 return privilegeFromSim;
4819 } finally {
4820 Binder.restoreCallingIdentity(identity);
4821 }
4822 }
4823
4824 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4825 String pkgName) {
4826 //load access rules from carrier configs, and check those as well: b/139133814
4827 SubscriptionController subController = SubscriptionController.getInstance();
4828 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4829 || subController == null) return privilegeFromSim;
4830
4831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4834 SubscriptionManager subManager = (SubscriptionManager)
4835 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4836 return subManager.canManageSubscription(subInfo, pkgName)
4837 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
4841 }
4842
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004843 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004844 public int getCarrierPrivilegeStatus(int subId) {
4845 final Phone phone = getPhone(subId);
4846 if (phone == null) {
4847 loge("getCarrierPrivilegeStatus: Invalid subId");
4848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4849 }
4850 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004851 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004852 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004853 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4854 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004855
4856 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4857 card.getCarrierPrivilegeStatusForCurrentTransaction(
4858 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004859 }
Junda Liu29340342014-07-10 15:23:27 -07004860
4861 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004862 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4863 final Phone phone = getPhone(subId);
4864 if (phone == null) {
4865 loge("getCarrierPrivilegeStatus: Invalid subId");
4866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4867 }
4868 UiccProfile profile =
4869 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4870 if (profile == null) {
4871 loge("getCarrierPrivilegeStatus: No UICC");
4872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4873 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004874 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4875 profile.getCarrierPrivilegeStatusForUid(
4876 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004877 }
4878
4879 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004880 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4881 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004883 }
4884
4885 int phoneId = SubscriptionManager.getPhoneId(subId);
4886 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004887 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004888 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004889 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4890 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004891 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4892 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4893 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004894 }
4895
4896 @Override
4897 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004898 if (TextUtils.isEmpty(pkgName))
4899 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004900 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4901 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4902 UiccCard card = UiccController.getInstance().getUiccCard(i);
4903 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004904 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004905 continue;
4906 }
4907
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004908 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
4909 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4910 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004911 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4912 break;
4913 }
4914 }
4915
4916 return result;
Junda Liu29340342014-07-10 15:23:27 -07004917 }
Derek Tan89e89d42014-07-08 17:00:10 -07004918
4919 @Override
Junda Liue64de782015-04-16 17:19:16 -07004920 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4921 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4922 loge("phoneId " + phoneId + " is not valid.");
4923 return null;
4924 }
4925 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004926 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004927 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004928 return null ;
4929 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004930 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004931 }
4932
Amith Yamasani6e118872016-02-19 12:53:51 -08004933 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004934 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004935 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004936 List<String> privilegedPackages = new ArrayList<>();
4937 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004938 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4939 // has UICC in that slot.
4940 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004941 if (card.hasCarrierPrivilegeRules()) {
4942 if (packages == null) {
4943 // Only check packages in user 0 for now
4944 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004945 PackageManager.MATCH_DISABLED_COMPONENTS
4946 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09004947 | PackageManager.GET_SIGNING_CERTIFICATES,
4948 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004949 }
4950 for (int p = packages.size() - 1; p >= 0; p--) {
4951 PackageInfo pkgInfo = packages.get(p);
4952 if (pkgInfo != null && pkgInfo.packageName != null
4953 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004954 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004955 privilegedPackages.add(pkgInfo.packageName);
4956 }
4957 }
4958 }
4959 }
4960 return privilegedPackages;
4961 }
4962
chen xuf7e9fe82019-05-09 19:31:02 -07004963 @Override
4964 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4965 List<String> privilegedPackages = new ArrayList<>();
4966 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4967 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4968 }
4969 return privilegedPackages;
4970 }
4971
Wink Savilleb564aae2014-10-23 10:18:09 -07004972 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004973 final Phone phone = getPhone(subId);
4974 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004975 if (card == null) {
4976 loge("getIccId: No UICC");
4977 return null;
4978 }
4979 String iccId = card.getIccId();
4980 if (TextUtils.isEmpty(iccId)) {
4981 loge("getIccId: ICC ID is null or empty.");
4982 return null;
4983 }
4984 return iccId;
4985 }
4986
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004987 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004988 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4989 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004990 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4991 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004992
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 final long identity = Binder.clearCallingIdentity();
4994 try {
4995 final String iccId = getIccId(subId);
4996 final Phone phone = getPhone(subId);
4997 if (phone == null) {
4998 return false;
4999 }
5000 final String subscriberId = phone.getSubscriberId();
5001
5002 if (DBG_MERGE) {
5003 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5004 + subscriberId + " to " + number);
5005 }
5006
5007 if (TextUtils.isEmpty(iccId)) {
5008 return false;
5009 }
5010
5011 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5012
5013 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5014 if (alphaTag == null) {
5015 editor.remove(alphaTagPrefKey);
5016 } else {
5017 editor.putString(alphaTagPrefKey, alphaTag);
5018 }
5019
5020 // Record both the line number and IMSI for this ICCID, since we need to
5021 // track all merged IMSIs based on line number
5022 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5023 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5024 if (number == null) {
5025 editor.remove(numberPrefKey);
5026 editor.remove(subscriberPrefKey);
5027 } else {
5028 editor.putString(numberPrefKey, number);
5029 editor.putString(subscriberPrefKey, subscriberId);
5030 }
5031
5032 editor.commit();
5033 return true;
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005036 }
Derek Tan7226c842014-07-02 17:42:23 -07005037 }
5038
5039 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005040 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005041 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005043 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005044 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005045 return null;
5046 }
Derek Tan97ebb422014-09-05 16:55:38 -07005047
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
5049 try {
5050 String iccId = getIccId(subId);
5051 if (iccId != null) {
5052 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5053 if (DBG_MERGE) {
5054 log("getLine1NumberForDisplay returning "
5055 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5056 }
5057 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005058 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005059 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5060 return null;
5061 } finally {
5062 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005063 }
Derek Tan7226c842014-07-02 17:42:23 -07005064 }
5065
5066 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005067 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005069 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005070 return null;
5071 }
Derek Tan97ebb422014-09-05 16:55:38 -07005072
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 final long identity = Binder.clearCallingIdentity();
5074 try {
5075 String iccId = getIccId(subId);
5076 if (iccId != null) {
5077 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5078 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5079 }
5080 return null;
5081 } finally {
5082 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005083 }
Derek Tan7226c842014-07-02 17:42:23 -07005084 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005085
5086 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005087 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005088 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5089 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005091 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5092 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005093 return null;
5094 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005095
Jordan Liub49b04b2019-05-06 14:45:15 -07005096 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5097 // the process, where TelephonyManager was instantiated.
5098 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005099 final long identity = Binder.clearCallingIdentity();
5100 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005101 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005102 final TelephonyManager tele = TelephonyManager.from(context);
5103 final SubscriptionManager sub = SubscriptionManager.from(context);
5104
5105 // Figure out what subscribers are currently active
5106 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107
Jordan Liub49b04b2019-05-06 14:45:15 -07005108 // Only consider subs which match the current subId
5109 // This logic can be simplified. See b/131189269 for progress.
5110 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005111 activeSubscriberIds.add(tele.getSubscriberId(subId));
5112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113
5114 // First pass, find a number override for an active subscriber
5115 String mergeNumber = null;
5116 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5117 for (String key : prefs.keySet()) {
5118 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5119 final String subscriberId = (String) prefs.get(key);
5120 if (activeSubscriberIds.contains(subscriberId)) {
5121 final String iccId = key.substring(
5122 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5123 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5124 mergeNumber = (String) prefs.get(numberKey);
5125 if (DBG_MERGE) {
5126 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5127 + " for active subscriber " + subscriberId);
5128 }
5129 if (!TextUtils.isEmpty(mergeNumber)) {
5130 break;
5131 }
5132 }
5133 }
5134 }
5135
5136 // Shortcut when no active merged subscribers
5137 if (TextUtils.isEmpty(mergeNumber)) {
5138 return null;
5139 }
5140
5141 // Second pass, find all subscribers under that line override
5142 final ArraySet<String> result = new ArraySet<>();
5143 for (String key : prefs.keySet()) {
5144 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5145 final String number = (String) prefs.get(key);
5146 if (mergeNumber.equals(number)) {
5147 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5148 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5149 final String subscriberId = (String) prefs.get(subscriberKey);
5150 if (!TextUtils.isEmpty(subscriberId)) {
5151 result.add(subscriberId);
5152 }
5153 }
5154 }
5155 }
5156
5157 final String[] resultArray = result.toArray(new String[result.size()]);
5158 Arrays.sort(resultArray);
5159 if (DBG_MERGE) {
5160 Slog.d(LOG_TAG,
5161 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5162 }
5163 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005166 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005167 }
5168
5169 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005170 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5171 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5172
5173 final long identity = Binder.clearCallingIdentity();
5174 try {
5175 final TelephonyManager telephonyManager = mApp.getSystemService(
5176 TelephonyManager.class);
5177 String subscriberId = telephonyManager.getSubscriberId(subId);
5178 if (subscriberId == null) {
5179 if (DBG) {
5180 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5181 + subId);
5182 }
5183 return null;
5184 }
5185
5186 final SubscriptionInfo info = SubscriptionController.getInstance()
5187 .getSubscriptionInfo(subId);
5188 final ParcelUuid groupUuid = info.getGroupUuid();
5189 // If it doesn't belong to any group, return just subscriberId of itself.
5190 if (groupUuid == null) {
5191 return new String[]{subscriberId};
5192 }
5193
5194 // Get all subscriberIds from the group.
5195 final List<String> mergedSubscriberIds = new ArrayList<>();
5196 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5197 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5198 for (SubscriptionInfo subInfo : groupInfos) {
5199 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5200 if (subscriberId != null) {
5201 mergedSubscriberIds.add(subscriberId);
5202 }
5203 }
5204
5205 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208
5209 }
5210 }
5211
5212 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005213 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5215 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216
5217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 final Phone phone = getPhone(subId);
5220 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5221 } finally {
5222 Binder.restoreCallingIdentity(identity);
5223 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005224 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005225
5226 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005227 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005228 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5229 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005230 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231
5232 final long identity = Binder.clearCallingIdentity();
5233 try {
5234 final Phone phone = getPhone(subId);
5235 if (phone == null) {
5236 return false;
5237 }
5238 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5239 cdmaNonRoamingList);
5240 } finally {
5241 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005242 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005243 }
5244
5245 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005246 @Deprecated
5247 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5248 enforceModifyPermission();
5249
5250 int returnValue = 0;
5251 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005252 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005253 if(result.exception == null) {
5254 if (result.result != null) {
5255 byte[] responseData = (byte[])(result.result);
5256 if(responseData.length > oemResp.length) {
5257 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5258 responseData.length + "bytes. Buffer Size is " +
5259 oemResp.length + "bytes.");
5260 }
5261 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5262 returnValue = responseData.length;
5263 }
5264 } else {
5265 CommandException ex = (CommandException) result.exception;
5266 returnValue = ex.getCommandError().ordinal();
5267 if(returnValue > 0) returnValue *= -1;
5268 }
5269 } catch (RuntimeException e) {
5270 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5271 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5272 if(returnValue > 0) returnValue *= -1;
5273 }
5274
5275 return returnValue;
5276 }
5277
5278 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005279 public void setRadioCapability(RadioAccessFamily[] rafs) {
5280 try {
5281 ProxyController.getInstance().setRadioCapability(rafs);
5282 } catch (RuntimeException e) {
5283 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5284 }
5285 }
5286
5287 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005288 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005289 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005290 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005291 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005292 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
chen xub97461a2018-10-26 14:17:57 -07005296 TelephonyPermissions
5297 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5298 mApp, phone.getSubId(), "getRadioAccessFamily");
5299 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
chen xub97461a2018-10-26 14:17:57 -07005303 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005304 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005305
5306 @Override
5307 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005308 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005309 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310
5311 final long identity = Binder.clearCallingIdentity();
5312 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005313 ImsManager.getInstance(defaultPhone.getContext(),
5314 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005318 }
5319
5320 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005321 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005322 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005324 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005325 return false;
5326 }
Svet Ganovb320e182015-04-16 12:30:10 -07005327
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 final long identity = Binder.clearCallingIdentity();
5329 try {
5330 // Check the user preference and the system-level IMS setting. Even if the user has
5331 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5332 // In the long run, we may instead need to check if there exists a connection service
5333 // which can support video calling.
5334 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005335 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005336 return imsManager.isVtEnabledByPlatform()
5337 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5338 && imsManager.isVtEnabledByUser();
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005342 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005343
Andrew Leea1239f22015-03-02 17:44:07 -08005344 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5346 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5347 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5348 return false;
5349 }
5350
5351 final long identity = Binder.clearCallingIdentity();
5352 try {
5353 CarrierConfigManager configManager =
5354 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005355 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5357 } finally {
5358 Binder.restoreCallingIdentity(identity);
5359 }
Andrew Leea1239f22015-03-02 17:44:07 -08005360 }
5361
5362 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005363 public boolean isWorldPhone(int subId, String callingPackage) {
5364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5365 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5366 return false;
5367 }
5368
5369 final long identity = Binder.clearCallingIdentity();
5370 try {
5371 CarrierConfigManager configManager =
5372 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005374 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
5377 }
Andrew Leea1239f22015-03-02 17:44:07 -08005378 }
5379
Andrew Lee9431b832015-03-09 18:46:45 -07005380 @Override
5381 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005383 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005384 }
5385
5386 @Override
5387 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005390 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
Andrew Lee9431b832015-03-09 18:46:45 -07005394 }
5395
Hall Liuf6668912018-10-31 17:05:23 -07005396 /**
5397 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5398 * support for the feature and device firmware support.
5399 *
5400 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5401 */
5402 @Override
5403 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005405 final Phone phone = getPhone(subscriptionId);
5406 if (phone == null) {
5407 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5408 return false;
5409 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005411 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5413 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005414 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 return isCarrierSupported && isDeviceSupported;
5416 } finally {
5417 Binder.restoreCallingIdentity(identity);
5418 }
Hall Liu98187582018-01-22 19:15:32 -08005419 }
5420
Hall Liuf6668912018-10-31 17:05:23 -07005421 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005422 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5423 * RTT setting, will return true if the device and carrier both support RTT.
5424 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005425 */
5426 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427 final long identity = Binder.clearCallingIdentity();
5428 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005429 boolean isRttSupported = isRttSupported(subscriptionId);
5430 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005431 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005432 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5433 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5434 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005438 }
5439
Sanket Padawe7310cc72015-01-14 09:53:20 -08005440 /**
5441 * Returns the unique device ID of phone, for example, the IMEI for
5442 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5443 *
5444 * <p>Requires Permission:
5445 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5446 */
5447 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005448 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005449 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005450 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005451 return null;
5452 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005453 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005454 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5455 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005456 return null;
5457 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458
5459 final long identity = Binder.clearCallingIdentity();
5460 try {
5461 return phone.getDeviceId();
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005465 }
5466
Ping Sunc67b7c22016-03-02 19:16:45 +08005467 /**
5468 * {@hide}
5469 * Returns the IMS Registration Status on a particular subid
5470 *
5471 * @param subId
5472 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005473 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005474 Phone phone = getPhone(subId);
5475 if (phone != null) {
5476 return phone.isImsRegistered();
5477 } else {
5478 return false;
5479 }
5480 }
5481
Santos Cordon7a1885b2015-02-03 11:15:19 -08005482 @Override
5483 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 final long identity = Binder.clearCallingIdentity();
5485 try {
5486 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5487 } finally {
5488 Binder.restoreCallingIdentity(identity);
5489 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005490 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005491
Tyler Gunnf70ed162019-04-03 15:28:53 -07005492 @Override
5493 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5494 final long identity = Binder.clearCallingIdentity();
5495 try {
5496 Phone phone = getPhone(subscriptionId);
5497 if (phone == null) {
5498 return null;
5499 }
5500 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5501 } finally {
5502 Binder.restoreCallingIdentity(identity);
5503 }
5504 }
5505
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005506 /**
5507 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005508 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005509 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
5511 try {
5512 Phone phone = getPhone(subId);
5513 if (phone != null) {
5514 return phone.isWifiCallingEnabled();
5515 } else {
5516 return false;
5517 }
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005520 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005521 }
5522
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005523 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005524 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005525 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005526 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final long identity = Binder.clearCallingIdentity();
5528 try {
5529 Phone phone = getPhone(subId);
5530 if (phone != null) {
5531 return phone.isVideoEnabled();
5532 } else {
5533 return false;
5534 }
5535 } finally {
5536 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005537 }
5538 }
5539
5540 /**
5541 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5542 * defined in {@link ImsRegistrationImplBase}.
5543 */
5544 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545 final long identity = Binder.clearCallingIdentity();
5546 try {
5547 Phone phone = getPhone(subId);
5548 if (phone != null) {
5549 return phone.getImsRegistrationTech();
5550 } else {
5551 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5552 }
5553 } finally {
5554 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005555 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005556 }
5557
Stuart Scott8eef64f2015-04-08 15:13:54 -07005558 @Override
5559 public void factoryReset(int subId) {
5560 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005561 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5562 return;
5563 }
5564
Svet Ganovcc087f82015-05-12 20:35:54 -07005565 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005566
Svet Ganovcc087f82015-05-12 20:35:54 -07005567 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005568 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5569 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005570 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005571 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005572 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005573 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5574 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005575 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005576 // There has been issues when Sms raw table somehow stores orphan
5577 // fragments. They lead to garbled message when new fragments come
5578 // in and combined with those stale ones. In case this happens again,
5579 // user can reset all network settings which will clean up this table.
5580 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005581 } finally {
5582 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005583 }
5584 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005585
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005586 private void cleanUpSmsRawTable(Context context) {
5587 ContentResolver resolver = context.getContentResolver();
5588 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5589 resolver.delete(uri, null, null);
5590 }
5591
Narayan Kamath1c496c22015-04-16 14:40:19 +01005592 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005593 public String getSimLocaleForSubscriber(int subId) {
5594 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5595 final Phone phone = getPhone(subId);
5596 if (phone == null) {
5597 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005598 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 final long identity = Binder.clearCallingIdentity();
5601 try {
chen xu5d3637b2019-01-21 23:31:38 -08005602 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5603 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005604 if (info == null) {
5605 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5606 return null;
5607 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 // Try and fetch the locale from the carrier properties or from the SIM language
5609 // preferences (EF-PL and EF-LI)...
5610 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005612 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5613 if (localeFromDefaultSim != null) {
5614 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5615 if (DBG) log("Using locale from subId: " + subId + " locale: "
5616 + localeFromDefaultSim);
5617 return localeFromDefaultSim.toLanguageTag();
5618 } else {
5619 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 }
5621 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 // The SIM language preferences only store a language (e.g. fr = French), not an
5624 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5625 // the SIM and carrier preferences does not include a country we add the country
5626 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005627 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005629 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005630 return mccLocale.toLanguageTag();
5631 }
5632
5633 if (DBG) log("No locale found - returning null");
5634 return null;
5635 } finally {
5636 Binder.restoreCallingIdentity(identity);
5637 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005638 }
5639
5640 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005641 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005642 }
5643
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 /**
5645 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5646 */
5647 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005648 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005649 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005650
Chenjie Yu1ba97252018-01-11 18:16:20 -08005651 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005652 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005653
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005654 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005655 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5656 * representing the state of the modem.
5657 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005658 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5659 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005660 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005661 */
5662 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005663 public void requestModemActivityInfo(ResultReceiver result) {
5664 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
5669 ModemActivityInfo ret = null;
5670 synchronized (mLastModemActivityInfo) {
5671 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5672 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005673 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005674 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005676 int[] txTimeMs = info.getTransmitTimeMillis();
5677 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005679 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 }
5681 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005682 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5683 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 mLastModemActivityInfo.setIdleTimeMillis(
5685 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005686 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5687 mLastModemActivityInfo.setReceiveTimeMillis(
5688 info.getReceiveTimeMillis() + mLastModemActivityInfo
5689 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005690 }
Chen Xud78231e2019-09-10 18:49:52 -07005691
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5693 mLastModemActivityInfo.getSleepTimeMillis(),
5694 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005695 mLastModemActivityInfo.getTransmitTimeMillis(),
5696 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 Bundle bundle = new Bundle();
5699 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5700 result.send(0, bundle);
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005703 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005704 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005705
Siddharth Rayb8114062018-06-17 15:02:38 -07005706 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5707 // less than total activity duration.
5708 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5709 if (info == null) {
5710 return false;
5711 }
5712 int activityDurationMs =
5713 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5714 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005715 int[] txTimeMs = info.getTransmitTimeMillis();
5716 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5717 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005718 }
5719 return (info.isValid()
5720 && (info.getSleepTimeMillis() <= activityDurationMs)
5721 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005722 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005723 && (totalTxTimeMs <= activityDurationMs));
5724 }
5725
Jack Yu85bd38a2015-11-09 11:34:32 -08005726 /**
5727 * {@hide}
5728 * Returns the service state information on specified subscription.
5729 */
5730 @Override
5731 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005733 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005734 return null;
5735 }
5736
Hall Liuf19c44f2018-11-27 14:38:17 -08005737 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5738 LocationAccessPolicy.checkLocationPermission(mApp,
5739 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5740 .setCallingPackage(callingPackage)
5741 .setCallingPid(Binder.getCallingPid())
5742 .setCallingUid(Binder.getCallingUid())
5743 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005744 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005745 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5746 .build());
5747
5748 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5749 LocationAccessPolicy.checkLocationPermission(mApp,
5750 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5751 .setCallingPackage(callingPackage)
5752 .setCallingPid(Binder.getCallingPid())
5753 .setCallingUid(Binder.getCallingUid())
5754 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005755 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005756 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5757 .build());
5758 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5759 boolean hasFinePermission =
5760 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5761 boolean hasCoarsePermission =
5762 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 final long identity = Binder.clearCallingIdentity();
5765 try {
5766 final Phone phone = getPhone(subId);
5767 if (phone == null) {
5768 return null;
5769 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005770
Hall Liuf19c44f2018-11-27 14:38:17 -08005771 ServiceState ss = phone.getServiceState();
5772
5773 // Scrub out the location info in ServiceState depending on what level of access
5774 // the caller has.
5775 if (hasFinePermission) return ss;
5776 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5777 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005778 } finally {
5779 Binder.restoreCallingIdentity(identity);
5780 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005781 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005782
5783 /**
5784 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5785 *
5786 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5787 * voicemail ringtone.
5788 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5789 * PhoneAccount.
5790 */
5791 @Override
5792 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 final long identity = Binder.clearCallingIdentity();
5794 try {
5795 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5796 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005797 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005799
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005804 }
5805
5806 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005807 * Sets the per-account voicemail ringtone.
5808 *
5809 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5810 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5811 *
5812 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5813 * voicemail ringtone.
5814 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5815 * PhoneAccount.
5816 */
5817 @Override
5818 public void setVoicemailRingtoneUri(String callingPackage,
5819 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005820 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005821 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5822 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005823 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005824 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5825 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5826 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005827 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005828
5829 final long identity = Binder.clearCallingIdentity();
5830 try {
5831 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5832 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005833 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834 }
5835 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5836 } finally {
5837 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005838 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005839 }
5840
5841 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005842 * Returns whether vibration is set for voicemail notification in Phone settings.
5843 *
5844 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5845 * voicemail vibration setting.
5846 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5847 */
5848 @Override
5849 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5853 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005854 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5858 } finally {
5859 Binder.restoreCallingIdentity(identity);
5860 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005861 }
5862
Youhan Wange64578a2016-05-02 15:32:42 -07005863 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005864 * Sets the per-account voicemail vibration.
5865 *
5866 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5867 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5868 *
5869 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5870 * voicemail vibration setting.
5871 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5872 * specific PhoneAccount.
5873 */
5874 @Override
5875 public void setVoicemailVibrationEnabled(String callingPackage,
5876 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005877 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005878 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5879 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005880 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005881 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5882 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5883 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005884 }
5885
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 final long identity = Binder.clearCallingIdentity();
5887 try {
5888 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5889 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 }
5892 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5893 } finally {
5894 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005895 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005896 }
5897
5898 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005899 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5900 *
5901 * @throws SecurityException if the caller does not have the required permission
5902 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005903 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005904 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005905 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005906 }
5907
5908 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005909 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5910 * permission.
5911 *
5912 * @throws SecurityException if the caller does not have the required permission
5913 */
5914 private void enforceSendSmsPermission() {
5915 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5916 }
5917
5918 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005919 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005920 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005921 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005922 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005923 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 final long identity = Binder.clearCallingIdentity();
5925 try {
5926 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005927 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005928 if (componentName == null) {
5929 throw new SecurityException(
5930 "Caller not current active visual voicemail package[null]");
5931 }
5932 String vvmPackage = componentName.getPackageName();
5933 if (!callingPackage.equals(vvmPackage)) {
5934 throw new SecurityException("Caller not current active visual voicemail package["
5935 + vvmPackage + "]");
5936 }
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005939 }
5940 }
5941
5942 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005943 * Return the application ID for the app type.
5944 *
5945 * @param subId the subscription ID that this request applies to.
5946 * @param appType the uicc app type.
5947 * @return Application ID for specificied app type, or null if no uicc.
5948 */
5949 @Override
5950 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005951 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005952 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005953
5954 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005955 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005956 if (phone == null) {
5957 return null;
5958 }
5959 String aid = null;
5960 try {
5961 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5962 .getApplicationByType(appType).getAid();
5963 } catch (Exception e) {
5964 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5965 }
5966 return aid;
5967 } finally {
5968 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005969 }
Youhan Wange64578a2016-05-02 15:32:42 -07005970 }
5971
Youhan Wang4001d252016-05-11 10:29:41 -07005972 /**
5973 * Return the Electronic Serial Number.
5974 *
5975 * @param subId the subscription ID that this request applies to.
5976 * @return ESN or null if error.
5977 */
5978 @Override
5979 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005980 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005981 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982
5983 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005984 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005985 if (phone == null) {
5986 return null;
5987 }
5988 String esn = null;
5989 try {
5990 esn = phone.getEsn();
5991 } catch (Exception e) {
5992 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5993 }
5994 return esn;
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005997 }
Youhan Wang4001d252016-05-11 10:29:41 -07005998 }
5999
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006000 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006001 * Return the Preferred Roaming List Version.
6002 *
6003 * @param subId the subscription ID that this request applies to.
6004 * @return PRLVersion or null if error.
6005 */
6006 @Override
6007 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006008 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006009 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010
6011 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006012 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 if (phone == null) {
6014 return null;
6015 }
6016 String cdmaPrlVersion = null;
6017 try {
6018 cdmaPrlVersion = phone.getCdmaPrlVersion();
6019 } catch (Exception e) {
6020 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6021 }
6022 return cdmaPrlVersion;
6023 } finally {
6024 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006025 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006026 }
6027
6028 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006029 * Get snapshot of Telephony histograms
6030 * @return List of Telephony histograms
6031 * @hide
6032 */
6033 @Override
6034 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6036 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006037
6038 final long identity = Binder.clearCallingIdentity();
6039 try {
6040 return RIL.getTelephonyRILTimingHistograms();
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
6043 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006044 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006045
6046 /**
6047 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006048 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6049 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006050 * Require system privileges. In the future we may add this to carrier APIs.
6051 *
Michele Berionne482f8202018-11-27 18:57:59 -08006052 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006053 */
6054 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006055 @TelephonyManager.SetCarrierRestrictionResult
6056 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006057 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006058 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006059
Michele Berionne482f8202018-11-27 18:57:59 -08006060 if (carrierRestrictionRules == null) {
6061 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006062 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 final long identity = Binder.clearCallingIdentity();
6065 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006066 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006067 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068 } finally {
6069 Binder.restoreCallingIdentity(identity);
6070 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006071 }
6072
6073 /**
6074 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006075 * Get the allowed carrier list and the excluded carrier list, including the priority between
6076 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006077 * Require system privileges. In the future we may add this to carrier APIs.
6078 *
Michele Berionne482f8202018-11-27 18:57:59 -08006079 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006080 */
6081 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006082 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006083 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006084 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085
6086 final long identity = Binder.clearCallingIdentity();
6087 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006088 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6089 if (response instanceof CarrierRestrictionRules) {
6090 return (CarrierRestrictionRules) response;
6091 }
6092 // Response is an Exception of some kind,
6093 // which is signalled to the user as a NULL retval
6094 return null;
6095 } catch (Exception e) {
6096 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6097 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 } finally {
6099 Binder.restoreCallingIdentity(identity);
6100 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006101 }
6102
fionaxu59545b42016-05-25 15:53:37 -07006103 /**
6104 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6105 * @param subId the subscription ID that this action applies to.
6106 * @param enabled control enable or disable metered apns.
6107 * {@hide}
6108 */
6109 @Override
6110 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6111 enforceModifyPermission();
6112 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113
6114 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006115 if (phone == null) {
6116 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6117 return;
6118 }
6119 try {
6120 phone.carrierActionSetMeteredApnsEnabled(enabled);
6121 } catch (Exception e) {
6122 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 } finally {
6124 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006125 }
6126 }
6127
6128 /**
6129 * Action set from carrier signalling broadcast receivers to enable/disable radio
6130 * @param subId the subscription ID that this action applies to.
6131 * @param enabled control enable or disable radio.
6132 * {@hide}
6133 */
6134 @Override
6135 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6136 enforceModifyPermission();
6137 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006138
6139 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006140 if (phone == null) {
6141 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6142 return;
6143 }
6144 try {
6145 phone.carrierActionSetRadioEnabled(enabled);
6146 } catch (Exception e) {
6147 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148 } finally {
6149 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006150 }
6151 }
6152
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006153 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006154 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6155 * network status based on which carrier apps could apply actions accordingly,
6156 * enable/disable default url handler for example.
6157 *
6158 * @param subId the subscription ID that this action applies to.
6159 * @param report control start/stop reporting the default network status.
6160 * {@hide}
6161 */
6162 @Override
6163 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6164 enforceModifyPermission();
6165 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166
6167 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006168 if (phone == null) {
6169 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6170 return;
6171 }
6172 try {
6173 phone.carrierActionReportDefaultNetworkStatus(report);
6174 } catch (Exception e) {
6175 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006178 }
6179 }
6180
6181 /**
fionaxud9622282017-07-17 17:51:30 -07006182 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6183 * @param subId the subscription ID that this action applies to.
6184 * {@hide}
6185 */
6186 @Override
6187 public void carrierActionResetAll(int subId) {
6188 enforceModifyPermission();
6189 final Phone phone = getPhone(subId);
6190 if (phone == null) {
6191 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6192 return;
6193 }
6194 try {
6195 phone.carrierActionResetAll();
6196 } catch (Exception e) {
6197 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6198 }
6199 }
6200
6201 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006202 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6203 * bug report is being generated.
6204 */
6205 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006206 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006207 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6208 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006209 writer.println("Permission Denial: can't dump Phone from pid="
6210 + Binder.getCallingPid()
6211 + ", uid=" + Binder.getCallingUid()
6212 + "without permission "
6213 + android.Manifest.permission.DUMP);
6214 return;
6215 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006216 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006217 }
Jack Yueb89b242016-06-22 13:27:47 -07006218
Brad Ebingerdac2f002018-04-03 15:17:52 -07006219 @Override
6220 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6221 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6222 throws RemoteException {
6223 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6224 }
6225
Jack Yueb89b242016-06-22 13:27:47 -07006226 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006227 * Get aggregated video call data usage since boot.
6228 *
6229 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6230 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006231 * {@hide}
6232 */
6233 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006234 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006235 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6236 null);
6237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 final long identity = Binder.clearCallingIdentity();
6239 try {
6240 // NetworkStatsService keeps tracking the active network interface and identity. It
6241 // records the delta with the corresponding network identity.
6242 // We just return the total video call data usage snapshot since boot.
6243 Phone phone = getPhone(subId);
6244 if (phone != null) {
6245 return phone.getVtDataUsage(perUidStats);
6246 }
6247 return null;
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006250 }
Jack Yueb89b242016-06-22 13:27:47 -07006251 }
Jack Yu75ab2952016-07-08 14:29:33 -07006252
6253 /**
6254 * Policy control of data connection. Usually used when data limit is passed.
6255 * @param enabled True if enabling the data, otherwise disabling.
6256 * @param subId Subscription index
6257 * {@hide}
6258 */
6259 @Override
6260 public void setPolicyDataEnabled(boolean enabled, int subId) {
6261 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006262
6263 final long identity = Binder.clearCallingIdentity();
6264 try {
6265 Phone phone = getPhone(subId);
6266 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006267 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268 }
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006271 }
6272 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006273
6274 /**
6275 * Get Client request stats
6276 * @return List of Client Request Stats
6277 * @hide
6278 */
6279 @Override
6280 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006282 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006283 return null;
6284 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006285 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006287 final long identity = Binder.clearCallingIdentity();
6288 try {
6289 if (phone != null) {
6290 return phone.getClientRequestStats();
6291 }
6292
6293 return null;
6294 } finally {
6295 Binder.restoreCallingIdentity(identity);
6296 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006297 }
6298
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006299 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006300 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006301 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006302 }
Jack Yueb4124c2017-02-16 15:32:43 -08006303
6304 /**
Grace Chen70990072017-03-24 17:21:30 -07006305 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006306 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006307 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006308 * @param state State of SIM (power down, power up, pass through)
6309 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6310 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6311 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006312 *
6313 **/
6314 @Override
Grace Chen70990072017-03-24 17:21:30 -07006315 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006316 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006317 Phone phone = PhoneFactory.getPhone(slotIndex);
6318
vagdeviaf9a5b92018-08-15 16:01:53 -07006319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6320
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 final long identity = Binder.clearCallingIdentity();
6322 try {
6323 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006324 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006325 }
6326 } finally {
6327 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006328 }
6329 }
Shuo Qiandd210312017-04-12 22:11:33 +00006330
Tyler Gunn65d45c22017-06-05 11:22:26 -07006331 private boolean isUssdApiAllowed(int subId) {
6332 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006333 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006334 if (configManager == null) {
6335 return false;
6336 }
6337 PersistableBundle pb = configManager.getConfigForSubId(subId);
6338 if (pb == null) {
6339 return false;
6340 }
6341 return pb.getBoolean(
6342 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6343 }
6344
Shuo Qiandd210312017-04-12 22:11:33 +00006345 /**
6346 * Check if phone is in emergency callback mode
6347 * @return true if phone is in emergency callback mode
6348 * @param subId sub id
6349 */
goneil9c5f4872017-12-05 14:07:56 -08006350 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006351 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006352 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006353 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 if (phone != null) {
6358 return phone.isInEcm();
6359 } else {
6360 return false;
6361 }
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006364 }
6365 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006366
6367 /**
6368 * Get the current signal strength information for the given subscription.
6369 * Because this information is not updated when the device is in a low power state
6370 * it should not be relied-upon to be current.
6371 * @param subId Subscription index
6372 * @return the most recent cached signal strength info from the modem
6373 */
6374 @Override
6375 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 Phone p = getPhone(subId);
6379 if (p == null) {
6380 return null;
6381 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 return p.getSignalStrength();
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006387 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006388
Pengquan Meng77b7f132018-08-22 14:49:57 -07006389 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006390 * Get the current modem radio state for the given slot.
6391 * @param slotIndex slot index.
6392 * @param callingPackage the name of the package making the call.
6393 * @return the current radio power state from the modem
6394 */
6395 @Override
6396 public int getRadioPowerState(int slotIndex, String callingPackage) {
6397 Phone phone = PhoneFactory.getPhone(slotIndex);
6398 if (phone != null) {
6399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6400 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6401 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6402 }
6403
6404 final long identity = Binder.clearCallingIdentity();
6405 try {
6406 return phone.getRadioPowerState();
6407 } finally {
6408 Binder.restoreCallingIdentity(identity);
6409 }
6410 }
6411 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6412 }
6413
6414 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006415 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6416 *
6417 * <p>Requires one of the following permissions:
6418 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6419 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6420 * privileges.
6421 *
6422 * @param subId subscription id
6423 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6424 * {@code false}.
6425 */
6426 @Override
6427 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006428 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6429 null /* message */);
6430
Pengquan Menga1bb6272018-09-06 09:59:22 -07006431 boolean isEnabled = false;
6432 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006433 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006434 Phone phone = getPhone(subId);
6435 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006436 } catch (Exception e) {
6437 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6438 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006439 } finally {
6440 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006441 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006442 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006443 }
6444
6445
6446 /**
6447 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6448 *
6449 * <p> Requires permission:
6450 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6451 * privileges.
6452 *
6453 * @param subId subscription id
6454 * @param isEnabled {@code true} means enable, {@code false} means disable.
6455 */
6456 @Override
6457 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6459 mApp, subId, "setDataRoamingEnabled");
6460
Pengquan Menga1bb6272018-09-06 09:59:22 -07006461 final long identity = Binder.clearCallingIdentity();
6462 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006463 Phone phone = getPhone(subId);
6464 if (phone != null) {
6465 phone.setDataRoamingEnabled(isEnabled);
6466 }
6467 } finally {
6468 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006469 }
6470 }
6471
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006472 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006473 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006474 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6475 mApp, subId, "isManualNetworkSelectionAllowed");
6476
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006477 boolean isAllowed = true;
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006480 Phone phone = getPhone(subId);
6481 if (phone != null) {
6482 isAllowed = phone.isCspPlmnEnabled();
6483 }
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
6486 }
6487 return isAllowed;
6488 }
6489
6490 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006491 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006492 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006493 try {
6494 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006495 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006496 } catch (SecurityException e) {
6497 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6498 // has carrier privileges on an active UICC
6499 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6500 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006501 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006502 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006503 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006504
6505 final long identity = Binder.clearCallingIdentity();
6506 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006507 UiccController uiccController = UiccController.getInstance();
6508 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006509 if (hasReadPermission) {
6510 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006511 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006512
6513 // Remove private info if the caller doesn't have access
6514 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6515 for (UiccCardInfo cardInfo : cardInfos) {
6516 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6517 // is available
6518 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6519 if (card == null || card.getUiccProfile() == null) {
6520 // assume no access if the card or profile is unavailable
6521 filteredInfos.add(cardInfo.getUnprivileged());
6522 continue;
6523 }
6524 UiccProfile profile = card.getUiccProfile();
6525 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6526 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6527 filteredInfos.add(cardInfo);
6528 } else {
6529 filteredInfos.add(cardInfo.getUnprivileged());
6530 }
6531 }
6532 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
6536 }
6537
6538 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006539 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006540 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006541
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6545 if (slots == null) {
6546 Rlog.i(LOG_TAG, "slots is null.");
6547 return null;
6548 }
6549
6550 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6551 for (int i = 0; i < slots.length; i++) {
6552 UiccSlot slot = slots[i];
6553 if (slot == null) {
6554 continue;
6555 }
6556
Jordan Liu7be7e652019-05-06 18:55:02 +00006557 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006558 UiccCard card = slot.getUiccCard();
6559 if (card != null) {
6560 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006561 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006562 cardId = slot.getEid();
6563 if (TextUtils.isEmpty(cardId)) {
6564 cardId = slot.getIccId();
6565 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 }
6567
Jordan Liu857451f2019-05-09 16:35:35 -07006568 if (cardId != null) {
6569 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6570 // if cardId is an EID, it's all digits so this is fine
6571 cardId = IccUtils.stripTrailingFs(cardId);
6572 }
6573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006574 int cardState = 0;
6575 switch (slot.getCardState()) {
6576 case CARDSTATE_ABSENT:
6577 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6578 break;
6579 case CARDSTATE_PRESENT:
6580 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6581 break;
6582 case CARDSTATE_ERROR:
6583 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6584 break;
6585 case CARDSTATE_RESTRICTED:
6586 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6587 break;
6588 default:
6589 break;
6590
6591 }
6592
6593 infos[i] = new UiccSlotInfo(
6594 slot.isActive(),
6595 slot.isEuicc(),
6596 cardId,
6597 cardState,
6598 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006599 slot.isExtendedApduSupported(),
6600 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006601 }
6602 return infos;
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006605 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006606 }
6607
6608 @Override
6609 public boolean switchSlots(int[] physicalSlots) {
6610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
6617 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006618 }
Jack Yu4c988042018-02-27 15:30:01 -08006619
6620 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006621 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 return UiccController.getInstance().getCardIdForDefaultEuicc();
6625 } finally {
6626 Binder.restoreCallingIdentity(identity);
6627 }
6628 }
6629
6630 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006631 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6632 enforceModifyPermission();
6633 final Phone phone = getPhone(subId);
6634 if (phone == null) {
6635 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6636 return;
6637 }
6638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006639 final long identity = Binder.clearCallingIdentity();
6640 try {
6641 phone.setRadioIndicationUpdateMode(filters, mode);
6642 } finally {
6643 Binder.restoreCallingIdentity(identity);
6644 }
Jack Yu4c988042018-02-27 15:30:01 -08006645 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006646
6647 /**
goneil47ffb6e2018-04-06 15:40:58 -07006648 * A test API to reload the UICC profile.
6649 *
6650 * <p>Requires that the calling app has permission
6651 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6652 * @hide
6653 */
6654 @Override
6655 public void refreshUiccProfile(int subId) {
6656 enforceModifyPermission();
6657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 Phone phone = getPhone(subId);
6661 if (phone == null) {
6662 return;
6663 }
6664 UiccCard uiccCard = phone.getUiccCard();
6665 if (uiccCard == null) {
6666 return;
6667 }
6668 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6669 if (uiccProfile == null) {
6670 return;
6671 }
6672 uiccProfile.refresh();
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 }
6677
6678 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006679 * Returns false if the mobile data is disabled by default, otherwise return true.
6680 */
6681 private boolean getDefaultDataEnabled() {
6682 return "true".equalsIgnoreCase(
6683 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6684 }
6685
6686 /**
6687 * Returns true if the data roaming is enabled by default, i.e the system property
6688 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6689 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6690 */
6691 private boolean getDefaultDataRoamingEnabled(int subId) {
6692 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006693 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006694 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6695 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6696 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6697 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6698 return isDataRoamingEnabled;
6699 }
6700
6701 /**
6702 * Returns the default network type for the given {@code subId}, if the default network type is
6703 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6704 */
6705 private int getDefaultNetworkType(int subId) {
6706 return Integer.parseInt(
6707 TelephonyManager.getTelephonyProperty(
6708 mSubscriptionController.getPhoneId(subId),
6709 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6710 String.valueOf(Phone.PREFERRED_NT_MODE)));
6711 }
fionaxua13278b2018-03-21 00:08:13 -07006712
6713 @Override
6714 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006715 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006716 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717
6718 final long identity = Binder.clearCallingIdentity();
6719 try {
6720 final Phone phone = getPhone(subId);
6721 if (phone == null) {
6722 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6723 return;
6724 }
chen xueaba88a2019-03-15 13:15:10 -07006725 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6726 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006729 }
fionaxua13278b2018-03-21 00:08:13 -07006730 }
6731
6732 @Override
6733 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006734 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735
6736 final long identity = Binder.clearCallingIdentity();
6737 try {
6738 final Phone phone = getPhone(subId);
6739 if (phone == null) {
6740 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6741 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6742 }
6743 return phone.getCarrierIdListVersion();
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006746 }
fionaxua13278b2018-03-21 00:08:13 -07006747 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006748
6749 @Override
6750 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6752 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6753 return -1;
6754 }
6755
6756 final long identity = Binder.clearCallingIdentity();
6757 try {
6758 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
6762 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006763
6764 @Override
6765 public int getCdmaRoamingMode(int subId) {
6766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6767 mApp, subId, "getCdmaRoamingMode");
6768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
6775 }
6776
6777 @Override
6778 public boolean setCdmaRoamingMode(int subId, int mode) {
6779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6780 mApp, subId, "setCdmaRoamingMode");
6781
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
6787 }
6788 }
6789
6790 @Override
6791 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6793 mApp, subId, "setCdmaSubscriptionMode");
6794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006802
6803 private void ensureUserRunning(int userId) {
6804 if (!mUserManager.isUserRunning(userId)) {
6805 throw new IllegalStateException("User " + userId + " does not exist or not running");
6806 }
6807 }
6808
6809 /**
6810 * Returns a list of SMS apps on a given user.
6811 *
6812 * Only the shell user (UID 2000 or 0) can call it.
6813 * Target user must be running.
6814 */
6815 @Override
6816 public String[] getSmsApps(int userId) {
6817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6818 ensureUserRunning(userId);
6819
6820 final Collection<SmsApplicationData> apps =
6821 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6822
6823 String[] ret = new String[apps.size()];
6824 int i = 0;
6825 for (SmsApplicationData app : apps) {
6826 ret[i++] = app.mPackageName;
6827 }
6828 return ret;
6829 }
6830
6831 /**
6832 * Returns the default SMS app package name on a given user.
6833 *
6834 * Only the shell user (UID 2000 or 0) can call it.
6835 * Target user must be running.
6836 */
6837 @Override
6838 public String getDefaultSmsApp(int userId) {
6839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6840 ensureUserRunning(userId);
6841
6842 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6843 /* updateIfNeeded= */ true, userId);
6844 return cn == null ? null : cn.getPackageName();
6845 }
6846
6847 /**
6848 * Set a package as the default SMS app on a given user.
6849 *
6850 * Only the shell user (UID 2000 or 0) can call it.
6851 * Target user must be running.
6852 */
6853 @Override
6854 public void setDefaultSmsApp(int userId, String packageName) {
6855 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6856 ensureUserRunning(userId);
6857
6858 boolean found = false;
6859 for (String pkg : getSmsApps(userId)) {
6860 if (TextUtils.equals(packageName, pkg)) {
6861 found = true;
6862 break;
6863 }
6864 }
6865 if (!found) {
6866 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6867 }
6868
6869 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6870 }
sqianc5eccab2018-10-19 18:46:41 -07006871
6872 @Override
sqian8c685422019-02-22 15:55:18 -08006873 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006874 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006876 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006877 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6878 }
6879 final long identity = Binder.clearCallingIdentity();
6880 try {
sqian854d44b2018-12-12 16:48:18 -08006881 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6882 for (Phone phone: PhoneFactory.getPhones()) {
6883 if (phone.getEmergencyNumberTracker() != null
6884 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6885 emergencyNumberListInternal.put(
6886 phone.getSubId(),
6887 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6888 }
sqian11b7a0e2018-12-05 18:48:28 -08006889 }
sqian854d44b2018-12-12 16:48:18 -08006890 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006891 } finally {
6892 Binder.restoreCallingIdentity(identity);
6893 }
sqianc5eccab2018-10-19 18:46:41 -07006894 }
6895
6896 @Override
sqian8c685422019-02-22 15:55:18 -08006897 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006898 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006899 if (!exactMatch) {
6900 TelephonyPermissions
6901 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006902 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006903 }
6904 final long identity = Binder.clearCallingIdentity();
6905 try {
sqian854d44b2018-12-12 16:48:18 -08006906 for (Phone phone: PhoneFactory.getPhones()) {
6907 if (phone.getEmergencyNumberTracker() != null
6908 && phone.getEmergencyNumberTracker() != null) {
6909 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6910 number, exactMatch)) {
6911 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006912 }
6913 }
sqian11b7a0e2018-12-05 18:48:28 -08006914 }
6915 return false;
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
6918 }
6919 }
6920
sqianf4ca7ed2019-01-15 18:32:07 -08006921 /**
6922 * Update emergency number list for test mode.
6923 */
6924 @Override
6925 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6926 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6927 "updateEmergencyNumberListTestMode");
6928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 for (Phone phone: PhoneFactory.getPhones()) {
6932 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6933 if (tracker != null) {
6934 tracker.executeEmergencyNumberTestModeCommand(action, num);
6935 }
6936 }
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
6939 }
6940 }
6941
6942 /**
6943 * Get the full emergency number list for test mode.
6944 */
6945 @Override
6946 public List<String> getEmergencyNumberListTestMode() {
6947 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6948 "getEmergencyNumberListTestMode");
6949
6950 final long identity = Binder.clearCallingIdentity();
6951 try {
6952 Set<String> emergencyNumbers = new HashSet<>();
6953 for (Phone phone: PhoneFactory.getPhones()) {
6954 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6955 if (tracker != null) {
6956 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6957 emergencyNumbers.add(num.getNumber());
6958 }
6959 }
6960 }
6961 return new ArrayList<>(emergencyNumbers);
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
6964 }
6965 }
6966
chen xud6b45bd2018-10-30 22:27:10 -07006967 @Override
6968 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6969 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6970 Phone phone = getPhone(subId);
6971 if (phone == null) {
6972 return null;
6973 }
6974 final long identity = Binder.clearCallingIdentity();
6975 try {
6976 UiccProfile profile = UiccController.getInstance()
6977 .getUiccProfileForPhone(phone.getPhoneId());
6978 if (profile != null) {
6979 return profile.getCertsFromCarrierPrivilegeAccessRules();
6980 }
6981 } finally {
6982 Binder.restoreCallingIdentity(identity);
6983 }
6984 return null;
6985 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006986
6987 /**
6988 * Enable or disable a modem stack.
6989 */
6990 @Override
6991 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6992 enforceModifyPermission();
6993
6994 final long identity = Binder.clearCallingIdentity();
6995 try {
6996 Phone phone = PhoneFactory.getPhone(slotIndex);
6997 if (phone == null) {
6998 return false;
6999 } else {
7000 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7001 }
7002 } finally {
7003 Binder.restoreCallingIdentity(identity);
7004 }
7005 }
Michelecea4cf22018-12-21 15:00:11 -08007006
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007007 /**
7008 * Whether a modem stack is enabled or not.
7009 */
7010 @Override
7011 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7012 Phone phone = PhoneFactory.getPhone(slotIndex);
7013 if (phone == null) return false;
7014
7015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7016 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7017 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7018 }
7019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007022 try {
7023 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7024 } catch (NoSuchElementException ex) {
7025 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7026 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
7030 }
7031
Michelecea4cf22018-12-21 15:00:11 -08007032 @Override
Michele0ea7d782019-03-19 14:58:42 -07007033 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007034 enforceModifyPermission();
7035
7036 final long identity = Binder.clearCallingIdentity();
7037 try {
7038 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007039 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007040 .commit();
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 @Override
Michele0ea7d782019-03-19 14:58:42 -07007047 @TelephonyManager.IsMultiSimSupportedResult
7048 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007049 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007050 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7051 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007052 }
Michelecea4cf22018-12-21 15:00:11 -08007053
7054 final long identity = Binder.clearCallingIdentity();
7055 try {
Michele0ea7d782019-03-19 14:58:42 -07007056 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
7060 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007061
Michele0ea7d782019-03-19 14:58:42 -07007062 @TelephonyManager.IsMultiSimSupportedResult
7063 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007064 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7065 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7066 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007067 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7068 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007069 }
7070 // Check if the hardware supports multisim functionality. If usage of multisim is not
7071 // supported by the modem, indicate that it is restricted.
7072 PhoneCapability staticCapability =
7073 mPhoneConfigurationManager.getStaticPhoneCapability();
7074 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007075 loge("isMultiSimSupportedInternal: no static configuration available");
7076 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007077 }
7078 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007079 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7080 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007081 }
7082 // Check if support of multiple SIMs is restricted by carrier
7083 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007084 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007085 }
7086
Michele0ea7d782019-03-19 14:58:42 -07007087 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007088 }
7089
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007090 /**
7091 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007092 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7093 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7094 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007095 * @param numOfSims number of active sims we want to switch to
7096 */
7097 @Override
7098 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007099 if (numOfSims == 1) {
7100 enforceModifyPermission();
7101 } else {
7102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7103 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7104 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007105 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007106
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007107 try {
Michele30b57b22019-03-01 12:01:14 -08007108 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007109 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007110 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7111 return;
7112 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007113 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
7117 }
7118
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007119 @Override
7120 public boolean isApplicationOnUicc(int subId, int appType) {
7121 enforceReadPrivilegedPermission("isApplicationOnUicc");
7122 Phone phone = getPhone(subId);
7123 if (phone == null) {
7124 return false;
7125 }
7126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 UiccCard uiccCard = phone.getUiccCard();
7129 if (uiccCard == null) {
7130 return false;
7131 }
7132 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7133 if (uiccProfile == null) {
7134 return false;
7135 }
7136 if (TelephonyManager.APPTYPE_SIM <= appType
7137 && appType <= TelephonyManager.APPTYPE_ISIM) {
7138 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7139 }
7140 return false;
7141 } finally {
7142 Binder.restoreCallingIdentity(identity);
7143 }
7144 }
7145
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007146 /**
chen xub4baa772019-04-03 10:23:41 -07007147 * Get whether making changes to modem configurations will trigger reboot.
7148 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007149 */
7150 @Override
chen xub4baa772019-04-03 10:23:41 -07007151 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7153 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7154 return false;
7155 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
7162 }
7163
Nathan Harold29f5f052019-02-15 13:41:57 -08007164 private void updateModemStateMetrics() {
7165 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7166 // TODO: check the state for each modem if the api is ready.
7167 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7168 }
7169
Pengquan Meng3889a572019-01-23 11:16:29 -08007170 @Override
7171 public int[] getSlotsMapping() {
7172 enforceReadPrivilegedPermission("getSlotsMapping");
7173
7174 final long identity = Binder.clearCallingIdentity();
7175 try {
7176 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7177 // All logical slots should have a mapping to a physical slot.
7178 int[] logicalSlotsMapping = new int[phoneCount];
7179 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7180 for (int i = 0; i < slotInfos.length; i++) {
7181 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7182 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7183 }
7184 }
7185 return logicalSlotsMapping;
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
7189 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007190
7191 /**
7192 * Get the IRadio HAL Version
7193 */
7194 @Override
7195 public int getRadioHalVersion() {
7196 Phone phone = getDefaultPhone();
7197 if (phone == null) return -1;
7198 HalVersion hv = phone.getHalVersion();
7199 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7200 return hv.major * 100 + hv.minor;
7201 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007202
7203 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007204 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7205 * corresponding network requests on a subId.
7206 *
7207 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007208 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007209 * 2) APN is un-metered for this subscription, or
7210 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7211 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7212 *
7213 * @return whether data is allowed for a apn type.
7214 *
7215 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007216 */
7217 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007218 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007220 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7221 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007222 }
7223
7224 // Now that all security checks passes, perform the operation as ourselves.
7225 final long identity = Binder.clearCallingIdentity();
7226 try {
7227 Phone phone = getPhone(subId);
7228 if (phone == null) return false;
7229
Jack Yu41407ee2019-05-13 16:54:09 -07007230 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007231 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7232 } finally {
7233 Binder.restoreCallingIdentity(identity);
7234 }
7235 }
7236
7237 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007238 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007239 enforceReadPrivilegedPermission("isApnMetered");
7240
7241 // Now that all security checks passes, perform the operation as ourselves.
7242 final long identity = Binder.clearCallingIdentity();
7243 try {
7244 Phone phone = getPhone(subId);
7245 if (phone == null) return true; // By default return true.
7246
Jack Yu41407ee2019-05-13 16:54:09 -07007247 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007248 } finally {
7249 Binder.restoreCallingIdentity(identity);
7250 }
7251 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007252
7253 @Override
7254 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7255 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7256 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7257 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7258 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7259 }
7260 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7261 Intent intent = new Intent();
7262 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7263 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7264 // Bring up choose default SMS subscription dialog right now
7265 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7266 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7267 mApp.startActivity(intent);
7268 }
chen xud5ca2d52019-05-28 15:20:57 -07007269
7270 @Override
7271 public String getMmsUAProfUrl(int subId) {
7272 //TODO investigate if this API should require proper permission check in R b/133791609
7273 final long identity = Binder.clearCallingIdentity();
7274 try {
7275 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7276 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7277 } finally {
7278 Binder.restoreCallingIdentity(identity);
7279 }
7280 }
7281
7282 @Override
7283 public String getMmsUserAgent(int subId) {
7284 //TODO investigate if this API should require proper permission check in R b/133791609
7285 final long identity = Binder.clearCallingIdentity();
7286 try {
7287 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7288 .getString(com.android.internal.R.string.config_mms_user_agent);
7289 } finally {
7290 Binder.restoreCallingIdentity(identity);
7291 }
7292 }
Jack Yub07d4972019-05-28 16:12:25 -07007293
7294 @Override
7295 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7296 enforceModifyPermission();
7297
7298 // Now that all security checks passes, perform the operation as ourselves.
7299 final long identity = Binder.clearCallingIdentity();
7300 try {
7301 Phone phone = getPhone(subId);
7302 if (phone == null) return false;
7303
7304 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7305 } finally {
7306 Binder.restoreCallingIdentity(identity);
7307 }
7308 }
7309
7310 @Override
7311 public boolean isDataAllowedInVoiceCall(int subId) {
7312 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7313
7314 // Now that all security checks passes, perform the operation as ourselves.
7315 final long identity = Binder.clearCallingIdentity();
7316 try {
7317 Phone phone = getPhone(subId);
7318 if (phone == null) return false;
7319
7320 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
7324 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007325}