blob: ae459366b9b608d9097aa2de663fa24cbf80bcb5 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070047import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070064import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080065import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070067import android.telephony.CellInfoGsm;
68import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070069import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070071import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070072import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080073import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070074import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070076import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080077import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080078import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070079import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080080import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070081import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080083import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080084import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070087import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080089import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000090import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070091import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070095import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070098import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700102import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsMmTelFeature;
104import android.telephony.ims.aidl.IImsRcsFeature;
105import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800107import android.telephony.ims.feature.MmTelFeature;
108import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800109import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Andrew Lee312e8172014-10-23 17:01:36 -0700116import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800117import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700119import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700120import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800121import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800125import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700126import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800127import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700130import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700132import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700133import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700135import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800136import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700137import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700138import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700139import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700140import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700141import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import com.android.internal.telephony.SmsApplication;
144import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800153import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700154import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700155import com.android.internal.telephony.uicc.IccIoResult;
156import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700158import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800159import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700160import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800161import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000162import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700163import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800164import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800167import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700168import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700169import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800170
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700171import java.io.FileDescriptor;
172import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700173import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800174import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700175import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800176import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800177import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800178import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100179import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700181import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800182import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184/**
185 * Implementation of the ITelephony interface.
186 */
Santos Cordon117fee72014-05-16 17:56:12 -0700187public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188 private static final String LOG_TAG = "PhoneInterfaceManager";
189 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
190 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700192
193 // Message codes used with mMainThreadHandler
194 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700195 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
196 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700197 private static final int CMD_OPEN_CHANNEL = 9;
198 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
199 private static final int CMD_CLOSE_CHANNEL = 11;
200 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800201 private static final int CMD_NV_READ_ITEM = 13;
202 private static final int EVENT_NV_READ_ITEM_DONE = 14;
203 private static final int CMD_NV_WRITE_ITEM = 15;
204 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
205 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
206 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700207 private static final int CMD_RESET_MODEM_CONFIG = 19;
208 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800209 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
210 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
211 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
212 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800213 private static final int CMD_SEND_ENVELOPE = 25;
214 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000215 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
216 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700217 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
218 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
219 private static final int CMD_EXCHANGE_SIM_IO = 31;
220 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800221 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
222 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700223 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
224 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700225 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
226 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700227 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
228 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
229 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
230 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700231 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
232 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
233 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
234 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700235 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800236 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
237 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000238 private static final int CMD_SWITCH_SLOTS = 50;
239 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700240 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
241 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
242 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
243 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
244 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
245 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
246 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
247 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700248 private static final int CMD_GET_ALL_CELL_INFO = 60;
249 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
250 private static final int CMD_GET_CELL_LOCATION = 62;
251 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700252 private static final int CMD_MODEM_REBOOT = 64;
253 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700254 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
255 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800256 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
257 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700258 private static final int CMD_GET_MODEM_STATUS = 70;
259 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800261 // Parameters of select command.
262 private static final int SELECT_COMMAND = 0xA4;
263 private static final int SELECT_P1 = 0x04;
264 private static final int SELECT_P2 = 0;
265 private static final int SELECT_P3 = 0x10;
266
Pengquan Meng85728fb2018-03-12 16:31:21 -0700267 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
268 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
269 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
270
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271 /** The singleton instance. */
272 private static PhoneInterfaceManager sInstance;
273
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700276 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private AppOpsManager mAppOps;
278 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800279 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700281 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700282
Derek Tan97ebb422014-09-05 16:55:38 -0700283 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
284 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800285 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800286 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700287
Michelecea4cf22018-12-21 15:00:11 -0800288 // String to store multi SIM allowed
289 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
290
Derek Tan740e1672017-06-27 14:56:27 -0700291 // The AID of ISD-R.
292 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
293
yinxub1bed742017-04-17 11:45:04 -0700294 private NetworkScanRequestTracker mNetworkScanRequestTracker;
295
David Kelly5e06a7f2018-03-12 14:10:59 +0000296 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
297 private static final int MANUFACTURER_CODE_LENGTH = 8;
298
Derek Tan89e89d42014-07-08 17:00:10 -0700299 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700300 * A request object to use for transmitting data to an ICC.
301 */
302 private static final class IccAPDUArgument {
303 public int channel, cla, command, p1, p2, p3;
304 public String data;
305
306 public IccAPDUArgument(int channel, int cla, int command,
307 int p1, int p2, int p3, String data) {
308 this.channel = channel;
309 this.cla = cla;
310 this.command = command;
311 this.p1 = p1;
312 this.p2 = p2;
313 this.p3 = p3;
314 this.data = data;
315 }
316 }
317
318 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700319 * A request object to use for transmitting data to an ICC.
320 */
321 private static final class ManualNetworkSelectionArgument {
322 public OperatorInfo operatorInfo;
323 public boolean persistSelection;
324
325 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
326 this.operatorInfo = operatorInfo;
327 this.persistSelection = persistSelection;
328 }
329 }
330
331 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
333 * request after sending. The main thread will notify the request when it is complete.
334 */
335 private static final class MainThreadRequest {
336 /** The argument to use for the request */
337 public Object argument;
338 /** The result of the request that is run on the main thread */
339 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800340 // The subscriber id that this request applies to. Defaults to
341 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
342 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Nathan Harold92bed182018-10-12 18:16:49 -0700344 // In cases where subId is unavailable, the caller needs to specify the phone.
345 public Phone phone;
346
vagdeviaf9a5b92018-08-15 16:01:53 -0700347 public WorkSource workSource;
348
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700349 public MainThreadRequest(Object argument) {
350 this.argument = argument;
351 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800352
Nathan Harold92bed182018-10-12 18:16:49 -0700353 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
354 this.argument = argument;
355 if (phone != null) {
356 this.phone = phone;
357 }
358 this.workSource = workSource;
359 }
360
vagdeviaf9a5b92018-08-15 16:01:53 -0700361 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800363 if (subId != null) {
364 this.subId = subId;
365 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 }
369
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800370 private static final class IncomingThirdPartyCallArgs {
371 public final ComponentName component;
372 public final String callId;
373 public final String callerDisplayName;
374
375 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
376 String callerDisplayName) {
377 this.component = component;
378 this.callId = callId;
379 this.callerDisplayName = callerDisplayName;
380 }
381 }
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 /**
384 * A handler that processes messages on the main thread in the phone process. Since many
385 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
386 * inbound binder threads to the main thread in the phone process. The Binder thread
387 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
388 * on, which will be notified when the operation completes and will contain the result of the
389 * request.
390 *
391 * <p>If a MainThreadRequest object is provided in the msg.obj field,
392 * note that request.result must be set to something non-null for the calling thread to
393 * unblock.
394 */
395 private final class MainThreadHandler extends Handler {
396 @Override
397 public void handleMessage(Message msg) {
398 MainThreadRequest request;
399 Message onCompleted;
400 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800401 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700402 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800403 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700404
405 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700406 case CMD_HANDLE_USSD_REQUEST: {
407 request = (MainThreadRequest) msg.obj;
408 final Phone phone = getPhoneFromRequest(request);
409 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
410 String ussdRequest = ussdObject.first;
411 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700412
Pengquan Menga1bb6272018-09-06 09:59:22 -0700413 if (!isUssdApiAllowed(request.subId)) {
414 // Carrier does not support use of this API, return failure.
415 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
416 UssdResponse response = new UssdResponse(ussdRequest, null);
417 Bundle returnData = new Bundle();
418 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
419 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700420
Pengquan Menga1bb6272018-09-06 09:59:22 -0700421 request.result = true;
422 notifyRequester(request);
423 return;
424 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 try {
427 request.result = phone != null
428 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
429 } catch (CallStateException cse) {
430 request.result = false;
431 }
432 // Wake up the requesting thread
433 notifyRequester(request);
434 break;
pkanwar32d516d2016-10-14 19:37:38 -0700435 }
436
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700439 final Phone phone = getPhoneFromRequest(request);
440 request.result = phone != null ?
441 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
442 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700444 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700447
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800451 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 if (uiccCard == null) {
453 loge("iccTransmitApduLogicalChannel: No UICC");
454 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700456 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700457 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
458 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700459 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument.channel, iccArgument.cla, iccArgument.command,
461 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700463 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 break;
465
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700466 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 ar = (AsyncResult) msg.obj;
468 request = (MainThreadRequest) ar.userObj;
469 if (ar.exception == null && ar.result != null) {
470 request.result = ar.result;
471 } else {
472 request.result = new IccIoResult(0x6F, 0, (byte[])null);
473 if (ar.result == null) {
474 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800475 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800477 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700478 } else {
479 loge("iccTransmitApduLogicalChannel: Unknown exception");
480 }
481 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 break;
484
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
486 request = (MainThreadRequest) msg.obj;
487 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800488 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 if (uiccCard == null) {
490 loge("iccTransmitApduBasicChannel: No UICC");
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 } else {
494 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
495 request);
496 uiccCard.iccTransmitApduBasicChannel(
497 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
498 iccArgument.p3, iccArgument.data, onCompleted);
499 }
500 break;
501
502 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
503 ar = (AsyncResult) msg.obj;
504 request = (MainThreadRequest) ar.userObj;
505 if (ar.exception == null && ar.result != null) {
506 request.result = ar.result;
507 } else {
508 request.result = new IccIoResult(0x6F, 0, (byte[])null);
509 if (ar.result == null) {
510 loge("iccTransmitApduBasicChannel: Empty response");
511 } else if (ar.exception instanceof CommandException) {
512 loge("iccTransmitApduBasicChannel: CommandException: " +
513 ar.exception);
514 } else {
515 loge("iccTransmitApduBasicChannel: Unknown exception");
516 }
517 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700518 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 break;
520
521 case CMD_EXCHANGE_SIM_IO:
522 request = (MainThreadRequest) msg.obj;
523 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800524 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 if (uiccCard == null) {
526 loge("iccExchangeSimIO: No UICC");
527 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 } else {
530 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
531 request);
532 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
533 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
534 iccArgument.data, onCompleted);
535 }
536 break;
537
538 case EVENT_EXCHANGE_SIM_IO_DONE:
539 ar = (AsyncResult) msg.obj;
540 request = (MainThreadRequest) ar.userObj;
541 if (ar.exception == null && ar.result != null) {
542 request.result = ar.result;
543 } else {
544 request.result = new IccIoResult(0x6f, 0, (byte[])null);
545 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700546 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700547 break;
548
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 case CMD_SEND_ENVELOPE:
550 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700552 if (uiccCard == null) {
553 loge("sendEnvelopeWithStatus: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
558 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
559 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800560 break;
561
562 case EVENT_SEND_ENVELOPE_DONE:
563 ar = (AsyncResult) msg.obj;
564 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700565 if (ar.exception == null && ar.result != null) {
566 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800567 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
569 if (ar.result == null) {
570 loge("sendEnvelopeWithStatus: Empty response");
571 } else if (ar.exception instanceof CommandException) {
572 loge("sendEnvelopeWithStatus: CommandException: " +
573 ar.exception);
574 } else {
575 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
576 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700578 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800579 break;
580
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 case CMD_OPEN_CHANNEL:
582 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800583 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800584 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 if (uiccCard == null) {
586 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800587 request.result = new IccOpenLogicalChannelResponse(-1,
588 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 } else {
591 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800592 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
593 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700595 break;
596
597 case EVENT_OPEN_CHANNEL_DONE:
598 ar = (AsyncResult) msg.obj;
599 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 int[] result = (int[]) ar.result;
603 int channelId = result[0];
604 byte[] selectResponse = null;
605 if (result.length > 1) {
606 selectResponse = new byte[result.length - 1];
607 for (int i = 1; i < result.length; ++i) {
608 selectResponse[i - 1] = (byte) result[i];
609 }
610 }
611 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 if (ar.result == null) {
615 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700616 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700617 if (ar.exception != null) {
618 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
619 }
620
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700621 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700622 if (ar.exception instanceof CommandException) {
623 CommandException.Error error =
624 ((CommandException) (ar.exception)).getCommandError();
625 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700627 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700628 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 }
630 }
631 openChannelResp = new IccOpenLogicalChannelResponse(
632 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700634 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700635 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case CMD_CLOSE_CHANNEL:
639 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800640 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700641 if (uiccCard == null) {
642 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900643 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700645 } else {
646 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
647 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
648 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 break;
650
651 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800652 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
653 break;
654
655 case CMD_NV_READ_ITEM:
656 request = (MainThreadRequest) msg.obj;
657 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800658 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
659 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800660 break;
661
662 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 ar = (AsyncResult) msg.obj;
664 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800665 if (ar.exception == null && ar.result != null) {
666 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800668 request.result = "";
669 if (ar.result == null) {
670 loge("nvReadItem: Empty response");
671 } else if (ar.exception instanceof CommandException) {
672 loge("nvReadItem: CommandException: " +
673 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800675 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 }
677 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 break;
680
Jake Hambye994d462014-02-03 13:10:13 -0800681 case CMD_NV_WRITE_ITEM:
682 request = (MainThreadRequest) msg.obj;
683 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
684 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700686 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_WRITE_ITEM_DONE:
690 handleNullReturnEvent(msg, "nvWriteItem");
691 break;
692
693 case CMD_NV_WRITE_CDMA_PRL:
694 request = (MainThreadRequest) msg.obj;
695 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800696 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_CDMA_PRL_DONE:
700 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
701 break;
702
chen xu6dac5ab2018-10-26 17:39:23 -0700703 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800704 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700705 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
chen xu6dac5ab2018-10-26 17:39:23 -0700709 case EVENT_RESET_MODEM_CONFIG_DONE:
710 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800711 break;
712
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 case CMD_GET_PREFERRED_NETWORK_TYPE:
714 request = (MainThreadRequest) msg.obj;
715 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700716 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800717 break;
718
719 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
720 ar = (AsyncResult) msg.obj;
721 request = (MainThreadRequest) ar.userObj;
722 if (ar.exception == null && ar.result != null) {
723 request.result = ar.result; // Integer
724 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800725 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800726 if (ar.result == null) {
727 loge("getPreferredNetworkType: Empty response");
728 } else if (ar.exception instanceof CommandException) {
729 loge("getPreferredNetworkType: CommandException: " +
730 ar.exception);
731 } else {
732 loge("getPreferredNetworkType: Unknown exception");
733 }
734 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700735 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 break;
737
738 case CMD_SET_PREFERRED_NETWORK_TYPE:
739 request = (MainThreadRequest) msg.obj;
740 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
741 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700742 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800743 break;
744
745 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
746 handleNullReturnEvent(msg, "setPreferredNetworkType");
747 break;
748
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
750 request = (MainThreadRequest)msg.obj;
751 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800752 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000753 break;
754
755 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
756 ar = (AsyncResult)msg.obj;
757 request = (MainThreadRequest)ar.userObj;
758 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700759 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000760 break;
761
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800762 case CMD_SET_VOICEMAIL_NUMBER:
763 request = (MainThreadRequest) msg.obj;
764 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
765 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800766 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
767 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800768 break;
769
770 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
771 handleNullReturnEvent(msg, "setVoicemailNumber");
772 break;
773
Stuart Scott54788802015-03-30 13:18:01 -0700774 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
777 request);
778 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
779 break;
780
781 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
782 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
783 break;
784
Shishir Agrawal302c8692015-06-19 13:49:39 -0700785 case CMD_PERFORM_NETWORK_SCAN:
786 request = (MainThreadRequest) msg.obj;
787 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
788 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
789 break;
790
791 case EVENT_PERFORM_NETWORK_SCAN_DONE:
792 ar = (AsyncResult) msg.obj;
793 request = (MainThreadRequest) ar.userObj;
794 CellNetworkScanResult cellScanResult;
795 if (ar.exception == null && ar.result != null) {
796 cellScanResult = new CellNetworkScanResult(
797 CellNetworkScanResult.STATUS_SUCCESS,
798 (List<OperatorInfo>) ar.result);
799 } else {
800 if (ar.result == null) {
801 loge("getCellNetworkScanResults: Empty response");
802 }
803 if (ar.exception != null) {
804 loge("getCellNetworkScanResults: Exception: " + ar.exception);
805 }
806 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
807 if (ar.exception instanceof CommandException) {
808 CommandException.Error error =
809 ((CommandException) (ar.exception)).getCommandError();
810 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
812 } else if (error == CommandException.Error.GENERIC_FAILURE) {
813 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
814 }
815 }
816 cellScanResult = new CellNetworkScanResult(errorCode, null);
817 }
818 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700819 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 break;
821
822 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
823 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700824 ManualNetworkSelectionArgument selArg =
825 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
827 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700828 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
829 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700833 ar = (AsyncResult) msg.obj;
834 request = (MainThreadRequest) ar.userObj;
835 if (ar.exception == null) {
836 request.result = true;
837 } else {
838 request.result = false;
839 loge("setNetworkSelectionModeManual " + ar.exception);
840 }
841 notifyRequester(request);
842 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700843 break;
844
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700845 case CMD_GET_MODEM_ACTIVITY_INFO:
846 request = (MainThreadRequest) msg.obj;
847 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700848 if (defaultPhone != null) {
849 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
850 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700851 break;
852
853 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
854 ar = (AsyncResult) msg.obj;
855 request = (MainThreadRequest) ar.userObj;
856 if (ar.exception == null && ar.result != null) {
857 request.result = ar.result;
858 } else {
859 if (ar.result == null) {
860 loge("queryModemActivityInfo: Empty response");
861 } else if (ar.exception instanceof CommandException) {
862 loge("queryModemActivityInfo: CommandException: " +
863 ar.exception);
864 } else {
865 loge("queryModemActivityInfo: Unknown exception");
866 }
867 }
Amit Mahajand4766222016-01-28 15:28:28 -0800868 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
869 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700870 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800871 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700872 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700873 break;
874
Meng Wang1a7c35a2016-05-05 20:56:15 -0700875 case CMD_SET_ALLOWED_CARRIERS:
876 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800877 CarrierRestrictionRules argument =
878 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800880 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 break;
882
883 case EVENT_SET_ALLOWED_CARRIERS_DONE:
884 ar = (AsyncResult) msg.obj;
885 request = (MainThreadRequest) ar.userObj;
886 if (ar.exception == null && ar.result != null) {
887 request.result = ar.result;
888 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800889 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
890 if (ar.exception instanceof CommandException) {
891 loge("setAllowedCarriers: CommandException: " + ar.exception);
892 CommandException.Error error =
893 ((CommandException) (ar.exception)).getCommandError();
894 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
895 request.result =
896 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
897 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700898 } else {
899 loge("setAllowedCarriers: Unknown exception");
900 }
901 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700902 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 break;
904
905 case CMD_GET_ALLOWED_CARRIERS:
906 request = (MainThreadRequest) msg.obj;
907 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800908 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700909 break;
910
911 case EVENT_GET_ALLOWED_CARRIERS_DONE:
912 ar = (AsyncResult) msg.obj;
913 request = (MainThreadRequest) ar.userObj;
914 if (ar.exception == null && ar.result != null) {
915 request.result = ar.result;
916 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800917 request.result = new IllegalStateException(
918 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 if (ar.result == null) {
920 loge("getAllowedCarriers: Empty response");
921 } else if (ar.exception instanceof CommandException) {
922 loge("getAllowedCarriers: CommandException: " +
923 ar.exception);
924 } else {
925 loge("getAllowedCarriers: Unknown exception");
926 }
927 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 break;
930
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
932 ar = (AsyncResult) msg.obj;
933 request = (MainThreadRequest) ar.userObj;
934 if (ar.exception == null && ar.result != null) {
935 request.result = ar.result;
936 } else {
937 request.result = new IllegalArgumentException(
938 "Failed to retrieve Forbidden Plmns");
939 if (ar.result == null) {
940 loge("getForbiddenPlmns: Empty response");
941 } else {
942 loge("getForbiddenPlmns: Unknown exception");
943 }
944 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700945 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800946 break;
947
948 case CMD_GET_FORBIDDEN_PLMNS:
949 request = (MainThreadRequest) msg.obj;
950 uiccCard = getUiccCardFromRequest(request);
951 if (uiccCard == null) {
952 loge("getForbiddenPlmns() UiccCard is null");
953 request.result = new IllegalArgumentException(
954 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957 }
958 Integer appType = (Integer) request.argument;
959 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
960 if (uiccApp == null) {
961 loge("getForbiddenPlmns() no app with specified type -- "
962 + appType);
963 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700964 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800965 break;
966 } else {
967 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
968 + " specified type -- " + appType);
969 }
970 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
971 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
972 onCompleted);
973 break;
974
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000975 case CMD_SWITCH_SLOTS:
976 request = (MainThreadRequest) msg.obj;
977 int[] physicalSlots = (int[]) request.argument;
978 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
979 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
980 break;
981
982 case EVENT_SWITCH_SLOTS_DONE:
983 ar = (AsyncResult) msg.obj;
984 request = (MainThreadRequest) ar.userObj;
985 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700986 notifyRequester(request);
987 break;
988 case CMD_GET_NETWORK_SELECTION_MODE:
989 request = (MainThreadRequest) msg.obj;
990 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
991 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
992 break;
993
994 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
995 ar = (AsyncResult) msg.obj;
996 request = (MainThreadRequest) ar.userObj;
997 if (ar.exception != null) {
998 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
999 } else {
1000 int mode = ((int[]) ar.result)[0];
1001 if (mode == 0) {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1003 } else {
1004 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1005 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001006 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001007 notifyRequester(request);
1008 break;
1009 case CMD_GET_CDMA_ROAMING_MODE:
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1012 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1013 break;
1014 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 if (ar.exception != null) {
1018 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1019 } else {
1020 request.result = ((int[]) ar.result)[0];
1021 }
1022 notifyRequester(request);
1023 break;
1024 case CMD_SET_CDMA_ROAMING_MODE:
1025 request = (MainThreadRequest) msg.obj;
1026 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1027 int mode = (int) request.argument;
1028 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1029 break;
1030 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1031 ar = (AsyncResult) msg.obj;
1032 request = (MainThreadRequest) ar.userObj;
1033 request.result = ar.exception == null;
1034 notifyRequester(request);
1035 break;
1036 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1037 request = (MainThreadRequest) msg.obj;
1038 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1039 int subscriptionMode = (int) request.argument;
1040 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1041 break;
1042 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
1045 request.result = ar.exception == null;
1046 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001047 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 case CMD_GET_ALL_CELL_INFO:
1049 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001051 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case EVENT_GET_ALL_CELL_INFO_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001056 // If a timeout occurs, the response will be null
1057 request.result = (ar.exception == null && ar.result != null)
1058 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001059 synchronized (request) {
1060 request.notifyAll();
1061 }
1062 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 case CMD_REQUEST_CELL_INFO_UPDATE:
1064 request = (MainThreadRequest) msg.obj;
1065 request.phone.requestCellInfoUpdate(request.workSource,
1066 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1067 break;
1068 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1069 ar = (AsyncResult) msg.obj;
1070 request = (MainThreadRequest) ar.userObj;
1071 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1072 try {
1073 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001074 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
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 }
Meng Wangafbc5852019-09-19 17:37:13 -07002877 final long token = Binder.clearCallingIdentity();
2878 try {
2879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2880 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2881 .removeRegistrationCallbackForSubscription(c, subId);
2882 } catch (ImsException e) {
2883 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 } finally {
2888 Binder.restoreCallingIdentity(token);
2889 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002890 }
2891
2892 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002893 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2894 throws RemoteException {
2895 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2897 final long token = Binder.clearCallingIdentity();
2898 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002899 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002900 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002901 } catch (ImsException e) {
2902 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002903 } finally {
2904 Binder.restoreCallingIdentity(token);
2905 }
2906 }
2907
2908 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002909 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2910 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002911 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2912 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2913 }
Meng Wangafbc5852019-09-19 17:37:13 -07002914
2915 final long token = Binder.clearCallingIdentity();
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002919 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002920 } catch (ImsException e) {
2921 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2922 + "is inactive, ignoring unregister.");
2923 // If the subscription is no longer active, just return, since the callback
2924 // will already have been removed internally.
2925 } finally {
2926 Binder.restoreCallingIdentity(token);
2927 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002928 }
2929
2930 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002931 public boolean isCapable(int subId, int capability, int regTech) {
2932 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2934 final long token = Binder.clearCallingIdentity();
2935 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002938 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002939 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2940 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002941 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002942 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2943 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 } finally {
2945 Binder.restoreCallingIdentity(token);
2946 }
2947 }
2948
2949 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002950 public boolean isAvailable(int subId, int capability, int regTech) {
2951 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 final long token = Binder.clearCallingIdentity();
2953 try {
2954 Phone phone = getPhone(subId);
2955 if (phone == null) return false;
2956 return phone.isImsCapabilityAvailable(capability, regTech);
2957 } finally {
2958 Binder.restoreCallingIdentity(token);
2959 }
2960 }
2961
2962 @Override
2963 public boolean isAdvancedCallingSettingEnabled(int subId) {
2964 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2965 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2966 final long token = Binder.clearCallingIdentity();
2967 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002969 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002970 } catch (ImsException e) {
2971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002972 } finally {
2973 Binder.restoreCallingIdentity(token);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002978 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002980 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002986 } catch (ImsException e) {
2987 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002994 public boolean isVtSettingEnabled(int subId) {
2995 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002999 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3000 } catch (ImsException e) {
3001 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003008 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003010 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003011 final long identity = Binder.clearCallingIdentity();
3012 try {
3013 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003014 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003015 } catch (ImsException e) {
3016 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 @Override
3023 public boolean isVoWiFiSettingEnabled(int subId) {
3024 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003029 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003030 } catch (ImsException e) {
3031 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003038 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003040 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003045 } catch (ImsException e) {
3046 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
3053 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3054 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003060 } catch (ImsException e) {
3061 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003068 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003070 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003074 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003076 } catch (ImsException e) {
3077 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003078 } finally {
3079 Binder.restoreCallingIdentity(identity);
3080 }
3081 }
3082
3083 @Override
3084 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3086 "setVoWiFiNonPersistent");
3087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003090 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003091 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003092 } catch (ImsException e) {
3093 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003094 } finally {
3095 Binder.restoreCallingIdentity(identity);
3096 }
3097 }
3098
3099 @Override
3100 public int getVoWiFiModeSetting(int subId) {
3101 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003105 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003107 } catch (ImsException e) {
3108 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
3115 public void setVoWiFiModeSetting(int subId, int mode) {
3116 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3117 "setVoWiFiModeSetting");
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003121 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003122 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003123 } catch (ImsException e) {
3124 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003125 } finally {
3126 Binder.restoreCallingIdentity(identity);
3127 }
3128 }
3129
3130 @Override
3131 public int getVoWiFiRoamingModeSetting(int subId) {
3132 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003136 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003138 } catch (ImsException e) {
3139 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 } finally {
3141 Binder.restoreCallingIdentity(identity);
3142 }
3143 }
3144
3145 @Override
3146 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3148 "setVoWiFiRoamingModeSetting");
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003153 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003154 } catch (ImsException e) {
3155 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003156 } finally {
3157 Binder.restoreCallingIdentity(identity);
3158 }
3159 }
3160
3161 @Override
3162 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3163 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3164 "setRttCapabilityEnabled");
3165 final long identity = Binder.clearCallingIdentity();
3166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003168 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3169 } catch (ImsException e) {
3170 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003171 } finally {
3172 Binder.restoreCallingIdentity(identity);
3173 }
3174 }
3175
3176 @Override
3177 public boolean isTtyOverVolteEnabled(int subId) {
3178 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3179 final long identity = Binder.clearCallingIdentity();
3180 try {
3181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003182 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003183 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003184 } catch (ImsException e) {
3185 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
3189 }
3190
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003191 @Override
3192 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3193 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003197 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003198 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003199 } catch (ImsException e) {
3200 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003201 } finally {
3202 Binder.restoreCallingIdentity(identity);
3203 }
3204 }
3205
3206 @Override
3207 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3208 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3209 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003210 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3211 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3212 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003213 try {
3214 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003216 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003217 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003218 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3219 + "is inactive, ignoring unregister.");
3220 // If the subscription is no longer active, just return, since the callback will already
3221 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
3225 }
3226
3227 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003228 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3229 boolean isProvisioned) {
3230 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3231 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3232 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3233 }
3234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3235 "setProvisioningStatusForCapability");
3236 final long identity = Binder.clearCallingIdentity();
3237 try {
3238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3239 Phone phone = getPhone(subId);
3240 if (phone == null) {
3241 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3242 + subId);
3243 return;
3244 }
3245 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3246 return;
3247 }
3248
3249 // this capability requires provisioning, route to the correct API.
3250 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3251 switch (capability) {
3252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3253 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3254 ims.setVolteProvisioned(isProvisioned);
3255 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3256 ims.setWfcProvisioned(isProvisioned);
3257 }
3258 break;
3259 }
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3261 // There is currently no difference in VT provisioning type.
3262 ims.setVtProvisioned(isProvisioned);
3263 break;
3264 }
3265 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3266 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3267 // change the capability of the feature instead if needed.
3268 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3269 == isProvisioned) {
3270 // No change in provisioning.
3271 return;
3272 }
3273 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3274 try {
3275 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003276 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003277 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3278 + ", Exception" + e.getMessage());
3279 }
3280 break;
3281 }
3282 default: {
3283 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3284 + capability + "', which does not require provisioning.");
3285 }
3286 }
3287
3288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3295 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3296 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3297 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3298 }
3299 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3300 final long identity = Binder.clearCallingIdentity();
3301 try {
3302 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3303 Phone phone = getPhone(subId);
3304 if (phone == null) {
3305 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3306 + subId);
3307 // We will fail with "true" as the provisioning status because this is the default
3308 // if we do not require provisioning.
3309 return true;
3310 }
3311
3312 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3313 return true;
3314 }
3315
3316 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3317 switch (capability) {
3318 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3319 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3320 return ims.isVolteProvisionedOnDevice();
3321 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3322 return ims.isWfcProvisionedOnDevice();
3323 }
3324 // This should never happen, since we are checking tech above to make sure it
3325 // is either LTE or IWLAN.
3326 throw new IllegalArgumentException("Invalid radio technology for voice "
3327 + "capability.");
3328 }
3329 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3330 // There is currently no difference in VT provisioning type.
3331 return ims.isVtProvisionedOnDevice();
3332 }
3333 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3334 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3335 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3336 }
3337 default: {
3338 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3339 + capability + "', which does not require provisioning.");
3340 }
3341 }
3342
3343 } finally {
3344 Binder.restoreCallingIdentity(identity);
3345 }
3346 }
3347
3348 @Override
3349 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3350 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3351 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3352 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3353 }
3354 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3355 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3356 return (provisionedBits & capability) > 0;
3357 }
3358
3359 @Override
3360 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3361 boolean isProvisioned) {
3362 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3363 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3364 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3365 }
3366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3367 "setProvisioningStatusForCapability");
3368 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3369 // If the current provisioning status for capability already matches isProvisioned,
3370 // do nothing.
3371 if (((provisionedBits & capability) > 0) == isProvisioned) {
3372 return;
3373 }
3374 if (isProvisioned) {
3375 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3376 } else {
3377 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3378 }
3379 }
3380
3381 /**
3382 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3383 * technology. The bitfield should mirror the bitfield defined by
3384 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3385 */
3386 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3387 String key = getMmTelProvisioningKey(subId, tech);
3388 // Default is no capabilities are provisioned.
3389 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3390 }
3391
3392 /**
3393 * Sets the MmTel capability provisioning bitfield (defined by
3394 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3395 * technology specified.
3396 *
3397 * Note: This is a synchronous command and should not be called on UI thread.
3398 */
3399 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3400 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3401 String key = getMmTelProvisioningKey(subId, tech);
3402 editor.putInt(key, newField);
3403 editor.commit();
3404 }
3405
3406 private static String getMmTelProvisioningKey(int subId, int tech) {
3407 // resulting key is provision_ims_mmtel_{subId}_{tech}
3408 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3409 }
3410
3411 /**
3412 * Query CarrierConfig to see if the specified capability requires provisioning for the
3413 * carrier associated with the subscription id.
3414 */
3415 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3416 int capability) {
3417 CarrierConfigManager configManager = new CarrierConfigManager(context);
3418 PersistableBundle c = configManager.getConfigForSubId(subId);
3419 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003420 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3422 false);
3423 boolean requireVoiceVtProvisioning = c.getBoolean(
3424 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3425
3426 // First check to make sure that the capability requires provisioning.
3427 switch (capability) {
3428 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3429 // intentional fallthrough
3430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3431 if (requireVoiceVtProvisioning) {
3432 // Voice and Video requires provisioning
3433 return true;
3434 }
3435 break;
3436 }
3437 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3438 if (requireUtProvisioning) {
3439 // UT requires provisioning
3440 return true;
3441 }
3442 break;
3443 }
3444 }
3445 return false;
3446 }
3447
3448 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3451 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3452 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003453 enforceReadPrivilegedPermission("getImsProvisioningInt");
3454 final long identity = Binder.clearCallingIdentity();
3455 try {
3456 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 int slotId = getSlotIndex(subId);
3458 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3459 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3460 + subId + "' for key:" + key);
3461 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3462 }
3463 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003464 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3466 + subId + "' for key:" + key);
3467 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
3473 @Override
3474 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003475 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3476 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3477 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003478 enforceReadPrivilegedPermission("getImsProvisioningString");
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 int slotId = getSlotIndex(subId);
3483 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3484 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3485 + subId + "' for key:" + key);
3486 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3487 }
3488 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003489 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3491 + subId + "' for key:" + key);
3492 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
3496 }
3497
3498 @Override
3499 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3501 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3502 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3504 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003508 int slotId = getSlotIndex(subId);
3509 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3510 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3511 + subId + "' for key:" + key);
3512 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3513 }
3514 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003515 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003516 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3517 + "' for key:" + key);
3518 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
3522 }
3523
3524 @Override
3525 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003526 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3527 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3528 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3530 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003534 int slotId = getSlotIndex(subId);
3535 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3536 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3537 + subId + "' for key:" + key);
3538 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3539 }
3540 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003541 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003542 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3543 + "' for key:" + key);
3544 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003545 } finally {
3546 Binder.restoreCallingIdentity(identity);
3547 }
3548 }
3549
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003550 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003551 int slotId = SubscriptionManager.getSlotIndex(subId);
3552 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3554 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 }
3556 return slotId;
3557 }
3558
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003559 private int getSlotIndex(int subId) {
3560 int slotId = SubscriptionManager.getSlotIndex(subId);
3561 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3562 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3563 }
3564 return slotId;
3565 }
3566
Wink Saville36469e72014-06-11 15:17:00 -07003567 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003568 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003569 */
3570 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003571 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003572 final int targetSdk = getTargetSdk(callingPackage);
3573 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3574 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3575 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003576 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3577 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003578 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3579 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 final Phone phone = getPhone(subId);
3584 if (phone != null) {
3585 return phone.getServiceState().getDataNetworkType();
3586 } else {
3587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3588 }
3589 } finally {
3590 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003591 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003592 }
3593
3594 /**
3595 * Returns the data network type
3596 */
3597 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 public int getDataNetworkType(String callingPackage) {
3599 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
3602 /**
3603 * Returns the data network type for a subId
3604 */
3605 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003607 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003608 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003609 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3610 }
3611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003612 final long identity = Binder.clearCallingIdentity();
3613 try {
3614 final Phone phone = getPhone(subId);
3615 if (phone != null) {
3616 return phone.getServiceState().getDataNetworkType();
3617 } else {
3618 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3619 }
3620 } finally {
3621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003623 }
3624
3625 /**
Wink Saville36469e72014-06-11 15:17:00 -07003626 * Returns the Voice network type for a subId
3627 */
3628 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003629 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003631 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003632 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3633 }
3634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = getPhone(subId);
3638 if (phone != null) {
3639 return phone.getServiceState().getVoiceNetworkType();
3640 } else {
3641 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3642 }
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003645 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003646 }
3647
3648 /**
3649 * @return true if a ICC card is present
3650 */
3651 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003652 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003653 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3654 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003655 }
3656
3657 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003658 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003659 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003660 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003661 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 final Phone phone = PhoneFactory.getPhone(slotIndex);
3665 if (phone != null) {
3666 return phone.getIccCard().hasIccCard();
3667 } else {
3668 return false;
3669 }
3670 } finally {
3671 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 }
3674
3675 /**
3676 * Return if the current radio is LTE on CDMA. This
3677 * is a tri-state return value as for a period of time
3678 * the mode may be unknown.
3679 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003680 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003682 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003683 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003684 @Override
3685 public int getLteOnCdmaMode(String callingPackage) {
3686 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003687 }
3688
Sanket Padawe356d7632015-06-22 14:03:32 -07003689 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003690 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003691 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003692 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003693 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3694 }
3695
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003696 final long identity = Binder.clearCallingIdentity();
3697 try {
3698 final Phone phone = getPhone(subId);
3699 if (phone == null) {
3700 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3701 } else {
3702 return phone.getLteOnCdmaMode();
3703 }
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003706 }
Wink Saville36469e72014-06-11 15:17:00 -07003707 }
3708
Wink Saville36469e72014-06-11 15:17:00 -07003709 /**
3710 * {@hide}
3711 * Returns Default subId, 0 in the case of single standby.
3712 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003714 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003715 }
3716
Shishir Agrawala9f32182016-04-12 12:00:16 -07003717 private int getSlotForDefaultSubscription() {
3718 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3719 }
3720
Wink Savilleb564aae2014-10-23 10:18:09 -07003721 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003722 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003723 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003724
Pengquan Menge92a50d2018-09-21 15:54:48 -07003725 private boolean isActiveSubscription(int subId) {
3726 return mSubscriptionController.isActiveSubId(subId);
3727 }
3728
Ihab Awadf2177b72013-11-25 13:33:23 -08003729 /**
3730 * @see android.telephony.TelephonyManager.WifiCallingChoices
3731 */
3732 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003735 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003736 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3737 getWhenToMakeWifiCallsDefaultPreference());
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003741 }
3742
3743 /**
3744 * @see android.telephony.TelephonyManager.WifiCallingChoices
3745 */
3746 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003747 final long identity = Binder.clearCallingIdentity();
3748 try {
3749 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003750 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003755 }
3756
Sailesh Nepald1e68152013-12-12 19:08:02 -08003757 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003758 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003759 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003760 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003761
Jordan Liu4c733742019-02-28 12:03:40 -08003762 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3763 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3764 if (phoneId == -1) {
3765 throw new IllegalArgumentException("Given slot index: " + slotIndex
3766 + " does not correspond to an active phone");
3767 }
3768 return PhoneFactory.getPhone(phoneId);
3769 }
3770
Shishir Agrawal566b7612013-10-28 14:41:00 -07003771 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003772 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3773 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003774 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3775 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003777 if (DBG) {
3778 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3779 }
3780 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3781 p2);
3782 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003783
Jordan Liu4c733742019-02-28 12:03:40 -08003784
3785 @Override
3786 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3787 int slotIndex, String callingPackage, String aid, int p2) {
3788 enforceModifyPermission();
3789 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3790 if (DBG) {
3791 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3792 }
3793 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3794 callingPackage, aid, p2);
3795 }
3796
3797 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3798 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003799 final long identity = Binder.clearCallingIdentity();
3800 try {
3801 if (TextUtils.equals(ISDR_AID, aid)) {
3802 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003803 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3804 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 if (bestComponent == null
3806 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3807 loge("The calling package is not allowed to access ISD-R.");
3808 throw new SecurityException(
3809 "The calling package is not allowed to access ISD-R.");
3810 }
Derek Tan740e1672017-06-27 14:56:27 -07003811 }
Derek Tan740e1672017-06-27 14:56:27 -07003812
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003814 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3815 null /* workSource */);
3816 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003817 return response;
3818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003821 }
3822
3823 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003824 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3826 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003827 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3828 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3829 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003830
Jordan Liu4c733742019-02-28 12:03:40 -08003831 @Override
3832 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3833 enforceModifyPermission();
3834 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3835 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3836 channel);
3837 }
3838
3839 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 final long identity = Binder.clearCallingIdentity();
3841 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 if (channel < 0) {
3843 return false;
3844 }
Jordan Liu4c733742019-02-28 12:03:40 -08003845 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3846 null /* workSource */);
3847 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 return success;
3849 } finally {
3850 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003851 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003852 }
3853
3854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003855 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003856 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003857 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3858 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003859 if (DBG) {
3860 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3861 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3862 + p3 + " data=" + data);
3863 }
3864 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3865 command, p1, p2, p3, data);
3866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003867
Jordan Liu4c733742019-02-28 12:03:40 -08003868 @Override
3869 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3870 int command, int p1, int p2, int p3, String data) {
3871 enforceModifyPermission();
3872 if (DBG) {
3873 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3874 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3875 + p3 + " data=" + data);
3876 }
3877 return iccTransmitApduLogicalChannelWithPermission(
3878 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3879 data);
3880 }
3881
3882 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3883 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 final long identity = Binder.clearCallingIdentity();
3885 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003886 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 return "";
3888 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003890 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003891 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3892 null /* workSource */);
3893 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 // Append the returned status code to the end of the response payload.
3896 String s = Integer.toHexString(
3897 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3898 if (response.payload != null) {
3899 s = IccUtils.bytesToHexString(response.payload) + s;
3900 }
3901 return s;
3902 } finally {
3903 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003905 }
Jake Hambye994d462014-02-03 13:10:13 -08003906
Evan Charltonc66da362014-05-16 14:06:40 -07003907 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003908 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3909 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003910 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3911 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003913 if (DBG) {
3914 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3915 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3916 }
3917 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3918 cla, command, p1, p2, p3, data);
3919 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003920
Jordan Liu4c733742019-02-28 12:03:40 -08003921 @Override
3922 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3923 int command, int p1, int p2, int p3, String data) {
3924 enforceModifyPermission();
3925 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3926 if (DBG) {
3927 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3928 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3929 + " data=" + data);
3930 }
3931
3932 return iccTransmitApduBasicChannelWithPermission(
3933 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3934 p2, p3, data);
3935 }
3936
3937 // open APDU basic channel assuming the caller has sufficient permissions
3938 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3939 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3943 && TextUtils.equals(ISDR_AID, data)) {
3944 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003945 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3946 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 if (bestComponent == null
3948 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3949 loge("The calling package is not allowed to select ISD-R.");
3950 throw new SecurityException(
3951 "The calling package is not allowed to select ISD-R.");
3952 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003953 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003956 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3957 null /* workSource */);
3958 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003960 // Append the returned status code to the end of the response payload.
3961 String s = Integer.toHexString(
3962 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3963 if (response.payload != null) {
3964 s = IccUtils.bytesToHexString(response.payload) + s;
3965 }
3966 return s;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003969 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003970 }
3971
3972 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003973 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003974 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003975 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3976 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 if (DBG) {
3981 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3982 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3983 }
3984
3985 IccIoResult response =
3986 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3987 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3988 subId);
3989
3990 if (DBG) {
3991 log("Exchange SIM_IO [R]" + response);
3992 }
3993
3994 byte[] result = null;
3995 int length = 2;
3996 if (response.payload != null) {
3997 length = 2 + response.payload.length;
3998 result = new byte[length];
3999 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4000 } else {
4001 result = new byte[length];
4002 }
4003
4004 result[length - 1] = (byte) response.sw2;
4005 result[length - 2] = (byte) response.sw1;
4006 return result;
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004009 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004010 }
4011
Nathan Haroldb3014052017-01-25 15:57:32 -08004012 /**
4013 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4014 * on a particular subscription
4015 */
sqianb6e41952018-03-12 14:54:01 -07004016 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4017 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4018 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4019 return null;
4020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021
4022 final long identity = Binder.clearCallingIdentity();
4023 try {
4024 if (appType != TelephonyManager.APPTYPE_USIM
4025 && appType != TelephonyManager.APPTYPE_SIM) {
4026 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4027 return null;
4028 }
4029 Object response = sendRequest(
4030 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4031 if (response instanceof String[]) {
4032 return (String[]) response;
4033 }
4034 // Response is an Exception of some kind,
4035 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004036 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004039 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004040 }
4041
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004042 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004043 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4045 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004047 final long identity = Binder.clearCallingIdentity();
4048 try {
4049 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4050 if (response.payload == null) {
4051 return "";
4052 }
Evan Charltonc66da362014-05-16 14:06:40 -07004053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004054 // Append the returned status code to the end of the response payload.
4055 String s = Integer.toHexString(
4056 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4057 s = IccUtils.bytesToHexString(response.payload) + s;
4058 return s;
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Evan Charltonc66da362014-05-16 14:06:40 -07004062 }
4063
Jake Hambye994d462014-02-03 13:10:13 -08004064 /**
4065 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4066 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4067 *
4068 * @param itemID the ID of the item to read
4069 * @return the NV item as a String, or null on error.
4070 */
4071 @Override
4072 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004073 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004074 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4075 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004080 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004081 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4082 return value;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Jake Hambye994d462014-02-03 13:10:13 -08004086 }
4087
4088 /**
4089 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4090 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4091 *
4092 * @param itemID the ID of the item to read
4093 * @param itemValue the value to write, as a String
4094 * @return true on success; false on any failure
4095 */
4096 @Override
4097 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004098 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4100 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004101
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4105 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004106 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004107 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
Jake Hambye994d462014-02-03 13:10:13 -08004112 }
4113
4114 /**
4115 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4116 * Used for device configuration by some CDMA operators.
4117 *
4118 * @param preferredRoamingList byte array containing the new PRL
4119 * @return true on success; false on any failure
4120 */
4121 @Override
4122 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004123 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4124 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004125
4126 final long identity = Binder.clearCallingIdentity();
4127 try {
4128 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4129 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4130 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4131 return success;
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Jake Hambye994d462014-02-03 13:10:13 -08004135 }
4136
4137 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004138 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004139 * Used for device configuration by some CDMA operators.
4140 *
chen xu6dac5ab2018-10-26 17:39:23 -07004141 * @param slotIndex - device slot.
4142 *
Jake Hambye994d462014-02-03 13:10:13 -08004143 * @return true on success; false on any failure
4144 */
4145 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004146 public boolean resetModemConfig(int slotIndex) {
4147 Phone phone = PhoneFactory.getPhone(slotIndex);
4148 if (phone != null) {
4149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4150 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151
chen xu6dac5ab2018-10-26 17:39:23 -07004152 final long identity = Binder.clearCallingIdentity();
4153 try {
4154 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4155 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4156 return success;
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004160 }
chen xu6dac5ab2018-10-26 17:39:23 -07004161 return false;
4162 }
4163
4164 /**
4165 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4166 *
4167 * @param slotIndex - device slot.
4168 *
4169 * @return true on success; false on any failure
4170 */
4171 @Override
4172 public boolean rebootModem(int slotIndex) {
4173 Phone phone = PhoneFactory.getPhone(slotIndex);
4174 if (phone != null) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4176 mApp, phone.getSubId(), "rebootModem");
4177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4181 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4182 return success;
4183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004188 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004189
Svet Ganovb320e182015-04-16 12:30:10 -07004190 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004193 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004194 return new String[0];
4195 }
4196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004197 final long identity = Binder.clearCallingIdentity();
4198 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004200 } finally {
4201 Binder.restoreCallingIdentity(identity);
4202 }
Wink Saville36469e72014-06-11 15:17:00 -07004203 }
4204
Brad Ebinger51f743a2017-01-23 13:50:20 -08004205 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004206 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4207 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004208 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004209 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004210 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004214 ImsResolver resolver = PhoneFactory.getImsResolver();
4215 if (resolver == null) {
4216 // may happen if the device does not support IMS.
4217 return;
4218 }
4219 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 } finally {
4221 Binder.restoreCallingIdentity(identity);
4222 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004223 }
4224
4225 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004226 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4227 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004228 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004229 public void disableIms(int slotId) {
4230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004231
4232 final long identity = Binder.clearCallingIdentity();
4233 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004234 ImsResolver resolver = PhoneFactory.getImsResolver();
4235 if (resolver == null) {
4236 // may happen if the device does not support IMS.
4237 return;
4238 }
4239 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004240 } finally {
4241 Binder.restoreCallingIdentity(identity);
4242 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004243 }
4244
4245 /**
4246 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4247 * feature or {@link null} if the service is not available. If the feature is available, the
4248 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4249 */
4250 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004251 IImsServiceFeatureCallback callback) {
4252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253
4254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004256 ImsResolver resolver = PhoneFactory.getImsResolver();
4257 if (resolver == null) {
4258 // may happen if the device does not support IMS.
4259 return null;
4260 }
4261 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004262 } finally {
4263 Binder.restoreCallingIdentity(identity);
4264 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004265 }
4266
4267 /**
4268 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4269 * feature during emergency calling or {@link null} if the service is not available. If the
4270 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4271 * listener for feature updates.
4272 */
4273 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4274 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004275
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004278 ImsResolver resolver = PhoneFactory.getImsResolver();
4279 if (resolver == null) {
4280 // may happen if the device does not support IMS.
4281 return null;
4282 }
4283 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004284 } finally {
4285 Binder.restoreCallingIdentity(identity);
4286 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004287 }
4288
Brad Ebinger5f64b052017-12-14 14:26:15 -08004289 /**
4290 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004291 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004292 */
4293 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4294 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295
4296 final long identity = Binder.clearCallingIdentity();
4297 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004298 ImsResolver resolver = PhoneFactory.getImsResolver();
4299 if (resolver == null) {
4300 // may happen if the device does not support IMS.
4301 return null;
4302 }
4303 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004307 }
4308
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004309 /**
4310 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004311 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004312 */
4313 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4314 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004318 ImsResolver resolver = PhoneFactory.getImsResolver();
4319 if (resolver == null) {
4320 // may happen if the device does not support IMS.
4321 return null;
4322 }
4323 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004324 } finally {
4325 Binder.restoreCallingIdentity(identity);
4326 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004327 }
4328
Brad Ebinger884c07b2018-02-15 16:17:40 -08004329 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004330 * Sets the ImsService Package Name that Telephony will bind to.
4331 *
4332 * @param slotId the slot ID that the ImsService should bind for.
4333 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4334 * ImsService is the device default ImsService.
4335 * @param packageName The package name of the application that contains the ImsService to bind
4336 * to.
4337 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4338 * @hide
4339 */
4340 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004341 int[] subIds = SubscriptionManager.getSubId(slotId);
4342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4343 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4344 "setImsService");
4345
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004348 ImsResolver resolver = PhoneFactory.getImsResolver();
4349 if (resolver == null) {
4350 // may happen if the device does not support IMS.
4351 return false;
4352 }
4353 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4354 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004358 }
4359
4360 /**
4361 * Return the ImsService configuration.
4362 *
4363 * @param slotId The slot that the ImsService is associated with.
4364 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4365 * the device default.
4366 * @return the package name of the ImsService configuration.
4367 */
4368 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004369 int[] subIds = SubscriptionManager.getSubId(slotId);
4370 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4371 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4372 "getImsService");
4373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004376 ImsResolver resolver = PhoneFactory.getImsResolver();
4377 if (resolver == null) {
4378 // may happen if the device does not support IMS.
4379 return "";
4380 }
4381 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 } finally {
4383 Binder.restoreCallingIdentity(identity);
4384 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004385 }
4386
Wink Saville36469e72014-06-11 15:17:00 -07004387 public void setImsRegistrationState(boolean registered) {
4388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389
4390 final long identity = Binder.clearCallingIdentity();
4391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004392 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
Wink Saville36469e72014-06-11 15:17:00 -07004396 }
4397
4398 /**
Stuart Scott54788802015-03-30 13:18:01 -07004399 * Set the network selection mode to automatic.
4400 *
4401 */
4402 @Override
4403 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4405 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406
Pengquan Menge92a50d2018-09-21 15:54:48 -07004407 if (!isActiveSubscription(subId)) {
4408 return;
4409 }
4410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 final long identity = Binder.clearCallingIdentity();
4412 try {
4413 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4414 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4415 } finally {
4416 Binder.restoreCallingIdentity(identity);
4417 }
Stuart Scott54788802015-03-30 13:18:01 -07004418 }
4419
Pengquan Mengea84e042018-09-20 14:57:26 -07004420 /**
4421 * Ask the radio to connect to the input network and change selection mode to manual.
4422 *
4423 * @param subId the id of the subscription.
4424 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4425 * the operator to attach to.
4426 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4427 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4428 * normal network selection next time.
4429 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004430 */
4431 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004432 public boolean setNetworkSelectionModeManual(
4433 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4435 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004436
4437 if (!isActiveSubscription(subId)) {
4438 return false;
4439 }
4440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 final long identity = Binder.clearCallingIdentity();
4442 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004443 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004444 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004445 if (DBG) {
4446 log("setNetworkSelectionModeManual: subId: " + subId
4447 + " operator: " + operatorInfo);
4448 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4450 } finally {
4451 Binder.restoreCallingIdentity(identity);
4452 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004453 }
4454
4455 /**
4456 * Scans for available networks.
4457 */
4458 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004459 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4461 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004462 LocationAccessPolicy.LocationPermissionResult locationResult =
4463 LocationAccessPolicy.checkLocationPermission(mApp,
4464 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4465 .setCallingPackage(callingPackage)
4466 .setCallingPid(Binder.getCallingPid())
4467 .setCallingUid(Binder.getCallingUid())
4468 .setMethod("getCellNetworkScanResults")
4469 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4470 .build());
4471 switch (locationResult) {
4472 case DENIED_HARD:
4473 throw new SecurityException("Not allowed to access scan results -- location");
4474 case DENIED_SOFT:
4475 return null;
4476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477
Pengquan Menga1bb6272018-09-06 09:59:22 -07004478 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 try {
4480 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004481 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004482 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483 } finally {
4484 Binder.restoreCallingIdentity(identity);
4485 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004486 }
4487
4488 /**
yinxub1bed742017-04-17 11:45:04 -07004489 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004490 *
yinxub1bed742017-04-17 11:45:04 -07004491 * @param subId id of the subscription
4492 * @param request contains the radio access networks with bands/channels to scan
4493 * @param messenger callback messenger for scan results or errors
4494 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004495 * @return the id of the requested scan which can be used to stop the scan.
4496 */
4497 @Override
4498 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004499 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4501 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004502 LocationAccessPolicy.LocationPermissionResult locationResult =
4503 LocationAccessPolicy.checkLocationPermission(mApp,
4504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4505 .setCallingPackage(callingPackage)
4506 .setCallingPid(Binder.getCallingPid())
4507 .setCallingUid(Binder.getCallingUid())
4508 .setMethod("requestNetworkScan")
4509 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4510 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004511 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004512 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004513 if (e != null) {
4514 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4515 throw e;
4516 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004517 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004518 return TelephonyScanManager.INVALID_SCAN_ID;
4519 }
4520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521 }
Hall Liu912dfd32019-04-25 14:02:26 -07004522 int callingUid = Binder.getCallingUid();
4523 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004524 final long identity = Binder.clearCallingIdentity();
4525 try {
4526 return mNetworkScanRequestTracker.startNetworkScan(
4527 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004528 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004529 } finally {
4530 Binder.restoreCallingIdentity(identity);
4531 }
yinxu504e1392017-04-12 16:03:22 -07004532 }
4533
Hall Liub2ac8ef2019-02-28 15:56:23 -08004534 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004535 NetworkScanRequest request, int subId) {
4536 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4537 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4538 boolean hasNetworkScanPermission =
4539 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4540 == PERMISSION_GRANTED;
4541
4542 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4543 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4544 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004545 }
4546
4547 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4548 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004549 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4550 return new SecurityException("Specific channels must not be"
4551 + " scanned without location access.");
4552 }
4553 }
4554 }
4555
Hall Liub2ac8ef2019-02-28 15:56:23 -08004556 return null;
4557 }
4558
yinxu504e1392017-04-12 16:03:22 -07004559 /**
4560 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004561 *
4562 * @param subId id of the subscription
4563 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004564 */
4565 @Override
4566 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4568 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569
Hall Liu912dfd32019-04-25 14:02:26 -07004570 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004571 final long identity = Binder.clearCallingIdentity();
4572 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004573 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 } finally {
4575 Binder.restoreCallingIdentity(identity);
4576 }
yinxu504e1392017-04-12 16:03:22 -07004577 }
4578
4579 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004580 * Get the calculated preferred network type.
4581 * Used for debugging incorrect network type.
4582 *
4583 * @return the preferred network type, defined in RILConstants.java.
4584 */
4585 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004586 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004587 final Phone defaultPhone = getDefaultPhone();
4588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4589 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004590 return RILConstants.PREFERRED_NETWORK_MODE;
4591 }
4592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004593 final long identity = Binder.clearCallingIdentity();
4594 try {
4595 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004596 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 } finally {
4598 Binder.restoreCallingIdentity(identity);
4599 }
Junda Liu84d15a22014-07-02 11:21:04 -07004600 }
4601
4602 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004603 * Get the preferred network type.
4604 * Used for device configuration by some CDMA operators.
4605 *
4606 * @return the preferred network type, defined in RILConstants.java.
4607 */
4608 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004609 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004610 TelephonyPermissions
4611 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4612 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 if (DBG) log("getPreferredNetworkType");
4617 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4618 int networkType = (result != null ? result[0] : -1);
4619 if (DBG) log("getPreferredNetworkType: " + networkType);
4620 return networkType;
4621 } finally {
4622 Binder.restoreCallingIdentity(identity);
4623 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004624 }
4625
4626 /**
4627 * Set the preferred network type.
4628 * Used for device configuration by some CDMA operators.
4629 *
4630 * @param networkType the preferred network type, defined in RILConstants.java.
4631 * @return true on success; false on any failure.
4632 */
4633 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004634 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4636 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
4640 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4641 Boolean success = (Boolean) sendRequest(
4642 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4643 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4644 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004645 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4647 }
4648 return success;
4649 } finally {
4650 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004651 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004652 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004653
4654 /**
Miaoa84611c2019-03-15 09:21:10 +08004655 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004656 *
Miaoa84611c2019-03-15 09:21:10 +08004657 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004658 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004659 * @hide
4660 */
4661 @Override
Miaoa84611c2019-03-15 09:21:10 +08004662 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004663 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004665 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004666 try {
Miaoa84611c2019-03-15 09:21:10 +08004667 if (phone != null) {
4668 return phone.hasMatchedTetherApnSetting();
4669 } else {
4670 return false;
4671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 } finally {
4673 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004674 }
Junda Liu475951f2014-11-07 16:45:03 -08004675 }
4676
4677 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004678 * Set mobile data enabled
4679 * Used by the user through settings etc to turn on/off mobile data
4680 *
4681 * @param enable {@code true} turn turn data on, else {@code false}
4682 */
4683 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004684 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004685 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4686 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687
4688 final long identity = Binder.clearCallingIdentity();
4689 try {
4690 int phoneId = mSubscriptionController.getPhoneId(subId);
4691 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4692 Phone phone = PhoneFactory.getPhone(phoneId);
4693 if (phone != null) {
4694 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004695 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004696 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004697 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 }
4699 } finally {
4700 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004701 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004702 }
4703
4704 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004705 * Get the user enabled state of Mobile Data.
4706 *
4707 * TODO: remove and use isUserDataEnabled.
4708 * This can't be removed now because some vendor codes
4709 * calls through ITelephony directly while they should
4710 * use TelephonyManager.
4711 *
4712 * @return true on enabled
4713 */
4714 @Override
4715 public boolean getDataEnabled(int subId) {
4716 return isUserDataEnabled(subId);
4717 }
4718
4719 /**
4720 * Get whether mobile data is enabled per user setting.
4721 *
4722 * There are other factors deciding whether mobile data is actually enabled, but they are
4723 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004724 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004725 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004726 *
4727 * @return {@code true} if data is enabled else {@code false}
4728 */
4729 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004730 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004731 try {
4732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4733 null);
4734 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4736 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738
4739 final long identity = Binder.clearCallingIdentity();
4740 try {
4741 int phoneId = mSubscriptionController.getPhoneId(subId);
4742 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4743 Phone phone = PhoneFactory.getPhone(phoneId);
4744 if (phone != null) {
4745 boolean retVal = phone.isUserDataEnabled();
4746 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4747 return retVal;
4748 } else {
4749 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4750 return false;
4751 }
4752 } finally {
4753 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004754 }
4755 }
4756
4757 /**
4758 * Get whether mobile data is enabled.
4759 *
4760 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4761 * whether mobile data is actually enabled.
4762 *
4763 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4764 *
4765 * @return {@code true} if data is enabled else {@code false}
4766 */
4767 @Override
4768 public boolean isDataEnabled(int subId) {
4769 try {
4770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4771 null);
4772 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776
4777 final long identity = Binder.clearCallingIdentity();
4778 try {
4779 int phoneId = mSubscriptionController.getPhoneId(subId);
4780 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4781 Phone phone = PhoneFactory.getPhone(phoneId);
4782 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004783 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4785 return retVal;
4786 } else {
4787 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4788 return false;
4789 }
4790 } finally {
4791 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004792 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004793 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004794
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004795 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4796 Phone phone) {
4797 //load access rules from carrier configs, and check those as well: b/139133814
4798 SubscriptionController subController = SubscriptionController.getInstance();
4799 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4800 || subController == null) return privilegeFromSim;
4801
4802 int uid = Binder.getCallingUid();
4803 PackageManager pkgMgr = phone.getContext().getPackageManager();
4804 String[] packages = pkgMgr.getPackagesForUid(uid);
4805
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4809 SubscriptionManager subManager = (SubscriptionManager)
4810 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4811 for (String pkg : packages) {
4812 if (subManager.canManageSubscription(subInfo, pkg)) {
4813 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4814 }
4815 }
4816 return privilegeFromSim;
4817 } finally {
4818 Binder.restoreCallingIdentity(identity);
4819 }
4820 }
4821
4822 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4823 String pkgName) {
4824 //load access rules from carrier configs, and check those as well: b/139133814
4825 SubscriptionController subController = SubscriptionController.getInstance();
4826 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4827 || subController == null) return privilegeFromSim;
4828
4829 final long identity = Binder.clearCallingIdentity();
4830 try {
4831 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4832 SubscriptionManager subManager = (SubscriptionManager)
4833 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4834 return subManager.canManageSubscription(subInfo, pkgName)
4835 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4836 } finally {
4837 Binder.restoreCallingIdentity(identity);
4838 }
4839 }
4840
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004841 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004842 public int getCarrierPrivilegeStatus(int subId) {
4843 final Phone phone = getPhone(subId);
4844 if (phone == null) {
4845 loge("getCarrierPrivilegeStatus: Invalid subId");
4846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4847 }
4848 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004849 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004850 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4852 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004853
4854 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4855 card.getCarrierPrivilegeStatusForCurrentTransaction(
4856 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004857 }
Junda Liu29340342014-07-10 15:23:27 -07004858
4859 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004860 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4861 final Phone phone = getPhone(subId);
4862 if (phone == null) {
4863 loge("getCarrierPrivilegeStatus: Invalid subId");
4864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4865 }
4866 UiccProfile profile =
4867 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4868 if (profile == null) {
4869 loge("getCarrierPrivilegeStatus: No UICC");
4870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4871 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004872 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4873 profile.getCarrierPrivilegeStatusForUid(
4874 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004875 }
4876
4877 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004878 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4879 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004880 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004881 }
4882
4883 int phoneId = SubscriptionManager.getPhoneId(subId);
4884 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004885 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004886 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004887 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4888 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004889 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4890 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4891 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004892 }
4893
4894 @Override
4895 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004896 if (TextUtils.isEmpty(pkgName))
4897 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004898 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4899 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4900 UiccCard card = UiccController.getInstance().getUiccCard(i);
4901 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004902 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004903 continue;
4904 }
4905
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004906 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
4907 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4908 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004909 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4910 break;
4911 }
4912 }
4913
4914 return result;
Junda Liu29340342014-07-10 15:23:27 -07004915 }
Derek Tan89e89d42014-07-08 17:00:10 -07004916
4917 @Override
Junda Liue64de782015-04-16 17:19:16 -07004918 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4919 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4920 loge("phoneId " + phoneId + " is not valid.");
4921 return null;
4922 }
4923 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004924 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004925 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004926 return null ;
4927 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004928 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004929 }
4930
Amith Yamasani6e118872016-02-19 12:53:51 -08004931 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004932 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004933 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004934 List<String> privilegedPackages = new ArrayList<>();
4935 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004936 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4937 // has UICC in that slot.
4938 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004939 if (card.hasCarrierPrivilegeRules()) {
4940 if (packages == null) {
4941 // Only check packages in user 0 for now
4942 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004943 PackageManager.MATCH_DISABLED_COMPONENTS
4944 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09004945 | PackageManager.GET_SIGNING_CERTIFICATES,
4946 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004947 }
4948 for (int p = packages.size() - 1; p >= 0; p--) {
4949 PackageInfo pkgInfo = packages.get(p);
4950 if (pkgInfo != null && pkgInfo.packageName != null
4951 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004952 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004953 privilegedPackages.add(pkgInfo.packageName);
4954 }
4955 }
4956 }
4957 }
4958 return privilegedPackages;
4959 }
4960
chen xuf7e9fe82019-05-09 19:31:02 -07004961 @Override
4962 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4963 List<String> privilegedPackages = new ArrayList<>();
4964 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4965 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4966 }
4967 return privilegedPackages;
4968 }
4969
Wink Savilleb564aae2014-10-23 10:18:09 -07004970 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004971 final Phone phone = getPhone(subId);
4972 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004973 if (card == null) {
4974 loge("getIccId: No UICC");
4975 return null;
4976 }
4977 String iccId = card.getIccId();
4978 if (TextUtils.isEmpty(iccId)) {
4979 loge("getIccId: ICC ID is null or empty.");
4980 return null;
4981 }
4982 return iccId;
4983 }
4984
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004985 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004986 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4987 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004988 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4989 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 final String iccId = getIccId(subId);
4994 final Phone phone = getPhone(subId);
4995 if (phone == null) {
4996 return false;
4997 }
4998 final String subscriberId = phone.getSubscriberId();
4999
5000 if (DBG_MERGE) {
5001 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5002 + subscriberId + " to " + number);
5003 }
5004
5005 if (TextUtils.isEmpty(iccId)) {
5006 return false;
5007 }
5008
5009 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5010
5011 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5012 if (alphaTag == null) {
5013 editor.remove(alphaTagPrefKey);
5014 } else {
5015 editor.putString(alphaTagPrefKey, alphaTag);
5016 }
5017
5018 // Record both the line number and IMSI for this ICCID, since we need to
5019 // track all merged IMSIs based on line number
5020 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5021 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5022 if (number == null) {
5023 editor.remove(numberPrefKey);
5024 editor.remove(subscriberPrefKey);
5025 } else {
5026 editor.putString(numberPrefKey, number);
5027 editor.putString(subscriberPrefKey, subscriberId);
5028 }
5029
5030 editor.commit();
5031 return true;
5032 } finally {
5033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005034 }
Derek Tan7226c842014-07-02 17:42:23 -07005035 }
5036
5037 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005038 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005039 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005041 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005042 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005043 return null;
5044 }
Derek Tan97ebb422014-09-05 16:55:38 -07005045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 final long identity = Binder.clearCallingIdentity();
5047 try {
5048 String iccId = getIccId(subId);
5049 if (iccId != null) {
5050 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5051 if (DBG_MERGE) {
5052 log("getLine1NumberForDisplay returning "
5053 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5054 }
5055 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5058 return null;
5059 } finally {
5060 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005061 }
Derek Tan7226c842014-07-02 17:42:23 -07005062 }
5063
5064 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005065 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005067 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005068 return null;
5069 }
Derek Tan97ebb422014-09-05 16:55:38 -07005070
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071 final long identity = Binder.clearCallingIdentity();
5072 try {
5073 String iccId = getIccId(subId);
5074 if (iccId != null) {
5075 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5076 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5077 }
5078 return null;
5079 } finally {
5080 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005081 }
Derek Tan7226c842014-07-02 17:42:23 -07005082 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005083
5084 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005085 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005086 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5087 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005088 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005089 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5090 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005091 return null;
5092 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005093
Jordan Liub49b04b2019-05-06 14:45:15 -07005094 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5095 // the process, where TelephonyManager was instantiated.
5096 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005097 final long identity = Binder.clearCallingIdentity();
5098 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005099 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 final TelephonyManager tele = TelephonyManager.from(context);
5101 final SubscriptionManager sub = SubscriptionManager.from(context);
5102
5103 // Figure out what subscribers are currently active
5104 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105
Jordan Liub49b04b2019-05-06 14:45:15 -07005106 // Only consider subs which match the current subId
5107 // This logic can be simplified. See b/131189269 for progress.
5108 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005109 activeSubscriberIds.add(tele.getSubscriberId(subId));
5110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111
5112 // First pass, find a number override for an active subscriber
5113 String mergeNumber = null;
5114 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5115 for (String key : prefs.keySet()) {
5116 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5117 final String subscriberId = (String) prefs.get(key);
5118 if (activeSubscriberIds.contains(subscriberId)) {
5119 final String iccId = key.substring(
5120 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5121 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5122 mergeNumber = (String) prefs.get(numberKey);
5123 if (DBG_MERGE) {
5124 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5125 + " for active subscriber " + subscriberId);
5126 }
5127 if (!TextUtils.isEmpty(mergeNumber)) {
5128 break;
5129 }
5130 }
5131 }
5132 }
5133
5134 // Shortcut when no active merged subscribers
5135 if (TextUtils.isEmpty(mergeNumber)) {
5136 return null;
5137 }
5138
5139 // Second pass, find all subscribers under that line override
5140 final ArraySet<String> result = new ArraySet<>();
5141 for (String key : prefs.keySet()) {
5142 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5143 final String number = (String) prefs.get(key);
5144 if (mergeNumber.equals(number)) {
5145 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5146 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5147 final String subscriberId = (String) prefs.get(subscriberKey);
5148 if (!TextUtils.isEmpty(subscriberId)) {
5149 result.add(subscriberId);
5150 }
5151 }
5152 }
5153 }
5154
5155 final String[] resultArray = result.toArray(new String[result.size()]);
5156 Arrays.sort(resultArray);
5157 if (DBG_MERGE) {
5158 Slog.d(LOG_TAG,
5159 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5160 }
5161 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005164 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005165 }
5166
5167 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005168 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5169 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5170
5171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 final TelephonyManager telephonyManager = mApp.getSystemService(
5174 TelephonyManager.class);
5175 String subscriberId = telephonyManager.getSubscriberId(subId);
5176 if (subscriberId == null) {
5177 if (DBG) {
5178 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5179 + subId);
5180 }
5181 return null;
5182 }
5183
5184 final SubscriptionInfo info = SubscriptionController.getInstance()
5185 .getSubscriptionInfo(subId);
5186 final ParcelUuid groupUuid = info.getGroupUuid();
5187 // If it doesn't belong to any group, return just subscriberId of itself.
5188 if (groupUuid == null) {
5189 return new String[]{subscriberId};
5190 }
5191
5192 // Get all subscriberIds from the group.
5193 final List<String> mergedSubscriberIds = new ArrayList<>();
5194 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5195 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5196 for (SubscriptionInfo subInfo : groupInfos) {
5197 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5198 if (subscriberId != null) {
5199 mergedSubscriberIds.add(subscriberId);
5200 }
5201 }
5202
5203 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5204 } finally {
5205 Binder.restoreCallingIdentity(identity);
5206
5207 }
5208 }
5209
5210 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005211 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005212 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5213 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005214
5215 final long identity = Binder.clearCallingIdentity();
5216 try {
5217 final Phone phone = getPhone(subId);
5218 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5219 } finally {
5220 Binder.restoreCallingIdentity(identity);
5221 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005222 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005223
5224 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005225 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005226 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5227 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005228 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229
5230 final long identity = Binder.clearCallingIdentity();
5231 try {
5232 final Phone phone = getPhone(subId);
5233 if (phone == null) {
5234 return false;
5235 }
5236 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5237 cdmaNonRoamingList);
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005240 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005241 }
5242
5243 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005244 @Deprecated
5245 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5246 enforceModifyPermission();
5247
5248 int returnValue = 0;
5249 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005250 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005251 if(result.exception == null) {
5252 if (result.result != null) {
5253 byte[] responseData = (byte[])(result.result);
5254 if(responseData.length > oemResp.length) {
5255 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5256 responseData.length + "bytes. Buffer Size is " +
5257 oemResp.length + "bytes.");
5258 }
5259 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5260 returnValue = responseData.length;
5261 }
5262 } else {
5263 CommandException ex = (CommandException) result.exception;
5264 returnValue = ex.getCommandError().ordinal();
5265 if(returnValue > 0) returnValue *= -1;
5266 }
5267 } catch (RuntimeException e) {
5268 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5269 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5270 if(returnValue > 0) returnValue *= -1;
5271 }
5272
5273 return returnValue;
5274 }
5275
5276 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005277 public void setRadioCapability(RadioAccessFamily[] rafs) {
5278 try {
5279 ProxyController.getInstance().setRadioCapability(rafs);
5280 } catch (RuntimeException e) {
5281 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5282 }
5283 }
5284
5285 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005286 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005287 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005288 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005289 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005290 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005291 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 final long identity = Binder.clearCallingIdentity();
5293 try {
chen xub97461a2018-10-26 14:17:57 -07005294 TelephonyPermissions
5295 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5296 mApp, phone.getSubId(), "getRadioAccessFamily");
5297 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
chen xub97461a2018-10-26 14:17:57 -07005301 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005302 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005303
5304 @Override
5305 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005306 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005307 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308
5309 final long identity = Binder.clearCallingIdentity();
5310 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005311 ImsManager.getInstance(defaultPhone.getContext(),
5312 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005316 }
5317
5318 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005319 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005320 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005322 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005323 return false;
5324 }
Svet Ganovb320e182015-04-16 12:30:10 -07005325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 // Check the user preference and the system-level IMS setting. Even if the user has
5329 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5330 // In the long run, we may instead need to check if there exists a connection service
5331 // which can support video calling.
5332 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005333 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 return imsManager.isVtEnabledByPlatform()
5335 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5336 && imsManager.isVtEnabledByUser();
5337 } finally {
5338 Binder.restoreCallingIdentity(identity);
5339 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005340 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005341
Andrew Leea1239f22015-03-02 17:44:07 -08005342 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005343 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5345 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5346 return false;
5347 }
5348
5349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 CarrierConfigManager configManager =
5352 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005353 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005354 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5355 } finally {
5356 Binder.restoreCallingIdentity(identity);
5357 }
Andrew Leea1239f22015-03-02 17:44:07 -08005358 }
5359
5360 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005361 public boolean isWorldPhone(int subId, String callingPackage) {
5362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5363 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5364 return false;
5365 }
5366
5367 final long identity = Binder.clearCallingIdentity();
5368 try {
5369 CarrierConfigManager configManager =
5370 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005371 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Andrew Leea1239f22015-03-02 17:44:07 -08005376 }
5377
Andrew Lee9431b832015-03-09 18:46:45 -07005378 @Override
5379 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005380 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005381 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005382 }
5383
5384 @Override
5385 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 final long identity = Binder.clearCallingIdentity();
5387 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
Andrew Lee9431b832015-03-09 18:46:45 -07005392 }
5393
Hall Liuf6668912018-10-31 17:05:23 -07005394 /**
5395 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5396 * support for the feature and device firmware support.
5397 *
5398 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5399 */
5400 @Override
5401 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005403 final Phone phone = getPhone(subscriptionId);
5404 if (phone == null) {
5405 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5406 return false;
5407 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005409 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5411 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005412 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005413 return isCarrierSupported && isDeviceSupported;
5414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
Hall Liu98187582018-01-22 19:15:32 -08005417 }
5418
Hall Liuf6668912018-10-31 17:05:23 -07005419 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005420 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5421 * RTT setting, will return true if the device and carrier both support RTT.
5422 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005423 */
5424 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005425 final long identity = Binder.clearCallingIdentity();
5426 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005427 boolean isRttSupported = isRttSupported(subscriptionId);
5428 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005429 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005430 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5431 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5432 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 } finally {
5434 Binder.restoreCallingIdentity(identity);
5435 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005436 }
5437
Sanket Padawe7310cc72015-01-14 09:53:20 -08005438 /**
5439 * Returns the unique device ID of phone, for example, the IMEI for
5440 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5441 *
5442 * <p>Requires Permission:
5443 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5444 */
5445 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005446 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005447 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005448 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005449 return null;
5450 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005451 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005452 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5453 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005454 return null;
5455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005456
5457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 return phone.getDeviceId();
5460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005463 }
5464
Ping Sunc67b7c22016-03-02 19:16:45 +08005465 /**
5466 * {@hide}
5467 * Returns the IMS Registration Status on a particular subid
5468 *
5469 * @param subId
5470 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005471 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005472 Phone phone = getPhone(subId);
5473 if (phone != null) {
5474 return phone.isImsRegistered();
5475 } else {
5476 return false;
5477 }
5478 }
5479
Santos Cordon7a1885b2015-02-03 11:15:19 -08005480 @Override
5481 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005488 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005489
Tyler Gunnf70ed162019-04-03 15:28:53 -07005490 @Override
5491 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5492 final long identity = Binder.clearCallingIdentity();
5493 try {
5494 Phone phone = getPhone(subscriptionId);
5495 if (phone == null) {
5496 return null;
5497 }
5498 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5499 } finally {
5500 Binder.restoreCallingIdentity(identity);
5501 }
5502 }
5503
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005504 /**
5505 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005506 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005507 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 final long identity = Binder.clearCallingIdentity();
5509 try {
5510 Phone phone = getPhone(subId);
5511 if (phone != null) {
5512 return phone.isWifiCallingEnabled();
5513 } else {
5514 return false;
5515 }
5516 } finally {
5517 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005518 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005519 }
5520
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005521 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005522 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005523 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005524 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005525 final long identity = Binder.clearCallingIdentity();
5526 try {
5527 Phone phone = getPhone(subId);
5528 if (phone != null) {
5529 return phone.isVideoEnabled();
5530 } else {
5531 return false;
5532 }
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005535 }
5536 }
5537
5538 /**
5539 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5540 * defined in {@link ImsRegistrationImplBase}.
5541 */
5542 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 final long identity = Binder.clearCallingIdentity();
5544 try {
5545 Phone phone = getPhone(subId);
5546 if (phone != null) {
5547 return phone.getImsRegistrationTech();
5548 } else {
5549 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5550 }
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005553 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005554 }
5555
Stuart Scott8eef64f2015-04-08 15:13:54 -07005556 @Override
5557 public void factoryReset(int subId) {
5558 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005559 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5560 return;
5561 }
5562
Svet Ganovcc087f82015-05-12 20:35:54 -07005563 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005564
Svet Ganovcc087f82015-05-12 20:35:54 -07005565 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005566 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5567 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005568 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005569 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005570 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005571 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5572 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005573 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005574 // There has been issues when Sms raw table somehow stores orphan
5575 // fragments. They lead to garbled message when new fragments come
5576 // in and combined with those stale ones. In case this happens again,
5577 // user can reset all network settings which will clean up this table.
5578 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005579 } finally {
5580 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005581 }
5582 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005583
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005584 private void cleanUpSmsRawTable(Context context) {
5585 ContentResolver resolver = context.getContentResolver();
5586 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5587 resolver.delete(uri, null, null);
5588 }
5589
Narayan Kamath1c496c22015-04-16 14:40:19 +01005590 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005591 public String getSimLocaleForSubscriber(int subId) {
5592 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5593 final Phone phone = getPhone(subId);
5594 if (phone == null) {
5595 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005596 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005598 final long identity = Binder.clearCallingIdentity();
5599 try {
chen xu5d3637b2019-01-21 23:31:38 -08005600 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5601 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005602 if (info == null) {
5603 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5604 return null;
5605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 // Try and fetch the locale from the carrier properties or from the SIM language
5607 // preferences (EF-PL and EF-LI)...
5608 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005610 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5611 if (localeFromDefaultSim != null) {
5612 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5613 if (DBG) log("Using locale from subId: " + subId + " locale: "
5614 + localeFromDefaultSim);
5615 return localeFromDefaultSim.toLanguageTag();
5616 } else {
5617 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005618 }
5619 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005621 // The SIM language preferences only store a language (e.g. fr = French), not an
5622 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5623 // the SIM and carrier preferences does not include a country we add the country
5624 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005625 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005627 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005628 return mccLocale.toLanguageTag();
5629 }
5630
5631 if (DBG) log("No locale found - returning null");
5632 return null;
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005636 }
5637
5638 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005639 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005640 }
5641
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005642 /**
5643 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5644 */
5645 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005646 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005647 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005648
Chenjie Yu1ba97252018-01-11 18:16:20 -08005649 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005650 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005651
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005652 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005653 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5654 * representing the state of the modem.
5655 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005656 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5657 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005658 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005659 */
5660 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005661 public void requestModemActivityInfo(ResultReceiver result) {
5662 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005663 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005664
5665 final long identity = Binder.clearCallingIdentity();
5666 try {
5667 ModemActivityInfo ret = null;
5668 synchronized (mLastModemActivityInfo) {
5669 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5670 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005671 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005672 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005674 int[] txTimeMs = info.getTransmitTimeMillis();
5675 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005677 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 }
5679 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5681 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 mLastModemActivityInfo.setIdleTimeMillis(
5683 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005684 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5685 mLastModemActivityInfo.setReceiveTimeMillis(
5686 info.getReceiveTimeMillis() + mLastModemActivityInfo
5687 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005688 }
Chen Xud78231e2019-09-10 18:49:52 -07005689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5691 mLastModemActivityInfo.getSleepTimeMillis(),
5692 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005693 mLastModemActivityInfo.getTransmitTimeMillis(),
5694 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005696 Bundle bundle = new Bundle();
5697 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5698 result.send(0, bundle);
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005701 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005702 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005703
Siddharth Rayb8114062018-06-17 15:02:38 -07005704 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5705 // less than total activity duration.
5706 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5707 if (info == null) {
5708 return false;
5709 }
5710 int activityDurationMs =
5711 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5712 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005713 int[] txTimeMs = info.getTransmitTimeMillis();
5714 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5715 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005716 }
5717 return (info.isValid()
5718 && (info.getSleepTimeMillis() <= activityDurationMs)
5719 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005720 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005721 && (totalTxTimeMs <= activityDurationMs));
5722 }
5723
Jack Yu85bd38a2015-11-09 11:34:32 -08005724 /**
5725 * {@hide}
5726 * Returns the service state information on specified subscription.
5727 */
5728 @Override
5729 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005731 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005732 return null;
5733 }
5734
Hall Liuf19c44f2018-11-27 14:38:17 -08005735 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5736 LocationAccessPolicy.checkLocationPermission(mApp,
5737 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5738 .setCallingPackage(callingPackage)
5739 .setCallingPid(Binder.getCallingPid())
5740 .setCallingUid(Binder.getCallingUid())
5741 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005742 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005743 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5744 .build());
5745
5746 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5747 LocationAccessPolicy.checkLocationPermission(mApp,
5748 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5749 .setCallingPackage(callingPackage)
5750 .setCallingPid(Binder.getCallingPid())
5751 .setCallingUid(Binder.getCallingUid())
5752 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005753 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005754 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5755 .build());
5756 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5757 boolean hasFinePermission =
5758 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5759 boolean hasCoarsePermission =
5760 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5761
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 final long identity = Binder.clearCallingIdentity();
5763 try {
5764 final Phone phone = getPhone(subId);
5765 if (phone == null) {
5766 return null;
5767 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005768
Hall Liuf19c44f2018-11-27 14:38:17 -08005769 ServiceState ss = phone.getServiceState();
5770
5771 // Scrub out the location info in ServiceState depending on what level of access
5772 // the caller has.
5773 if (hasFinePermission) return ss;
5774 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5775 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005779 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005780
5781 /**
5782 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5783 *
5784 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5785 * voicemail ringtone.
5786 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5787 * PhoneAccount.
5788 */
5789 @Override
5790 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5794 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005795 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005796 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005798 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
5801 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005802 }
5803
5804 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005805 * Sets the per-account voicemail ringtone.
5806 *
5807 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5808 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5809 *
5810 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5811 * voicemail ringtone.
5812 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5813 * PhoneAccount.
5814 */
5815 @Override
5816 public void setVoicemailRingtoneUri(String callingPackage,
5817 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005818 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005819 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5820 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005821 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5823 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5824 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005825 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005826
5827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5830 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005831 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 }
5833 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5834 } finally {
5835 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005836 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005837 }
5838
5839 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005840 * Returns whether vibration is set for voicemail notification in Phone settings.
5841 *
5842 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5843 * voicemail vibration setting.
5844 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5845 */
5846 @Override
5847 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005848 final long identity = Binder.clearCallingIdentity();
5849 try {
5850 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5851 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005852 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005853 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005855 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
5858 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005859 }
5860
Youhan Wange64578a2016-05-02 15:32:42 -07005861 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005862 * Sets the per-account voicemail vibration.
5863 *
5864 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5865 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5866 *
5867 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5868 * voicemail vibration setting.
5869 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5870 * specific PhoneAccount.
5871 */
5872 @Override
5873 public void setVoicemailVibrationEnabled(String callingPackage,
5874 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005875 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005876 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5877 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005878 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5880 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5881 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005882 }
5883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005884 final long identity = Binder.clearCallingIdentity();
5885 try {
5886 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5887 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005888 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005889 }
5890 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5891 } finally {
5892 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005893 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005894 }
5895
5896 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005897 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5898 *
5899 * @throws SecurityException if the caller does not have the required permission
5900 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005901 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005902 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005903 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005904 }
5905
5906 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005907 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5908 * permission.
5909 *
5910 * @throws SecurityException if the caller does not have the required permission
5911 */
5912 private void enforceSendSmsPermission() {
5913 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5914 }
5915
5916 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005917 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005918 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005919 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005920 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005921 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005922 final long identity = Binder.clearCallingIdentity();
5923 try {
5924 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005925 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 if (componentName == null) {
5927 throw new SecurityException(
5928 "Caller not current active visual voicemail package[null]");
5929 }
5930 String vvmPackage = componentName.getPackageName();
5931 if (!callingPackage.equals(vvmPackage)) {
5932 throw new SecurityException("Caller not current active visual voicemail package["
5933 + vvmPackage + "]");
5934 }
5935 } finally {
5936 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005937 }
5938 }
5939
5940 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005941 * Return the application ID for the app type.
5942 *
5943 * @param subId the subscription ID that this request applies to.
5944 * @param appType the uicc app type.
5945 * @return Application ID for specificied app type, or null if no uicc.
5946 */
5947 @Override
5948 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005949 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005950 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951
5952 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005953 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 if (phone == null) {
5955 return null;
5956 }
5957 String aid = null;
5958 try {
5959 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5960 .getApplicationByType(appType).getAid();
5961 } catch (Exception e) {
5962 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5963 }
5964 return aid;
5965 } finally {
5966 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005967 }
Youhan Wange64578a2016-05-02 15:32:42 -07005968 }
5969
Youhan Wang4001d252016-05-11 10:29:41 -07005970 /**
5971 * Return the Electronic Serial Number.
5972 *
5973 * @param subId the subscription ID that this request applies to.
5974 * @return ESN or null if error.
5975 */
5976 @Override
5977 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005978 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005979 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980
5981 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005982 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 if (phone == null) {
5984 return null;
5985 }
5986 String esn = null;
5987 try {
5988 esn = phone.getEsn();
5989 } catch (Exception e) {
5990 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5991 }
5992 return esn;
5993 } finally {
5994 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005995 }
Youhan Wang4001d252016-05-11 10:29:41 -07005996 }
5997
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005998 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005999 * Return the Preferred Roaming List Version.
6000 *
6001 * @param subId the subscription ID that this request applies to.
6002 * @return PRLVersion or null if error.
6003 */
6004 @Override
6005 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006006 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006007 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008
6009 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006010 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 if (phone == null) {
6012 return null;
6013 }
6014 String cdmaPrlVersion = null;
6015 try {
6016 cdmaPrlVersion = phone.getCdmaPrlVersion();
6017 } catch (Exception e) {
6018 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6019 }
6020 return cdmaPrlVersion;
6021 } finally {
6022 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006023 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006024 }
6025
6026 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006027 * Get snapshot of Telephony histograms
6028 * @return List of Telephony histograms
6029 * @hide
6030 */
6031 @Override
6032 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6034 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035
6036 final long identity = Binder.clearCallingIdentity();
6037 try {
6038 return RIL.getTelephonyRILTimingHistograms();
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006042 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006043
6044 /**
6045 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006046 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6047 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006048 * Require system privileges. In the future we may add this to carrier APIs.
6049 *
Michele Berionne482f8202018-11-27 18:57:59 -08006050 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006051 */
6052 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006053 @TelephonyManager.SetCarrierRestrictionResult
6054 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006055 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006056 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006057
Michele Berionne482f8202018-11-27 18:57:59 -08006058 if (carrierRestrictionRules == null) {
6059 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006060 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 final long identity = Binder.clearCallingIdentity();
6063 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006064 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006065 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006069 }
6070
6071 /**
6072 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006073 * Get the allowed carrier list and the excluded carrier list, including the priority between
6074 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006075 * Require system privileges. In the future we may add this to carrier APIs.
6076 *
Michele Berionne482f8202018-11-27 18:57:59 -08006077 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006078 */
6079 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006080 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006081 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006083
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006086 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6087 if (response instanceof CarrierRestrictionRules) {
6088 return (CarrierRestrictionRules) response;
6089 }
6090 // Response is an Exception of some kind,
6091 // which is signalled to the user as a NULL retval
6092 return null;
6093 } catch (Exception e) {
6094 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6095 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 } finally {
6097 Binder.restoreCallingIdentity(identity);
6098 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006099 }
6100
fionaxu59545b42016-05-25 15:53:37 -07006101 /**
6102 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6103 * @param subId the subscription ID that this action applies to.
6104 * @param enabled control enable or disable metered apns.
6105 * {@hide}
6106 */
6107 @Override
6108 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6109 enforceModifyPermission();
6110 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006111
6112 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006113 if (phone == null) {
6114 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6115 return;
6116 }
6117 try {
6118 phone.carrierActionSetMeteredApnsEnabled(enabled);
6119 } catch (Exception e) {
6120 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006123 }
6124 }
6125
6126 /**
6127 * Action set from carrier signalling broadcast receivers to enable/disable radio
6128 * @param subId the subscription ID that this action applies to.
6129 * @param enabled control enable or disable radio.
6130 * {@hide}
6131 */
6132 @Override
6133 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6134 enforceModifyPermission();
6135 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136
6137 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006138 if (phone == null) {
6139 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6140 return;
6141 }
6142 try {
6143 phone.carrierActionSetRadioEnabled(enabled);
6144 } catch (Exception e) {
6145 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006146 } finally {
6147 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006148 }
6149 }
6150
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006151 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006152 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6153 * network status based on which carrier apps could apply actions accordingly,
6154 * enable/disable default url handler for example.
6155 *
6156 * @param subId the subscription ID that this action applies to.
6157 * @param report control start/stop reporting the default network status.
6158 * {@hide}
6159 */
6160 @Override
6161 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6162 enforceModifyPermission();
6163 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
6165 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006166 if (phone == null) {
6167 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6168 return;
6169 }
6170 try {
6171 phone.carrierActionReportDefaultNetworkStatus(report);
6172 } catch (Exception e) {
6173 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174 } finally {
6175 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006176 }
6177 }
6178
6179 /**
fionaxud9622282017-07-17 17:51:30 -07006180 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6181 * @param subId the subscription ID that this action applies to.
6182 * {@hide}
6183 */
6184 @Override
6185 public void carrierActionResetAll(int subId) {
6186 enforceModifyPermission();
6187 final Phone phone = getPhone(subId);
6188 if (phone == null) {
6189 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6190 return;
6191 }
6192 try {
6193 phone.carrierActionResetAll();
6194 } catch (Exception e) {
6195 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6196 }
6197 }
6198
6199 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006200 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6201 * bug report is being generated.
6202 */
6203 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006204 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006205 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6206 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006207 writer.println("Permission Denial: can't dump Phone from pid="
6208 + Binder.getCallingPid()
6209 + ", uid=" + Binder.getCallingUid()
6210 + "without permission "
6211 + android.Manifest.permission.DUMP);
6212 return;
6213 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006214 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006215 }
Jack Yueb89b242016-06-22 13:27:47 -07006216
Brad Ebingerdac2f002018-04-03 15:17:52 -07006217 @Override
6218 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6219 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6220 throws RemoteException {
6221 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6222 }
6223
Jack Yueb89b242016-06-22 13:27:47 -07006224 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006225 * Get aggregated video call data usage since boot.
6226 *
6227 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6228 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006229 * {@hide}
6230 */
6231 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006232 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006233 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6234 null);
6235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 final long identity = Binder.clearCallingIdentity();
6237 try {
6238 // NetworkStatsService keeps tracking the active network interface and identity. It
6239 // records the delta with the corresponding network identity.
6240 // We just return the total video call data usage snapshot since boot.
6241 Phone phone = getPhone(subId);
6242 if (phone != null) {
6243 return phone.getVtDataUsage(perUidStats);
6244 }
6245 return null;
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006248 }
Jack Yueb89b242016-06-22 13:27:47 -07006249 }
Jack Yu75ab2952016-07-08 14:29:33 -07006250
6251 /**
6252 * Policy control of data connection. Usually used when data limit is passed.
6253 * @param enabled True if enabling the data, otherwise disabling.
6254 * @param subId Subscription index
6255 * {@hide}
6256 */
6257 @Override
6258 public void setPolicyDataEnabled(boolean enabled, int subId) {
6259 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
6263 Phone phone = getPhone(subId);
6264 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006265 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 }
6267 } finally {
6268 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006269 }
6270 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006271
6272 /**
6273 * Get Client request stats
6274 * @return List of Client Request Stats
6275 * @hide
6276 */
6277 @Override
6278 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006279 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006280 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006281 return null;
6282 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006283 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006284
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 if (phone != null) {
6288 return phone.getClientRequestStats();
6289 }
6290
6291 return null;
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006295 }
6296
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006297 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006298 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006299 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006300 }
Jack Yueb4124c2017-02-16 15:32:43 -08006301
6302 /**
Grace Chen70990072017-03-24 17:21:30 -07006303 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006304 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006305 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006306 * @param state State of SIM (power down, power up, pass through)
6307 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6308 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6309 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006310 *
6311 **/
6312 @Override
Grace Chen70990072017-03-24 17:21:30 -07006313 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006314 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006315 Phone phone = PhoneFactory.getPhone(slotIndex);
6316
vagdeviaf9a5b92018-08-15 16:01:53 -07006317 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006322 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006323 }
6324 } finally {
6325 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006326 }
6327 }
Shuo Qiandd210312017-04-12 22:11:33 +00006328
Tyler Gunn65d45c22017-06-05 11:22:26 -07006329 private boolean isUssdApiAllowed(int subId) {
6330 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006332 if (configManager == null) {
6333 return false;
6334 }
6335 PersistableBundle pb = configManager.getConfigForSubId(subId);
6336 if (pb == null) {
6337 return false;
6338 }
6339 return pb.getBoolean(
6340 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6341 }
6342
Shuo Qiandd210312017-04-12 22:11:33 +00006343 /**
6344 * Check if phone is in emergency callback mode
6345 * @return true if phone is in emergency callback mode
6346 * @param subId sub id
6347 */
goneil9c5f4872017-12-05 14:07:56 -08006348 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006349 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006350 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006351 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 if (phone != null) {
6356 return phone.isInEcm();
6357 } else {
6358 return false;
6359 }
6360 } finally {
6361 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006362 }
6363 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006364
6365 /**
6366 * Get the current signal strength information for the given subscription.
6367 * Because this information is not updated when the device is in a low power state
6368 * it should not be relied-upon to be current.
6369 * @param subId Subscription index
6370 * @return the most recent cached signal strength info from the modem
6371 */
6372 @Override
6373 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 Phone p = getPhone(subId);
6377 if (p == null) {
6378 return null;
6379 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 return p.getSignalStrength();
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006385 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006386
Pengquan Meng77b7f132018-08-22 14:49:57 -07006387 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006388 * Get the current modem radio state for the given slot.
6389 * @param slotIndex slot index.
6390 * @param callingPackage the name of the package making the call.
6391 * @return the current radio power state from the modem
6392 */
6393 @Override
6394 public int getRadioPowerState(int slotIndex, String callingPackage) {
6395 Phone phone = PhoneFactory.getPhone(slotIndex);
6396 if (phone != null) {
6397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6398 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6399 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6400 }
6401
6402 final long identity = Binder.clearCallingIdentity();
6403 try {
6404 return phone.getRadioPowerState();
6405 } finally {
6406 Binder.restoreCallingIdentity(identity);
6407 }
6408 }
6409 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6410 }
6411
6412 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006413 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6414 *
6415 * <p>Requires one of the following permissions:
6416 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6417 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6418 * privileges.
6419 *
6420 * @param subId subscription id
6421 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6422 * {@code false}.
6423 */
6424 @Override
6425 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006426 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6427 null /* message */);
6428
Pengquan Menga1bb6272018-09-06 09:59:22 -07006429 boolean isEnabled = false;
6430 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006431 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006432 Phone phone = getPhone(subId);
6433 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006434 } catch (Exception e) {
6435 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6436 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006437 } finally {
6438 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006439 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006440 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006441 }
6442
6443
6444 /**
6445 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6446 *
6447 * <p> Requires permission:
6448 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6449 * privileges.
6450 *
6451 * @param subId subscription id
6452 * @param isEnabled {@code true} means enable, {@code false} means disable.
6453 */
6454 @Override
6455 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6457 mApp, subId, "setDataRoamingEnabled");
6458
Pengquan Menga1bb6272018-09-06 09:59:22 -07006459 final long identity = Binder.clearCallingIdentity();
6460 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006461 Phone phone = getPhone(subId);
6462 if (phone != null) {
6463 phone.setDataRoamingEnabled(isEnabled);
6464 }
6465 } finally {
6466 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006467 }
6468 }
6469
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006470 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006471 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006472 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6473 mApp, subId, "isManualNetworkSelectionAllowed");
6474
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006475 boolean isAllowed = true;
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006478 Phone phone = getPhone(subId);
6479 if (phone != null) {
6480 isAllowed = phone.isCspPlmnEnabled();
6481 }
6482 } finally {
6483 Binder.restoreCallingIdentity(identity);
6484 }
6485 return isAllowed;
6486 }
6487
6488 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006489 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006490 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006491 try {
6492 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006493 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006494 } catch (SecurityException e) {
6495 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6496 // has carrier privileges on an active UICC
6497 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6498 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006499 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006500 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006501 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006502
6503 final long identity = Binder.clearCallingIdentity();
6504 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006505 UiccController uiccController = UiccController.getInstance();
6506 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006507 if (hasReadPermission) {
6508 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006509 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006510
6511 // Remove private info if the caller doesn't have access
6512 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6513 for (UiccCardInfo cardInfo : cardInfos) {
6514 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6515 // is available
6516 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6517 if (card == null || card.getUiccProfile() == null) {
6518 // assume no access if the card or profile is unavailable
6519 filteredInfos.add(cardInfo.getUnprivileged());
6520 continue;
6521 }
6522 UiccProfile profile = card.getUiccProfile();
6523 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6524 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6525 filteredInfos.add(cardInfo);
6526 } else {
6527 filteredInfos.add(cardInfo.getUnprivileged());
6528 }
6529 }
6530 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006537 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006538 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006539
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 final long identity = Binder.clearCallingIdentity();
6541 try {
6542 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6543 if (slots == null) {
6544 Rlog.i(LOG_TAG, "slots is null.");
6545 return null;
6546 }
6547
6548 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6549 for (int i = 0; i < slots.length; i++) {
6550 UiccSlot slot = slots[i];
6551 if (slot == null) {
6552 continue;
6553 }
6554
Jordan Liu7be7e652019-05-06 18:55:02 +00006555 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 UiccCard card = slot.getUiccCard();
6557 if (card != null) {
6558 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006559 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006560 cardId = slot.getEid();
6561 if (TextUtils.isEmpty(cardId)) {
6562 cardId = slot.getIccId();
6563 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 }
6565
Jordan Liu857451f2019-05-09 16:35:35 -07006566 if (cardId != null) {
6567 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6568 // if cardId is an EID, it's all digits so this is fine
6569 cardId = IccUtils.stripTrailingFs(cardId);
6570 }
6571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 int cardState = 0;
6573 switch (slot.getCardState()) {
6574 case CARDSTATE_ABSENT:
6575 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6576 break;
6577 case CARDSTATE_PRESENT:
6578 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6579 break;
6580 case CARDSTATE_ERROR:
6581 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6582 break;
6583 case CARDSTATE_RESTRICTED:
6584 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6585 break;
6586 default:
6587 break;
6588
6589 }
6590
6591 infos[i] = new UiccSlotInfo(
6592 slot.isActive(),
6593 slot.isEuicc(),
6594 cardId,
6595 cardState,
6596 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006597 slot.isExtendedApduSupported(),
6598 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006599 }
6600 return infos;
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006603 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006604 }
6605
6606 @Override
6607 public boolean switchSlots(int[] physicalSlots) {
6608 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006609
6610 final long identity = Binder.clearCallingIdentity();
6611 try {
6612 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006616 }
Jack Yu4c988042018-02-27 15:30:01 -08006617
6618 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006619 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006620 final long identity = Binder.clearCallingIdentity();
6621 try {
6622 return UiccController.getInstance().getCardIdForDefaultEuicc();
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
6625 }
6626 }
6627
6628 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006629 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6630 enforceModifyPermission();
6631 final Phone phone = getPhone(subId);
6632 if (phone == null) {
6633 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6634 return;
6635 }
6636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 phone.setRadioIndicationUpdateMode(filters, mode);
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
Jack Yu4c988042018-02-27 15:30:01 -08006643 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006644
6645 /**
goneil47ffb6e2018-04-06 15:40:58 -07006646 * A test API to reload the UICC profile.
6647 *
6648 * <p>Requires that the calling app has permission
6649 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6650 * @hide
6651 */
6652 @Override
6653 public void refreshUiccProfile(int subId) {
6654 enforceModifyPermission();
6655
6656 final long identity = Binder.clearCallingIdentity();
6657 try {
6658 Phone phone = getPhone(subId);
6659 if (phone == null) {
6660 return;
6661 }
6662 UiccCard uiccCard = phone.getUiccCard();
6663 if (uiccCard == null) {
6664 return;
6665 }
6666 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6667 if (uiccProfile == null) {
6668 return;
6669 }
6670 uiccProfile.refresh();
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
6673 }
6674 }
6675
6676 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006677 * Returns false if the mobile data is disabled by default, otherwise return true.
6678 */
6679 private boolean getDefaultDataEnabled() {
6680 return "true".equalsIgnoreCase(
6681 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6682 }
6683
6684 /**
6685 * Returns true if the data roaming is enabled by default, i.e the system property
6686 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6687 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6688 */
6689 private boolean getDefaultDataRoamingEnabled(int subId) {
6690 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006691 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006692 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6693 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6694 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6695 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6696 return isDataRoamingEnabled;
6697 }
6698
6699 /**
6700 * Returns the default network type for the given {@code subId}, if the default network type is
6701 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6702 */
6703 private int getDefaultNetworkType(int subId) {
6704 return Integer.parseInt(
6705 TelephonyManager.getTelephonyProperty(
6706 mSubscriptionController.getPhoneId(subId),
6707 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6708 String.valueOf(Phone.PREFERRED_NT_MODE)));
6709 }
fionaxua13278b2018-03-21 00:08:13 -07006710
6711 @Override
6712 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006713 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 final Phone phone = getPhone(subId);
6719 if (phone == null) {
6720 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6721 return;
6722 }
chen xueaba88a2019-03-15 13:15:10 -07006723 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6724 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006727 }
fionaxua13278b2018-03-21 00:08:13 -07006728 }
6729
6730 @Override
6731 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006732 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 final Phone phone = getPhone(subId);
6737 if (phone == null) {
6738 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6739 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6740 }
6741 return phone.getCarrierIdListVersion();
6742 } finally {
6743 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006744 }
fionaxua13278b2018-03-21 00:08:13 -07006745 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006746
6747 @Override
6748 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6750 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6751 return -1;
6752 }
6753
6754 final long identity = Binder.clearCallingIdentity();
6755 try {
6756 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6757 } finally {
6758 Binder.restoreCallingIdentity(identity);
6759 }
6760 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006761
6762 @Override
6763 public int getCdmaRoamingMode(int subId) {
6764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6765 mApp, subId, "getCdmaRoamingMode");
6766
6767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6770 } finally {
6771 Binder.restoreCallingIdentity(identity);
6772 }
6773 }
6774
6775 @Override
6776 public boolean setCdmaRoamingMode(int subId, int mode) {
6777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6778 mApp, subId, "setCdmaRoamingMode");
6779
6780 final long identity = Binder.clearCallingIdentity();
6781 try {
6782 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
6786 }
6787
6788 @Override
6789 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6790 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6791 mApp, subId, "setCdmaSubscriptionMode");
6792
6793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
6799 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006800
6801 private void ensureUserRunning(int userId) {
6802 if (!mUserManager.isUserRunning(userId)) {
6803 throw new IllegalStateException("User " + userId + " does not exist or not running");
6804 }
6805 }
6806
6807 /**
6808 * Returns a list of SMS apps on a given user.
6809 *
6810 * Only the shell user (UID 2000 or 0) can call it.
6811 * Target user must be running.
6812 */
6813 @Override
6814 public String[] getSmsApps(int userId) {
6815 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6816 ensureUserRunning(userId);
6817
6818 final Collection<SmsApplicationData> apps =
6819 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6820
6821 String[] ret = new String[apps.size()];
6822 int i = 0;
6823 for (SmsApplicationData app : apps) {
6824 ret[i++] = app.mPackageName;
6825 }
6826 return ret;
6827 }
6828
6829 /**
6830 * Returns the default SMS app package name on a given user.
6831 *
6832 * Only the shell user (UID 2000 or 0) can call it.
6833 * Target user must be running.
6834 */
6835 @Override
6836 public String getDefaultSmsApp(int userId) {
6837 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6838 ensureUserRunning(userId);
6839
6840 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6841 /* updateIfNeeded= */ true, userId);
6842 return cn == null ? null : cn.getPackageName();
6843 }
6844
6845 /**
6846 * Set a package as the default SMS app on a given user.
6847 *
6848 * Only the shell user (UID 2000 or 0) can call it.
6849 * Target user must be running.
6850 */
6851 @Override
6852 public void setDefaultSmsApp(int userId, String packageName) {
6853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6854 ensureUserRunning(userId);
6855
6856 boolean found = false;
6857 for (String pkg : getSmsApps(userId)) {
6858 if (TextUtils.equals(packageName, pkg)) {
6859 found = true;
6860 break;
6861 }
6862 }
6863 if (!found) {
6864 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6865 }
6866
6867 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6868 }
sqianc5eccab2018-10-19 18:46:41 -07006869
6870 @Override
sqian8c685422019-02-22 15:55:18 -08006871 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006872 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006874 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006875 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6876 }
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
sqian854d44b2018-12-12 16:48:18 -08006879 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6880 for (Phone phone: PhoneFactory.getPhones()) {
6881 if (phone.getEmergencyNumberTracker() != null
6882 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6883 emergencyNumberListInternal.put(
6884 phone.getSubId(),
6885 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6886 }
sqian11b7a0e2018-12-05 18:48:28 -08006887 }
sqian854d44b2018-12-12 16:48:18 -08006888 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
sqianc5eccab2018-10-19 18:46:41 -07006892 }
6893
6894 @Override
sqian8c685422019-02-22 15:55:18 -08006895 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006896 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006897 if (!exactMatch) {
6898 TelephonyPermissions
6899 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006900 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006901 }
6902 final long identity = Binder.clearCallingIdentity();
6903 try {
sqian854d44b2018-12-12 16:48:18 -08006904 for (Phone phone: PhoneFactory.getPhones()) {
6905 if (phone.getEmergencyNumberTracker() != null
6906 && phone.getEmergencyNumberTracker() != null) {
6907 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6908 number, exactMatch)) {
6909 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006910 }
6911 }
sqian11b7a0e2018-12-05 18:48:28 -08006912 }
6913 return false;
6914 } finally {
6915 Binder.restoreCallingIdentity(identity);
6916 }
6917 }
6918
sqianf4ca7ed2019-01-15 18:32:07 -08006919 /**
6920 * Update emergency number list for test mode.
6921 */
6922 @Override
6923 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6924 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6925 "updateEmergencyNumberListTestMode");
6926
6927 final long identity = Binder.clearCallingIdentity();
6928 try {
6929 for (Phone phone: PhoneFactory.getPhones()) {
6930 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6931 if (tracker != null) {
6932 tracker.executeEmergencyNumberTestModeCommand(action, num);
6933 }
6934 }
6935 } finally {
6936 Binder.restoreCallingIdentity(identity);
6937 }
6938 }
6939
6940 /**
6941 * Get the full emergency number list for test mode.
6942 */
6943 @Override
6944 public List<String> getEmergencyNumberListTestMode() {
6945 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6946 "getEmergencyNumberListTestMode");
6947
6948 final long identity = Binder.clearCallingIdentity();
6949 try {
6950 Set<String> emergencyNumbers = new HashSet<>();
6951 for (Phone phone: PhoneFactory.getPhones()) {
6952 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6953 if (tracker != null) {
6954 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6955 emergencyNumbers.add(num.getNumber());
6956 }
6957 }
6958 }
6959 return new ArrayList<>(emergencyNumbers);
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
6963 }
6964
chen xud6b45bd2018-10-30 22:27:10 -07006965 @Override
6966 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6967 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6968 Phone phone = getPhone(subId);
6969 if (phone == null) {
6970 return null;
6971 }
6972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 UiccProfile profile = UiccController.getInstance()
6975 .getUiccProfileForPhone(phone.getPhoneId());
6976 if (profile != null) {
6977 return profile.getCertsFromCarrierPrivilegeAccessRules();
6978 }
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
6982 return null;
6983 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006984
6985 /**
6986 * Enable or disable a modem stack.
6987 */
6988 @Override
6989 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6990 enforceModifyPermission();
6991
6992 final long identity = Binder.clearCallingIdentity();
6993 try {
6994 Phone phone = PhoneFactory.getPhone(slotIndex);
6995 if (phone == null) {
6996 return false;
6997 } else {
6998 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6999 }
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
7002 }
7003 }
Michelecea4cf22018-12-21 15:00:11 -08007004
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007005 /**
7006 * Whether a modem stack is enabled or not.
7007 */
7008 @Override
7009 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7010 Phone phone = PhoneFactory.getPhone(slotIndex);
7011 if (phone == null) return false;
7012
7013 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7014 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7015 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7016 }
7017
7018 final long identity = Binder.clearCallingIdentity();
7019 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007020 try {
7021 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7022 } catch (NoSuchElementException ex) {
7023 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7024 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007025 } finally {
7026 Binder.restoreCallingIdentity(identity);
7027 }
7028 }
7029
Michelecea4cf22018-12-21 15:00:11 -08007030 @Override
Michele0ea7d782019-03-19 14:58:42 -07007031 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007032 enforceModifyPermission();
7033
7034 final long identity = Binder.clearCallingIdentity();
7035 try {
7036 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007037 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007038 .commit();
7039 } finally {
7040 Binder.restoreCallingIdentity(identity);
7041 }
7042 }
7043
7044 @Override
Michele0ea7d782019-03-19 14:58:42 -07007045 @TelephonyManager.IsMultiSimSupportedResult
7046 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007048 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7049 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007050 }
Michelecea4cf22018-12-21 15:00:11 -08007051
7052 final long identity = Binder.clearCallingIdentity();
7053 try {
Michele0ea7d782019-03-19 14:58:42 -07007054 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007055 } finally {
7056 Binder.restoreCallingIdentity(identity);
7057 }
7058 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007059
Michele0ea7d782019-03-19 14:58:42 -07007060 @TelephonyManager.IsMultiSimSupportedResult
7061 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007062 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7063 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7064 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007065 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7066 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007067 }
7068 // Check if the hardware supports multisim functionality. If usage of multisim is not
7069 // supported by the modem, indicate that it is restricted.
7070 PhoneCapability staticCapability =
7071 mPhoneConfigurationManager.getStaticPhoneCapability();
7072 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007073 loge("isMultiSimSupportedInternal: no static configuration available");
7074 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007075 }
7076 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007077 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7078 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007079 }
7080 // Check if support of multiple SIMs is restricted by carrier
7081 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007082 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007083 }
7084
Michele0ea7d782019-03-19 14:58:42 -07007085 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007086 }
7087
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007088 /**
7089 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007090 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7091 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7092 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007093 * @param numOfSims number of active sims we want to switch to
7094 */
7095 @Override
7096 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007097 if (numOfSims == 1) {
7098 enforceModifyPermission();
7099 } else {
7100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7101 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7102 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007103 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007104
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007105 try {
Michele30b57b22019-03-01 12:01:14 -08007106 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007107 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007108 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7109 return;
7110 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007111 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7112 } finally {
7113 Binder.restoreCallingIdentity(identity);
7114 }
7115 }
7116
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007117 @Override
7118 public boolean isApplicationOnUicc(int subId, int appType) {
7119 enforceReadPrivilegedPermission("isApplicationOnUicc");
7120 Phone phone = getPhone(subId);
7121 if (phone == null) {
7122 return false;
7123 }
7124 final long identity = Binder.clearCallingIdentity();
7125 try {
7126 UiccCard uiccCard = phone.getUiccCard();
7127 if (uiccCard == null) {
7128 return false;
7129 }
7130 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7131 if (uiccProfile == null) {
7132 return false;
7133 }
7134 if (TelephonyManager.APPTYPE_SIM <= appType
7135 && appType <= TelephonyManager.APPTYPE_ISIM) {
7136 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7137 }
7138 return false;
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
7142 }
7143
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007144 /**
chen xub4baa772019-04-03 10:23:41 -07007145 * Get whether making changes to modem configurations will trigger reboot.
7146 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007147 */
7148 @Override
chen xub4baa772019-04-03 10:23:41 -07007149 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7151 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7152 return false;
7153 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
7160 }
7161
Nathan Harold29f5f052019-02-15 13:41:57 -08007162 private void updateModemStateMetrics() {
7163 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7164 // TODO: check the state for each modem if the api is ready.
7165 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7166 }
7167
Pengquan Meng3889a572019-01-23 11:16:29 -08007168 @Override
7169 public int[] getSlotsMapping() {
7170 enforceReadPrivilegedPermission("getSlotsMapping");
7171
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7175 // All logical slots should have a mapping to a physical slot.
7176 int[] logicalSlotsMapping = new int[phoneCount];
7177 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7178 for (int i = 0; i < slotInfos.length; i++) {
7179 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7180 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7181 }
7182 }
7183 return logicalSlotsMapping;
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007188
7189 /**
7190 * Get the IRadio HAL Version
7191 */
7192 @Override
7193 public int getRadioHalVersion() {
7194 Phone phone = getDefaultPhone();
7195 if (phone == null) return -1;
7196 HalVersion hv = phone.getHalVersion();
7197 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7198 return hv.major * 100 + hv.minor;
7199 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007200
7201 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007202 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7203 * corresponding network requests on a subId.
7204 *
7205 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007206 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007207 * 2) APN is un-metered for this subscription, or
7208 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7209 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7210 *
7211 * @return whether data is allowed for a apn type.
7212 *
7213 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007214 */
7215 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007216 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007218 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7219 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007220 }
7221
7222 // Now that all security checks passes, perform the operation as ourselves.
7223 final long identity = Binder.clearCallingIdentity();
7224 try {
7225 Phone phone = getPhone(subId);
7226 if (phone == null) return false;
7227
Jack Yu41407ee2019-05-13 16:54:09 -07007228 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007229 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7230 } finally {
7231 Binder.restoreCallingIdentity(identity);
7232 }
7233 }
7234
7235 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007236 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007237 enforceReadPrivilegedPermission("isApnMetered");
7238
7239 // Now that all security checks passes, perform the operation as ourselves.
7240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 Phone phone = getPhone(subId);
7243 if (phone == null) return true; // By default return true.
7244
Jack Yu41407ee2019-05-13 16:54:09 -07007245 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007246 } finally {
7247 Binder.restoreCallingIdentity(identity);
7248 }
7249 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007250
7251 @Override
7252 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7253 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7254 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7255 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7256 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7257 }
7258 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7259 Intent intent = new Intent();
7260 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7261 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7262 // Bring up choose default SMS subscription dialog right now
7263 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7264 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7265 mApp.startActivity(intent);
7266 }
chen xud5ca2d52019-05-28 15:20:57 -07007267
7268 @Override
7269 public String getMmsUAProfUrl(int subId) {
7270 //TODO investigate if this API should require proper permission check in R b/133791609
7271 final long identity = Binder.clearCallingIdentity();
7272 try {
7273 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7274 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7275 } finally {
7276 Binder.restoreCallingIdentity(identity);
7277 }
7278 }
7279
7280 @Override
7281 public String getMmsUserAgent(int subId) {
7282 //TODO investigate if this API should require proper permission check in R b/133791609
7283 final long identity = Binder.clearCallingIdentity();
7284 try {
7285 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7286 .getString(com.android.internal.R.string.config_mms_user_agent);
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
7290 }
Jack Yub07d4972019-05-28 16:12:25 -07007291
7292 @Override
7293 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7294 enforceModifyPermission();
7295
7296 // Now that all security checks passes, perform the operation as ourselves.
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 Phone phone = getPhone(subId);
7300 if (phone == null) return false;
7301
7302 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7303 } finally {
7304 Binder.restoreCallingIdentity(identity);
7305 }
7306 }
7307
7308 @Override
7309 public boolean isDataAllowedInVoiceCall(int subId) {
7310 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7311
7312 // Now that all security checks passes, perform the operation as ourselves.
7313 final long identity = Binder.clearCallingIdentity();
7314 try {
7315 Phone phone = getPhone(subId);
7316 if (phone == null) return false;
7317
7318 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
7321 }
7322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007323}