blob: f6fbffa49882f2431447d7971ff016ae21164fad [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;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.IccIoResult;
155import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700157import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800158import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800160import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000161import com.android.internal.telephony.uicc.UiccSlot;
Hyungjun Parkbb07fde2019-01-10 15:28:51 +0900162import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
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);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001075 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1076 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001079 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001080 } else {
1081 // use the result as returned
1082 cb.onCellInfo((List<CellInfo>) ar.result);
1083 }
1084 } catch (RemoteException re) {
1085 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1086 }
1087 break;
1088 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001089 request = (MainThreadRequest) msg.obj;
1090 WorkSource ws = (WorkSource) request.argument;
1091 Phone phone = getPhoneFromRequest(request);
1092 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1093 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001094 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001095 ar = (AsyncResult) msg.obj;
1096 request = (MainThreadRequest) ar.userObj;
1097 if (ar.exception == null) {
1098 request.result = ar.result;
1099 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001100 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1102 ? new CdmaCellLocation() : new GsmCellLocation();
1103 }
1104
1105 synchronized (request) {
1106 request.notifyAll();
1107 }
1108 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001109 case CMD_MODEM_REBOOT:
1110 request = (MainThreadRequest) msg.obj;
1111 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001112 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001113 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001114 case EVENT_CMD_MODEM_REBOOT_DONE:
1115 handleNullReturnEvent(msg, "rebootModem");
1116 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001117 case CMD_REQUEST_ENABLE_MODEM:
1118 request = (MainThreadRequest) msg.obj;
1119 boolean enable = (boolean) request.argument;
1120 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001121 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001122 PhoneConfigurationManager.getInstance()
1123 .enablePhone(request.phone, enable, onCompleted);
1124 break;
1125 case EVENT_ENABLE_MODEM_DONE:
1126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
1128 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001129 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001130 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001131 if ((boolean) request.result) {
1132 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1133 updateModemStateMetrics();
1134 } else {
1135 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1136 + ar.exception);
1137 }
1138 notifyRequester(request);
1139 break;
1140 case CMD_GET_MODEM_STATUS:
1141 request = (MainThreadRequest) msg.obj;
1142 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1143 PhoneConfigurationManager.getInstance()
1144 .getPhoneStatusFromModem(request.phone, onCompleted);
1145 break;
1146 case EVENT_GET_MODEM_STATUS_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 int id = request.phone.getPhoneId();
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result;
1152 //update the cache as modem status has changed
1153 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1154 (boolean) request.result);
1155 } else {
1156 // Return true if modem status cannot be retrieved. For most cases,
1157 // modem status is on. And for older version modems, GET_MODEM_STATUS
1158 // and disable modem are not supported. Modem is always on.
1159 // TODO: this should be fixed in R to support a third
1160 // status UNKNOWN b/131631629
1161 request.result = true;
1162 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1163 + ar.exception);
1164 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001165 notifyRequester(request);
1166 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001167 default:
1168 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1169 break;
1170 }
1171 }
Jake Hambye994d462014-02-03 13:10:13 -08001172
Pengquan Menga1bb6272018-09-06 09:59:22 -07001173 private void notifyRequester(MainThreadRequest request) {
1174 synchronized (request) {
1175 request.notifyAll();
1176 }
1177 }
1178
Jake Hambye994d462014-02-03 13:10:13 -08001179 private void handleNullReturnEvent(Message msg, String command) {
1180 AsyncResult ar = (AsyncResult) msg.obj;
1181 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null) {
1183 request.result = true;
1184 } else {
1185 request.result = false;
1186 if (ar.exception instanceof CommandException) {
1187 loge(command + ": CommandException: " + ar.exception);
1188 } else {
1189 loge(command + ": Unknown exception");
1190 }
1191 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001192 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001193 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001194 }
1195
1196 /**
1197 * Posts the specified command to be executed on the main thread,
1198 * waits for the request to complete, and returns the result.
1199 * @see #sendRequestAsync
1200 */
1201 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001202 return sendRequest(
1203 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001204 }
1205
1206 /**
1207 * Posts the specified command to be executed on the main thread,
1208 * waits for the request to complete, and returns the result.
1209 * @see #sendRequestAsync
1210 */
1211 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1212 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001213 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001214 }
1215
1216 /**
1217 * Posts the specified command to be executed on the main thread,
1218 * waits for the request to complete, and returns the result.
1219 * @see #sendRequestAsync
1220 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001221 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001222 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001223 }
1224
1225 /**
1226 * Posts the specified command to be executed on the main thread,
1227 * waits for the request to complete, and returns the result.
1228 * @see #sendRequestAsync
1229 */
Nathan Harold92bed182018-10-12 18:16:49 -07001230 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1231 return sendRequest(command, argument, subId, null, workSource);
1232 }
1233
1234 /**
1235 * Posts the specified command to be executed on the main thread,
1236 * waits for the request to complete, and returns the result.
1237 * @see #sendRequestAsync
1238 */
1239 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1240 return sendRequest(
1241 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1242 }
1243
1244 /**
1245 * Posts the specified command to be executed on the main thread,
1246 * waits for the request to complete, and returns the result.
1247 * @see #sendRequestAsync
1248 */
1249 private Object sendRequest(
1250 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001251 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1252 throw new RuntimeException("This method will deadlock if called from the main thread.");
1253 }
1254
Nathan Harold92bed182018-10-12 18:16:49 -07001255 MainThreadRequest request = null;
1256 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1257 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1258 } else if (phone != null) {
1259 request = new MainThreadRequest(argument, phone, workSource);
1260 } else {
1261 request = new MainThreadRequest(argument, subId, workSource);
1262 }
1263
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 Message msg = mMainThreadHandler.obtainMessage(command, request);
1265 msg.sendToTarget();
1266
1267 // Wait for the request to complete
1268 synchronized (request) {
1269 while (request.result == null) {
1270 try {
1271 request.wait();
1272 } catch (InterruptedException e) {
1273 // Do nothing, go back and wait until the request is complete
1274 }
1275 }
1276 }
1277 return request.result;
1278 }
1279
1280 /**
1281 * Asynchronous ("fire and forget") version of sendRequest():
1282 * Posts the specified command to be executed on the main thread, and
1283 * returns immediately.
1284 * @see #sendRequest
1285 */
1286 private void sendRequestAsync(int command) {
1287 mMainThreadHandler.sendEmptyMessage(command);
1288 }
1289
1290 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001293 */
1294 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 sendRequestAsync(command, argument, null, null);
1296 }
1297
1298 /**
1299 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1300 * @see {@link #sendRequest(int,Object)}
1301 */
1302 private void sendRequestAsync(
1303 int command, Object argument, Phone phone, WorkSource workSource) {
1304 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001305 Message msg = mMainThreadHandler.obtainMessage(command, request);
1306 msg.sendToTarget();
1307 }
1308
1309 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001310 * Initialize the singleton PhoneInterfaceManager instance.
1311 * This is only done once, at startup, from PhoneApp.onCreate().
1312 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001313 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314 synchronized (PhoneInterfaceManager.class) {
1315 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001316 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317 } else {
1318 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1319 }
1320 return sInstance;
1321 }
1322 }
1323
1324 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001325 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001328 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1330 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001331 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001332 mTelephonySharedPreferences =
1333 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001334 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001335 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001336
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001337 publish();
1338 }
1339
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001340 private Phone getDefaultPhone() {
1341 Phone thePhone = getPhone(getDefaultSubscription());
1342 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1343 }
1344
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001345 private void publish() {
1346 if (DBG) log("publish: " + this);
1347
1348 ServiceManager.addService("phone", this);
1349 }
1350
Stuart Scott584921c2015-01-15 17:10:34 -08001351 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001352 if (request.phone != null) {
1353 return request.phone;
1354 } else {
1355 return getPhoneFromSubId(request.subId);
1356 }
1357 }
1358
1359 private Phone getPhoneFromSubId(int subId) {
1360 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1361 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001362 }
1363
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001364 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1365 Phone phone = getPhoneFromRequest(request);
1366 return phone == null ? null :
1367 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1368 }
1369
Wink Saville36469e72014-06-11 15:17:00 -07001370 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001371 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001372 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001373 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374
1375 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001376 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001377 }
1378
Wink Savilleb564aae2014-10-23 10:18:09 -07001379 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 if (DBG) log("dial: " + number);
1381 // No permission check needed here: This is just a wrapper around the
1382 // ACTION_DIAL intent, which is available to any app since it puts up
1383 // the UI before it does anything.
1384
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001385 final long identity = Binder.clearCallingIdentity();
1386 try {
1387 String url = createTelUrl(number);
1388 if (url == null) {
1389 return;
1390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001392 // PENDING: should we just silently fail if phone is offhook or ringing?
1393 PhoneConstants.State state = mCM.getState(subId);
1394 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1395 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1396 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1397 mApp.startActivity(intent);
1398 }
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001401 }
1402 }
1403
1404 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001409 if (DBG) log("call: " + number);
1410
1411 // This is just a wrapper around the ACTION_CALL intent, but we still
1412 // need to do a permission check since we're calling startActivity()
1413 // from the context of the phone app.
1414 enforceCallPermission();
1415
Jordan Liu1617b712019-07-10 15:06:26 -07001416 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 != AppOpsManager.MODE_ALLOWED) {
1418 return;
1419 }
1420
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001421 final long identity = Binder.clearCallingIdentity();
1422 try {
1423 String url = createTelUrl(number);
1424 if (url == null) {
1425 return;
1426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001428 boolean isValid = false;
1429 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1430 if (slist != null) {
1431 for (SubscriptionInfo subInfoRecord : slist) {
1432 if (subInfoRecord.getSubscriptionId() == subId) {
1433 isValid = true;
1434 break;
1435 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001436 }
Wink Saville08874612014-08-31 19:19:58 -07001437 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001438 if (!isValid) {
1439 return;
1440 }
Wink Saville08874612014-08-31 19:19:58 -07001441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001442 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1443 intent.putExtra(SUBSCRIPTION_KEY, subId);
1444 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1445 mApp.startActivity(intent);
1446 } finally {
1447 Binder.restoreCallingIdentity(identity);
1448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 }
1450
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001451 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001452 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001453 }
1454
Wink Savilleb564aae2014-10-23 10:18:09 -07001455 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001457 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1458 }
1459
1460 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001461 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001462 }
1463
Wink Savilleb564aae2014-10-23 10:18:09 -07001464 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001465 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001466 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1467 }
1468
1469 /** {@hide} */
1470 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001471 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001472 }
1473
Wink Savilleb564aae2014-10-23 10:18:09 -07001474 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001476
1477 final long identity = Binder.clearCallingIdentity();
1478 try {
1479 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1480 checkSimPin.start();
1481 return checkSimPin.unlockSim(null, pin);
1482 } finally {
1483 Binder.restoreCallingIdentity(identity);
1484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 }
1486
Wink Saville9de0f752013-10-22 19:04:03 -07001487 /** {@hide} */
1488 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001489 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001490 }
1491
Wink Savilleb564aae2014-10-23 10:18:09 -07001492 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001494
1495 final long identity = Binder.clearCallingIdentity();
1496 try {
1497 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1498 checkSimPuk.start();
1499 return checkSimPuk.unlockSim(puk, pin);
1500 } finally {
1501 Binder.restoreCallingIdentity(identity);
1502 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001503 }
1504
1505 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001506 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001507 * a synchronous one.
1508 */
1509 private static class UnlockSim extends Thread {
1510
1511 private final IccCard mSimCard;
1512
1513 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001514 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1515 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001516
1517 // For replies from SimCard interface
1518 private Handler mHandler;
1519
1520 // For async handler to identify request type
1521 private static final int SUPPLY_PIN_COMPLETE = 100;
1522
1523 public UnlockSim(IccCard simCard) {
1524 mSimCard = simCard;
1525 }
1526
1527 @Override
1528 public void run() {
1529 Looper.prepare();
1530 synchronized (UnlockSim.this) {
1531 mHandler = new Handler() {
1532 @Override
1533 public void handleMessage(Message msg) {
1534 AsyncResult ar = (AsyncResult) msg.obj;
1535 switch (msg.what) {
1536 case SUPPLY_PIN_COMPLETE:
1537 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1538 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001539 mRetryCount = msg.arg1;
1540 if (ar.exception != null) {
1541 if (ar.exception instanceof CommandException &&
1542 ((CommandException)(ar.exception)).getCommandError()
1543 == CommandException.Error.PASSWORD_INCORRECT) {
1544 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1545 } else {
1546 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1547 }
1548 } else {
1549 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1550 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001551 mDone = true;
1552 UnlockSim.this.notifyAll();
1553 }
1554 break;
1555 }
1556 }
1557 };
1558 UnlockSim.this.notifyAll();
1559 }
1560 Looper.loop();
1561 }
1562
1563 /*
1564 * Use PIN or PUK to unlock SIM card
1565 *
1566 * If PUK is null, unlock SIM card with PIN
1567 *
1568 * If PUK is not null, unlock SIM card with PUK and set PIN code
1569 */
Wink Saville9de0f752013-10-22 19:04:03 -07001570 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001571
1572 while (mHandler == null) {
1573 try {
1574 wait();
1575 } catch (InterruptedException e) {
1576 Thread.currentThread().interrupt();
1577 }
1578 }
1579 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1580
1581 if (puk == null) {
1582 mSimCard.supplyPin(pin, callback);
1583 } else {
1584 mSimCard.supplyPuk(puk, pin, callback);
1585 }
1586
1587 while (!mDone) {
1588 try {
1589 Log.d(LOG_TAG, "wait for done");
1590 wait();
1591 } catch (InterruptedException e) {
1592 // Restore the interrupted status
1593 Thread.currentThread().interrupt();
1594 }
1595 }
1596 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001597 int[] resultArray = new int[2];
1598 resultArray[0] = mResult;
1599 resultArray[1] = mRetryCount;
1600 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 }
1602 }
1603
1604 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001605 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001606
1607 }
1608
Wink Savilleb564aae2014-10-23 10:18:09 -07001609 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001610 // No permission check needed here: this call is harmless, and it's
1611 // needed for the ServiceState.requestStateUpdate() call (which is
1612 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001613 final long identity = Binder.clearCallingIdentity();
1614 try {
1615 final Phone phone = getPhone(subId);
1616 if (phone != null) {
1617 phone.updateServiceLocation();
1618 }
1619 } finally {
1620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622 }
1623
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001624 @Override
1625 public boolean isRadioOn(String callingPackage) {
1626 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001629 @Override
1630 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001632 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001633 return false;
1634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001635
1636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 return isRadioOnForSubscriber(subId);
1639 } finally {
1640 Binder.restoreCallingIdentity(identity);
1641 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001642 }
1643
1644 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 final Phone phone = getPhone(subId);
1648 if (phone != null) {
1649 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1650 } else {
1651 return false;
1652 }
1653 } finally {
1654 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001655 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 }
1657
1658 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001659 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 }
Wink Saville36469e72014-06-11 15:17:00 -07001661
Wink Savilleb564aae2014-10-23 10:18:09 -07001662 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664
1665 final long identity = Binder.clearCallingIdentity();
1666 try {
1667 final Phone phone = getPhone(subId);
1668 if (phone != null) {
1669 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1670 }
1671 } finally {
1672 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001673 }
Wink Saville36469e72014-06-11 15:17:00 -07001674 }
1675
1676 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001677 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Wink Savilleb564aae2014-10-23 10:18:09 -07001680 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001681 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001682
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final Phone phone = getPhone(subId);
1686 if (phone == null) {
1687 return false;
1688 }
1689 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1690 toggleRadioOnOffForSubscriber(subId);
1691 }
1692 return true;
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001695 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001696 }
Wink Saville36469e72014-06-11 15:17:00 -07001697
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001698 public boolean needMobileRadioShutdown() {
1699 /*
1700 * If any of the Radios are available, it will need to be
1701 * shutdown. So return true if any Radio is available.
1702 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001703 final long identity = Binder.clearCallingIdentity();
1704 try {
1705 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1706 Phone phone = PhoneFactory.getPhone(i);
1707 if (phone != null && phone.isRadioAvailable()) return true;
1708 }
1709 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1710 return false;
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001714 }
1715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001717 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001718 enforceModifyPermission();
1719
1720 final long identity = Binder.clearCallingIdentity();
1721 try {
1722 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1723 logv("Shutting down Phone " + i);
1724 shutdownRadioUsingPhoneId(i);
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001728 }
1729 }
1730
1731 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001732 Phone phone = PhoneFactory.getPhone(phoneId);
1733 if (phone != null && phone.isRadioAvailable()) {
1734 phone.shutdownRadio();
1735 }
1736 }
1737
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001739 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001740
1741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1744 if (defaultPhone != null) {
1745 defaultPhone.setRadioPower(turnOn);
1746 return true;
1747 } else {
1748 loge("There's no default phone.");
1749 return false;
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754 }
1755
Wink Savilleb564aae2014-10-23 10:18:09 -07001756 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001758
1759 final long identity = Binder.clearCallingIdentity();
1760 try {
1761 final Phone phone = getPhone(subId);
1762 if (phone != null) {
1763 phone.setRadioPower(turnOn);
1764 return true;
1765 } else {
1766 return false;
1767 }
1768 } finally {
1769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771 }
1772
Wink Saville36469e72014-06-11 15:17:00 -07001773 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001774 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001775 public boolean enableDataConnectivity() {
1776 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001777
1778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 int subId = mSubscriptionController.getDefaultDataSubId();
1781 final Phone phone = getPhone(subId);
1782 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001783 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001784 return true;
1785 } else {
1786 return false;
1787 }
1788 } finally {
1789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001790 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 }
1792
Wink Saville36469e72014-06-11 15:17:00 -07001793 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001794 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 public boolean disableDataConnectivity() {
1796 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797
1798 final long identity = Binder.clearCallingIdentity();
1799 try {
1800 int subId = mSubscriptionController.getDefaultDataSubId();
1801 final Phone phone = getPhone(subId);
1802 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001803 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001804 return true;
1805 } else {
1806 return false;
1807 }
1808 } finally {
1809 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001810 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001811 }
1812
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001814 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001815 final long identity = Binder.clearCallingIdentity();
1816 try {
1817 final Phone phone = getPhone(subId);
1818 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001819 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820 } else {
1821 return false;
1822 }
1823 } finally {
1824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 }
1827
1828 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001829 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001830 }
1831
pkanwarae03a6b2016-11-06 20:37:09 -08001832 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833 enforceCallPermission();
1834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1838 return;
1839 }
1840 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1841 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
1844 }
pkanwar32d516d2016-10-14 19:37:38 -07001845 };
1846
Wink Savilleb564aae2014-10-23 10:18:09 -07001847 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001849
1850 final long identity = Binder.clearCallingIdentity();
1851 try {
1852 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1853 return false;
1854 }
1855 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1856 } finally {
1857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 }
1860
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001862 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001863 }
1864
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001865 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 Phone phone = PhoneFactory.getPhone(slotIndex);
1869 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1870 PhoneConstantConversions.convertCallState(phone.getState());
1871 } finally {
1872 Binder.restoreCallingIdentity(identity);
1873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001874 }
1875
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001877 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001878 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1879 }
1880
1881 @Override
1882 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001883 final long identity = Binder.clearCallingIdentity();
1884 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001885 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001886 if (phone != null) {
1887 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1888 } else {
1889 return PhoneConstantConversions.convertDataState(
1890 PhoneConstants.DataState.DISCONNECTED);
1891 }
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 }
1896
Sanket Padawe356d7632015-06-22 14:03:32 -07001897 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001898 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001899 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1900 }
1901
1902 @Override
1903 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001904 final long identity = Binder.clearCallingIdentity();
1905 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001906 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001907 if (phone != null) {
1908 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1909 } else {
1910 return TelephonyManager.DATA_ACTIVITY_NONE;
1911 }
1912 } finally {
1913 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001914 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915 }
1916
1917 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001918 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001919 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001920 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001921
1922 LocationAccessPolicy.LocationPermissionResult locationResult =
1923 LocationAccessPolicy.checkLocationPermission(mApp,
1924 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1925 .setCallingPackage(callingPackage)
1926 .setCallingPid(Binder.getCallingPid())
1927 .setCallingUid(Binder.getCallingUid())
1928 .setMethod("getCellLocation")
1929 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1930 .build());
1931 switch (locationResult) {
1932 case DENIED_HARD:
1933 throw new SecurityException("Not allowed to access cell location");
1934 case DENIED_SOFT:
1935 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001938 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001939 final long identity = Binder.clearCallingIdentity();
1940 try {
1941 if (DBG_LOC) log("getCellLocation: is active user");
1942 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001943 int subId = mSubscriptionController.getDefaultDataSubId();
1944 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1945 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001946 return data;
1947 } finally {
1948 Binder.restoreCallingIdentity(identity);
1949 }
Svetoslav64fad262015-04-14 14:35:21 -07001950 }
1951
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001953 public String getNetworkCountryIsoForPhone(int phoneId) {
1954 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1955 // registered cell info, so return a NULL country instead.
1956 final long identity = Binder.clearCallingIdentity();
1957 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001958 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1959 // Get default phone in this case.
1960 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1961 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001962 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001963 // Todo: fix this when we can get the actual cellular network info when the device
1964 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001965 if (TelephonyManager.NETWORK_TYPE_IWLAN
1966 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1967 return "";
1968 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001969 Phone phone = PhoneFactory.getPhone(phoneId);
1970 if (phone != null) {
1971 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07001972 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001973 if (sst != null) {
1974 LocaleTracker lt = sst.getLocaleTracker();
1975 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07001976 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1977 return lt.getCurrentCountry();
1978 } else if (emergencyNumberTracker != null) {
1979 return emergencyNumberTracker.getEmergencyCountryIso();
1980 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 }
1982 }
1983 }
1984 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001985 } finally {
1986 Binder.restoreCallingIdentity(identity);
1987 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001988 }
1989
1990 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001992 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001993 }
1994
Sanket Padawe356d7632015-06-22 14:03:32 -07001995 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001996 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001997 mApp.enforceCallingOrSelfPermission(
1998 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001999
2000 final long identity = Binder.clearCallingIdentity();
2001 try {
2002 final Phone phone = getPhone(subId);
2003 if (phone != null) {
2004 phone.enableLocationUpdates();
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
2012 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002013 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002014 }
2015
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002017 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002018 mApp.enforceCallingOrSelfPermission(
2019 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002020
2021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 final Phone phone = getPhone(subId);
2024 if (phone != null) {
2025 phone.disableLocationUpdates();
2026 }
2027 } finally {
2028 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002029 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002030 }
2031
Nathan Harold31d7ff32018-10-15 20:20:30 -07002032 /**
2033 * Returns the target SDK version number for a given package name.
2034 *
Nathan Haroldec184742019-07-10 17:04:16 -07002035 * This call MUST be invoked before clearing the calling UID.
2036 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002037 * @return target SDK if the package is found or INT_MAX.
2038 */
2039 private int getTargetSdk(String packageName) {
2040 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002041 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002042 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002043 if (ai != null) return ai.targetSdkVersion;
2044 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002045 loge("Failed to get package info for pkg="
2046 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002047 }
2048 return Integer.MAX_VALUE;
2049 }
2050
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 @Override
2052 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002053 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2054 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002055 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2056 throw new SecurityException(
2057 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2058 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002059
Jordan Liu1617b712019-07-10 15:06:26 -07002060 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002061 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2062 return null;
2063 }
Svetoslav64fad262015-04-14 14:35:21 -07002064
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002065 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066
Nathan Haroldf180aac2018-06-01 18:43:55 -07002067 List<CellInfo> info = getAllCellInfo(callingPackage);
2068 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069
Nathan Haroldf180aac2018-06-01 18:43:55 -07002070 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2071 for (CellInfo ci : info) {
2072 if (ci instanceof CellInfoGsm) {
2073 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2074 } else if (ci instanceof CellInfoWcdma) {
2075 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2076 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002078 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002079 }
2080
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002081 private List<CellInfo> getCachedCellInfo() {
2082 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2083 for (Phone phone : PhoneFactory.getPhones()) {
2084 List<CellInfo> info = phone.getAllCellInfo();
2085 if (info != null) cellInfos.addAll(info);
2086 }
2087 return cellInfos;
2088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089
2090 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002091 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002092 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002093 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002094
2095 LocationAccessPolicy.LocationPermissionResult locationResult =
2096 LocationAccessPolicy.checkLocationPermission(mApp,
2097 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2098 .setCallingPackage(callingPackage)
2099 .setCallingPid(Binder.getCallingPid())
2100 .setCallingUid(Binder.getCallingUid())
2101 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002102 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002103 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2104 .build());
2105 switch (locationResult) {
2106 case DENIED_HARD:
2107 throw new SecurityException("Not allowed to access cell info");
2108 case DENIED_SOFT:
2109 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002112 final int targetSdk = getTargetSdk(callingPackage);
2113 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2114 return getCachedCellInfo();
2115 }
2116
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002117 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002118 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2122 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002123 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002124 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002125 if (info != null) cellInfos.addAll(info);
2126 }
2127 return cellInfos;
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131 }
2132
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002133 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002134 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2135 requestCellInfoUpdateInternal(
2136 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2137 }
2138
2139 @Override
2140 public void requestCellInfoUpdateWithWorkSource(
2141 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2142 enforceModifyPermission();
2143 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2144 }
2145
2146 private void requestCellInfoUpdateInternal(
2147 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002148 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002149 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002150
2151 LocationAccessPolicy.LocationPermissionResult locationResult =
2152 LocationAccessPolicy.checkLocationPermission(mApp,
2153 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2154 .setCallingPackage(callingPackage)
2155 .setCallingPid(Binder.getCallingPid())
2156 .setCallingUid(Binder.getCallingUid())
2157 .setMethod("requestCellInfoUpdate")
2158 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2159 .build());
2160 switch (locationResult) {
2161 case DENIED_HARD:
2162 throw new SecurityException("Not allowed to access cell info");
2163 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002164 try {
2165 cb.onCellInfo(new ArrayList<CellInfo>());
2166 } catch (RemoteException re) {
2167 // Drop without consequences
2168 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002169 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002170 }
2171
Nathan Harolda939a962019-05-09 10:13:47 -07002172
2173 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002174 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2175
2176 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2177 }
2178
2179 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002180 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002181 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002182 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002186 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
Shishir Agrawala9f32182016-04-12 12:00:16 -07002192 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002193 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002194 Phone phone = PhoneFactory.getPhone(slotIndex);
2195 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002196 return null;
2197 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002198 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002199 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2200 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002201 return null;
2202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002203
2204 final long identity = Binder.clearCallingIdentity();
2205 try {
2206 return phone.getImei();
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
2209 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002210 }
2211
2212 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002213 public String getTypeAllocationCodeForSlot(int slotIndex) {
2214 Phone phone = PhoneFactory.getPhone(slotIndex);
2215 String tac = null;
2216 if (phone != null) {
2217 String imei = phone.getImei();
2218 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2219 }
2220 return tac;
2221 }
2222
2223 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002224 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002225 Phone phone = PhoneFactory.getPhone(slotIndex);
2226 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002227 return null;
2228 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002229
Jeff Davidson913390f2018-02-23 17:11:49 -08002230 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002231 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2232 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002233 return null;
2234 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002235
2236 final long identity = Binder.clearCallingIdentity();
2237 try {
2238 return phone.getMeid();
2239 } finally {
2240 Binder.restoreCallingIdentity(identity);
2241 }
Jack Yu2af8d712017-03-15 17:14:14 -07002242 }
2243
2244 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002245 public String getManufacturerCodeForSlot(int slotIndex) {
2246 Phone phone = PhoneFactory.getPhone(slotIndex);
2247 String manufacturerCode = null;
2248 if (phone != null) {
2249 String meid = phone.getMeid();
2250 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2251 }
2252 return manufacturerCode;
2253 }
2254
2255 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002256 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002257 Phone phone = PhoneFactory.getPhone(slotIndex);
2258 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002259 return null;
2260 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002261 int subId = phone.getSubId();
2262 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2263 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2264 return null;
2265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266
2267 final long identity = Binder.clearCallingIdentity();
2268 try {
2269 return phone.getDeviceSvn();
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002273 }
2274
fionaxu43304da2017-11-27 22:51:16 -08002275 @Override
2276 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
fionaxu43304da2017-11-27 22:51:16 -08002284 }
2285
2286 @Override
2287 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone phone = getPhone(subId);
2291 return phone == null ? null : phone.getCarrierName();
2292 } finally {
2293 Binder.restoreCallingIdentity(identity);
2294 }
fionaxu43304da2017-11-27 22:51:16 -08002295 }
2296
calvinpanffe225e2018-11-01 19:43:06 +08002297 @Override
chen xu0026ca62019-03-06 15:28:50 -08002298 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002299 final long identity = Binder.clearCallingIdentity();
2300 try {
2301 final Phone phone = getPhone(subId);
2302 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002303 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002304 } finally {
2305 Binder.restoreCallingIdentity(identity);
2306 }
2307 }
2308
2309 @Override
chen xu0026ca62019-03-06 15:28:50 -08002310 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002314 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002315 } finally {
2316 Binder.restoreCallingIdentity(identity);
2317 }
2318 }
2319
chen xu651eec72018-11-11 19:03:44 -08002320 @Override
chen xu864e11c2018-12-06 22:10:03 -08002321 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2322 if (!isSubscriptionMccMnc) {
2323 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2324 }
chen xu651eec72018-11-11 19:03:44 -08002325 final Phone phone = PhoneFactory.getPhone(slotIndex);
2326 if (phone == null) {
2327 return TelephonyManager.UNKNOWN_CARRIER_ID;
2328 }
2329 final long identity = Binder.clearCallingIdentity();
2330 try {
2331 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2332 } finally {
2333 Binder.restoreCallingIdentity(identity);
2334 }
2335 }
2336
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002337 //
2338 // Internal helper methods.
2339 //
2340
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2343 *
2344 * @throws SecurityException if the caller does not have the required permission
2345 */
2346 private void enforceModifyPermission() {
2347 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2348 }
2349
2350 /**
2351 * Make sure the caller has the CALL_PHONE permission.
2352 *
2353 * @throws SecurityException if the caller does not have the required permission
2354 */
2355 private void enforceCallPermission() {
2356 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2357 }
2358
Stuart Scott8eef64f2015-04-08 15:13:54 -07002359 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002360 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002361 "ConnectivityService");
2362 }
2363
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 private String createTelUrl(String number) {
2365 if (TextUtils.isEmpty(number)) {
2366 return null;
2367 }
2368
Jake Hambye994d462014-02-03 13:10:13 -08002369 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 }
2371
Ihab Awadf9e92732013-12-05 18:02:52 -08002372 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2374 }
2375
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002376 private static void logv(String msg) {
2377 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2378 }
2379
Ihab Awadf9e92732013-12-05 18:02:52 -08002380 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2382 }
2383
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002384 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002385 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002386 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002387 }
2388
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002390 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002391 final long identity = Binder.clearCallingIdentity();
2392 try {
2393 final Phone phone = PhoneFactory.getPhone(slotIndex);
2394 if (phone == null) {
2395 return PhoneConstants.PHONE_TYPE_NONE;
2396 } else {
2397 return phone.getPhoneType();
2398 }
2399 } finally {
2400 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 }
2403
2404 /**
2405 * Returns the CDMA ERI icon index to display
2406 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 @Override
2408 public int getCdmaEriIconIndex(String callingPackage) {
2409 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002410 }
2411
Sanket Padawe356d7632015-06-22 14:03:32 -07002412 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002414 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002415 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002416 return -1;
2417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418
2419 final long identity = Binder.clearCallingIdentity();
2420 try {
2421 final Phone phone = getPhone(subId);
2422 if (phone != null) {
2423 return phone.getCdmaEriIconIndex();
2424 } else {
2425 return -1;
2426 }
2427 } finally {
2428 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002429 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 }
2431
2432 /**
2433 * Returns the CDMA ERI icon mode,
2434 * 0 - ON
2435 * 1 - FLASHING
2436 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002437 @Override
2438 public int getCdmaEriIconMode(String callingPackage) {
2439 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002440 }
2441
Sanket Padawe356d7632015-06-22 14:03:32 -07002442 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002444 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002445 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002446 return -1;
2447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002448
2449 final long identity = Binder.clearCallingIdentity();
2450 try {
2451 final Phone phone = getPhone(subId);
2452 if (phone != null) {
2453 return phone.getCdmaEriIconMode();
2454 } else {
2455 return -1;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
2462 /**
2463 * Returns the CDMA ERI text,
2464 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 @Override
2466 public String getCdmaEriText(String callingPackage) {
2467 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002468 }
2469
Sanket Padawe356d7632015-06-22 14:03:32 -07002470 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002472 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002473 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002474 return null;
2475 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476
2477 final long identity = Binder.clearCallingIdentity();
2478 try {
2479 final Phone phone = getPhone(subId);
2480 if (phone != null) {
2481 return phone.getCdmaEriText();
2482 } else {
2483 return null;
2484 }
2485 } finally {
2486 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
2489
2490 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002491 * Returns the CDMA MDN.
2492 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002493 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002494 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2496 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002501 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002502 return phone.getLine1Number();
2503 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002504 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505 return null;
2506 }
2507 } finally {
2508 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002509 }
2510 }
2511
2512 /**
2513 * Returns the CDMA MIN.
2514 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002515 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002516 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2518 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002519
2520 final long identity = Binder.clearCallingIdentity();
2521 try {
2522 final Phone phone = getPhone(subId);
2523 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2524 return phone.getCdmaMin();
2525 } else {
2526 return null;
2527 }
2528 } finally {
2529 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002530 }
2531 }
2532
Hall Liud892bec2018-11-30 14:51:45 -08002533 @Override
2534 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2535 INumberVerificationCallback callback, String callingPackage) {
2536 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2537 != PERMISSION_GRANTED) {
2538 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2539 }
2540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2541
2542 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2543 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2544 throw new SecurityException("Calling package must be configured in the device config");
2545 }
2546
2547 if (range == null) {
2548 throw new NullPointerException("Range must be non-null");
2549 }
2550
2551 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002552 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002553
2554 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2555 }
2556
Junda Liuca05d5d2014-08-14 22:36:34 -07002557 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 * Returns true if CDMA provisioning needs to run.
2559 */
2560 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002563 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 } finally {
2565 Binder.restoreCallingIdentity(identity);
2566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
2569 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002570 * Sets the voice mail number of a given subId.
2571 */
2572 @Override
2573 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575
2576 final long identity = Binder.clearCallingIdentity();
2577 try {
2578 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2579 new Pair<String, String>(alphaTag, number), new Integer(subId));
2580 return success;
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
2583 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002584 }
2585
Ta-wei Yen87c49842016-05-13 21:19:52 -07002586 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002587 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2588 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002589 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002590 if (!TextUtils.equals(callingPackage, systemDialer)) {
2591 throw new SecurityException("caller must be system dialer");
2592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2597 if (phoneAccountHandle == null) {
2598 return null;
2599 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002600 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002603 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002604 }
2605
2606 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002607 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002610 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002611 return null;
2612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002614 final long identity = Binder.clearCallingIdentity();
2615 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002616 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002620 }
2621
2622 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002623 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2624 VisualVoicemailSmsFilterSettings settings) {
2625 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002630 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 } finally {
2632 Binder.restoreCallingIdentity(identity);
2633 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002634 }
2635
2636 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002637 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2638 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002643 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644 } finally {
2645 Binder.restoreCallingIdentity(identity);
2646 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002647 }
2648
2649 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002650 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2651 String callingPackage, int subId) {
2652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002653
2654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002657 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002661 }
2662
2663 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002664 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002665 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002670 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 } finally {
2672 Binder.restoreCallingIdentity(identity);
2673 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002674 }
2675
2676 @Override
2677 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2678 String number, int port, String text, PendingIntent sentIntent) {
2679 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002680 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002681 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002682 SmsController smsController = PhoneFactory.getSmsController();
2683 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2684 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002685 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002686
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002687 /**
fionaxu0152e512016-11-14 13:36:14 -08002688 * Sets the voice activation state of a given subId.
2689 */
2690 @Override
2691 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2693 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 final Phone phone = getPhone(subId);
2698 if (phone != null) {
2699 phone.setVoiceActivationState(activationState);
2700 } else {
2701 loge("setVoiceActivationState fails with invalid subId: " + subId);
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002705 }
2706 }
2707
2708 /**
2709 * Sets the data activation state of a given subId.
2710 */
2711 @Override
2712 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2714 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715
2716 final long identity = Binder.clearCallingIdentity();
2717 try {
2718 final Phone phone = getPhone(subId);
2719 if (phone != null) {
2720 phone.setDataActivationState(activationState);
2721 } else {
2722 loge("setVoiceActivationState fails with invalid subId: " + subId);
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002726 }
2727 }
2728
2729 /**
2730 * Returns the voice activation state of a given subId.
2731 */
2732 @Override
2733 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002734 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735
fionaxu0152e512016-11-14 13:36:14 -08002736 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002737 final long identity = Binder.clearCallingIdentity();
2738 try {
2739 if (phone != null) {
2740 return phone.getVoiceActivationState();
2741 } else {
2742 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002746 }
2747 }
2748
2749 /**
2750 * Returns the data activation state of a given subId.
2751 */
2752 @Override
2753 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002754 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755
fionaxu0152e512016-11-14 13:36:14 -08002756 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002757 final long identity = Binder.clearCallingIdentity();
2758 try {
2759 if (phone != null) {
2760 return phone.getDataActivationState();
2761 } else {
2762 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2763 }
2764 } finally {
2765 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002766 }
2767 }
2768
2769 /**
Wink Saville36469e72014-06-11 15:17:00 -07002770 * Returns the unread count of voicemails for a subId
2771 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002772 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002773 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2774 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2775 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2776 return 0;
2777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 final Phone phone = getPhone(subId);
2781 if (phone != null) {
2782 return phone.getVoiceMessageCount();
2783 } else {
2784 return 0;
2785 }
2786 } finally {
2787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 }
2790
2791 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002792 * returns true, if the device is in a state where both voice and data
2793 * are supported simultaneously. This can change based on location or network condition.
2794 */
2795 @Override
2796 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 final Phone phone = getPhone(subId);
2800 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2801 } finally {
2802 Binder.restoreCallingIdentity(identity);
2803 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002804 }
2805
2806 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002807 * Send the dialer code if called from the current default dialer or the caller has
2808 * carrier privilege.
2809 * @param inputCode The dialer code to send
2810 */
2811 @Override
2812 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002813 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002814 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002815 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2816 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002817 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002818 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2819 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002820 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002821
2822 final long identity = Binder.clearCallingIdentity();
2823 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002824 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002825 } finally {
2826 Binder.restoreCallingIdentity(identity);
2827 }
fionaxu235cc5e2017-03-06 22:25:57 -08002828 }
2829
Pengquan Menga1bb6272018-09-06 09:59:22 -07002830 @Override
2831 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002832 if (!isActiveSubscription(subId)) {
2833 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2834 }
2835
Pengquan Menga1bb6272018-09-06 09:59:22 -07002836 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2837 }
2838
Brad Ebinger35c841c2018-10-01 10:40:55 -07002839 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002840 public boolean isInEmergencySmsMode() {
2841 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2842 final long identity = Binder.clearCallingIdentity();
2843 try {
2844 for (Phone phone : PhoneFactory.getPhones()) {
2845 if (phone.isInEmergencySmsMode()) {
2846 return true;
2847 }
2848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
2851 }
2852 return false;
2853 }
2854
2855 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002856 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2857 throws RemoteException {
2858 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 final long token = Binder.clearCallingIdentity();
2860 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002862 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002863 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002864 } catch (ImsException e) {
2865 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002866 } finally {
2867 Binder.restoreCallingIdentity(token);
2868 }
2869 }
2870
2871 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002872 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2873 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002874 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2875 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2876 }
2877 Binder.withCleanCallingIdentity(() -> {
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002881 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002882 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002883 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2884 + "is inactive, ignoring unregister.");
2885 // If the subscription is no longer active, just return, since the callback
2886 // will already have been removed internally.
2887 }
2888 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002889 }
2890
2891 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002892 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2893 throws RemoteException {
2894 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002895 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2896 final long token = Binder.clearCallingIdentity();
2897 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002898 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002899 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002900 } catch (ImsException e) {
2901 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002902 } finally {
2903 Binder.restoreCallingIdentity(token);
2904 }
2905 }
2906
2907 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002908 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2909 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002910
2911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2913 }
2914 Binder.withCleanCallingIdentity(() -> {
2915 try {
2916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002917 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002918 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002919 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002920 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2921 + "is inactive, ignoring unregister.");
2922 // If the subscription is no longer active, just return, since the callback
2923 // will already have been removed internally.
2924 }
2925 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 }
2927
2928 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002929 public boolean isCapable(int subId, int capability, int regTech) {
2930 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2932 final long token = Binder.clearCallingIdentity();
2933 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002934 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002936 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2938 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002939 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002940 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2941 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002942 } finally {
2943 Binder.restoreCallingIdentity(token);
2944 }
2945 }
2946
2947 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002948 public boolean isAvailable(int subId, int capability, int regTech) {
2949 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 final long token = Binder.clearCallingIdentity();
2951 try {
2952 Phone phone = getPhone(subId);
2953 if (phone == null) return false;
2954 return phone.isImsCapabilityAvailable(capability, regTech);
2955 } finally {
2956 Binder.restoreCallingIdentity(token);
2957 }
2958 }
2959
2960 @Override
2961 public boolean isAdvancedCallingSettingEnabled(int subId) {
2962 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2964 final long token = Binder.clearCallingIdentity();
2965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002966 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002967 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002968 } catch (ImsException e) {
2969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002970 } finally {
2971 Binder.restoreCallingIdentity(token);
2972 }
2973 }
2974
2975 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002976 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002978 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002984 } catch (ImsException e) {
2985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002992 public boolean isVtSettingEnabled(int subId) {
2993 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 final long identity = Binder.clearCallingIdentity();
2995 try {
2996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002997 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2998 } catch (ImsException e) {
2999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003000 } finally {
3001 Binder.restoreCallingIdentity(identity);
3002 }
3003 }
3004
3005 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003006 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003008 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003012 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003013 } catch (ImsException e) {
3014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
3021 public boolean isVoWiFiSettingEnabled(int subId) {
3022 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3023 final long identity = Binder.clearCallingIdentity();
3024 try {
3025 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003027 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003028 } catch (ImsException e) {
3029 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
3033 }
3034
3035 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003036 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003038 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003042 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003043 } catch (ImsException e) {
3044 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 } finally {
3046 Binder.restoreCallingIdentity(identity);
3047 }
3048 }
3049
3050 @Override
3051 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3052 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003056 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003058 } catch (ImsException e) {
3059 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003066 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003068 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003074 } catch (ImsException e) {
3075 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 @Override
3082 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3084 "setVoWiFiNonPersistent");
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003089 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003090 } catch (ImsException e) {
3091 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
3095 }
3096
3097 @Override
3098 public int getVoWiFiModeSetting(int subId) {
3099 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003103 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003104 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003105 } catch (ImsException e) {
3106 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003107 } finally {
3108 Binder.restoreCallingIdentity(identity);
3109 }
3110 }
3111
3112 @Override
3113 public void setVoWiFiModeSetting(int subId, int mode) {
3114 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3115 "setVoWiFiModeSetting");
3116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003119 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003120 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003121 } catch (ImsException e) {
3122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 } finally {
3124 Binder.restoreCallingIdentity(identity);
3125 }
3126 }
3127
3128 @Override
3129 public int getVoWiFiRoamingModeSetting(int subId) {
3130 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003134 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003136 } catch (ImsException e) {
3137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003138 } finally {
3139 Binder.restoreCallingIdentity(identity);
3140 }
3141 }
3142
3143 @Override
3144 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3145 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3146 "setVoWiFiRoamingModeSetting");
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003150 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003151 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003152 } catch (ImsException e) {
3153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
3159 @Override
3160 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3162 "setRttCapabilityEnabled");
3163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003166 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3167 } catch (ImsException e) {
3168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 } finally {
3170 Binder.restoreCallingIdentity(identity);
3171 }
3172 }
3173
3174 @Override
3175 public boolean isTtyOverVolteEnabled(int subId) {
3176 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3177 final long identity = Binder.clearCallingIdentity();
3178 try {
3179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003180 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003181 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003182 } catch (ImsException e) {
3183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 } finally {
3185 Binder.restoreCallingIdentity(identity);
3186 }
3187 }
3188
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003189 @Override
3190 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3191 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003195 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003196 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003197 } catch (ImsException e) {
3198 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003199 } finally {
3200 Binder.restoreCallingIdentity(identity);
3201 }
3202 }
3203
3204 @Override
3205 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3206 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3207 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003208 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3209 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3210 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003211 try {
3212 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003213 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003214 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003215 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003216 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3217 + "is inactive, ignoring unregister.");
3218 // If the subscription is no longer active, just return, since the callback will already
3219 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 }
3224
3225 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003226 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3227 boolean isProvisioned) {
3228 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3229 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3230 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3231 }
3232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3233 "setProvisioningStatusForCapability");
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3237 Phone phone = getPhone(subId);
3238 if (phone == null) {
3239 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3240 + subId);
3241 return;
3242 }
3243 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3244 return;
3245 }
3246
3247 // this capability requires provisioning, route to the correct API.
3248 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3249 switch (capability) {
3250 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3251 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3252 ims.setVolteProvisioned(isProvisioned);
3253 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3254 ims.setWfcProvisioned(isProvisioned);
3255 }
3256 break;
3257 }
3258 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3259 // There is currently no difference in VT provisioning type.
3260 ims.setVtProvisioned(isProvisioned);
3261 break;
3262 }
3263 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3264 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3265 // change the capability of the feature instead if needed.
3266 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3267 == isProvisioned) {
3268 // No change in provisioning.
3269 return;
3270 }
3271 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3272 try {
3273 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003274 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003275 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3276 + ", Exception" + e.getMessage());
3277 }
3278 break;
3279 }
3280 default: {
3281 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3282 + capability + "', which does not require provisioning.");
3283 }
3284 }
3285
3286 } finally {
3287 Binder.restoreCallingIdentity(identity);
3288 }
3289 }
3290
3291 @Override
3292 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3293 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3294 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3295 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3296 }
3297 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3298 final long identity = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3301 Phone phone = getPhone(subId);
3302 if (phone == null) {
3303 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3304 + subId);
3305 // We will fail with "true" as the provisioning status because this is the default
3306 // if we do not require provisioning.
3307 return true;
3308 }
3309
3310 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3311 return true;
3312 }
3313
3314 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3315 switch (capability) {
3316 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3317 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3318 return ims.isVolteProvisionedOnDevice();
3319 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3320 return ims.isWfcProvisionedOnDevice();
3321 }
3322 // This should never happen, since we are checking tech above to make sure it
3323 // is either LTE or IWLAN.
3324 throw new IllegalArgumentException("Invalid radio technology for voice "
3325 + "capability.");
3326 }
3327 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3328 // There is currently no difference in VT provisioning type.
3329 return ims.isVtProvisionedOnDevice();
3330 }
3331 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3332 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3333 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3334 }
3335 default: {
3336 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3337 + capability + "', which does not require provisioning.");
3338 }
3339 }
3340
3341 } finally {
3342 Binder.restoreCallingIdentity(identity);
3343 }
3344 }
3345
3346 @Override
3347 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3348 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3349 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3350 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3351 }
3352 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3353 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3354 return (provisionedBits & capability) > 0;
3355 }
3356
3357 @Override
3358 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3359 boolean isProvisioned) {
3360 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3361 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3362 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3363 }
3364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3365 "setProvisioningStatusForCapability");
3366 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3367 // If the current provisioning status for capability already matches isProvisioned,
3368 // do nothing.
3369 if (((provisionedBits & capability) > 0) == isProvisioned) {
3370 return;
3371 }
3372 if (isProvisioned) {
3373 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3374 } else {
3375 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3376 }
3377 }
3378
3379 /**
3380 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3381 * technology. The bitfield should mirror the bitfield defined by
3382 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3383 */
3384 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3385 String key = getMmTelProvisioningKey(subId, tech);
3386 // Default is no capabilities are provisioned.
3387 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3388 }
3389
3390 /**
3391 * Sets the MmTel capability provisioning bitfield (defined by
3392 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3393 * technology specified.
3394 *
3395 * Note: This is a synchronous command and should not be called on UI thread.
3396 */
3397 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3398 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3399 String key = getMmTelProvisioningKey(subId, tech);
3400 editor.putInt(key, newField);
3401 editor.commit();
3402 }
3403
3404 private static String getMmTelProvisioningKey(int subId, int tech) {
3405 // resulting key is provision_ims_mmtel_{subId}_{tech}
3406 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3407 }
3408
3409 /**
3410 * Query CarrierConfig to see if the specified capability requires provisioning for the
3411 * carrier associated with the subscription id.
3412 */
3413 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3414 int capability) {
3415 CarrierConfigManager configManager = new CarrierConfigManager(context);
3416 PersistableBundle c = configManager.getConfigForSubId(subId);
3417 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003418 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003419 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3420 false);
3421 boolean requireVoiceVtProvisioning = c.getBoolean(
3422 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3423
3424 // First check to make sure that the capability requires provisioning.
3425 switch (capability) {
3426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3427 // intentional fallthrough
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3429 if (requireVoiceVtProvisioning) {
3430 // Voice and Video requires provisioning
3431 return true;
3432 }
3433 break;
3434 }
3435 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3436 if (requireUtProvisioning) {
3437 // UT requires provisioning
3438 return true;
3439 }
3440 break;
3441 }
3442 }
3443 return false;
3444 }
3445
3446 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003448 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3449 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3450 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003451 enforceReadPrivilegedPermission("getImsProvisioningInt");
3452 final long identity = Binder.clearCallingIdentity();
3453 try {
3454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 int slotId = getSlotIndex(subId);
3456 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3457 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3458 + subId + "' for key:" + key);
3459 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3460 }
3461 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003462 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003463 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3464 + subId + "' for key:" + key);
3465 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
3469 }
3470
3471 @Override
3472 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3474 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3475 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 enforceReadPrivilegedPermission("getImsProvisioningString");
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003480 int slotId = getSlotIndex(subId);
3481 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3482 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3483 + subId + "' for key:" + key);
3484 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3485 }
3486 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003487 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003488 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3489 + subId + "' for key:" + key);
3490 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
3494 }
3495
3496 @Override
3497 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003498 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3499 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3500 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3502 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003503 final long identity = Binder.clearCallingIdentity();
3504 try {
3505 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003506 int slotId = getSlotIndex(subId);
3507 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3508 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3509 + subId + "' for key:" + key);
3510 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3511 }
3512 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003513 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003514 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3515 + "' for key:" + key);
3516 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003517 } finally {
3518 Binder.restoreCallingIdentity(identity);
3519 }
3520 }
3521
3522 @Override
3523 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003524 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3525 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3526 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3528 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003532 int slotId = getSlotIndex(subId);
3533 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3534 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3535 + subId + "' for key:" + key);
3536 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3537 }
3538 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003539 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003540 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3541 + "' for key:" + key);
3542 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003543 } finally {
3544 Binder.restoreCallingIdentity(identity);
3545 }
3546 }
3547
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003548 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003549 int slotId = SubscriptionManager.getSlotIndex(subId);
3550 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003551 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3552 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 }
3554 return slotId;
3555 }
3556
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003557 private int getSlotIndex(int subId) {
3558 int slotId = SubscriptionManager.getSlotIndex(subId);
3559 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3560 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3561 }
3562 return slotId;
3563 }
3564
Wink Saville36469e72014-06-11 15:17:00 -07003565 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003566 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003567 */
3568 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003569 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003570 final int targetSdk = getTargetSdk(callingPackage);
3571 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3572 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3573 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003574 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3575 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003576 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3577 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003578
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003579 final long identity = Binder.clearCallingIdentity();
3580 try {
3581 final Phone phone = getPhone(subId);
3582 if (phone != null) {
3583 return phone.getServiceState().getDataNetworkType();
3584 } else {
3585 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3586 }
3587 } finally {
3588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003590 }
3591
3592 /**
3593 * Returns the data network type
3594 */
3595 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003596 public int getDataNetworkType(String callingPackage) {
3597 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003598 }
3599
3600 /**
3601 * Returns the data network type for a subId
3602 */
3603 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003604 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003605 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003606 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003607 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3608 }
3609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003610 final long identity = Binder.clearCallingIdentity();
3611 try {
3612 final Phone phone = getPhone(subId);
3613 if (phone != null) {
3614 return phone.getServiceState().getDataNetworkType();
3615 } else {
3616 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3617 }
3618 } finally {
3619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
3622
3623 /**
Wink Saville36469e72014-06-11 15:17:00 -07003624 * Returns the Voice network type for a subId
3625 */
3626 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003627 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003629 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003630 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3631 }
3632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 final Phone phone = getPhone(subId);
3636 if (phone != null) {
3637 return phone.getServiceState().getVoiceNetworkType();
3638 } else {
3639 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3640 }
3641 } finally {
3642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003644 }
3645
3646 /**
3647 * @return true if a ICC card is present
3648 */
3649 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003650 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003651 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3652 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003653 }
3654
3655 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003656 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003657 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003658 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003659 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 final Phone phone = PhoneFactory.getPhone(slotIndex);
3663 if (phone != null) {
3664 return phone.getIccCard().hasIccCard();
3665 } else {
3666 return false;
3667 }
3668 } finally {
3669 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003671 }
3672
3673 /**
3674 * Return if the current radio is LTE on CDMA. This
3675 * is a tri-state return value as for a period of time
3676 * the mode may be unknown.
3677 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003678 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003679 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003680 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003682 @Override
3683 public int getLteOnCdmaMode(String callingPackage) {
3684 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003685 }
3686
Sanket Padawe356d7632015-06-22 14:03:32 -07003687 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003688 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003689 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003690 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003691 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3692 }
3693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 final Phone phone = getPhone(subId);
3697 if (phone == null) {
3698 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3699 } else {
3700 return phone.getLteOnCdmaMode();
3701 }
3702 } finally {
3703 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003704 }
Wink Saville36469e72014-06-11 15:17:00 -07003705 }
3706
Wink Saville36469e72014-06-11 15:17:00 -07003707 /**
3708 * {@hide}
3709 * Returns Default subId, 0 in the case of single standby.
3710 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003711 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003712 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003713 }
3714
Shishir Agrawala9f32182016-04-12 12:00:16 -07003715 private int getSlotForDefaultSubscription() {
3716 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3717 }
3718
Wink Savilleb564aae2014-10-23 10:18:09 -07003719 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003720 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003721 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003722
Pengquan Menge92a50d2018-09-21 15:54:48 -07003723 private boolean isActiveSubscription(int subId) {
3724 return mSubscriptionController.isActiveSubId(subId);
3725 }
3726
Ihab Awadf2177b72013-11-25 13:33:23 -08003727 /**
3728 * @see android.telephony.TelephonyManager.WifiCallingChoices
3729 */
3730 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003731 final long identity = Binder.clearCallingIdentity();
3732 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003733 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003734 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3735 getWhenToMakeWifiCallsDefaultPreference());
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
3738 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003739 }
3740
3741 /**
3742 * @see android.telephony.TelephonyManager.WifiCallingChoices
3743 */
3744 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003748 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003749 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3750 } finally {
3751 Binder.restoreCallingIdentity(identity);
3752 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003753 }
3754
Sailesh Nepald1e68152013-12-12 19:08:02 -08003755 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003756 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003757 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003758 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003759
Jordan Liu4c733742019-02-28 12:03:40 -08003760 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3761 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3762 if (phoneId == -1) {
3763 throw new IllegalArgumentException("Given slot index: " + slotIndex
3764 + " does not correspond to an active phone");
3765 }
3766 return PhoneFactory.getPhone(phoneId);
3767 }
3768
Shishir Agrawal566b7612013-10-28 14:41:00 -07003769 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003770 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3771 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3773 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003774 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003775 if (DBG) {
3776 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3777 }
3778 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3779 p2);
3780 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003781
Jordan Liu4c733742019-02-28 12:03:40 -08003782
3783 @Override
3784 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3785 int slotIndex, String callingPackage, String aid, int p2) {
3786 enforceModifyPermission();
3787 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3788 if (DBG) {
3789 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3790 }
3791 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3792 callingPackage, aid, p2);
3793 }
3794
3795 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3796 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 final long identity = Binder.clearCallingIdentity();
3798 try {
3799 if (TextUtils.equals(ISDR_AID, aid)) {
3800 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003801 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3802 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003803 if (bestComponent == null
3804 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3805 loge("The calling package is not allowed to access ISD-R.");
3806 throw new SecurityException(
3807 "The calling package is not allowed to access ISD-R.");
3808 }
Derek Tan740e1672017-06-27 14:56:27 -07003809 }
Derek Tan740e1672017-06-27 14:56:27 -07003810
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003811 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003812 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3813 null /* workSource */);
3814 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003815 return response;
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819 }
3820
3821 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003822 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3824 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003825 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3826 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3827 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003828
Jordan Liu4c733742019-02-28 12:03:40 -08003829 @Override
3830 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3831 enforceModifyPermission();
3832 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3833 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3834 channel);
3835 }
3836
3837 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003838 final long identity = Binder.clearCallingIdentity();
3839 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 if (channel < 0) {
3841 return false;
3842 }
Jordan Liu4c733742019-02-28 12:03:40 -08003843 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3844 null /* workSource */);
3845 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003846 return success;
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003849 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003850 }
3851
3852 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003853 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003854 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003855 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3856 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003857 if (DBG) {
3858 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3859 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3860 + p3 + " data=" + data);
3861 }
3862 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3863 command, p1, p2, p3, data);
3864 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003865
Jordan Liu4c733742019-02-28 12:03:40 -08003866 @Override
3867 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3868 int command, int p1, int p2, int p3, String data) {
3869 enforceModifyPermission();
3870 if (DBG) {
3871 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3872 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3873 + p3 + " data=" + data);
3874 }
3875 return iccTransmitApduLogicalChannelWithPermission(
3876 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3877 data);
3878 }
3879
3880 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3881 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 final long identity = Binder.clearCallingIdentity();
3883 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003884 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003885 return "";
3886 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003887
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003888 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003889 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3890 null /* workSource */);
3891 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003893 // Append the returned status code to the end of the response payload.
3894 String s = Integer.toHexString(
3895 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3896 if (response.payload != null) {
3897 s = IccUtils.bytesToHexString(response.payload) + s;
3898 }
3899 return s;
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003902 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003903 }
Jake Hambye994d462014-02-03 13:10:13 -08003904
Evan Charltonc66da362014-05-16 14:06:40 -07003905 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003906 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3907 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003908 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3909 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003911 if (DBG) {
3912 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3913 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3914 }
3915 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3916 cla, command, p1, p2, p3, data);
3917 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003918
Jordan Liu4c733742019-02-28 12:03:40 -08003919 @Override
3920 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3921 int command, int p1, int p2, int p3, String data) {
3922 enforceModifyPermission();
3923 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3924 if (DBG) {
3925 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3926 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3927 + " data=" + data);
3928 }
3929
3930 return iccTransmitApduBasicChannelWithPermission(
3931 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3932 p2, p3, data);
3933 }
3934
3935 // open APDU basic channel assuming the caller has sufficient permissions
3936 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3937 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3941 && TextUtils.equals(ISDR_AID, data)) {
3942 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003943 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3944 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945 if (bestComponent == null
3946 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3947 loge("The calling package is not allowed to select ISD-R.");
3948 throw new SecurityException(
3949 "The calling package is not allowed to select ISD-R.");
3950 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003951 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003952
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003953 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003954 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3955 null /* workSource */);
3956 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003958 // Append the returned status code to the end of the response payload.
3959 String s = Integer.toHexString(
3960 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3961 if (response.payload != null) {
3962 s = IccUtils.bytesToHexString(response.payload) + s;
3963 }
3964 return s;
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003967 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968 }
3969
3970 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003971 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003972 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3974 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003975
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 final long identity = Binder.clearCallingIdentity();
3977 try {
3978 if (DBG) {
3979 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3980 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3981 }
3982
3983 IccIoResult response =
3984 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3985 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3986 subId);
3987
3988 if (DBG) {
3989 log("Exchange SIM_IO [R]" + response);
3990 }
3991
3992 byte[] result = null;
3993 int length = 2;
3994 if (response.payload != null) {
3995 length = 2 + response.payload.length;
3996 result = new byte[length];
3997 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3998 } else {
3999 result = new byte[length];
4000 }
4001
4002 result[length - 1] = (byte) response.sw2;
4003 result[length - 2] = (byte) response.sw1;
4004 return result;
4005 } finally {
4006 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004007 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004008 }
4009
Nathan Haroldb3014052017-01-25 15:57:32 -08004010 /**
4011 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4012 * on a particular subscription
4013 */
sqianb6e41952018-03-12 14:54:01 -07004014 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4015 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4016 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4017 return null;
4018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004019
4020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 if (appType != TelephonyManager.APPTYPE_USIM
4023 && appType != TelephonyManager.APPTYPE_SIM) {
4024 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4025 return null;
4026 }
4027 Object response = sendRequest(
4028 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4029 if (response instanceof String[]) {
4030 return (String[]) response;
4031 }
4032 // Response is an Exception of some kind,
4033 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004034 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004035 } finally {
4036 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004037 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004038 }
4039
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004040 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004041 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4043 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004044
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4048 if (response.payload == null) {
4049 return "";
4050 }
Evan Charltonc66da362014-05-16 14:06:40 -07004051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004052 // Append the returned status code to the end of the response payload.
4053 String s = Integer.toHexString(
4054 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4055 s = IccUtils.bytesToHexString(response.payload) + s;
4056 return s;
4057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Evan Charltonc66da362014-05-16 14:06:40 -07004060 }
4061
Jake Hambye994d462014-02-03 13:10:13 -08004062 /**
4063 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4064 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4065 *
4066 * @param itemID the ID of the item to read
4067 * @return the NV item as a String, or null on error.
4068 */
4069 @Override
4070 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004071 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004072 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4073 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004074
4075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004078 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004079 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4080 return value;
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
Jake Hambye994d462014-02-03 13:10:13 -08004084 }
4085
4086 /**
4087 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4088 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4089 *
4090 * @param itemID the ID of the item to read
4091 * @param itemValue the value to write, as a String
4092 * @return true on success; false on any failure
4093 */
4094 @Override
4095 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004096 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4098 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4103 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004104 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004105 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4106 return success;
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
Jake Hambye994d462014-02-03 13:10:13 -08004110 }
4111
4112 /**
4113 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4114 * Used for device configuration by some CDMA operators.
4115 *
4116 * @param preferredRoamingList byte array containing the new PRL
4117 * @return true on success; false on any failure
4118 */
4119 @Override
4120 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4122 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004123
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4127 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4128 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4129 return success;
4130 } finally {
4131 Binder.restoreCallingIdentity(identity);
4132 }
Jake Hambye994d462014-02-03 13:10:13 -08004133 }
4134
4135 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004136 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004137 * Used for device configuration by some CDMA operators.
4138 *
chen xu6dac5ab2018-10-26 17:39:23 -07004139 * @param slotIndex - device slot.
4140 *
Jake Hambye994d462014-02-03 13:10:13 -08004141 * @return true on success; false on any failure
4142 */
4143 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004144 public boolean resetModemConfig(int slotIndex) {
4145 Phone phone = PhoneFactory.getPhone(slotIndex);
4146 if (phone != null) {
4147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4148 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149
chen xu6dac5ab2018-10-26 17:39:23 -07004150 final long identity = Binder.clearCallingIdentity();
4151 try {
4152 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4153 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4154 return success;
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004158 }
chen xu6dac5ab2018-10-26 17:39:23 -07004159 return false;
4160 }
4161
4162 /**
4163 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4164 *
4165 * @param slotIndex - device slot.
4166 *
4167 * @return true on success; false on any failure
4168 */
4169 @Override
4170 public boolean rebootModem(int slotIndex) {
4171 Phone phone = PhoneFactory.getPhone(slotIndex);
4172 if (phone != null) {
4173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4174 mApp, phone.getSubId(), "rebootModem");
4175
4176 final long identity = Binder.clearCallingIdentity();
4177 try {
4178 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4179 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4180 return success;
4181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
4184 }
4185 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004186 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004187
Svet Ganovb320e182015-04-16 12:30:10 -07004188 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004189 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004192 return new String[0];
4193 }
4194
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004195 final long identity = Binder.clearCallingIdentity();
4196 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004197 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 } finally {
4199 Binder.restoreCallingIdentity(identity);
4200 }
Wink Saville36469e72014-06-11 15:17:00 -07004201 }
4202
Brad Ebinger51f743a2017-01-23 13:50:20 -08004203 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004204 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4205 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004206 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004207 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004208 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004209
4210 final long identity = Binder.clearCallingIdentity();
4211 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004212 ImsResolver resolver = PhoneFactory.getImsResolver();
4213 if (resolver == null) {
4214 // may happen if the device does not support IMS.
4215 return;
4216 }
4217 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 } finally {
4219 Binder.restoreCallingIdentity(identity);
4220 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004221 }
4222
4223 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004224 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4225 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004226 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004227 public void disableIms(int slotId) {
4228 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229
4230 final long identity = Binder.clearCallingIdentity();
4231 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004232 ImsResolver resolver = PhoneFactory.getImsResolver();
4233 if (resolver == null) {
4234 // may happen if the device does not support IMS.
4235 return;
4236 }
4237 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004238 } finally {
4239 Binder.restoreCallingIdentity(identity);
4240 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004241 }
4242
4243 /**
4244 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4245 * feature or {@link null} if the service is not available. If the feature is available, the
4246 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4247 */
4248 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004249 IImsServiceFeatureCallback callback) {
4250 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004251
4252 final long identity = Binder.clearCallingIdentity();
4253 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004254 ImsResolver resolver = PhoneFactory.getImsResolver();
4255 if (resolver == null) {
4256 // may happen if the device does not support IMS.
4257 return null;
4258 }
4259 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004263 }
4264
4265 /**
4266 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4267 * feature during emergency calling or {@link null} if the service is not available. If the
4268 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4269 * listener for feature updates.
4270 */
4271 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4272 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004276 ImsResolver resolver = PhoneFactory.getImsResolver();
4277 if (resolver == null) {
4278 // may happen if the device does not support IMS.
4279 return null;
4280 }
4281 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004282 } finally {
4283 Binder.restoreCallingIdentity(identity);
4284 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004285 }
4286
Brad Ebinger5f64b052017-12-14 14:26:15 -08004287 /**
4288 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004289 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004290 */
4291 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4292 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293
4294 final long identity = Binder.clearCallingIdentity();
4295 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004296 ImsResolver resolver = PhoneFactory.getImsResolver();
4297 if (resolver == null) {
4298 // may happen if the device does not support IMS.
4299 return null;
4300 }
4301 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004302 } finally {
4303 Binder.restoreCallingIdentity(identity);
4304 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004305 }
4306
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004307 /**
4308 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004309 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004310 */
4311 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4312 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004316 ImsResolver resolver = PhoneFactory.getImsResolver();
4317 if (resolver == null) {
4318 // may happen if the device does not support IMS.
4319 return null;
4320 }
4321 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004322 } finally {
4323 Binder.restoreCallingIdentity(identity);
4324 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004325 }
4326
Brad Ebinger884c07b2018-02-15 16:17:40 -08004327 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004328 * Sets the ImsService Package Name that Telephony will bind to.
4329 *
4330 * @param slotId the slot ID that the ImsService should bind for.
4331 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4332 * ImsService is the device default ImsService.
4333 * @param packageName The package name of the application that contains the ImsService to bind
4334 * to.
4335 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4336 * @hide
4337 */
4338 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004339 int[] subIds = SubscriptionManager.getSubId(slotId);
4340 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4341 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4342 "setImsService");
4343
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004344 final long identity = Binder.clearCallingIdentity();
4345 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004346 ImsResolver resolver = PhoneFactory.getImsResolver();
4347 if (resolver == null) {
4348 // may happen if the device does not support IMS.
4349 return false;
4350 }
4351 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4352 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004356 }
4357
4358 /**
4359 * Return the ImsService configuration.
4360 *
4361 * @param slotId The slot that the ImsService is associated with.
4362 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4363 * the device default.
4364 * @return the package name of the ImsService configuration.
4365 */
4366 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004367 int[] subIds = SubscriptionManager.getSubId(slotId);
4368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4369 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4370 "getImsService");
4371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004372 final long identity = Binder.clearCallingIdentity();
4373 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004374 ImsResolver resolver = PhoneFactory.getImsResolver();
4375 if (resolver == null) {
4376 // may happen if the device does not support IMS.
4377 return "";
4378 }
4379 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 } finally {
4381 Binder.restoreCallingIdentity(identity);
4382 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004383 }
4384
Wink Saville36469e72014-06-11 15:17:00 -07004385 public void setImsRegistrationState(boolean registered) {
4386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387
4388 final long identity = Binder.clearCallingIdentity();
4389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004390 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
Wink Saville36469e72014-06-11 15:17:00 -07004394 }
4395
4396 /**
Stuart Scott54788802015-03-30 13:18:01 -07004397 * Set the network selection mode to automatic.
4398 *
4399 */
4400 @Override
4401 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4403 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404
Pengquan Menge92a50d2018-09-21 15:54:48 -07004405 if (!isActiveSubscription(subId)) {
4406 return;
4407 }
4408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 final long identity = Binder.clearCallingIdentity();
4410 try {
4411 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4412 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Stuart Scott54788802015-03-30 13:18:01 -07004416 }
4417
Pengquan Mengea84e042018-09-20 14:57:26 -07004418 /**
4419 * Ask the radio to connect to the input network and change selection mode to manual.
4420 *
4421 * @param subId the id of the subscription.
4422 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4423 * the operator to attach to.
4424 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4425 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4426 * normal network selection next time.
4427 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004428 */
4429 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004430 public boolean setNetworkSelectionModeManual(
4431 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4433 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004434
4435 if (!isActiveSubscription(subId)) {
4436 return false;
4437 }
4438
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004439 final long identity = Binder.clearCallingIdentity();
4440 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004441 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004442 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004443 if (DBG) {
4444 log("setNetworkSelectionModeManual: subId: " + subId
4445 + " operator: " + operatorInfo);
4446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004447 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4448 } finally {
4449 Binder.restoreCallingIdentity(identity);
4450 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004451 }
4452
4453 /**
4454 * Scans for available networks.
4455 */
4456 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004457 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4459 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004460 LocationAccessPolicy.LocationPermissionResult locationResult =
4461 LocationAccessPolicy.checkLocationPermission(mApp,
4462 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4463 .setCallingPackage(callingPackage)
4464 .setCallingPid(Binder.getCallingPid())
4465 .setCallingUid(Binder.getCallingUid())
4466 .setMethod("getCellNetworkScanResults")
4467 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4468 .build());
4469 switch (locationResult) {
4470 case DENIED_HARD:
4471 throw new SecurityException("Not allowed to access scan results -- location");
4472 case DENIED_SOFT:
4473 return null;
4474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475
Pengquan Menga1bb6272018-09-06 09:59:22 -07004476 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 try {
4478 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004479 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004484 }
4485
4486 /**
yinxub1bed742017-04-17 11:45:04 -07004487 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004488 *
yinxub1bed742017-04-17 11:45:04 -07004489 * @param subId id of the subscription
4490 * @param request contains the radio access networks with bands/channels to scan
4491 * @param messenger callback messenger for scan results or errors
4492 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004493 * @return the id of the requested scan which can be used to stop the scan.
4494 */
4495 @Override
4496 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004497 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4499 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004500 LocationAccessPolicy.LocationPermissionResult locationResult =
4501 LocationAccessPolicy.checkLocationPermission(mApp,
4502 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4503 .setCallingPackage(callingPackage)
4504 .setCallingPid(Binder.getCallingPid())
4505 .setCallingUid(Binder.getCallingUid())
4506 .setMethod("requestNetworkScan")
4507 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4508 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004509 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004510 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004511 if (e != null) {
4512 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4513 throw e;
4514 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004515 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004516 return TelephonyScanManager.INVALID_SCAN_ID;
4517 }
4518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004519 }
Hall Liu912dfd32019-04-25 14:02:26 -07004520 int callingUid = Binder.getCallingUid();
4521 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 return mNetworkScanRequestTracker.startNetworkScan(
4525 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004526 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004527 } finally {
4528 Binder.restoreCallingIdentity(identity);
4529 }
yinxu504e1392017-04-12 16:03:22 -07004530 }
4531
Hall Liub2ac8ef2019-02-28 15:56:23 -08004532 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004533 NetworkScanRequest request, int subId) {
4534 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4535 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4536 boolean hasNetworkScanPermission =
4537 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4538 == PERMISSION_GRANTED;
4539
4540 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4541 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4542 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004543 }
4544
4545 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4546 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004547 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4548 return new SecurityException("Specific channels must not be"
4549 + " scanned without location access.");
4550 }
4551 }
4552 }
4553
Hall Liub2ac8ef2019-02-28 15:56:23 -08004554 return null;
4555 }
4556
yinxu504e1392017-04-12 16:03:22 -07004557 /**
4558 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004559 *
4560 * @param subId id of the subscription
4561 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004562 */
4563 @Override
4564 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4566 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567
Hall Liu912dfd32019-04-25 14:02:26 -07004568 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 final long identity = Binder.clearCallingIdentity();
4570 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004571 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 } finally {
4573 Binder.restoreCallingIdentity(identity);
4574 }
yinxu504e1392017-04-12 16:03:22 -07004575 }
4576
4577 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004578 * Get the calculated preferred network type.
4579 * Used for debugging incorrect network type.
4580 *
4581 * @return the preferred network type, defined in RILConstants.java.
4582 */
4583 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004584 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004585 final Phone defaultPhone = getDefaultPhone();
4586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4587 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004588 return RILConstants.PREFERRED_NETWORK_MODE;
4589 }
4590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004594 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004595 } finally {
4596 Binder.restoreCallingIdentity(identity);
4597 }
Junda Liu84d15a22014-07-02 11:21:04 -07004598 }
4599
4600 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004601 * Get the preferred network type.
4602 * Used for device configuration by some CDMA operators.
4603 *
4604 * @return the preferred network type, defined in RILConstants.java.
4605 */
4606 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004607 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004608 TelephonyPermissions
4609 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4610 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611
4612 final long identity = Binder.clearCallingIdentity();
4613 try {
4614 if (DBG) log("getPreferredNetworkType");
4615 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4616 int networkType = (result != null ? result[0] : -1);
4617 if (DBG) log("getPreferredNetworkType: " + networkType);
4618 return networkType;
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
4621 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004622 }
4623
4624 /**
4625 * Set the preferred network type.
4626 * Used for device configuration by some CDMA operators.
4627 *
4628 * @param networkType the preferred network type, defined in RILConstants.java.
4629 * @return true on success; false on any failure.
4630 */
4631 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004632 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4634 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4639 Boolean success = (Boolean) sendRequest(
4640 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4641 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4642 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004643 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004644 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4645 }
4646 return success;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004649 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004650 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004651
4652 /**
Miaoa84611c2019-03-15 09:21:10 +08004653 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004654 *
Miaoa84611c2019-03-15 09:21:10 +08004655 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004656 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004657 * @hide
4658 */
4659 @Override
Miaoa84611c2019-03-15 09:21:10 +08004660 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004662 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004663 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 try {
Miaoa84611c2019-03-15 09:21:10 +08004665 if (phone != null) {
4666 return phone.hasMatchedTetherApnSetting();
4667 } else {
4668 return false;
4669 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004670 } finally {
4671 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004672 }
Junda Liu475951f2014-11-07 16:45:03 -08004673 }
4674
4675 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004676 * Set mobile data enabled
4677 * Used by the user through settings etc to turn on/off mobile data
4678 *
4679 * @param enable {@code true} turn turn data on, else {@code false}
4680 */
4681 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004682 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4684 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004685
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 int phoneId = mSubscriptionController.getPhoneId(subId);
4689 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4690 Phone phone = PhoneFactory.getPhone(phoneId);
4691 if (phone != null) {
4692 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004693 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004694 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004695 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 }
4697 } finally {
4698 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004699 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004700 }
4701
4702 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004703 * Get the user enabled state of Mobile Data.
4704 *
4705 * TODO: remove and use isUserDataEnabled.
4706 * This can't be removed now because some vendor codes
4707 * calls through ITelephony directly while they should
4708 * use TelephonyManager.
4709 *
4710 * @return true on enabled
4711 */
4712 @Override
4713 public boolean getDataEnabled(int subId) {
4714 return isUserDataEnabled(subId);
4715 }
4716
4717 /**
4718 * Get whether mobile data is enabled per user setting.
4719 *
4720 * There are other factors deciding whether mobile data is actually enabled, but they are
4721 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004722 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004723 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004724 *
4725 * @return {@code true} if data is enabled else {@code false}
4726 */
4727 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004728 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004729 try {
4730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4731 null);
4732 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4734 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004735 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736
4737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 int phoneId = mSubscriptionController.getPhoneId(subId);
4740 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4741 Phone phone = PhoneFactory.getPhone(phoneId);
4742 if (phone != null) {
4743 boolean retVal = phone.isUserDataEnabled();
4744 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4745 return retVal;
4746 } else {
4747 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4748 return false;
4749 }
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004752 }
4753 }
4754
4755 /**
4756 * Get whether mobile data is enabled.
4757 *
4758 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4759 * whether mobile data is actually enabled.
4760 *
4761 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4762 *
4763 * @return {@code true} if data is enabled else {@code false}
4764 */
4765 @Override
4766 public boolean isDataEnabled(int subId) {
4767 try {
4768 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4769 null);
4770 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4772 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004774
4775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 int phoneId = mSubscriptionController.getPhoneId(subId);
4778 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4779 Phone phone = PhoneFactory.getPhone(phoneId);
4780 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004781 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4783 return retVal;
4784 } else {
4785 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4786 return false;
4787 }
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004790 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004791 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004792
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004793 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4794 Phone phone) {
4795 //load access rules from carrier configs, and check those as well: b/139133814
4796 SubscriptionController subController = SubscriptionController.getInstance();
4797 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4798 || subController == null) return privilegeFromSim;
4799
4800 int uid = Binder.getCallingUid();
4801 PackageManager pkgMgr = phone.getContext().getPackageManager();
4802 String[] packages = pkgMgr.getPackagesForUid(uid);
4803
4804 final long identity = Binder.clearCallingIdentity();
4805 try {
4806 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4807 SubscriptionManager subManager = (SubscriptionManager)
4808 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4809 for (String pkg : packages) {
4810 if (subManager.canManageSubscription(subInfo, pkg)) {
4811 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4812 }
4813 }
4814 return privilegeFromSim;
4815 } finally {
4816 Binder.restoreCallingIdentity(identity);
4817 }
4818 }
4819
4820 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4821 String pkgName) {
4822 //load access rules from carrier configs, and check those as well: b/139133814
4823 SubscriptionController subController = SubscriptionController.getInstance();
4824 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4825 || subController == null) return privilegeFromSim;
4826
4827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4830 SubscriptionManager subManager = (SubscriptionManager)
4831 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4832 return subManager.canManageSubscription(subInfo, pkgName)
4833 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4834 } finally {
4835 Binder.restoreCallingIdentity(identity);
4836 }
4837 }
4838
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004839 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004840 public int getCarrierPrivilegeStatus(int subId) {
4841 final Phone phone = getPhone(subId);
4842 if (phone == null) {
4843 loge("getCarrierPrivilegeStatus: Invalid subId");
4844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4845 }
4846 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004847 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004848 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004849 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4850 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004851
4852 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4853 card.getCarrierPrivilegeStatusForCurrentTransaction(
4854 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004855 }
Junda Liu29340342014-07-10 15:23:27 -07004856
4857 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4859 final Phone phone = getPhone(subId);
4860 if (phone == null) {
4861 loge("getCarrierPrivilegeStatus: Invalid subId");
4862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4863 }
4864 UiccProfile profile =
4865 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4866 if (profile == null) {
4867 loge("getCarrierPrivilegeStatus: No UICC");
4868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4869 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004870 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4871 profile.getCarrierPrivilegeStatusForUid(
4872 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004873 }
4874
4875 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004876 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4877 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004879 }
4880
4881 int phoneId = SubscriptionManager.getPhoneId(subId);
4882 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004883 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004884 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4886 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004887 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4888 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4889 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004890 }
4891
4892 @Override
4893 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004894 if (TextUtils.isEmpty(pkgName))
4895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004896 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4897 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4898 UiccCard card = UiccController.getInstance().getUiccCard(i);
4899 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004900 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004901 continue;
4902 }
4903
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004904 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
4905 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4906 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004907 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4908 break;
4909 }
4910 }
4911
4912 return result;
Junda Liu29340342014-07-10 15:23:27 -07004913 }
Derek Tan89e89d42014-07-08 17:00:10 -07004914
4915 @Override
Junda Liue64de782015-04-16 17:19:16 -07004916 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4917 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4918 loge("phoneId " + phoneId + " is not valid.");
4919 return null;
4920 }
4921 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004922 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004923 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004924 return null ;
4925 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004926 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004927 }
4928
Amith Yamasani6e118872016-02-19 12:53:51 -08004929 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004930 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004932 List<String> privilegedPackages = new ArrayList<>();
4933 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004934 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4935 // has UICC in that slot.
4936 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004937 if (card.hasCarrierPrivilegeRules()) {
4938 if (packages == null) {
4939 // Only check packages in user 0 for now
4940 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004941 PackageManager.MATCH_DISABLED_COMPONENTS
4942 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09004943 | PackageManager.GET_SIGNING_CERTIFICATES,
4944 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004945 }
4946 for (int p = packages.size() - 1; p >= 0; p--) {
4947 PackageInfo pkgInfo = packages.get(p);
4948 if (pkgInfo != null && pkgInfo.packageName != null
4949 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004950 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004951 privilegedPackages.add(pkgInfo.packageName);
4952 }
4953 }
4954 }
4955 }
4956 return privilegedPackages;
4957 }
4958
chen xuf7e9fe82019-05-09 19:31:02 -07004959 @Override
4960 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4961 List<String> privilegedPackages = new ArrayList<>();
4962 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4963 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4964 }
4965 return privilegedPackages;
4966 }
4967
Wink Savilleb564aae2014-10-23 10:18:09 -07004968 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004969 final Phone phone = getPhone(subId);
4970 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004971 if (card == null) {
4972 loge("getIccId: No UICC");
4973 return null;
4974 }
4975 String iccId = card.getIccId();
4976 if (TextUtils.isEmpty(iccId)) {
4977 loge("getIccId: ICC ID is null or empty.");
4978 return null;
4979 }
4980 return iccId;
4981 }
4982
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004983 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004984 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4985 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4987 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004988
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 final long identity = Binder.clearCallingIdentity();
4990 try {
4991 final String iccId = getIccId(subId);
4992 final Phone phone = getPhone(subId);
4993 if (phone == null) {
4994 return false;
4995 }
4996 final String subscriberId = phone.getSubscriberId();
4997
4998 if (DBG_MERGE) {
4999 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5000 + subscriberId + " to " + number);
5001 }
5002
5003 if (TextUtils.isEmpty(iccId)) {
5004 return false;
5005 }
5006
5007 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5008
5009 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5010 if (alphaTag == null) {
5011 editor.remove(alphaTagPrefKey);
5012 } else {
5013 editor.putString(alphaTagPrefKey, alphaTag);
5014 }
5015
5016 // Record both the line number and IMSI for this ICCID, since we need to
5017 // track all merged IMSIs based on line number
5018 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5019 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5020 if (number == null) {
5021 editor.remove(numberPrefKey);
5022 editor.remove(subscriberPrefKey);
5023 } else {
5024 editor.putString(numberPrefKey, number);
5025 editor.putString(subscriberPrefKey, subscriberId);
5026 }
5027
5028 editor.commit();
5029 return true;
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005032 }
Derek Tan7226c842014-07-02 17:42:23 -07005033 }
5034
5035 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005036 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005037 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005038 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005039 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005040 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005041 return null;
5042 }
Derek Tan97ebb422014-09-05 16:55:38 -07005043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 final long identity = Binder.clearCallingIdentity();
5045 try {
5046 String iccId = getIccId(subId);
5047 if (iccId != null) {
5048 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5049 if (DBG_MERGE) {
5050 log("getLine1NumberForDisplay returning "
5051 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5052 }
5053 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005054 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5056 return null;
5057 } finally {
5058 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005059 }
Derek Tan7226c842014-07-02 17:42:23 -07005060 }
5061
5062 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005063 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005065 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005066 return null;
5067 }
Derek Tan97ebb422014-09-05 16:55:38 -07005068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 String iccId = getIccId(subId);
5072 if (iccId != null) {
5073 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5074 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5075 }
5076 return null;
5077 } finally {
5078 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005079 }
Derek Tan7226c842014-07-02 17:42:23 -07005080 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005081
5082 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005083 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005084 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5085 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005087 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5088 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005089 return null;
5090 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005091
Jordan Liub49b04b2019-05-06 14:45:15 -07005092 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5093 // the process, where TelephonyManager was instantiated.
5094 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005095 final long identity = Binder.clearCallingIdentity();
5096 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005097 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final TelephonyManager tele = TelephonyManager.from(context);
5099 final SubscriptionManager sub = SubscriptionManager.from(context);
5100
5101 // Figure out what subscribers are currently active
5102 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103
Jordan Liub49b04b2019-05-06 14:45:15 -07005104 // Only consider subs which match the current subId
5105 // This logic can be simplified. See b/131189269 for progress.
5106 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005107 activeSubscriberIds.add(tele.getSubscriberId(subId));
5108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109
5110 // First pass, find a number override for an active subscriber
5111 String mergeNumber = null;
5112 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5113 for (String key : prefs.keySet()) {
5114 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5115 final String subscriberId = (String) prefs.get(key);
5116 if (activeSubscriberIds.contains(subscriberId)) {
5117 final String iccId = key.substring(
5118 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5119 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5120 mergeNumber = (String) prefs.get(numberKey);
5121 if (DBG_MERGE) {
5122 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5123 + " for active subscriber " + subscriberId);
5124 }
5125 if (!TextUtils.isEmpty(mergeNumber)) {
5126 break;
5127 }
5128 }
5129 }
5130 }
5131
5132 // Shortcut when no active merged subscribers
5133 if (TextUtils.isEmpty(mergeNumber)) {
5134 return null;
5135 }
5136
5137 // Second pass, find all subscribers under that line override
5138 final ArraySet<String> result = new ArraySet<>();
5139 for (String key : prefs.keySet()) {
5140 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5141 final String number = (String) prefs.get(key);
5142 if (mergeNumber.equals(number)) {
5143 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5144 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5145 final String subscriberId = (String) prefs.get(subscriberKey);
5146 if (!TextUtils.isEmpty(subscriberId)) {
5147 result.add(subscriberId);
5148 }
5149 }
5150 }
5151 }
5152
5153 final String[] resultArray = result.toArray(new String[result.size()]);
5154 Arrays.sort(resultArray);
5155 if (DBG_MERGE) {
5156 Slog.d(LOG_TAG,
5157 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5158 }
5159 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005162 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005163 }
5164
5165 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005166 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5167 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 final TelephonyManager telephonyManager = mApp.getSystemService(
5172 TelephonyManager.class);
5173 String subscriberId = telephonyManager.getSubscriberId(subId);
5174 if (subscriberId == null) {
5175 if (DBG) {
5176 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5177 + subId);
5178 }
5179 return null;
5180 }
5181
5182 final SubscriptionInfo info = SubscriptionController.getInstance()
5183 .getSubscriptionInfo(subId);
5184 final ParcelUuid groupUuid = info.getGroupUuid();
5185 // If it doesn't belong to any group, return just subscriberId of itself.
5186 if (groupUuid == null) {
5187 return new String[]{subscriberId};
5188 }
5189
5190 // Get all subscriberIds from the group.
5191 final List<String> mergedSubscriberIds = new ArrayList<>();
5192 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5193 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5194 for (SubscriptionInfo subInfo : groupInfos) {
5195 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5196 if (subscriberId != null) {
5197 mergedSubscriberIds.add(subscriberId);
5198 }
5199 }
5200
5201 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204
5205 }
5206 }
5207
5208 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005209 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005210 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5211 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212
5213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 final Phone phone = getPhone(subId);
5216 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005220 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005221
5222 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005223 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005224 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5225 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005226 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227
5228 final long identity = Binder.clearCallingIdentity();
5229 try {
5230 final Phone phone = getPhone(subId);
5231 if (phone == null) {
5232 return false;
5233 }
5234 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5235 cdmaNonRoamingList);
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005238 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005239 }
5240
5241 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005242 @Deprecated
5243 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5244 enforceModifyPermission();
5245
5246 int returnValue = 0;
5247 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005248 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005249 if(result.exception == null) {
5250 if (result.result != null) {
5251 byte[] responseData = (byte[])(result.result);
5252 if(responseData.length > oemResp.length) {
5253 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5254 responseData.length + "bytes. Buffer Size is " +
5255 oemResp.length + "bytes.");
5256 }
5257 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5258 returnValue = responseData.length;
5259 }
5260 } else {
5261 CommandException ex = (CommandException) result.exception;
5262 returnValue = ex.getCommandError().ordinal();
5263 if(returnValue > 0) returnValue *= -1;
5264 }
5265 } catch (RuntimeException e) {
5266 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5267 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5268 if(returnValue > 0) returnValue *= -1;
5269 }
5270
5271 return returnValue;
5272 }
5273
5274 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005275 public void setRadioCapability(RadioAccessFamily[] rafs) {
5276 try {
5277 ProxyController.getInstance().setRadioCapability(rafs);
5278 } catch (RuntimeException e) {
5279 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5280 }
5281 }
5282
5283 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005284 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005285 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005286 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005287 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005288 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 final long identity = Binder.clearCallingIdentity();
5291 try {
chen xub97461a2018-10-26 14:17:57 -07005292 TelephonyPermissions
5293 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5294 mApp, phone.getSubId(), "getRadioAccessFamily");
5295 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
chen xub97461a2018-10-26 14:17:57 -07005299 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005300 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005301
5302 @Override
5303 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005304 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005305 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306
5307 final long identity = Binder.clearCallingIdentity();
5308 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005309 ImsManager.getInstance(defaultPhone.getContext(),
5310 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005314 }
5315
5316 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005317 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005319 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005320 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005321 return false;
5322 }
Svet Ganovb320e182015-04-16 12:30:10 -07005323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
5326 // Check the user preference and the system-level IMS setting. Even if the user has
5327 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5328 // In the long run, we may instead need to check if there exists a connection service
5329 // which can support video calling.
5330 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005331 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 return imsManager.isVtEnabledByPlatform()
5333 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5334 && imsManager.isVtEnabledByUser();
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
5337 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005338 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005339
Andrew Leea1239f22015-03-02 17:44:07 -08005340 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5343 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5344 return false;
5345 }
5346
5347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 CarrierConfigManager configManager =
5350 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005351 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
Andrew Leea1239f22015-03-02 17:44:07 -08005356 }
5357
5358 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 public boolean isWorldPhone(int subId, String callingPackage) {
5360 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5361 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5362 return false;
5363 }
5364
5365 final long identity = Binder.clearCallingIdentity();
5366 try {
5367 CarrierConfigManager configManager =
5368 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005369 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Andrew Leea1239f22015-03-02 17:44:07 -08005374 }
5375
Andrew Lee9431b832015-03-09 18:46:45 -07005376 @Override
5377 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005378 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005379 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005380 }
5381
5382 @Override
5383 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005386 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
Andrew Lee9431b832015-03-09 18:46:45 -07005390 }
5391
Hall Liuf6668912018-10-31 17:05:23 -07005392 /**
5393 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5394 * support for the feature and device firmware support.
5395 *
5396 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5397 */
5398 @Override
5399 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005401 final Phone phone = getPhone(subscriptionId);
5402 if (phone == null) {
5403 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5404 return false;
5405 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005407 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5409 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005410 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 return isCarrierSupported && isDeviceSupported;
5412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Hall Liu98187582018-01-22 19:15:32 -08005415 }
5416
Hall Liuf6668912018-10-31 17:05:23 -07005417 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005418 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5419 * RTT setting, will return true if the device and carrier both support RTT.
5420 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005421 */
5422 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423 final long identity = Binder.clearCallingIdentity();
5424 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005425 boolean isRttSupported = isRttSupported(subscriptionId);
5426 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005427 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005428 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5429 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5430 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005434 }
5435
Sanket Padawe7310cc72015-01-14 09:53:20 -08005436 /**
5437 * Returns the unique device ID of phone, for example, the IMEI for
5438 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5439 *
5440 * <p>Requires Permission:
5441 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5442 */
5443 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005444 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005445 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005446 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005447 return null;
5448 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005449 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005450 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5451 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005452 return null;
5453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454
5455 final long identity = Binder.clearCallingIdentity();
5456 try {
5457 return phone.getDeviceId();
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005461 }
5462
Ping Sunc67b7c22016-03-02 19:16:45 +08005463 /**
5464 * {@hide}
5465 * Returns the IMS Registration Status on a particular subid
5466 *
5467 * @param subId
5468 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005469 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005470 Phone phone = getPhone(subId);
5471 if (phone != null) {
5472 return phone.isImsRegistered();
5473 } else {
5474 return false;
5475 }
5476 }
5477
Santos Cordon7a1885b2015-02-03 11:15:19 -08005478 @Override
5479 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
5482 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005486 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005487
Tyler Gunnf70ed162019-04-03 15:28:53 -07005488 @Override
5489 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 Phone phone = getPhone(subscriptionId);
5493 if (phone == null) {
5494 return null;
5495 }
5496 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
5500 }
5501
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005502 /**
5503 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005504 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005505 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 final long identity = Binder.clearCallingIdentity();
5507 try {
5508 Phone phone = getPhone(subId);
5509 if (phone != null) {
5510 return phone.isWifiCallingEnabled();
5511 } else {
5512 return false;
5513 }
5514 } finally {
5515 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005516 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005517 }
5518
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005519 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005520 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005521 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005522 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 Phone phone = getPhone(subId);
5526 if (phone != null) {
5527 return phone.isVideoEnabled();
5528 } else {
5529 return false;
5530 }
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005533 }
5534 }
5535
5536 /**
5537 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5538 * defined in {@link ImsRegistrationImplBase}.
5539 */
5540 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005541 final long identity = Binder.clearCallingIdentity();
5542 try {
5543 Phone phone = getPhone(subId);
5544 if (phone != null) {
5545 return phone.getImsRegistrationTech();
5546 } else {
5547 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5548 }
5549 } finally {
5550 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005551 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005552 }
5553
Stuart Scott8eef64f2015-04-08 15:13:54 -07005554 @Override
5555 public void factoryReset(int subId) {
5556 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005557 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5558 return;
5559 }
5560
Svet Ganovcc087f82015-05-12 20:35:54 -07005561 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005562
Svet Ganovcc087f82015-05-12 20:35:54 -07005563 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005564 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5565 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005566 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005567 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005568 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005569 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5570 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005571 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005572 // There has been issues when Sms raw table somehow stores orphan
5573 // fragments. They lead to garbled message when new fragments come
5574 // in and combined with those stale ones. In case this happens again,
5575 // user can reset all network settings which will clean up this table.
5576 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005577 } finally {
5578 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005579 }
5580 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005581
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005582 private void cleanUpSmsRawTable(Context context) {
5583 ContentResolver resolver = context.getContentResolver();
5584 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5585 resolver.delete(uri, null, null);
5586 }
5587
Narayan Kamath1c496c22015-04-16 14:40:19 +01005588 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005589 public String getSimLocaleForSubscriber(int subId) {
5590 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5591 final Phone phone = getPhone(subId);
5592 if (phone == null) {
5593 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005594 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005595 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
5597 try {
chen xu5d3637b2019-01-21 23:31:38 -08005598 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5599 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005600 if (info == null) {
5601 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5602 return null;
5603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005604 // Try and fetch the locale from the carrier properties or from the SIM language
5605 // preferences (EF-PL and EF-LI)...
5606 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005608 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5609 if (localeFromDefaultSim != null) {
5610 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5611 if (DBG) log("Using locale from subId: " + subId + " locale: "
5612 + localeFromDefaultSim);
5613 return localeFromDefaultSim.toLanguageTag();
5614 } else {
5615 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005616 }
5617 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 // The SIM language preferences only store a language (e.g. fr = French), not an
5620 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5621 // the SIM and carrier preferences does not include a country we add the country
5622 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005623 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005624 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005625 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 return mccLocale.toLanguageTag();
5627 }
5628
5629 if (DBG) log("No locale found - returning null");
5630 return null;
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005634 }
5635
5636 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005637 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005638 }
5639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 /**
5641 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5642 */
5643 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005644 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005645 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005646
Chenjie Yu1ba97252018-01-11 18:16:20 -08005647 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005648 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005649
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005650 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005651 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5652 * representing the state of the modem.
5653 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005654 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5655 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005656 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005657 */
5658 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005659 public void requestModemActivityInfo(ResultReceiver result) {
5660 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005661 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005662
5663 final long identity = Binder.clearCallingIdentity();
5664 try {
5665 ModemActivityInfo ret = null;
5666 synchronized (mLastModemActivityInfo) {
5667 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5668 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005669 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005670 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005672 int[] txTimeMs = info.getTransmitTimeMillis();
5673 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005675 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 }
5677 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005678 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5679 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 mLastModemActivityInfo.setIdleTimeMillis(
5681 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005682 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5683 mLastModemActivityInfo.setReceiveTimeMillis(
5684 info.getReceiveTimeMillis() + mLastModemActivityInfo
5685 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005686 }
Chen Xud78231e2019-09-10 18:49:52 -07005687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5689 mLastModemActivityInfo.getSleepTimeMillis(),
5690 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005691 mLastModemActivityInfo.getTransmitTimeMillis(),
5692 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005693 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 Bundle bundle = new Bundle();
5695 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5696 result.send(0, bundle);
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005699 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005700 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005701
Siddharth Rayb8114062018-06-17 15:02:38 -07005702 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5703 // less than total activity duration.
5704 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5705 if (info == null) {
5706 return false;
5707 }
5708 int activityDurationMs =
5709 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5710 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005711 int[] txTimeMs = info.getTransmitTimeMillis();
5712 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5713 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005714 }
5715 return (info.isValid()
5716 && (info.getSleepTimeMillis() <= activityDurationMs)
5717 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005718 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005719 && (totalTxTimeMs <= activityDurationMs));
5720 }
5721
Jack Yu85bd38a2015-11-09 11:34:32 -08005722 /**
5723 * {@hide}
5724 * Returns the service state information on specified subscription.
5725 */
5726 @Override
5727 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005729 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005730 return null;
5731 }
5732
Hall Liuf19c44f2018-11-27 14:38:17 -08005733 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5734 LocationAccessPolicy.checkLocationPermission(mApp,
5735 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5736 .setCallingPackage(callingPackage)
5737 .setCallingPid(Binder.getCallingPid())
5738 .setCallingUid(Binder.getCallingUid())
5739 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005740 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005741 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5742 .build());
5743
5744 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5745 LocationAccessPolicy.checkLocationPermission(mApp,
5746 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5747 .setCallingPackage(callingPackage)
5748 .setCallingPid(Binder.getCallingPid())
5749 .setCallingUid(Binder.getCallingUid())
5750 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005751 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005752 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5753 .build());
5754 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5755 boolean hasFinePermission =
5756 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5757 boolean hasCoarsePermission =
5758 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005760 final long identity = Binder.clearCallingIdentity();
5761 try {
5762 final Phone phone = getPhone(subId);
5763 if (phone == null) {
5764 return null;
5765 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005766
Hall Liuf19c44f2018-11-27 14:38:17 -08005767 ServiceState ss = phone.getServiceState();
5768
5769 // Scrub out the location info in ServiceState depending on what level of access
5770 // the caller has.
5771 if (hasFinePermission) return ss;
5772 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5773 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005777 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005778
5779 /**
5780 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5781 *
5782 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5783 * voicemail ringtone.
5784 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5785 * PhoneAccount.
5786 */
5787 @Override
5788 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005789 final long identity = Binder.clearCallingIdentity();
5790 try {
5791 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5792 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005793 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005800 }
5801
5802 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005803 * Sets the per-account voicemail ringtone.
5804 *
5805 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5806 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5807 *
5808 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5809 * voicemail ringtone.
5810 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5811 * PhoneAccount.
5812 */
5813 @Override
5814 public void setVoicemailRingtoneUri(String callingPackage,
5815 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005816 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005817 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5818 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005820 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5821 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5822 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824
5825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5828 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005830 }
5831 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5832 } finally {
5833 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005834 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005835 }
5836
5837 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005838 * Returns whether vibration is set for voicemail notification in Phone settings.
5839 *
5840 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5841 * voicemail vibration setting.
5842 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5843 */
5844 @Override
5845 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 final long identity = Binder.clearCallingIdentity();
5847 try {
5848 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5849 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005850 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005852
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5854 } finally {
5855 Binder.restoreCallingIdentity(identity);
5856 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005857 }
5858
Youhan Wange64578a2016-05-02 15:32:42 -07005859 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005860 * Sets the per-account voicemail vibration.
5861 *
5862 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5863 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5864 *
5865 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5866 * voicemail vibration setting.
5867 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5868 * specific PhoneAccount.
5869 */
5870 @Override
5871 public void setVoicemailVibrationEnabled(String callingPackage,
5872 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005873 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005874 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5875 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005876 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5878 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5879 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005880 }
5881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5885 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005886 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005887 }
5888 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005891 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005892 }
5893
5894 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005895 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5896 *
5897 * @throws SecurityException if the caller does not have the required permission
5898 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005899 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005900 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005901 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005902 }
5903
5904 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005905 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5906 * permission.
5907 *
5908 * @throws SecurityException if the caller does not have the required permission
5909 */
5910 private void enforceSendSmsPermission() {
5911 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5912 }
5913
5914 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005915 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005916 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005917 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005918 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005919 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 final long identity = Binder.clearCallingIdentity();
5921 try {
5922 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005923 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005924 if (componentName == null) {
5925 throw new SecurityException(
5926 "Caller not current active visual voicemail package[null]");
5927 }
5928 String vvmPackage = componentName.getPackageName();
5929 if (!callingPackage.equals(vvmPackage)) {
5930 throw new SecurityException("Caller not current active visual voicemail package["
5931 + vvmPackage + "]");
5932 }
5933 } finally {
5934 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005935 }
5936 }
5937
5938 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005939 * Return the application ID for the app type.
5940 *
5941 * @param subId the subscription ID that this request applies to.
5942 * @param appType the uicc app type.
5943 * @return Application ID for specificied app type, or null if no uicc.
5944 */
5945 @Override
5946 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005947 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005948 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949
5950 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005951 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005952 if (phone == null) {
5953 return null;
5954 }
5955 String aid = null;
5956 try {
5957 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5958 .getApplicationByType(appType).getAid();
5959 } catch (Exception e) {
5960 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5961 }
5962 return aid;
5963 } finally {
5964 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005965 }
Youhan Wange64578a2016-05-02 15:32:42 -07005966 }
5967
Youhan Wang4001d252016-05-11 10:29:41 -07005968 /**
5969 * Return the Electronic Serial Number.
5970 *
5971 * @param subId the subscription ID that this request applies to.
5972 * @return ESN or null if error.
5973 */
5974 @Override
5975 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005976 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005977 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978
5979 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005980 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005981 if (phone == null) {
5982 return null;
5983 }
5984 String esn = null;
5985 try {
5986 esn = phone.getEsn();
5987 } catch (Exception e) {
5988 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5989 }
5990 return esn;
5991 } finally {
5992 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005993 }
Youhan Wang4001d252016-05-11 10:29:41 -07005994 }
5995
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005996 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005997 * Return the Preferred Roaming List Version.
5998 *
5999 * @param subId the subscription ID that this request applies to.
6000 * @return PRLVersion or null if error.
6001 */
6002 @Override
6003 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006004 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006005 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006
6007 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006008 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 if (phone == null) {
6010 return null;
6011 }
6012 String cdmaPrlVersion = null;
6013 try {
6014 cdmaPrlVersion = phone.getCdmaPrlVersion();
6015 } catch (Exception e) {
6016 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6017 }
6018 return cdmaPrlVersion;
6019 } finally {
6020 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006021 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006022 }
6023
6024 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006025 * Get snapshot of Telephony histograms
6026 * @return List of Telephony histograms
6027 * @hide
6028 */
6029 @Override
6030 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6032 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033
6034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 return RIL.getTelephonyRILTimingHistograms();
6037 } finally {
6038 Binder.restoreCallingIdentity(identity);
6039 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006040 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006041
6042 /**
6043 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006044 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6045 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006046 * Require system privileges. In the future we may add this to carrier APIs.
6047 *
Michele Berionne482f8202018-11-27 18:57:59 -08006048 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006049 */
6050 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006051 @TelephonyManager.SetCarrierRestrictionResult
6052 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006053 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006055
Michele Berionne482f8202018-11-27 18:57:59 -08006056 if (carrierRestrictionRules == null) {
6057 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006058 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006059
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006060 final long identity = Binder.clearCallingIdentity();
6061 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006062 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006063 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 } finally {
6065 Binder.restoreCallingIdentity(identity);
6066 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006067 }
6068
6069 /**
6070 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006071 * Get the allowed carrier list and the excluded carrier list, including the priority between
6072 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006073 * Require system privileges. In the future we may add this to carrier APIs.
6074 *
Michele Berionne482f8202018-11-27 18:57:59 -08006075 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006076 */
6077 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006078 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006079 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006080 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006081
6082 final long identity = Binder.clearCallingIdentity();
6083 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006084 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6085 if (response instanceof CarrierRestrictionRules) {
6086 return (CarrierRestrictionRules) response;
6087 }
6088 // Response is an Exception of some kind,
6089 // which is signalled to the user as a NULL retval
6090 return null;
6091 } catch (Exception e) {
6092 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6093 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006094 } finally {
6095 Binder.restoreCallingIdentity(identity);
6096 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006097 }
6098
fionaxu59545b42016-05-25 15:53:37 -07006099 /**
6100 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6101 * @param subId the subscription ID that this action applies to.
6102 * @param enabled control enable or disable metered apns.
6103 * {@hide}
6104 */
6105 @Override
6106 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6107 enforceModifyPermission();
6108 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109
6110 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006111 if (phone == null) {
6112 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6113 return;
6114 }
6115 try {
6116 phone.carrierActionSetMeteredApnsEnabled(enabled);
6117 } catch (Exception e) {
6118 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119 } finally {
6120 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006121 }
6122 }
6123
6124 /**
6125 * Action set from carrier signalling broadcast receivers to enable/disable radio
6126 * @param subId the subscription ID that this action applies to.
6127 * @param enabled control enable or disable radio.
6128 * {@hide}
6129 */
6130 @Override
6131 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6132 enforceModifyPermission();
6133 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134
6135 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006136 if (phone == null) {
6137 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6138 return;
6139 }
6140 try {
6141 phone.carrierActionSetRadioEnabled(enabled);
6142 } catch (Exception e) {
6143 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 } finally {
6145 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006146 }
6147 }
6148
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006149 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006150 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6151 * network status based on which carrier apps could apply actions accordingly,
6152 * enable/disable default url handler for example.
6153 *
6154 * @param subId the subscription ID that this action applies to.
6155 * @param report control start/stop reporting the default network status.
6156 * {@hide}
6157 */
6158 @Override
6159 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6160 enforceModifyPermission();
6161 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006162
6163 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006164 if (phone == null) {
6165 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6166 return;
6167 }
6168 try {
6169 phone.carrierActionReportDefaultNetworkStatus(report);
6170 } catch (Exception e) {
6171 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172 } finally {
6173 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006174 }
6175 }
6176
6177 /**
fionaxud9622282017-07-17 17:51:30 -07006178 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6179 * @param subId the subscription ID that this action applies to.
6180 * {@hide}
6181 */
6182 @Override
6183 public void carrierActionResetAll(int subId) {
6184 enforceModifyPermission();
6185 final Phone phone = getPhone(subId);
6186 if (phone == null) {
6187 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6188 return;
6189 }
6190 try {
6191 phone.carrierActionResetAll();
6192 } catch (Exception e) {
6193 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6194 }
6195 }
6196
6197 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006198 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6199 * bug report is being generated.
6200 */
6201 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006202 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006203 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6204 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006205 writer.println("Permission Denial: can't dump Phone from pid="
6206 + Binder.getCallingPid()
6207 + ", uid=" + Binder.getCallingUid()
6208 + "without permission "
6209 + android.Manifest.permission.DUMP);
6210 return;
6211 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006212 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006213 }
Jack Yueb89b242016-06-22 13:27:47 -07006214
Brad Ebingerdac2f002018-04-03 15:17:52 -07006215 @Override
6216 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6217 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6218 throws RemoteException {
6219 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6220 }
6221
Jack Yueb89b242016-06-22 13:27:47 -07006222 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006223 * Get aggregated video call data usage since boot.
6224 *
6225 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6226 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006227 * {@hide}
6228 */
6229 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006230 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006231 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6232 null);
6233
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 // NetworkStatsService keeps tracking the active network interface and identity. It
6237 // records the delta with the corresponding network identity.
6238 // We just return the total video call data usage snapshot since boot.
6239 Phone phone = getPhone(subId);
6240 if (phone != null) {
6241 return phone.getVtDataUsage(perUidStats);
6242 }
6243 return null;
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006246 }
Jack Yueb89b242016-06-22 13:27:47 -07006247 }
Jack Yu75ab2952016-07-08 14:29:33 -07006248
6249 /**
6250 * Policy control of data connection. Usually used when data limit is passed.
6251 * @param enabled True if enabling the data, otherwise disabling.
6252 * @param subId Subscription index
6253 * {@hide}
6254 */
6255 @Override
6256 public void setPolicyDataEnabled(boolean enabled, int subId) {
6257 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 Phone phone = getPhone(subId);
6262 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006263 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 }
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006267 }
6268 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006269
6270 /**
6271 * Get Client request stats
6272 * @return List of Client Request Stats
6273 * @hide
6274 */
6275 @Override
6276 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006277 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006278 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006279 return null;
6280 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006281 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 final long identity = Binder.clearCallingIdentity();
6284 try {
6285 if (phone != null) {
6286 return phone.getClientRequestStats();
6287 }
6288
6289 return null;
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
6292 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006293 }
6294
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006295 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006296 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006297 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006298 }
Jack Yueb4124c2017-02-16 15:32:43 -08006299
6300 /**
Grace Chen70990072017-03-24 17:21:30 -07006301 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006302 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006303 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006304 * @param state State of SIM (power down, power up, pass through)
6305 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6306 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6307 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006308 *
6309 **/
6310 @Override
Grace Chen70990072017-03-24 17:21:30 -07006311 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006312 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006313 Phone phone = PhoneFactory.getPhone(slotIndex);
6314
vagdeviaf9a5b92018-08-15 16:01:53 -07006315 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 final long identity = Binder.clearCallingIdentity();
6318 try {
6319 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006320 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006321 }
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006324 }
6325 }
Shuo Qiandd210312017-04-12 22:11:33 +00006326
Tyler Gunn65d45c22017-06-05 11:22:26 -07006327 private boolean isUssdApiAllowed(int subId) {
6328 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006329 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006330 if (configManager == null) {
6331 return false;
6332 }
6333 PersistableBundle pb = configManager.getConfigForSubId(subId);
6334 if (pb == null) {
6335 return false;
6336 }
6337 return pb.getBoolean(
6338 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6339 }
6340
Shuo Qiandd210312017-04-12 22:11:33 +00006341 /**
6342 * Check if phone is in emergency callback mode
6343 * @return true if phone is in emergency callback mode
6344 * @param subId sub id
6345 */
goneil9c5f4872017-12-05 14:07:56 -08006346 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006347 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006348 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006349 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006350
6351 final long identity = Binder.clearCallingIdentity();
6352 try {
6353 if (phone != null) {
6354 return phone.isInEcm();
6355 } else {
6356 return false;
6357 }
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006360 }
6361 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006362
6363 /**
6364 * Get the current signal strength information for the given subscription.
6365 * Because this information is not updated when the device is in a low power state
6366 * it should not be relied-upon to be current.
6367 * @param subId Subscription index
6368 * @return the most recent cached signal strength info from the modem
6369 */
6370 @Override
6371 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006372 final long identity = Binder.clearCallingIdentity();
6373 try {
6374 Phone p = getPhone(subId);
6375 if (p == null) {
6376 return null;
6377 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 return p.getSignalStrength();
6380 } finally {
6381 Binder.restoreCallingIdentity(identity);
6382 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006383 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006384
Pengquan Meng77b7f132018-08-22 14:49:57 -07006385 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006386 * Get the current modem radio state for the given slot.
6387 * @param slotIndex slot index.
6388 * @param callingPackage the name of the package making the call.
6389 * @return the current radio power state from the modem
6390 */
6391 @Override
6392 public int getRadioPowerState(int slotIndex, String callingPackage) {
6393 Phone phone = PhoneFactory.getPhone(slotIndex);
6394 if (phone != null) {
6395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6396 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6397 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6398 }
6399
6400 final long identity = Binder.clearCallingIdentity();
6401 try {
6402 return phone.getRadioPowerState();
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
6405 }
6406 }
6407 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6408 }
6409
6410 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006411 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6412 *
6413 * <p>Requires one of the following permissions:
6414 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6415 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6416 * privileges.
6417 *
6418 * @param subId subscription id
6419 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6420 * {@code false}.
6421 */
6422 @Override
6423 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006424 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6425 null /* message */);
6426
Pengquan Menga1bb6272018-09-06 09:59:22 -07006427 boolean isEnabled = false;
6428 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006429 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006430 Phone phone = getPhone(subId);
6431 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006432 } catch (Exception e) {
6433 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6434 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006435 } finally {
6436 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006438 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006439 }
6440
6441
6442 /**
6443 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6444 *
6445 * <p> Requires permission:
6446 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6447 * privileges.
6448 *
6449 * @param subId subscription id
6450 * @param isEnabled {@code true} means enable, {@code false} means disable.
6451 */
6452 @Override
6453 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6455 mApp, subId, "setDataRoamingEnabled");
6456
Pengquan Menga1bb6272018-09-06 09:59:22 -07006457 final long identity = Binder.clearCallingIdentity();
6458 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006459 Phone phone = getPhone(subId);
6460 if (phone != null) {
6461 phone.setDataRoamingEnabled(isEnabled);
6462 }
6463 } finally {
6464 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006465 }
6466 }
6467
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006468 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006469 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006470 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6471 mApp, subId, "isManualNetworkSelectionAllowed");
6472
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006473 boolean isAllowed = true;
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006476 Phone phone = getPhone(subId);
6477 if (phone != null) {
6478 isAllowed = phone.isCspPlmnEnabled();
6479 }
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 return isAllowed;
6484 }
6485
6486 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006487 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006488 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006489 try {
6490 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006491 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006492 } catch (SecurityException e) {
6493 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6494 // has carrier privileges on an active UICC
6495 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6496 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006497 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006498 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006499 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006500
6501 final long identity = Binder.clearCallingIdentity();
6502 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006503 UiccController uiccController = UiccController.getInstance();
6504 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006505 if (hasReadPermission) {
6506 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006507 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006508
6509 // Remove private info if the caller doesn't have access
6510 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6511 for (UiccCardInfo cardInfo : cardInfos) {
6512 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6513 // is available
6514 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6515 if (card == null || card.getUiccProfile() == null) {
6516 // assume no access if the card or profile is unavailable
6517 filteredInfos.add(cardInfo.getUnprivileged());
6518 continue;
6519 }
6520 UiccProfile profile = card.getUiccProfile();
6521 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6522 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6523 filteredInfos.add(cardInfo);
6524 } else {
6525 filteredInfos.add(cardInfo.getUnprivileged());
6526 }
6527 }
6528 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006535 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006536 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6541 if (slots == null) {
6542 Rlog.i(LOG_TAG, "slots is null.");
6543 return null;
6544 }
6545
6546 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6547 for (int i = 0; i < slots.length; i++) {
6548 UiccSlot slot = slots[i];
6549 if (slot == null) {
6550 continue;
6551 }
6552
Jordan Liu7be7e652019-05-06 18:55:02 +00006553 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006554 UiccCard card = slot.getUiccCard();
6555 if (card != null) {
6556 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006557 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006558 cardId = slot.getEid();
6559 if (TextUtils.isEmpty(cardId)) {
6560 cardId = slot.getIccId();
6561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 }
6563
Jordan Liu857451f2019-05-09 16:35:35 -07006564 if (cardId != null) {
6565 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6566 // if cardId is an EID, it's all digits so this is fine
6567 cardId = IccUtils.stripTrailingFs(cardId);
6568 }
6569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006570 int cardState = 0;
6571 switch (slot.getCardState()) {
6572 case CARDSTATE_ABSENT:
6573 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6574 break;
6575 case CARDSTATE_PRESENT:
6576 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6577 break;
6578 case CARDSTATE_ERROR:
6579 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6580 break;
6581 case CARDSTATE_RESTRICTED:
6582 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6583 break;
6584 default:
6585 break;
6586
6587 }
6588
6589 infos[i] = new UiccSlotInfo(
6590 slot.isActive(),
6591 slot.isEuicc(),
6592 cardId,
6593 cardState,
6594 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006595 slot.isExtendedApduSupported(),
6596 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006597 }
6598 return infos;
6599 } finally {
6600 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006602 }
6603
6604 @Override
6605 public boolean switchSlots(int[] physicalSlots) {
6606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607
6608 final long identity = Binder.clearCallingIdentity();
6609 try {
6610 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006614 }
Jack Yu4c988042018-02-27 15:30:01 -08006615
6616 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006617 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return UiccController.getInstance().getCardIdForDefaultEuicc();
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
6624 }
6625
6626 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006627 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6628 enforceModifyPermission();
6629 final Phone phone = getPhone(subId);
6630 if (phone == null) {
6631 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6632 return;
6633 }
6634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 final long identity = Binder.clearCallingIdentity();
6636 try {
6637 phone.setRadioIndicationUpdateMode(filters, mode);
6638 } finally {
6639 Binder.restoreCallingIdentity(identity);
6640 }
Jack Yu4c988042018-02-27 15:30:01 -08006641 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006642
6643 /**
goneil47ffb6e2018-04-06 15:40:58 -07006644 * A test API to reload the UICC profile.
6645 *
6646 * <p>Requires that the calling app has permission
6647 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6648 * @hide
6649 */
6650 @Override
6651 public void refreshUiccProfile(int subId) {
6652 enforceModifyPermission();
6653
6654 final long identity = Binder.clearCallingIdentity();
6655 try {
6656 Phone phone = getPhone(subId);
6657 if (phone == null) {
6658 return;
6659 }
6660 UiccCard uiccCard = phone.getUiccCard();
6661 if (uiccCard == null) {
6662 return;
6663 }
6664 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6665 if (uiccProfile == null) {
6666 return;
6667 }
6668 uiccProfile.refresh();
6669 } finally {
6670 Binder.restoreCallingIdentity(identity);
6671 }
6672 }
6673
6674 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006675 * Returns false if the mobile data is disabled by default, otherwise return true.
6676 */
6677 private boolean getDefaultDataEnabled() {
6678 return "true".equalsIgnoreCase(
6679 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6680 }
6681
6682 /**
6683 * Returns true if the data roaming is enabled by default, i.e the system property
6684 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6685 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6686 */
6687 private boolean getDefaultDataRoamingEnabled(int subId) {
6688 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006689 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006690 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6691 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6692 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6693 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6694 return isDataRoamingEnabled;
6695 }
6696
6697 /**
6698 * Returns the default network type for the given {@code subId}, if the default network type is
6699 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6700 */
6701 private int getDefaultNetworkType(int subId) {
6702 return Integer.parseInt(
6703 TelephonyManager.getTelephonyProperty(
6704 mSubscriptionController.getPhoneId(subId),
6705 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6706 String.valueOf(Phone.PREFERRED_NT_MODE)));
6707 }
fionaxua13278b2018-03-21 00:08:13 -07006708
6709 @Override
6710 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006711 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006712 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
6716 final Phone phone = getPhone(subId);
6717 if (phone == null) {
6718 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6719 return;
6720 }
chen xueaba88a2019-03-15 13:15:10 -07006721 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6722 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 } finally {
6724 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006725 }
fionaxua13278b2018-03-21 00:08:13 -07006726 }
6727
6728 @Override
6729 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006730 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006731
6732 final long identity = Binder.clearCallingIdentity();
6733 try {
6734 final Phone phone = getPhone(subId);
6735 if (phone == null) {
6736 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6737 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6738 }
6739 return phone.getCarrierIdListVersion();
6740 } finally {
6741 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006742 }
fionaxua13278b2018-03-21 00:08:13 -07006743 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006744
6745 @Override
6746 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6748 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6749 return -1;
6750 }
6751
6752 final long identity = Binder.clearCallingIdentity();
6753 try {
6754 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6755 } finally {
6756 Binder.restoreCallingIdentity(identity);
6757 }
6758 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006759
6760 @Override
6761 public int getCdmaRoamingMode(int subId) {
6762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6763 mApp, subId, "getCdmaRoamingMode");
6764
6765 final long identity = Binder.clearCallingIdentity();
6766 try {
6767 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770 }
6771 }
6772
6773 @Override
6774 public boolean setCdmaRoamingMode(int subId, int mode) {
6775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6776 mApp, subId, "setCdmaRoamingMode");
6777
6778 final long identity = Binder.clearCallingIdentity();
6779 try {
6780 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6781 } finally {
6782 Binder.restoreCallingIdentity(identity);
6783 }
6784 }
6785
6786 @Override
6787 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6789 mApp, subId, "setCdmaSubscriptionMode");
6790
6791 final long identity = Binder.clearCallingIdentity();
6792 try {
6793 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6794 } finally {
6795 Binder.restoreCallingIdentity(identity);
6796 }
6797 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006798
6799 private void ensureUserRunning(int userId) {
6800 if (!mUserManager.isUserRunning(userId)) {
6801 throw new IllegalStateException("User " + userId + " does not exist or not running");
6802 }
6803 }
6804
6805 /**
6806 * Returns a list of SMS apps on a given user.
6807 *
6808 * Only the shell user (UID 2000 or 0) can call it.
6809 * Target user must be running.
6810 */
6811 @Override
6812 public String[] getSmsApps(int userId) {
6813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6814 ensureUserRunning(userId);
6815
6816 final Collection<SmsApplicationData> apps =
6817 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6818
6819 String[] ret = new String[apps.size()];
6820 int i = 0;
6821 for (SmsApplicationData app : apps) {
6822 ret[i++] = app.mPackageName;
6823 }
6824 return ret;
6825 }
6826
6827 /**
6828 * Returns the default SMS app package name on a given user.
6829 *
6830 * Only the shell user (UID 2000 or 0) can call it.
6831 * Target user must be running.
6832 */
6833 @Override
6834 public String getDefaultSmsApp(int userId) {
6835 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6836 ensureUserRunning(userId);
6837
6838 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6839 /* updateIfNeeded= */ true, userId);
6840 return cn == null ? null : cn.getPackageName();
6841 }
6842
6843 /**
6844 * Set a package as the default SMS app on a given user.
6845 *
6846 * Only the shell user (UID 2000 or 0) can call it.
6847 * Target user must be running.
6848 */
6849 @Override
6850 public void setDefaultSmsApp(int userId, String packageName) {
6851 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6852 ensureUserRunning(userId);
6853
6854 boolean found = false;
6855 for (String pkg : getSmsApps(userId)) {
6856 if (TextUtils.equals(packageName, pkg)) {
6857 found = true;
6858 break;
6859 }
6860 }
6861 if (!found) {
6862 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6863 }
6864
6865 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6866 }
sqianc5eccab2018-10-19 18:46:41 -07006867
6868 @Override
sqian8c685422019-02-22 15:55:18 -08006869 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006870 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006872 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006873 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6874 }
6875 final long identity = Binder.clearCallingIdentity();
6876 try {
sqian854d44b2018-12-12 16:48:18 -08006877 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6878 for (Phone phone: PhoneFactory.getPhones()) {
6879 if (phone.getEmergencyNumberTracker() != null
6880 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6881 emergencyNumberListInternal.put(
6882 phone.getSubId(),
6883 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6884 }
sqian11b7a0e2018-12-05 18:48:28 -08006885 }
sqian854d44b2018-12-12 16:48:18 -08006886 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006887 } finally {
6888 Binder.restoreCallingIdentity(identity);
6889 }
sqianc5eccab2018-10-19 18:46:41 -07006890 }
6891
6892 @Override
sqian8c685422019-02-22 15:55:18 -08006893 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006895 if (!exactMatch) {
6896 TelephonyPermissions
6897 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006898 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006899 }
6900 final long identity = Binder.clearCallingIdentity();
6901 try {
sqian854d44b2018-12-12 16:48:18 -08006902 for (Phone phone: PhoneFactory.getPhones()) {
6903 if (phone.getEmergencyNumberTracker() != null
6904 && phone.getEmergencyNumberTracker() != null) {
6905 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6906 number, exactMatch)) {
6907 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006908 }
6909 }
sqian11b7a0e2018-12-05 18:48:28 -08006910 }
6911 return false;
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
6915 }
6916
sqianf4ca7ed2019-01-15 18:32:07 -08006917 /**
6918 * Update emergency number list for test mode.
6919 */
6920 @Override
6921 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6923 "updateEmergencyNumberListTestMode");
6924
6925 final long identity = Binder.clearCallingIdentity();
6926 try {
6927 for (Phone phone: PhoneFactory.getPhones()) {
6928 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6929 if (tracker != null) {
6930 tracker.executeEmergencyNumberTestModeCommand(action, num);
6931 }
6932 }
6933 } finally {
6934 Binder.restoreCallingIdentity(identity);
6935 }
6936 }
6937
6938 /**
6939 * Get the full emergency number list for test mode.
6940 */
6941 @Override
6942 public List<String> getEmergencyNumberListTestMode() {
6943 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6944 "getEmergencyNumberListTestMode");
6945
6946 final long identity = Binder.clearCallingIdentity();
6947 try {
6948 Set<String> emergencyNumbers = new HashSet<>();
6949 for (Phone phone: PhoneFactory.getPhones()) {
6950 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6951 if (tracker != null) {
6952 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6953 emergencyNumbers.add(num.getNumber());
6954 }
6955 }
6956 }
6957 return new ArrayList<>(emergencyNumbers);
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
6961 }
6962
chen xud6b45bd2018-10-30 22:27:10 -07006963 @Override
6964 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6965 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6966 Phone phone = getPhone(subId);
6967 if (phone == null) {
6968 return null;
6969 }
6970 final long identity = Binder.clearCallingIdentity();
6971 try {
6972 UiccProfile profile = UiccController.getInstance()
6973 .getUiccProfileForPhone(phone.getPhoneId());
6974 if (profile != null) {
6975 return profile.getCertsFromCarrierPrivilegeAccessRules();
6976 }
6977 } finally {
6978 Binder.restoreCallingIdentity(identity);
6979 }
6980 return null;
6981 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006982
6983 /**
6984 * Enable or disable a modem stack.
6985 */
6986 @Override
6987 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6988 enforceModifyPermission();
6989
6990 final long identity = Binder.clearCallingIdentity();
6991 try {
6992 Phone phone = PhoneFactory.getPhone(slotIndex);
6993 if (phone == null) {
6994 return false;
6995 } else {
6996 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6997 }
6998 } finally {
6999 Binder.restoreCallingIdentity(identity);
7000 }
7001 }
Michelecea4cf22018-12-21 15:00:11 -08007002
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007003 /**
7004 * Whether a modem stack is enabled or not.
7005 */
7006 @Override
7007 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7008 Phone phone = PhoneFactory.getPhone(slotIndex);
7009 if (phone == null) return false;
7010
7011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7012 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7013 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7014 }
7015
7016 final long identity = Binder.clearCallingIdentity();
7017 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007018 try {
7019 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7020 } catch (NoSuchElementException ex) {
7021 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7022 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
7026 }
7027
Michelecea4cf22018-12-21 15:00:11 -08007028 @Override
Michele0ea7d782019-03-19 14:58:42 -07007029 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007030 enforceModifyPermission();
7031
7032 final long identity = Binder.clearCallingIdentity();
7033 try {
7034 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007035 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007036 .commit();
7037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
7040 }
7041
7042 @Override
Michele0ea7d782019-03-19 14:58:42 -07007043 @TelephonyManager.IsMultiSimSupportedResult
7044 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007046 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7047 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007048 }
Michelecea4cf22018-12-21 15:00:11 -08007049
7050 final long identity = Binder.clearCallingIdentity();
7051 try {
Michele0ea7d782019-03-19 14:58:42 -07007052 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007053 } finally {
7054 Binder.restoreCallingIdentity(identity);
7055 }
7056 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007057
Michele0ea7d782019-03-19 14:58:42 -07007058 @TelephonyManager.IsMultiSimSupportedResult
7059 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007060 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7061 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7062 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007063 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7064 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007065 }
7066 // Check if the hardware supports multisim functionality. If usage of multisim is not
7067 // supported by the modem, indicate that it is restricted.
7068 PhoneCapability staticCapability =
7069 mPhoneConfigurationManager.getStaticPhoneCapability();
7070 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007071 loge("isMultiSimSupportedInternal: no static configuration available");
7072 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007073 }
7074 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007075 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7076 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007077 }
7078 // Check if support of multiple SIMs is restricted by carrier
7079 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007080 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007081 }
7082
Michele0ea7d782019-03-19 14:58:42 -07007083 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007084 }
7085
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007086 /**
7087 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007088 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7089 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7090 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007091 * @param numOfSims number of active sims we want to switch to
7092 */
7093 @Override
7094 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007095 if (numOfSims == 1) {
7096 enforceModifyPermission();
7097 } else {
7098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7099 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7100 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007101 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007102
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007103 try {
Michele30b57b22019-03-01 12:01:14 -08007104 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007105 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007106 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7107 return;
7108 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007109 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
7112 }
7113 }
7114
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007115 @Override
7116 public boolean isApplicationOnUicc(int subId, int appType) {
7117 enforceReadPrivilegedPermission("isApplicationOnUicc");
7118 Phone phone = getPhone(subId);
7119 if (phone == null) {
7120 return false;
7121 }
7122 final long identity = Binder.clearCallingIdentity();
7123 try {
7124 UiccCard uiccCard = phone.getUiccCard();
7125 if (uiccCard == null) {
7126 return false;
7127 }
7128 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7129 if (uiccProfile == null) {
7130 return false;
7131 }
7132 if (TelephonyManager.APPTYPE_SIM <= appType
7133 && appType <= TelephonyManager.APPTYPE_ISIM) {
7134 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7135 }
7136 return false;
7137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
7140 }
7141
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007142 /**
chen xub4baa772019-04-03 10:23:41 -07007143 * Get whether making changes to modem configurations will trigger reboot.
7144 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007145 */
7146 @Override
chen xub4baa772019-04-03 10:23:41 -07007147 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7149 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7150 return false;
7151 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
7159
Nathan Harold29f5f052019-02-15 13:41:57 -08007160 private void updateModemStateMetrics() {
7161 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7162 // TODO: check the state for each modem if the api is ready.
7163 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7164 }
7165
Pengquan Meng3889a572019-01-23 11:16:29 -08007166 @Override
7167 public int[] getSlotsMapping() {
7168 enforceReadPrivilegedPermission("getSlotsMapping");
7169
7170 final long identity = Binder.clearCallingIdentity();
7171 try {
7172 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7173 // All logical slots should have a mapping to a physical slot.
7174 int[] logicalSlotsMapping = new int[phoneCount];
7175 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7176 for (int i = 0; i < slotInfos.length; i++) {
7177 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7178 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7179 }
7180 }
7181 return logicalSlotsMapping;
7182 } finally {
7183 Binder.restoreCallingIdentity(identity);
7184 }
7185 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007186
7187 /**
7188 * Get the IRadio HAL Version
7189 */
7190 @Override
7191 public int getRadioHalVersion() {
7192 Phone phone = getDefaultPhone();
7193 if (phone == null) return -1;
7194 HalVersion hv = phone.getHalVersion();
7195 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7196 return hv.major * 100 + hv.minor;
7197 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007198
7199 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007200 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7201 * corresponding network requests on a subId.
7202 *
7203 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007204 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007205 * 2) APN is un-metered for this subscription, or
7206 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7207 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7208 *
7209 * @return whether data is allowed for a apn type.
7210 *
7211 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007212 */
7213 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007214 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007215 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007216 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7217 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007218 }
7219
7220 // Now that all security checks passes, perform the operation as ourselves.
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
7223 Phone phone = getPhone(subId);
7224 if (phone == null) return false;
7225
Jack Yu41407ee2019-05-13 16:54:09 -07007226 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007227 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7228 } finally {
7229 Binder.restoreCallingIdentity(identity);
7230 }
7231 }
7232
7233 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007234 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007235 enforceReadPrivilegedPermission("isApnMetered");
7236
7237 // Now that all security checks passes, perform the operation as ourselves.
7238 final long identity = Binder.clearCallingIdentity();
7239 try {
7240 Phone phone = getPhone(subId);
7241 if (phone == null) return true; // By default return true.
7242
Jack Yu41407ee2019-05-13 16:54:09 -07007243 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
7247 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007248
7249 @Override
7250 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7251 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7252 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7253 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7254 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7255 }
7256 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7257 Intent intent = new Intent();
7258 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7259 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7260 // Bring up choose default SMS subscription dialog right now
7261 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7262 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7263 mApp.startActivity(intent);
7264 }
chen xud5ca2d52019-05-28 15:20:57 -07007265
7266 @Override
7267 public String getMmsUAProfUrl(int subId) {
7268 //TODO investigate if this API should require proper permission check in R b/133791609
7269 final long identity = Binder.clearCallingIdentity();
7270 try {
7271 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7272 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7273 } finally {
7274 Binder.restoreCallingIdentity(identity);
7275 }
7276 }
7277
7278 @Override
7279 public String getMmsUserAgent(int subId) {
7280 //TODO investigate if this API should require proper permission check in R b/133791609
7281 final long identity = Binder.clearCallingIdentity();
7282 try {
7283 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7284 .getString(com.android.internal.R.string.config_mms_user_agent);
7285 } finally {
7286 Binder.restoreCallingIdentity(identity);
7287 }
7288 }
Jack Yub07d4972019-05-28 16:12:25 -07007289
7290 @Override
7291 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7292 enforceModifyPermission();
7293
7294 // Now that all security checks passes, perform the operation as ourselves.
7295 final long identity = Binder.clearCallingIdentity();
7296 try {
7297 Phone phone = getPhone(subId);
7298 if (phone == null) return false;
7299
7300 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7301 } finally {
7302 Binder.restoreCallingIdentity(identity);
7303 }
7304 }
7305
7306 @Override
7307 public boolean isDataAllowedInVoiceCall(int subId) {
7308 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7309
7310 // Now that all security checks passes, perform the operation as ourselves.
7311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 Phone phone = getPhone(subId);
7314 if (phone == null) return false;
7315
7316 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
7320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007321}