blob: a847d6664d742077ea8110fa9bc5f3fd7a6e7b3c [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;
Chen Xu227e06f2019-09-26 22:48:11 -070064import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070065import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080066import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070068import android.telephony.CellInfoGsm;
69import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070070import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070071import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070072import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070073import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080074import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070075import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080076import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070077import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080078import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080079import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070080import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080081import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070082import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070083import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080084import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080085import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080086import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070087import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070088import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080090import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000091import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070092import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070094import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.data.ApnSetting;
96import 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
Jack Yu1e81ccd2019-09-26 11:48:33 -07001953 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
1954 if (!TextUtils.isEmpty(callingPackage)) {
1955 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
1956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
1957 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
1958 return "";
1959 }
1960 }
1961
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001962 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1963 // registered cell info, so return a NULL country instead.
1964 final long identity = Binder.clearCallingIdentity();
1965 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001966 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1967 // Get default phone in this case.
1968 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1969 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001970 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001971 // Todo: fix this when we can get the actual cellular network info when the device
1972 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001973 if (TelephonyManager.NETWORK_TYPE_IWLAN
1974 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1975 return "";
1976 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 Phone phone = PhoneFactory.getPhone(phoneId);
1978 if (phone != null) {
1979 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07001980 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 if (sst != null) {
1982 LocaleTracker lt = sst.getLocaleTracker();
1983 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07001984 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
1985 return lt.getCurrentCountry();
1986 } else if (emergencyNumberTracker != null) {
1987 return emergencyNumberTracker.getEmergencyCountryIso();
1988 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 }
1990 }
1991 }
1992 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001993 } finally {
1994 Binder.restoreCallingIdentity(identity);
1995 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001996 }
1997
1998 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001999 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002000 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002001 }
2002
Sanket Padawe356d7632015-06-22 14:03:32 -07002003 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002004 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 mApp.enforceCallingOrSelfPermission(
2006 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002007
2008 final long identity = Binder.clearCallingIdentity();
2009 try {
2010 final Phone phone = getPhone(subId);
2011 if (phone != null) {
2012 phone.enableLocationUpdates();
2013 }
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
2019 @Override
2020 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002021 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002022 }
2023
Sanket Padawe356d7632015-06-22 14:03:32 -07002024 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002025 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 mApp.enforceCallingOrSelfPermission(
2027 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 final Phone phone = getPhone(subId);
2032 if (phone != null) {
2033 phone.disableLocationUpdates();
2034 }
2035 } finally {
2036 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 }
2039
Nathan Harold31d7ff32018-10-15 20:20:30 -07002040 /**
2041 * Returns the target SDK version number for a given package name.
2042 *
Nathan Haroldec184742019-07-10 17:04:16 -07002043 * This call MUST be invoked before clearing the calling UID.
2044 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002045 * @return target SDK if the package is found or INT_MAX.
2046 */
2047 private int getTargetSdk(String packageName) {
2048 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002049 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002050 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002051 if (ai != null) return ai.targetSdkVersion;
2052 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002053 loge("Failed to get package info for pkg="
2054 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002055 }
2056 return Integer.MAX_VALUE;
2057 }
2058
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 @Override
2060 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002061 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2062 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002063 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2064 throw new SecurityException(
2065 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2066 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002067
Jordan Liu1617b712019-07-10 15:06:26 -07002068 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002069 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2070 return null;
2071 }
Svetoslav64fad262015-04-14 14:35:21 -07002072
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002073 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074
Nathan Haroldf180aac2018-06-01 18:43:55 -07002075 List<CellInfo> info = getAllCellInfo(callingPackage);
2076 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077
Nathan Haroldf180aac2018-06-01 18:43:55 -07002078 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2079 for (CellInfo ci : info) {
2080 if (ci instanceof CellInfoGsm) {
2081 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2082 } else if (ci instanceof CellInfoWcdma) {
2083 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002086 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 }
2088
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002089 private List<CellInfo> getCachedCellInfo() {
2090 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2091 for (Phone phone : PhoneFactory.getPhones()) {
2092 List<CellInfo> info = phone.getAllCellInfo();
2093 if (info != null) cellInfos.addAll(info);
2094 }
2095 return cellInfos;
2096 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097
2098 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002099 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002100 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002101 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002102
2103 LocationAccessPolicy.LocationPermissionResult locationResult =
2104 LocationAccessPolicy.checkLocationPermission(mApp,
2105 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2106 .setCallingPackage(callingPackage)
2107 .setCallingPid(Binder.getCallingPid())
2108 .setCallingUid(Binder.getCallingUid())
2109 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002110 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002111 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2112 .build());
2113 switch (locationResult) {
2114 case DENIED_HARD:
2115 throw new SecurityException("Not allowed to access cell info");
2116 case DENIED_SOFT:
2117 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002120 final int targetSdk = getTargetSdk(callingPackage);
2121 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2122 return getCachedCellInfo();
2123 }
2124
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002125 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002126 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002127 final long identity = Binder.clearCallingIdentity();
2128 try {
2129 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2130 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002131 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002132 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133 if (info != null) cellInfos.addAll(info);
2134 }
2135 return cellInfos;
2136 } finally {
2137 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 }
2139 }
2140
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002141 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002142 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2143 requestCellInfoUpdateInternal(
2144 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2145 }
2146
2147 @Override
2148 public void requestCellInfoUpdateWithWorkSource(
2149 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2150 enforceModifyPermission();
2151 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2152 }
2153
2154 private void requestCellInfoUpdateInternal(
2155 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002156 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002157 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002158
2159 LocationAccessPolicy.LocationPermissionResult locationResult =
2160 LocationAccessPolicy.checkLocationPermission(mApp,
2161 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2162 .setCallingPackage(callingPackage)
2163 .setCallingPid(Binder.getCallingPid())
2164 .setCallingUid(Binder.getCallingUid())
2165 .setMethod("requestCellInfoUpdate")
2166 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2167 .build());
2168 switch (locationResult) {
2169 case DENIED_HARD:
2170 throw new SecurityException("Not allowed to access cell info");
2171 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002172 try {
2173 cb.onCellInfo(new ArrayList<CellInfo>());
2174 } catch (RemoteException re) {
2175 // Drop without consequences
2176 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002177 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002178 }
2179
Nathan Harolda939a962019-05-09 10:13:47 -07002180
2181 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002182 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2183
2184 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2185 }
2186
2187 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002189 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002190 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002194 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002195 } finally {
2196 Binder.restoreCallingIdentity(identity);
2197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002198 }
2199
Shishir Agrawala9f32182016-04-12 12:00:16 -07002200 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002201 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002202 Phone phone = PhoneFactory.getPhone(slotIndex);
2203 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002204 return null;
2205 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002206 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002207 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2208 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002209 return null;
2210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 return phone.getImei();
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
2217 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002218 }
2219
2220 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002221 public String getTypeAllocationCodeForSlot(int slotIndex) {
2222 Phone phone = PhoneFactory.getPhone(slotIndex);
2223 String tac = null;
2224 if (phone != null) {
2225 String imei = phone.getImei();
2226 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2227 }
2228 return tac;
2229 }
2230
2231 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002232 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002233 Phone phone = PhoneFactory.getPhone(slotIndex);
2234 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002235 return null;
2236 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002237
Jeff Davidson913390f2018-02-23 17:11:49 -08002238 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002239 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2240 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002241 return null;
2242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 return phone.getMeid();
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
2249 }
Jack Yu2af8d712017-03-15 17:14:14 -07002250 }
2251
2252 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002253 public String getManufacturerCodeForSlot(int slotIndex) {
2254 Phone phone = PhoneFactory.getPhone(slotIndex);
2255 String manufacturerCode = null;
2256 if (phone != null) {
2257 String meid = phone.getMeid();
2258 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2259 }
2260 return manufacturerCode;
2261 }
2262
2263 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002264 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002265 Phone phone = PhoneFactory.getPhone(slotIndex);
2266 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002267 return null;
2268 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002269 int subId = phone.getSubId();
2270 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2271 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2272 return null;
2273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002274
2275 final long identity = Binder.clearCallingIdentity();
2276 try {
2277 return phone.getDeviceSvn();
2278 } finally {
2279 Binder.restoreCallingIdentity(identity);
2280 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002281 }
2282
fionaxu43304da2017-11-27 22:51:16 -08002283 @Override
2284 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 final long identity = Binder.clearCallingIdentity();
2286 try {
2287 final Phone phone = getPhone(subId);
2288 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
2291 }
fionaxu43304da2017-11-27 22:51:16 -08002292 }
2293
2294 @Override
2295 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 final long identity = Binder.clearCallingIdentity();
2297 try {
2298 final Phone phone = getPhone(subId);
2299 return phone == null ? null : phone.getCarrierName();
2300 } finally {
2301 Binder.restoreCallingIdentity(identity);
2302 }
fionaxu43304da2017-11-27 22:51:16 -08002303 }
2304
calvinpanffe225e2018-11-01 19:43:06 +08002305 @Override
chen xu0026ca62019-03-06 15:28:50 -08002306 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002307 final long identity = Binder.clearCallingIdentity();
2308 try {
2309 final Phone phone = getPhone(subId);
2310 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002311 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002312 } finally {
2313 Binder.restoreCallingIdentity(identity);
2314 }
2315 }
2316
2317 @Override
chen xu0026ca62019-03-06 15:28:50 -08002318 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002322 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002323 } finally {
2324 Binder.restoreCallingIdentity(identity);
2325 }
2326 }
2327
chen xu651eec72018-11-11 19:03:44 -08002328 @Override
chen xu864e11c2018-12-06 22:10:03 -08002329 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2330 if (!isSubscriptionMccMnc) {
2331 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2332 }
chen xu651eec72018-11-11 19:03:44 -08002333 final Phone phone = PhoneFactory.getPhone(slotIndex);
2334 if (phone == null) {
2335 return TelephonyManager.UNKNOWN_CARRIER_ID;
2336 }
2337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
2343 }
2344
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 //
2346 // Internal helper methods.
2347 //
2348
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002349 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2351 *
2352 * @throws SecurityException if the caller does not have the required permission
2353 */
2354 private void enforceModifyPermission() {
2355 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2356 }
2357
2358 /**
2359 * Make sure the caller has the CALL_PHONE permission.
2360 *
2361 * @throws SecurityException if the caller does not have the required permission
2362 */
2363 private void enforceCallPermission() {
2364 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2365 }
2366
Stuart Scott8eef64f2015-04-08 15:13:54 -07002367 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002368 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002369 "ConnectivityService");
2370 }
2371
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002372 private String createTelUrl(String number) {
2373 if (TextUtils.isEmpty(number)) {
2374 return null;
2375 }
2376
Jake Hambye994d462014-02-03 13:10:13 -08002377 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379
Ihab Awadf9e92732013-12-05 18:02:52 -08002380 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2382 }
2383
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002384 private static void logv(String msg) {
2385 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2386 }
2387
Ihab Awadf9e92732013-12-05 18:02:52 -08002388 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2390 }
2391
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002392 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002394 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002395 }
2396
Sanket Padawe356d7632015-06-22 14:03:32 -07002397 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002398 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002399 final long identity = Binder.clearCallingIdentity();
2400 try {
2401 final Phone phone = PhoneFactory.getPhone(slotIndex);
2402 if (phone == null) {
2403 return PhoneConstants.PHONE_TYPE_NONE;
2404 } else {
2405 return phone.getPhoneType();
2406 }
2407 } finally {
2408 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 }
2411
2412 /**
2413 * Returns the CDMA ERI icon index to display
2414 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002415 @Override
2416 public int getCdmaEriIconIndex(String callingPackage) {
2417 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002418 }
2419
Sanket Padawe356d7632015-06-22 14:03:32 -07002420 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002421 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002422 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002423 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002424 return -1;
2425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426
2427 final long identity = Binder.clearCallingIdentity();
2428 try {
2429 final Phone phone = getPhone(subId);
2430 if (phone != null) {
2431 return phone.getCdmaEriIconIndex();
2432 } else {
2433 return -1;
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438 }
2439
2440 /**
2441 * Returns the CDMA ERI icon mode,
2442 * 0 - ON
2443 * 1 - FLASHING
2444 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 @Override
2446 public int getCdmaEriIconMode(String callingPackage) {
2447 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002448 }
2449
Sanket Padawe356d7632015-06-22 14:03:32 -07002450 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002451 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002453 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002454 return -1;
2455 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002456
2457 final long identity = Binder.clearCallingIdentity();
2458 try {
2459 final Phone phone = getPhone(subId);
2460 if (phone != null) {
2461 return phone.getCdmaEriIconMode();
2462 } else {
2463 return -1;
2464 }
2465 } finally {
2466 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 }
2469
2470 /**
2471 * Returns the CDMA ERI text,
2472 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002473 @Override
2474 public String getCdmaEriText(String callingPackage) {
2475 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002476 }
2477
Sanket Padawe356d7632015-06-22 14:03:32 -07002478 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002479 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002480 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002481 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002482 return null;
2483 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484
2485 final long identity = Binder.clearCallingIdentity();
2486 try {
2487 final Phone phone = getPhone(subId);
2488 if (phone != null) {
2489 return phone.getCdmaEriText();
2490 } else {
2491 return null;
2492 }
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002495 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 }
2497
2498 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002499 * Returns the CDMA MDN.
2500 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002502 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2504 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002509 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 return phone.getLine1Number();
2511 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002512 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513 return null;
2514 }
2515 } finally {
2516 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002517 }
2518 }
2519
2520 /**
2521 * Returns the CDMA MIN.
2522 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002524 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2526 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527
2528 final long identity = Binder.clearCallingIdentity();
2529 try {
2530 final Phone phone = getPhone(subId);
2531 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2532 return phone.getCdmaMin();
2533 } else {
2534 return null;
2535 }
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002538 }
2539 }
2540
Hall Liud892bec2018-11-30 14:51:45 -08002541 @Override
2542 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2543 INumberVerificationCallback callback, String callingPackage) {
2544 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2545 != PERMISSION_GRANTED) {
2546 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2547 }
2548 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2549
2550 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2551 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2552 throw new SecurityException("Calling package must be configured in the device config");
2553 }
2554
2555 if (range == null) {
2556 throw new NullPointerException("Range must be non-null");
2557 }
2558
2559 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002560 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002561
2562 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2563 }
2564
Junda Liuca05d5d2014-08-14 22:36:34 -07002565 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 * Returns true if CDMA provisioning needs to run.
2567 */
2568 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569 final long identity = Binder.clearCallingIdentity();
2570 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002571 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002575 }
2576
2577 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002578 * Sets the voice mail number of a given subId.
2579 */
2580 @Override
2581 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002582 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2587 new Pair<String, String>(alphaTag, number), new Integer(subId));
2588 return success;
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002592 }
2593
Ta-wei Yen87c49842016-05-13 21:19:52 -07002594 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002595 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2596 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002597 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002598 if (!TextUtils.equals(callingPackage, systemDialer)) {
2599 throw new SecurityException("caller must be system dialer");
2600 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601
2602 final long identity = Binder.clearCallingIdentity();
2603 try {
2604 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2605 if (phoneAccountHandle == null) {
2606 return null;
2607 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002608 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002609 } finally {
2610 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002611 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002612 }
2613
2614 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002615 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002616 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002618 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002619 return null;
2620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002621
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002622 final long identity = Binder.clearCallingIdentity();
2623 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002628 }
2629
2630 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002631 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2632 VisualVoicemailSmsFilterSettings settings) {
2633 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002638 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002639 } finally {
2640 Binder.restoreCallingIdentity(identity);
2641 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002642 }
2643
2644 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002645 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002655 }
2656
2657 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002658 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2659 String callingPackage, int subId) {
2660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002661
2662 final long identity = Binder.clearCallingIdentity();
2663 try {
2664 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002665 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002669 }
2670
2671 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002672 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002673 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
2675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002678 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002679 } finally {
2680 Binder.restoreCallingIdentity(identity);
2681 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002682 }
2683
2684 @Override
2685 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2686 String number, int port, String text, PendingIntent sentIntent) {
2687 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002688 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002689 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002690 SmsController smsController = PhoneFactory.getSmsController();
2691 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2692 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002693 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002694
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002695 /**
fionaxu0152e512016-11-14 13:36:14 -08002696 * Sets the voice activation state of a given subId.
2697 */
2698 @Override
2699 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2701 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702
2703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = getPhone(subId);
2706 if (phone != null) {
2707 phone.setVoiceActivationState(activationState);
2708 } else {
2709 loge("setVoiceActivationState fails with invalid subId: " + subId);
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002713 }
2714 }
2715
2716 /**
2717 * Sets the data activation state of a given subId.
2718 */
2719 @Override
2720 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002721 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2722 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002723
2724 final long identity = Binder.clearCallingIdentity();
2725 try {
2726 final Phone phone = getPhone(subId);
2727 if (phone != null) {
2728 phone.setDataActivationState(activationState);
2729 } else {
2730 loge("setVoiceActivationState fails with invalid subId: " + subId);
2731 }
2732 } finally {
2733 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002734 }
2735 }
2736
2737 /**
2738 * Returns the voice activation state of a given subId.
2739 */
2740 @Override
2741 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002742 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743
fionaxu0152e512016-11-14 13:36:14 -08002744 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002745 final long identity = Binder.clearCallingIdentity();
2746 try {
2747 if (phone != null) {
2748 return phone.getVoiceActivationState();
2749 } else {
2750 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2751 }
2752 } finally {
2753 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002754 }
2755 }
2756
2757 /**
2758 * Returns the data activation state of a given subId.
2759 */
2760 @Override
2761 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002762 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002763
fionaxu0152e512016-11-14 13:36:14 -08002764 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 if (phone != null) {
2768 return phone.getDataActivationState();
2769 } else {
2770 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002774 }
2775 }
2776
2777 /**
Wink Saville36469e72014-06-11 15:17:00 -07002778 * Returns the unread count of voicemails for a subId
2779 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002781 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2783 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2784 return 0;
2785 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 if (phone != null) {
2790 return phone.getVoiceMessageCount();
2791 } else {
2792 return 0;
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
2799 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002800 * returns true, if the device is in a state where both voice and data
2801 * are supported simultaneously. This can change based on location or network condition.
2802 */
2803 @Override
2804 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002805 final long identity = Binder.clearCallingIdentity();
2806 try {
2807 final Phone phone = getPhone(subId);
2808 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002812 }
2813
2814 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002815 * Send the dialer code if called from the current default dialer or the caller has
2816 * carrier privilege.
2817 * @param inputCode The dialer code to send
2818 */
2819 @Override
2820 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002821 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002822 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002823 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2824 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002825 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002826 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2827 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002832 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833 } finally {
2834 Binder.restoreCallingIdentity(identity);
2835 }
fionaxu235cc5e2017-03-06 22:25:57 -08002836 }
2837
Pengquan Menga1bb6272018-09-06 09:59:22 -07002838 @Override
2839 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002840 if (!isActiveSubscription(subId)) {
2841 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2842 }
2843
Pengquan Menga1bb6272018-09-06 09:59:22 -07002844 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2845 }
2846
Brad Ebinger35c841c2018-10-01 10:40:55 -07002847 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002848 public boolean isInEmergencySmsMode() {
2849 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 for (Phone phone : PhoneFactory.getPhones()) {
2853 if (phone.isInEmergencySmsMode()) {
2854 return true;
2855 }
2856 }
2857 } finally {
2858 Binder.restoreCallingIdentity(identity);
2859 }
2860 return false;
2861 }
2862
2863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002864 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2865 throws RemoteException {
2866 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002867 final long token = Binder.clearCallingIdentity();
2868 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002870 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002872 } catch (ImsException e) {
2873 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002874 } finally {
2875 Binder.restoreCallingIdentity(token);
2876 }
2877 }
2878
2879 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002880 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2881 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002882 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2883 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2884 }
Meng Wangafbc5852019-09-19 17:37:13 -07002885 final long token = Binder.clearCallingIdentity();
2886 try {
2887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2888 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2889 .removeRegistrationCallbackForSubscription(c, subId);
2890 } catch (ImsException e) {
2891 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2892 + "is inactive, ignoring unregister.");
2893 // If the subscription is no longer active, just return, since the callback
2894 // will already have been removed internally.
2895 } finally {
2896 Binder.restoreCallingIdentity(token);
2897 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 }
2899
2900 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002901 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2902 throws RemoteException {
2903 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2905 final long token = Binder.clearCallingIdentity();
2906 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002908 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002909 } catch (ImsException e) {
2910 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 } finally {
2912 Binder.restoreCallingIdentity(token);
2913 }
2914 }
2915
2916 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002917 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2918 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002919 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2920 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2921 }
Meng Wangafbc5852019-09-19 17:37:13 -07002922
2923 final long token = Binder.clearCallingIdentity();
2924 try {
2925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2926 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002927 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07002928 } catch (ImsException e) {
2929 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2930 + "is inactive, ignoring unregister.");
2931 // If the subscription is no longer active, just return, since the callback
2932 // will already have been removed internally.
2933 } finally {
2934 Binder.restoreCallingIdentity(token);
2935 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 }
2937
2938 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002939 public boolean isCapable(int subId, int capability, int regTech) {
2940 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002941 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2942 final long token = Binder.clearCallingIdentity();
2943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002944 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002945 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002946 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002947 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2948 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002949 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002950 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2951 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 } finally {
2953 Binder.restoreCallingIdentity(token);
2954 }
2955 }
2956
2957 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002958 public boolean isAvailable(int subId, int capability, int regTech) {
2959 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 final long token = Binder.clearCallingIdentity();
2961 try {
2962 Phone phone = getPhone(subId);
2963 if (phone == null) return false;
2964 return phone.isImsCapabilityAvailable(capability, regTech);
2965 } finally {
2966 Binder.restoreCallingIdentity(token);
2967 }
2968 }
2969
2970 @Override
2971 public boolean isAdvancedCallingSettingEnabled(int subId) {
2972 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2974 final long token = Binder.clearCallingIdentity();
2975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002978 } catch (ImsException e) {
2979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 } finally {
2981 Binder.restoreCallingIdentity(token);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002986 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002988 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002989 final long identity = Binder.clearCallingIdentity();
2990 try {
2991 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002994 } catch (ImsException e) {
2995 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
3001 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003002 public boolean isVtSettingEnabled(int subId) {
3003 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003004 final long identity = Binder.clearCallingIdentity();
3005 try {
3006 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003007 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3008 } catch (ImsException e) {
3009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
3013 }
3014
3015 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003016 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003018 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003023 } catch (ImsException e) {
3024 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
3028 }
3029
3030 @Override
3031 public boolean isVoWiFiSettingEnabled(int subId) {
3032 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003037 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003038 } catch (ImsException e) {
3039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
3043 }
3044
3045 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003046 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003048 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003053 } catch (ImsException e) {
3054 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003055 } finally {
3056 Binder.restoreCallingIdentity(identity);
3057 }
3058 }
3059
3060 @Override
3061 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3062 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003066 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003068 } catch (ImsException e) {
3069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
3073 }
3074
3075 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003076 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003078 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003082 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003083 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003084 } catch (ImsException e) {
3085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
3091 @Override
3092 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3094 "setVoWiFiNonPersistent");
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003099 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003100 } catch (ImsException e) {
3101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003102 } finally {
3103 Binder.restoreCallingIdentity(identity);
3104 }
3105 }
3106
3107 @Override
3108 public int getVoWiFiModeSetting(int subId) {
3109 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003113 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003115 } catch (ImsException e) {
3116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
3123 public void setVoWiFiModeSetting(int subId, int mode) {
3124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3125 "setVoWiFiModeSetting");
3126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003129 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003130 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003131 } catch (ImsException e) {
3132 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
3138 @Override
3139 public int getVoWiFiRoamingModeSetting(int subId) {
3140 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (ImsException e) {
3147 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 }
3152
3153 @Override
3154 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3156 "setVoWiFiRoamingModeSetting");
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003160 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003162 } catch (ImsException e) {
3163 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003164 } finally {
3165 Binder.restoreCallingIdentity(identity);
3166 }
3167 }
3168
3169 @Override
3170 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3172 "setRttCapabilityEnabled");
3173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003176 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3177 } catch (ImsException e) {
3178 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003179 } finally {
3180 Binder.restoreCallingIdentity(identity);
3181 }
3182 }
3183
3184 @Override
3185 public boolean isTtyOverVolteEnabled(int subId) {
3186 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003190 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003191 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003192 } catch (ImsException e) {
3193 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003194 } finally {
3195 Binder.restoreCallingIdentity(identity);
3196 }
3197 }
3198
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003199 @Override
3200 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3201 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3202 final long identity = Binder.clearCallingIdentity();
3203 try {
3204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003206 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003207 } catch (ImsException e) {
3208 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003209 } finally {
3210 Binder.restoreCallingIdentity(identity);
3211 }
3212 }
3213
3214 @Override
3215 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3216 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3217 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003218 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3219 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3220 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003221 try {
3222 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003223 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003224 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003225 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003226 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3227 + "is inactive, ignoring unregister.");
3228 // If the subscription is no longer active, just return, since the callback will already
3229 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003230 } finally {
3231 Binder.restoreCallingIdentity(identity);
3232 }
3233 }
3234
3235 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003236 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3237 boolean isProvisioned) {
3238 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3239 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3240 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3241 }
3242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3243 "setProvisioningStatusForCapability");
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3247 Phone phone = getPhone(subId);
3248 if (phone == null) {
3249 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3250 + subId);
3251 return;
3252 }
3253 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3254 return;
3255 }
3256
3257 // this capability requires provisioning, route to the correct API.
3258 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3259 switch (capability) {
3260 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3261 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3262 ims.setVolteProvisioned(isProvisioned);
3263 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3264 ims.setWfcProvisioned(isProvisioned);
3265 }
3266 break;
3267 }
3268 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3269 // There is currently no difference in VT provisioning type.
3270 ims.setVtProvisioned(isProvisioned);
3271 break;
3272 }
3273 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3274 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3275 // change the capability of the feature instead if needed.
3276 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3277 == isProvisioned) {
3278 // No change in provisioning.
3279 return;
3280 }
3281 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3282 try {
3283 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003284 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003285 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3286 + ", Exception" + e.getMessage());
3287 }
3288 break;
3289 }
3290 default: {
3291 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3292 + capability + "', which does not require provisioning.");
3293 }
3294 }
3295
3296 } finally {
3297 Binder.restoreCallingIdentity(identity);
3298 }
3299 }
3300
3301 @Override
3302 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3303 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3304 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3305 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3306 }
3307 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3308 final long identity = Binder.clearCallingIdentity();
3309 try {
3310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3311 Phone phone = getPhone(subId);
3312 if (phone == null) {
3313 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3314 + subId);
3315 // We will fail with "true" as the provisioning status because this is the default
3316 // if we do not require provisioning.
3317 return true;
3318 }
3319
3320 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3321 return true;
3322 }
3323
3324 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3325 switch (capability) {
3326 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3327 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3328 return ims.isVolteProvisionedOnDevice();
3329 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3330 return ims.isWfcProvisionedOnDevice();
3331 }
3332 // This should never happen, since we are checking tech above to make sure it
3333 // is either LTE or IWLAN.
3334 throw new IllegalArgumentException("Invalid radio technology for voice "
3335 + "capability.");
3336 }
3337 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3338 // There is currently no difference in VT provisioning type.
3339 return ims.isVtProvisionedOnDevice();
3340 }
3341 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3342 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3343 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3344 }
3345 default: {
3346 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3347 + capability + "', which does not require provisioning.");
3348 }
3349 }
3350
3351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
3354 }
3355
3356 @Override
3357 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3358 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3359 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3360 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3361 }
3362 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3363 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3364 return (provisionedBits & capability) > 0;
3365 }
3366
3367 @Override
3368 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3369 boolean isProvisioned) {
3370 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3371 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3372 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3373 }
3374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3375 "setProvisioningStatusForCapability");
3376 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3377 // If the current provisioning status for capability already matches isProvisioned,
3378 // do nothing.
3379 if (((provisionedBits & capability) > 0) == isProvisioned) {
3380 return;
3381 }
3382 if (isProvisioned) {
3383 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3384 } else {
3385 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3386 }
3387 }
3388
3389 /**
3390 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3391 * technology. The bitfield should mirror the bitfield defined by
3392 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3393 */
3394 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3395 String key = getMmTelProvisioningKey(subId, tech);
3396 // Default is no capabilities are provisioned.
3397 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3398 }
3399
3400 /**
3401 * Sets the MmTel capability provisioning bitfield (defined by
3402 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3403 * technology specified.
3404 *
3405 * Note: This is a synchronous command and should not be called on UI thread.
3406 */
3407 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3408 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3409 String key = getMmTelProvisioningKey(subId, tech);
3410 editor.putInt(key, newField);
3411 editor.commit();
3412 }
3413
3414 private static String getMmTelProvisioningKey(int subId, int tech) {
3415 // resulting key is provision_ims_mmtel_{subId}_{tech}
3416 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3417 }
3418
3419 /**
3420 * Query CarrierConfig to see if the specified capability requires provisioning for the
3421 * carrier associated with the subscription id.
3422 */
3423 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3424 int capability) {
3425 CarrierConfigManager configManager = new CarrierConfigManager(context);
3426 PersistableBundle c = configManager.getConfigForSubId(subId);
3427 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003428 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3430 false);
3431 boolean requireVoiceVtProvisioning = c.getBoolean(
3432 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3433
3434 // First check to make sure that the capability requires provisioning.
3435 switch (capability) {
3436 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3437 // intentional fallthrough
3438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3439 if (requireVoiceVtProvisioning) {
3440 // Voice and Video requires provisioning
3441 return true;
3442 }
3443 break;
3444 }
3445 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3446 if (requireUtProvisioning) {
3447 // UT requires provisioning
3448 return true;
3449 }
3450 break;
3451 }
3452 }
3453 return false;
3454 }
3455
3456 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003457 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3459 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3460 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 enforceReadPrivilegedPermission("getImsProvisioningInt");
3462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 int slotId = getSlotIndex(subId);
3466 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3467 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3468 + subId + "' for key:" + key);
3469 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3470 }
3471 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003472 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3474 + subId + "' for key:" + key);
3475 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
3479 }
3480
3481 @Override
3482 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003483 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3484 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3485 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003486 enforceReadPrivilegedPermission("getImsProvisioningString");
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003490 int slotId = getSlotIndex(subId);
3491 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3492 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3493 + subId + "' for key:" + key);
3494 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3495 }
3496 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003497 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003498 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3499 + subId + "' for key:" + key);
3500 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
3504 }
3505
3506 @Override
3507 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003508 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3509 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3510 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3512 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003513 final long identity = Binder.clearCallingIdentity();
3514 try {
3515 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003516 int slotId = getSlotIndex(subId);
3517 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3518 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3519 + subId + "' for key:" + key);
3520 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3521 }
3522 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003523 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003524 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3525 + "' for key:" + key);
3526 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003527 } finally {
3528 Binder.restoreCallingIdentity(identity);
3529 }
3530 }
3531
3532 @Override
3533 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003534 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3535 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3536 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3538 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003539 final long identity = Binder.clearCallingIdentity();
3540 try {
3541 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003542 int slotId = getSlotIndex(subId);
3543 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3544 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3545 + subId + "' for key:" + key);
3546 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3547 }
3548 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003549 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003550 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3551 + "' for key:" + key);
3552 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003558 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003559 int slotId = SubscriptionManager.getSlotIndex(subId);
3560 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003561 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3562 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 }
3564 return slotId;
3565 }
3566
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003567 private int getSlotIndex(int subId) {
3568 int slotId = SubscriptionManager.getSlotIndex(subId);
3569 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3570 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3571 }
3572 return slotId;
3573 }
3574
Wink Saville36469e72014-06-11 15:17:00 -07003575 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003576 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003577 */
3578 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003580 final int targetSdk = getTargetSdk(callingPackage);
3581 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3582 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3583 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003584 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3585 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003586 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3587 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = getPhone(subId);
3592 if (phone != null) {
3593 return phone.getServiceState().getDataNetworkType();
3594 } else {
3595 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003600 }
3601
3602 /**
3603 * Returns the data network type
3604 */
3605 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 public int getDataNetworkType(String callingPackage) {
3607 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003608 }
3609
3610 /**
3611 * Returns the data network type for a subId
3612 */
3613 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003614 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003616 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003617 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3618 }
3619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 final Phone phone = getPhone(subId);
3623 if (phone != null) {
3624 return phone.getServiceState().getDataNetworkType();
3625 } else {
3626 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3627 }
3628 } finally {
3629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 }
3632
3633 /**
Wink Saville36469e72014-06-11 15:17:00 -07003634 * Returns the Voice network type for a subId
3635 */
3636 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003637 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003638 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003639 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003640 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3641 }
3642
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 final Phone phone = getPhone(subId);
3646 if (phone != null) {
3647 return phone.getServiceState().getVoiceNetworkType();
3648 } else {
3649 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3650 }
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003654 }
3655
3656 /**
3657 * @return true if a ICC card is present
3658 */
3659 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003660 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003661 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3662 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003663 }
3664
3665 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003666 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003667 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003668 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003669 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003670 final long identity = Binder.clearCallingIdentity();
3671 try {
3672 final Phone phone = PhoneFactory.getPhone(slotIndex);
3673 if (phone != null) {
3674 return phone.getIccCard().hasIccCard();
3675 } else {
3676 return false;
3677 }
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003680 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003681 }
3682
3683 /**
3684 * Return if the current radio is LTE on CDMA. This
3685 * is a tri-state return value as for a period of time
3686 * the mode may be unknown.
3687 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003688 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003689 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003690 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003691 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003692 @Override
3693 public int getLteOnCdmaMode(String callingPackage) {
3694 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003695 }
3696
Sanket Padawe356d7632015-06-22 14:03:32 -07003697 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003698 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003699 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003700 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003701 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3702 }
3703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 final Phone phone = getPhone(subId);
3707 if (phone == null) {
3708 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3709 } else {
3710 return phone.getLteOnCdmaMode();
3711 }
3712 } finally {
3713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003714 }
Wink Saville36469e72014-06-11 15:17:00 -07003715 }
3716
Wink Saville36469e72014-06-11 15:17:00 -07003717 /**
3718 * {@hide}
3719 * Returns Default subId, 0 in the case of single standby.
3720 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003721 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003722 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003723 }
3724
Shishir Agrawala9f32182016-04-12 12:00:16 -07003725 private int getSlotForDefaultSubscription() {
3726 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3727 }
3728
Wink Savilleb564aae2014-10-23 10:18:09 -07003729 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003730 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003731 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003732
Pengquan Menge92a50d2018-09-21 15:54:48 -07003733 private boolean isActiveSubscription(int subId) {
3734 return mSubscriptionController.isActiveSubId(subId);
3735 }
3736
Ihab Awadf2177b72013-11-25 13:33:23 -08003737 /**
3738 * @see android.telephony.TelephonyManager.WifiCallingChoices
3739 */
3740 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 final long identity = Binder.clearCallingIdentity();
3742 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003743 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003744 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3745 getWhenToMakeWifiCallsDefaultPreference());
3746 } finally {
3747 Binder.restoreCallingIdentity(identity);
3748 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003749 }
3750
3751 /**
3752 * @see android.telephony.TelephonyManager.WifiCallingChoices
3753 */
3754 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003763 }
3764
Sailesh Nepald1e68152013-12-12 19:08:02 -08003765 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003766 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003767 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003768 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003769
Jordan Liu4c733742019-02-28 12:03:40 -08003770 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3771 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3772 if (phoneId == -1) {
3773 throw new IllegalArgumentException("Given slot index: " + slotIndex
3774 + " does not correspond to an active phone");
3775 }
3776 return PhoneFactory.getPhone(phoneId);
3777 }
3778
Shishir Agrawal566b7612013-10-28 14:41:00 -07003779 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003780 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3781 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003782 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3783 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003784 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003785 if (DBG) {
3786 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3787 }
3788 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3789 p2);
3790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003791
Jordan Liu4c733742019-02-28 12:03:40 -08003792
3793 @Override
3794 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3795 int slotIndex, String callingPackage, String aid, int p2) {
3796 enforceModifyPermission();
3797 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3798 if (DBG) {
3799 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3800 }
3801 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3802 callingPackage, aid, p2);
3803 }
3804
3805 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3806 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003807 final long identity = Binder.clearCallingIdentity();
3808 try {
3809 if (TextUtils.equals(ISDR_AID, aid)) {
3810 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3812 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003813 if (bestComponent == null
3814 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3815 loge("The calling package is not allowed to access ISD-R.");
3816 throw new SecurityException(
3817 "The calling package is not allowed to access ISD-R.");
3818 }
Derek Tan740e1672017-06-27 14:56:27 -07003819 }
Derek Tan740e1672017-06-27 14:56:27 -07003820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003821 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003822 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3823 null /* workSource */);
3824 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003825 return response;
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
3828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829 }
3830
3831 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003832 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3834 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003835 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3836 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3837 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003838
Jordan Liu4c733742019-02-28 12:03:40 -08003839 @Override
3840 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3841 enforceModifyPermission();
3842 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3843 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3844 channel);
3845 }
3846
3847 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003850 if (channel < 0) {
3851 return false;
3852 }
Jordan Liu4c733742019-02-28 12:03:40 -08003853 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3854 null /* workSource */);
3855 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003856 return success;
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003859 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003860 }
3861
3862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003863 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003864 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3866 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003867 if (DBG) {
3868 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3869 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3870 + p3 + " data=" + data);
3871 }
3872 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3873 command, p1, p2, p3, data);
3874 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003875
Jordan Liu4c733742019-02-28 12:03:40 -08003876 @Override
3877 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3878 int command, int p1, int p2, int p3, String data) {
3879 enforceModifyPermission();
3880 if (DBG) {
3881 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3882 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3883 + p3 + " data=" + data);
3884 }
3885 return iccTransmitApduLogicalChannelWithPermission(
3886 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3887 data);
3888 }
3889
3890 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3891 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892 final long identity = Binder.clearCallingIdentity();
3893 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003894 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003895 return "";
3896 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003897
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003898 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003899 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3900 null /* workSource */);
3901 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003902
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003903 // Append the returned status code to the end of the response payload.
3904 String s = Integer.toHexString(
3905 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3906 if (response.payload != null) {
3907 s = IccUtils.bytesToHexString(response.payload) + s;
3908 }
3909 return s;
3910 } finally {
3911 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003912 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003913 }
Jake Hambye994d462014-02-03 13:10:13 -08003914
Evan Charltonc66da362014-05-16 14:06:40 -07003915 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003916 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3917 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003918 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3919 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003921 if (DBG) {
3922 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3923 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3924 }
3925 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3926 cla, command, p1, p2, p3, data);
3927 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003928
Jordan Liu4c733742019-02-28 12:03:40 -08003929 @Override
3930 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3931 int command, int p1, int p2, int p3, String data) {
3932 enforceModifyPermission();
3933 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3934 if (DBG) {
3935 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3936 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3937 + " data=" + data);
3938 }
3939
3940 return iccTransmitApduBasicChannelWithPermission(
3941 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3942 p2, p3, data);
3943 }
3944
3945 // open APDU basic channel assuming the caller has sufficient permissions
3946 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3947 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3951 && TextUtils.equals(ISDR_AID, data)) {
3952 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003953 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3954 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003955 if (bestComponent == null
3956 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3957 loge("The calling package is not allowed to select ISD-R.");
3958 throw new SecurityException(
3959 "The calling package is not allowed to select ISD-R.");
3960 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003961 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003962
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003963 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003964 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3965 null /* workSource */);
3966 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003968 // Append the returned status code to the end of the response payload.
3969 String s = Integer.toHexString(
3970 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3971 if (response.payload != null) {
3972 s = IccUtils.bytesToHexString(response.payload) + s;
3973 }
3974 return s;
3975 } finally {
3976 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003977 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003978 }
3979
3980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003981 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003982 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3984 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 final long identity = Binder.clearCallingIdentity();
3987 try {
3988 if (DBG) {
3989 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3990 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3991 }
3992
3993 IccIoResult response =
3994 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3995 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3996 subId);
3997
3998 if (DBG) {
3999 log("Exchange SIM_IO [R]" + response);
4000 }
4001
4002 byte[] result = null;
4003 int length = 2;
4004 if (response.payload != null) {
4005 length = 2 + response.payload.length;
4006 result = new byte[length];
4007 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4008 } else {
4009 result = new byte[length];
4010 }
4011
4012 result[length - 1] = (byte) response.sw2;
4013 result[length - 2] = (byte) response.sw1;
4014 return result;
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004017 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004018 }
4019
Nathan Haroldb3014052017-01-25 15:57:32 -08004020 /**
4021 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4022 * on a particular subscription
4023 */
sqianb6e41952018-03-12 14:54:01 -07004024 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4025 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4026 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4027 return null;
4028 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029
4030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 if (appType != TelephonyManager.APPTYPE_USIM
4033 && appType != TelephonyManager.APPTYPE_SIM) {
4034 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4035 return null;
4036 }
4037 Object response = sendRequest(
4038 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4039 if (response instanceof String[]) {
4040 return (String[]) response;
4041 }
4042 // Response is an Exception of some kind,
4043 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004044 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004045 } finally {
4046 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004047 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004048 }
4049
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004050 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004051 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004052 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4053 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004054
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004055 final long identity = Binder.clearCallingIdentity();
4056 try {
4057 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4058 if (response.payload == null) {
4059 return "";
4060 }
Evan Charltonc66da362014-05-16 14:06:40 -07004061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004062 // Append the returned status code to the end of the response payload.
4063 String s = Integer.toHexString(
4064 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4065 s = IccUtils.bytesToHexString(response.payload) + s;
4066 return s;
4067 } finally {
4068 Binder.restoreCallingIdentity(identity);
4069 }
Evan Charltonc66da362014-05-16 14:06:40 -07004070 }
4071
Jake Hambye994d462014-02-03 13:10:13 -08004072 /**
4073 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4074 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4075 *
4076 * @param itemID the ID of the item to read
4077 * @return the NV item as a String, or null on error.
4078 */
4079 @Override
4080 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4083 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084
4085 final long identity = Binder.clearCallingIdentity();
4086 try {
4087 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004088 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004089 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4090 return value;
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Jake Hambye994d462014-02-03 13:10:13 -08004094 }
4095
4096 /**
4097 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4098 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4099 *
4100 * @param itemID the ID of the item to read
4101 * @param itemValue the value to write, as a String
4102 * @return true on success; false on any failure
4103 */
4104 @Override
4105 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004106 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4108 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004109
4110 final long identity = Binder.clearCallingIdentity();
4111 try {
4112 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4113 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004114 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004115 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4116 return success;
4117 } finally {
4118 Binder.restoreCallingIdentity(identity);
4119 }
Jake Hambye994d462014-02-03 13:10:13 -08004120 }
4121
4122 /**
4123 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4124 * Used for device configuration by some CDMA operators.
4125 *
4126 * @param preferredRoamingList byte array containing the new PRL
4127 * @return true on success; false on any failure
4128 */
4129 @Override
4130 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4132 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133
4134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4137 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4138 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4139 return success;
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
4142 }
Jake Hambye994d462014-02-03 13:10:13 -08004143 }
4144
4145 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004146 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004147 * Used for device configuration by some CDMA operators.
4148 *
chen xu6dac5ab2018-10-26 17:39:23 -07004149 * @param slotIndex - device slot.
4150 *
Jake Hambye994d462014-02-03 13:10:13 -08004151 * @return true on success; false on any failure
4152 */
4153 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004154 public boolean resetModemConfig(int slotIndex) {
4155 Phone phone = PhoneFactory.getPhone(slotIndex);
4156 if (phone != null) {
4157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4158 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004159
chen xu6dac5ab2018-10-26 17:39:23 -07004160 final long identity = Binder.clearCallingIdentity();
4161 try {
4162 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4163 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4164 return success;
4165 } finally {
4166 Binder.restoreCallingIdentity(identity);
4167 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004168 }
chen xu6dac5ab2018-10-26 17:39:23 -07004169 return false;
4170 }
4171
4172 /**
4173 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4174 *
4175 * @param slotIndex - device slot.
4176 *
4177 * @return true on success; false on any failure
4178 */
4179 @Override
4180 public boolean rebootModem(int slotIndex) {
4181 Phone phone = PhoneFactory.getPhone(slotIndex);
4182 if (phone != null) {
4183 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4184 mApp, phone.getSubId(), "rebootModem");
4185
4186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4189 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4190 return success;
4191 } finally {
4192 Binder.restoreCallingIdentity(identity);
4193 }
4194 }
4195 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004196 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004197
Svet Ganovb320e182015-04-16 12:30:10 -07004198 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004202 return new String[0];
4203 }
4204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205 final long identity = Binder.clearCallingIdentity();
4206 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004207 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
Wink Saville36469e72014-06-11 15:17:00 -07004211 }
4212
Brad Ebinger51f743a2017-01-23 13:50:20 -08004213 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004214 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4215 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004216 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004217 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004222 ImsResolver resolver = PhoneFactory.getImsResolver();
4223 if (resolver == null) {
4224 // may happen if the device does not support IMS.
4225 return;
4226 }
4227 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004231 }
4232
4233 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004234 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4235 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004236 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004237 public void disableIms(int slotId) {
4238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004242 ImsResolver resolver = PhoneFactory.getImsResolver();
4243 if (resolver == null) {
4244 // may happen if the device does not support IMS.
4245 return;
4246 }
4247 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004251 }
4252
4253 /**
4254 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4255 * feature or {@link null} if the service is not available. If the feature is available, the
4256 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4257 */
4258 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004259 IImsServiceFeatureCallback callback) {
4260 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261
4262 final long identity = Binder.clearCallingIdentity();
4263 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004264 ImsResolver resolver = PhoneFactory.getImsResolver();
4265 if (resolver == null) {
4266 // may happen if the device does not support IMS.
4267 return null;
4268 }
4269 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 } finally {
4271 Binder.restoreCallingIdentity(identity);
4272 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004273 }
4274
4275 /**
4276 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4277 * feature during emergency calling or {@link null} if the service is not available. If the
4278 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4279 * listener for feature updates.
4280 */
4281 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4282 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004286 ImsResolver resolver = PhoneFactory.getImsResolver();
4287 if (resolver == null) {
4288 // may happen if the device does not support IMS.
4289 return null;
4290 }
4291 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004292 } finally {
4293 Binder.restoreCallingIdentity(identity);
4294 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004295 }
4296
Brad Ebinger5f64b052017-12-14 14:26:15 -08004297 /**
4298 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004299 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004300 */
4301 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4302 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004303
4304 final long identity = Binder.clearCallingIdentity();
4305 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004306 ImsResolver resolver = PhoneFactory.getImsResolver();
4307 if (resolver == null) {
4308 // may happen if the device does not support IMS.
4309 return null;
4310 }
4311 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 } finally {
4313 Binder.restoreCallingIdentity(identity);
4314 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004315 }
4316
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004317 /**
4318 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004319 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004320 */
4321 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4322 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004323
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004326 ImsResolver resolver = PhoneFactory.getImsResolver();
4327 if (resolver == null) {
4328 // may happen if the device does not support IMS.
4329 return null;
4330 }
4331 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 } finally {
4333 Binder.restoreCallingIdentity(identity);
4334 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004335 }
4336
Brad Ebinger884c07b2018-02-15 16:17:40 -08004337 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004338 * Sets the ImsService Package Name that Telephony will bind to.
4339 *
4340 * @param slotId the slot ID that the ImsService should bind for.
4341 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4342 * ImsService is the device default ImsService.
4343 * @param packageName The package name of the application that contains the ImsService to bind
4344 * to.
4345 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4346 * @hide
4347 */
4348 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004349 int[] subIds = SubscriptionManager.getSubId(slotId);
4350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4351 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4352 "setImsService");
4353
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354 final long identity = Binder.clearCallingIdentity();
4355 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004356 ImsResolver resolver = PhoneFactory.getImsResolver();
4357 if (resolver == null) {
4358 // may happen if the device does not support IMS.
4359 return false;
4360 }
4361 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4362 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 } finally {
4364 Binder.restoreCallingIdentity(identity);
4365 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004366 }
4367
4368 /**
4369 * Return the ImsService configuration.
4370 *
4371 * @param slotId The slot that the ImsService is associated with.
4372 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4373 * the device default.
4374 * @return the package name of the ImsService configuration.
4375 */
4376 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004377 int[] subIds = SubscriptionManager.getSubId(slotId);
4378 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4379 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4380 "getImsService");
4381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004384 ImsResolver resolver = PhoneFactory.getImsResolver();
4385 if (resolver == null) {
4386 // may happen if the device does not support IMS.
4387 return "";
4388 }
4389 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004393 }
4394
Wink Saville36469e72014-06-11 15:17:00 -07004395 public void setImsRegistrationState(boolean registered) {
4396 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004397
4398 final long identity = Binder.clearCallingIdentity();
4399 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004400 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 } finally {
4402 Binder.restoreCallingIdentity(identity);
4403 }
Wink Saville36469e72014-06-11 15:17:00 -07004404 }
4405
4406 /**
Stuart Scott54788802015-03-30 13:18:01 -07004407 * Set the network selection mode to automatic.
4408 *
4409 */
4410 @Override
4411 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4413 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414
Pengquan Menge92a50d2018-09-21 15:54:48 -07004415 if (!isActiveSubscription(subId)) {
4416 return;
4417 }
4418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4422 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Stuart Scott54788802015-03-30 13:18:01 -07004426 }
4427
Pengquan Mengea84e042018-09-20 14:57:26 -07004428 /**
4429 * Ask the radio to connect to the input network and change selection mode to manual.
4430 *
4431 * @param subId the id of the subscription.
4432 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4433 * the operator to attach to.
4434 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4435 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4436 * normal network selection next time.
4437 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004438 */
4439 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004440 public boolean setNetworkSelectionModeManual(
4441 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4443 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004444
4445 if (!isActiveSubscription(subId)) {
4446 return false;
4447 }
4448
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004449 final long identity = Binder.clearCallingIdentity();
4450 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004451 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004453 if (DBG) {
4454 log("setNetworkSelectionModeManual: subId: " + subId
4455 + " operator: " + operatorInfo);
4456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004457 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4458 } finally {
4459 Binder.restoreCallingIdentity(identity);
4460 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004461 }
4462
4463 /**
4464 * Scans for available networks.
4465 */
4466 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004467 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4469 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004470 LocationAccessPolicy.LocationPermissionResult locationResult =
4471 LocationAccessPolicy.checkLocationPermission(mApp,
4472 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4473 .setCallingPackage(callingPackage)
4474 .setCallingPid(Binder.getCallingPid())
4475 .setCallingUid(Binder.getCallingUid())
4476 .setMethod("getCellNetworkScanResults")
4477 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4478 .build());
4479 switch (locationResult) {
4480 case DENIED_HARD:
4481 throw new SecurityException("Not allowed to access scan results -- location");
4482 case DENIED_SOFT:
4483 return null;
4484 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485
Pengquan Menga1bb6272018-09-06 09:59:22 -07004486 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004487 try {
4488 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004489 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 } finally {
4492 Binder.restoreCallingIdentity(identity);
4493 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004494 }
4495
4496 /**
yinxub1bed742017-04-17 11:45:04 -07004497 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004498 *
yinxub1bed742017-04-17 11:45:04 -07004499 * @param subId id of the subscription
4500 * @param request contains the radio access networks with bands/channels to scan
4501 * @param messenger callback messenger for scan results or errors
4502 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004503 * @return the id of the requested scan which can be used to stop the scan.
4504 */
4505 @Override
4506 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004507 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4509 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004510 LocationAccessPolicy.LocationPermissionResult locationResult =
4511 LocationAccessPolicy.checkLocationPermission(mApp,
4512 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4513 .setCallingPackage(callingPackage)
4514 .setCallingPid(Binder.getCallingPid())
4515 .setCallingUid(Binder.getCallingUid())
4516 .setMethod("requestNetworkScan")
4517 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4518 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004519 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004520 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004521 if (e != null) {
4522 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4523 throw e;
4524 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004525 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004526 return TelephonyScanManager.INVALID_SCAN_ID;
4527 }
4528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 }
Hall Liu912dfd32019-04-25 14:02:26 -07004530 int callingUid = Binder.getCallingUid();
4531 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004532 final long identity = Binder.clearCallingIdentity();
4533 try {
4534 return mNetworkScanRequestTracker.startNetworkScan(
4535 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004536 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004537 } finally {
4538 Binder.restoreCallingIdentity(identity);
4539 }
yinxu504e1392017-04-12 16:03:22 -07004540 }
4541
Hall Liub2ac8ef2019-02-28 15:56:23 -08004542 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004543 NetworkScanRequest request, int subId) {
4544 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4545 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4546 boolean hasNetworkScanPermission =
4547 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4548 == PERMISSION_GRANTED;
4549
4550 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4551 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4552 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004553 }
4554
4555 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4556 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004557 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4558 return new SecurityException("Specific channels must not be"
4559 + " scanned without location access.");
4560 }
4561 }
4562 }
4563
Hall Liub2ac8ef2019-02-28 15:56:23 -08004564 return null;
4565 }
4566
yinxu504e1392017-04-12 16:03:22 -07004567 /**
4568 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004569 *
4570 * @param subId id of the subscription
4571 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004572 */
4573 @Override
4574 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004575 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4576 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004577
Hall Liu912dfd32019-04-25 14:02:26 -07004578 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 final long identity = Binder.clearCallingIdentity();
4580 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004581 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004582 } finally {
4583 Binder.restoreCallingIdentity(identity);
4584 }
yinxu504e1392017-04-12 16:03:22 -07004585 }
4586
4587 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004588 * Get the calculated preferred network type.
4589 * Used for debugging incorrect network type.
4590 *
4591 * @return the preferred network type, defined in RILConstants.java.
4592 */
4593 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004594 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004595 final Phone defaultPhone = getDefaultPhone();
4596 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4597 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004598 return RILConstants.PREFERRED_NETWORK_MODE;
4599 }
4600
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004601 final long identity = Binder.clearCallingIdentity();
4602 try {
4603 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004604 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605 } finally {
4606 Binder.restoreCallingIdentity(identity);
4607 }
Junda Liu84d15a22014-07-02 11:21:04 -07004608 }
4609
4610 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004611 * Get the preferred network type.
4612 * Used for device configuration by some CDMA operators.
4613 *
4614 * @return the preferred network type, defined in RILConstants.java.
4615 */
4616 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004617 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004618 TelephonyPermissions
4619 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4620 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 if (DBG) log("getPreferredNetworkType");
4625 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4626 int networkType = (result != null ? result[0] : -1);
4627 if (DBG) log("getPreferredNetworkType: " + networkType);
4628 return networkType;
4629 } finally {
4630 Binder.restoreCallingIdentity(identity);
4631 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004632 }
4633
4634 /**
4635 * Set the preferred network type.
4636 * Used for device configuration by some CDMA operators.
4637 *
4638 * @param networkType the preferred network type, defined in RILConstants.java.
4639 * @return true on success; false on any failure.
4640 */
4641 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004642 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004643 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4644 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645
4646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4649 Boolean success = (Boolean) sendRequest(
4650 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4651 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4652 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004653 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4655 }
4656 return success;
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004659 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004660 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004661
4662 /**
Miaoa84611c2019-03-15 09:21:10 +08004663 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004664 *
Miaoa84611c2019-03-15 09:21:10 +08004665 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004666 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004667 * @hide
4668 */
4669 @Override
Miaoa84611c2019-03-15 09:21:10 +08004670 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004672 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004673 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 try {
Miaoa84611c2019-03-15 09:21:10 +08004675 if (phone != null) {
4676 return phone.hasMatchedTetherApnSetting();
4677 } else {
4678 return false;
4679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004682 }
Junda Liu475951f2014-11-07 16:45:03 -08004683 }
4684
4685 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004686 * Set mobile data enabled
4687 * Used by the user through settings etc to turn on/off mobile data
4688 *
4689 * @param enable {@code true} turn turn data on, else {@code false}
4690 */
4691 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004692 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4694 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004695
4696 final long identity = Binder.clearCallingIdentity();
4697 try {
4698 int phoneId = mSubscriptionController.getPhoneId(subId);
4699 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4700 Phone phone = PhoneFactory.getPhone(phoneId);
4701 if (phone != null) {
4702 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004703 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004705 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004706 }
4707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004709 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004710 }
4711
4712 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004713 * Get the user enabled state of Mobile Data.
4714 *
4715 * TODO: remove and use isUserDataEnabled.
4716 * This can't be removed now because some vendor codes
4717 * calls through ITelephony directly while they should
4718 * use TelephonyManager.
4719 *
4720 * @return true on enabled
4721 */
4722 @Override
4723 public boolean getDataEnabled(int subId) {
4724 return isUserDataEnabled(subId);
4725 }
4726
4727 /**
4728 * Get whether mobile data is enabled per user setting.
4729 *
4730 * There are other factors deciding whether mobile data is actually enabled, but they are
4731 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004732 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004733 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004734 *
4735 * @return {@code true} if data is enabled else {@code false}
4736 */
4737 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004738 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004739 try {
4740 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4741 null);
4742 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004743 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4744 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004746
4747 final long identity = Binder.clearCallingIdentity();
4748 try {
4749 int phoneId = mSubscriptionController.getPhoneId(subId);
4750 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4751 Phone phone = PhoneFactory.getPhone(phoneId);
4752 if (phone != null) {
4753 boolean retVal = phone.isUserDataEnabled();
4754 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4755 return retVal;
4756 } else {
4757 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4758 return false;
4759 }
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004762 }
4763 }
4764
4765 /**
4766 * Get whether mobile data is enabled.
4767 *
4768 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4769 * whether mobile data is actually enabled.
4770 *
4771 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4772 *
4773 * @return {@code true} if data is enabled else {@code false}
4774 */
4775 @Override
4776 public boolean isDataEnabled(int subId) {
4777 try {
4778 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4779 null);
4780 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4782 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
4785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 int phoneId = mSubscriptionController.getPhoneId(subId);
4788 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4789 Phone phone = PhoneFactory.getPhone(phoneId);
4790 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004791 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004792 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4793 return retVal;
4794 } else {
4795 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4796 return false;
4797 }
4798 } finally {
4799 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004800 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004801 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004802
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004803 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
4804 Phone phone) {
4805 //load access rules from carrier configs, and check those as well: b/139133814
4806 SubscriptionController subController = SubscriptionController.getInstance();
4807 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4808 || subController == null) return privilegeFromSim;
4809
4810 int uid = Binder.getCallingUid();
4811 PackageManager pkgMgr = phone.getContext().getPackageManager();
4812 String[] packages = pkgMgr.getPackagesForUid(uid);
4813
4814 final long identity = Binder.clearCallingIdentity();
4815 try {
4816 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4817 SubscriptionManager subManager = (SubscriptionManager)
4818 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4819 for (String pkg : packages) {
4820 if (subManager.canManageSubscription(subInfo, pkg)) {
4821 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4822 }
4823 }
4824 return privilegeFromSim;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
4828 }
4829
4830 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
4831 String pkgName) {
4832 //load access rules from carrier configs, and check those as well: b/139133814
4833 SubscriptionController subController = SubscriptionController.getInstance();
4834 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
4835 || subController == null) return privilegeFromSim;
4836
4837 final long identity = Binder.clearCallingIdentity();
4838 try {
4839 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
4840 SubscriptionManager subManager = (SubscriptionManager)
4841 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
4842 return subManager.canManageSubscription(subInfo, pkgName)
4843 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
4844 } finally {
4845 Binder.restoreCallingIdentity(identity);
4846 }
4847 }
4848
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004850 public int getCarrierPrivilegeStatus(int subId) {
4851 final Phone phone = getPhone(subId);
4852 if (phone == null) {
4853 loge("getCarrierPrivilegeStatus: Invalid subId");
4854 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4855 }
4856 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004857 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004858 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004859 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4860 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004861
4862 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4863 card.getCarrierPrivilegeStatusForCurrentTransaction(
4864 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004865 }
Junda Liu29340342014-07-10 15:23:27 -07004866
4867 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004868 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4869 final Phone phone = getPhone(subId);
4870 if (phone == null) {
4871 loge("getCarrierPrivilegeStatus: Invalid subId");
4872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4873 }
4874 UiccProfile profile =
4875 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4876 if (profile == null) {
4877 loge("getCarrierPrivilegeStatus: No UICC");
4878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4879 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004880 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4881 profile.getCarrierPrivilegeStatusForUid(
4882 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08004883 }
4884
4885 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004886 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4887 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004888 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004889 }
4890
4891 int phoneId = SubscriptionManager.getPhoneId(subId);
4892 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004893 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004894 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4896 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004897 return getCarrierPrivilegeStatusFromCarrierConfigRules(
4898 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4899 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004900 }
4901
4902 @Override
4903 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004904 if (TextUtils.isEmpty(pkgName))
4905 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004906 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4907 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4908 UiccCard card = UiccController.getInstance().getUiccCard(i);
4909 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004910 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004911 continue;
4912 }
4913
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004914 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
4915 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
4916 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004917 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4918 break;
4919 }
4920 }
4921
4922 return result;
Junda Liu29340342014-07-10 15:23:27 -07004923 }
Derek Tan89e89d42014-07-08 17:00:10 -07004924
4925 @Override
Junda Liue64de782015-04-16 17:19:16 -07004926 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4927 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4928 loge("phoneId " + phoneId + " is not valid.");
4929 return null;
4930 }
4931 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004932 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004933 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004934 return null ;
4935 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004937 }
4938
Amith Yamasani6e118872016-02-19 12:53:51 -08004939 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004940 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004941 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004942 List<String> privilegedPackages = new ArrayList<>();
4943 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004944 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4945 // has UICC in that slot.
4946 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004947 if (card.hasCarrierPrivilegeRules()) {
4948 if (packages == null) {
4949 // Only check packages in user 0 for now
4950 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07004951 PackageManager.MATCH_DISABLED_COMPONENTS
4952 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09004953 | PackageManager.GET_SIGNING_CERTIFICATES,
4954 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004955 }
4956 for (int p = packages.size() - 1; p >= 0; p--) {
4957 PackageInfo pkgInfo = packages.get(p);
4958 if (pkgInfo != null && pkgInfo.packageName != null
4959 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004960 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004961 privilegedPackages.add(pkgInfo.packageName);
4962 }
4963 }
4964 }
4965 }
4966 return privilegedPackages;
4967 }
4968
chen xuf7e9fe82019-05-09 19:31:02 -07004969 @Override
4970 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4971 List<String> privilegedPackages = new ArrayList<>();
4972 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4973 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4974 }
4975 return privilegedPackages;
4976 }
4977
Wink Savilleb564aae2014-10-23 10:18:09 -07004978 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004979 final Phone phone = getPhone(subId);
4980 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004981 if (card == null) {
4982 loge("getIccId: No UICC");
4983 return null;
4984 }
4985 String iccId = card.getIccId();
4986 if (TextUtils.isEmpty(iccId)) {
4987 loge("getIccId: ICC ID is null or empty.");
4988 return null;
4989 }
4990 return iccId;
4991 }
4992
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004993 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004994 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4995 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004996 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4997 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final long identity = Binder.clearCallingIdentity();
5000 try {
5001 final String iccId = getIccId(subId);
5002 final Phone phone = getPhone(subId);
5003 if (phone == null) {
5004 return false;
5005 }
5006 final String subscriberId = phone.getSubscriberId();
5007
5008 if (DBG_MERGE) {
5009 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5010 + subscriberId + " to " + number);
5011 }
5012
5013 if (TextUtils.isEmpty(iccId)) {
5014 return false;
5015 }
5016
5017 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5018
5019 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5020 if (alphaTag == null) {
5021 editor.remove(alphaTagPrefKey);
5022 } else {
5023 editor.putString(alphaTagPrefKey, alphaTag);
5024 }
5025
5026 // Record both the line number and IMSI for this ICCID, since we need to
5027 // track all merged IMSIs based on line number
5028 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5029 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5030 if (number == null) {
5031 editor.remove(numberPrefKey);
5032 editor.remove(subscriberPrefKey);
5033 } else {
5034 editor.putString(numberPrefKey, number);
5035 editor.putString(subscriberPrefKey, subscriberId);
5036 }
5037
5038 editor.commit();
5039 return true;
5040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005042 }
Derek Tan7226c842014-07-02 17:42:23 -07005043 }
5044
5045 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005046 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005047 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005049 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005050 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005051 return null;
5052 }
Derek Tan97ebb422014-09-05 16:55:38 -07005053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 String iccId = getIccId(subId);
5057 if (iccId != null) {
5058 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5059 if (DBG_MERGE) {
5060 log("getLine1NumberForDisplay returning "
5061 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5062 }
5063 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5066 return null;
5067 } finally {
5068 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005069 }
Derek Tan7226c842014-07-02 17:42:23 -07005070 }
5071
5072 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005073 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005075 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005076 return null;
5077 }
Derek Tan97ebb422014-09-05 16:55:38 -07005078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 final long identity = Binder.clearCallingIdentity();
5080 try {
5081 String iccId = getIccId(subId);
5082 if (iccId != null) {
5083 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5084 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5085 }
5086 return null;
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005089 }
Derek Tan7226c842014-07-02 17:42:23 -07005090 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005091
5092 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005093 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005094 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5095 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005096 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005097 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5098 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005099 return null;
5100 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005101
Jordan Liub49b04b2019-05-06 14:45:15 -07005102 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5103 // the process, where TelephonyManager was instantiated.
5104 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005105 final long identity = Binder.clearCallingIdentity();
5106 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005107 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 final TelephonyManager tele = TelephonyManager.from(context);
5109 final SubscriptionManager sub = SubscriptionManager.from(context);
5110
5111 // Figure out what subscribers are currently active
5112 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113
Jordan Liub49b04b2019-05-06 14:45:15 -07005114 // Only consider subs which match the current subId
5115 // This logic can be simplified. See b/131189269 for progress.
5116 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005117 activeSubscriberIds.add(tele.getSubscriberId(subId));
5118 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119
5120 // First pass, find a number override for an active subscriber
5121 String mergeNumber = null;
5122 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5123 for (String key : prefs.keySet()) {
5124 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5125 final String subscriberId = (String) prefs.get(key);
5126 if (activeSubscriberIds.contains(subscriberId)) {
5127 final String iccId = key.substring(
5128 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5129 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5130 mergeNumber = (String) prefs.get(numberKey);
5131 if (DBG_MERGE) {
5132 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5133 + " for active subscriber " + subscriberId);
5134 }
5135 if (!TextUtils.isEmpty(mergeNumber)) {
5136 break;
5137 }
5138 }
5139 }
5140 }
5141
5142 // Shortcut when no active merged subscribers
5143 if (TextUtils.isEmpty(mergeNumber)) {
5144 return null;
5145 }
5146
5147 // Second pass, find all subscribers under that line override
5148 final ArraySet<String> result = new ArraySet<>();
5149 for (String key : prefs.keySet()) {
5150 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5151 final String number = (String) prefs.get(key);
5152 if (mergeNumber.equals(number)) {
5153 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5154 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5155 final String subscriberId = (String) prefs.get(subscriberKey);
5156 if (!TextUtils.isEmpty(subscriberId)) {
5157 result.add(subscriberId);
5158 }
5159 }
5160 }
5161 }
5162
5163 final String[] resultArray = result.toArray(new String[result.size()]);
5164 Arrays.sort(resultArray);
5165 if (DBG_MERGE) {
5166 Slog.d(LOG_TAG,
5167 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5168 }
5169 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005170 } finally {
5171 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005172 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005173 }
5174
5175 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005176 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5177 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5178
5179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 final TelephonyManager telephonyManager = mApp.getSystemService(
5182 TelephonyManager.class);
5183 String subscriberId = telephonyManager.getSubscriberId(subId);
5184 if (subscriberId == null) {
5185 if (DBG) {
5186 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5187 + subId);
5188 }
5189 return null;
5190 }
5191
5192 final SubscriptionInfo info = SubscriptionController.getInstance()
5193 .getSubscriptionInfo(subId);
5194 final ParcelUuid groupUuid = info.getGroupUuid();
5195 // If it doesn't belong to any group, return just subscriberId of itself.
5196 if (groupUuid == null) {
5197 return new String[]{subscriberId};
5198 }
5199
5200 // Get all subscriberIds from the group.
5201 final List<String> mergedSubscriberIds = new ArrayList<>();
5202 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5203 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5204 for (SubscriptionInfo subInfo : groupInfos) {
5205 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5206 if (subscriberId != null) {
5207 mergedSubscriberIds.add(subscriberId);
5208 }
5209 }
5210
5211 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214
5215 }
5216 }
5217
5218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005219 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005220 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5221 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 final Phone phone = getPhone(subId);
5226 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5227 } finally {
5228 Binder.restoreCallingIdentity(identity);
5229 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005230 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005231
5232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005233 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005234 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5235 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237
5238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 final Phone phone = getPhone(subId);
5241 if (phone == null) {
5242 return false;
5243 }
5244 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5245 cdmaNonRoamingList);
5246 } finally {
5247 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005248 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005249 }
5250
5251 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005252 @Deprecated
5253 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5254 enforceModifyPermission();
5255
5256 int returnValue = 0;
5257 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005258 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005259 if(result.exception == null) {
5260 if (result.result != null) {
5261 byte[] responseData = (byte[])(result.result);
5262 if(responseData.length > oemResp.length) {
5263 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5264 responseData.length + "bytes. Buffer Size is " +
5265 oemResp.length + "bytes.");
5266 }
5267 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5268 returnValue = responseData.length;
5269 }
5270 } else {
5271 CommandException ex = (CommandException) result.exception;
5272 returnValue = ex.getCommandError().ordinal();
5273 if(returnValue > 0) returnValue *= -1;
5274 }
5275 } catch (RuntimeException e) {
5276 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5277 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5278 if(returnValue > 0) returnValue *= -1;
5279 }
5280
5281 return returnValue;
5282 }
5283
5284 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005285 public void setRadioCapability(RadioAccessFamily[] rafs) {
5286 try {
5287 ProxyController.getInstance().setRadioCapability(rafs);
5288 } catch (RuntimeException e) {
5289 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5290 }
5291 }
5292
5293 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005294 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005295 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005296 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005297 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005298 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 final long identity = Binder.clearCallingIdentity();
5301 try {
chen xub97461a2018-10-26 14:17:57 -07005302 TelephonyPermissions
5303 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5304 mApp, phone.getSubId(), "getRadioAccessFamily");
5305 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
chen xub97461a2018-10-26 14:17:57 -07005309 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005310 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005311
5312 @Override
5313 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005314 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005315 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316
5317 final long identity = Binder.clearCallingIdentity();
5318 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005319 ImsManager.getInstance(defaultPhone.getContext(),
5320 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321 } finally {
5322 Binder.restoreCallingIdentity(identity);
5323 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005324 }
5325
5326 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005327 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005328 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005330 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005331 return false;
5332 }
Svet Ganovb320e182015-04-16 12:30:10 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 // Check the user preference and the system-level IMS setting. Even if the user has
5337 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5338 // In the long run, we may instead need to check if there exists a connection service
5339 // which can support video calling.
5340 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005341 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005342 return imsManager.isVtEnabledByPlatform()
5343 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5344 && imsManager.isVtEnabledByUser();
5345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005348 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005349
Andrew Leea1239f22015-03-02 17:44:07 -08005350 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5352 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5353 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5354 return false;
5355 }
5356
5357 final long identity = Binder.clearCallingIdentity();
5358 try {
5359 CarrierConfigManager configManager =
5360 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005361 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
Andrew Leea1239f22015-03-02 17:44:07 -08005366 }
5367
5368 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 public boolean isWorldPhone(int subId, String callingPackage) {
5370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5371 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5372 return false;
5373 }
5374
5375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 CarrierConfigManager configManager =
5378 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005379 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005380 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
Andrew Leea1239f22015-03-02 17:44:07 -08005384 }
5385
Andrew Lee9431b832015-03-09 18:46:45 -07005386 @Override
5387 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005388 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005389 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005390 }
5391
5392 @Override
5393 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005394 final long identity = Binder.clearCallingIdentity();
5395 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005396 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
Andrew Lee9431b832015-03-09 18:46:45 -07005400 }
5401
Hall Liuf6668912018-10-31 17:05:23 -07005402 /**
5403 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5404 * support for the feature and device firmware support.
5405 *
5406 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5407 */
5408 @Override
5409 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005411 final Phone phone = getPhone(subscriptionId);
5412 if (phone == null) {
5413 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5414 return false;
5415 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005417 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5419 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005420 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 return isCarrierSupported && isDeviceSupported;
5422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
Hall Liu98187582018-01-22 19:15:32 -08005425 }
5426
Hall Liuf6668912018-10-31 17:05:23 -07005427 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005428 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5429 * RTT setting, will return true if the device and carrier both support RTT.
5430 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005431 */
5432 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433 final long identity = Binder.clearCallingIdentity();
5434 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005435 boolean isRttSupported = isRttSupported(subscriptionId);
5436 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005438 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5439 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5440 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005444 }
5445
Sanket Padawe7310cc72015-01-14 09:53:20 -08005446 /**
5447 * Returns the unique device ID of phone, for example, the IMEI for
5448 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5449 *
5450 * <p>Requires Permission:
5451 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5452 */
5453 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005454 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005455 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005456 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005457 return null;
5458 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005459 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005460 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5461 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005462 return null;
5463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005464
5465 final long identity = Binder.clearCallingIdentity();
5466 try {
5467 return phone.getDeviceId();
5468 } finally {
5469 Binder.restoreCallingIdentity(identity);
5470 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005471 }
5472
Ping Sunc67b7c22016-03-02 19:16:45 +08005473 /**
5474 * {@hide}
5475 * Returns the IMS Registration Status on a particular subid
5476 *
5477 * @param subId
5478 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005479 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005480 Phone phone = getPhone(subId);
5481 if (phone != null) {
5482 return phone.isImsRegistered();
5483 } else {
5484 return false;
5485 }
5486 }
5487
Santos Cordon7a1885b2015-02-03 11:15:19 -08005488 @Override
5489 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
5495 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005496 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005497
Tyler Gunnf70ed162019-04-03 15:28:53 -07005498 @Override
5499 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 Phone phone = getPhone(subscriptionId);
5503 if (phone == null) {
5504 return null;
5505 }
5506 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5507 } finally {
5508 Binder.restoreCallingIdentity(identity);
5509 }
5510 }
5511
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005512 /**
5513 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005514 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005515 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516 final long identity = Binder.clearCallingIdentity();
5517 try {
5518 Phone phone = getPhone(subId);
5519 if (phone != null) {
5520 return phone.isWifiCallingEnabled();
5521 } else {
5522 return false;
5523 }
5524 } finally {
5525 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005526 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005527 }
5528
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005529 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005530 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005531 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005532 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533 final long identity = Binder.clearCallingIdentity();
5534 try {
5535 Phone phone = getPhone(subId);
5536 if (phone != null) {
5537 return phone.isVideoEnabled();
5538 } else {
5539 return false;
5540 }
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005543 }
5544 }
5545
5546 /**
5547 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5548 * defined in {@link ImsRegistrationImplBase}.
5549 */
5550 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 final long identity = Binder.clearCallingIdentity();
5552 try {
5553 Phone phone = getPhone(subId);
5554 if (phone != null) {
5555 return phone.getImsRegistrationTech();
5556 } else {
5557 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5558 }
5559 } finally {
5560 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005561 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005562 }
5563
Stuart Scott8eef64f2015-04-08 15:13:54 -07005564 @Override
5565 public void factoryReset(int subId) {
5566 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005567 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5568 return;
5569 }
5570
Svet Ganovcc087f82015-05-12 20:35:54 -07005571 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572
Svet Ganovcc087f82015-05-12 20:35:54 -07005573 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005574 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5575 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005576 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005577 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005578 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005579 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5580 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005581 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005582 // There has been issues when Sms raw table somehow stores orphan
5583 // fragments. They lead to garbled message when new fragments come
5584 // in and combined with those stale ones. In case this happens again,
5585 // user can reset all network settings which will clean up this table.
5586 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005587 } finally {
5588 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005589 }
5590 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005591
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005592 private void cleanUpSmsRawTable(Context context) {
5593 ContentResolver resolver = context.getContentResolver();
5594 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5595 resolver.delete(uri, null, null);
5596 }
5597
Narayan Kamath1c496c22015-04-16 14:40:19 +01005598 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005599 public String getSimLocaleForSubscriber(int subId) {
5600 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5601 final Phone phone = getPhone(subId);
5602 if (phone == null) {
5603 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005604 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005605 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 final long identity = Binder.clearCallingIdentity();
5607 try {
chen xu5d3637b2019-01-21 23:31:38 -08005608 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5609 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005610 if (info == null) {
5611 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5612 return null;
5613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 // Try and fetch the locale from the carrier properties or from the SIM language
5615 // preferences (EF-PL and EF-LI)...
5616 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005618 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5619 if (localeFromDefaultSim != null) {
5620 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5621 if (DBG) log("Using locale from subId: " + subId + " locale: "
5622 + localeFromDefaultSim);
5623 return localeFromDefaultSim.toLanguageTag();
5624 } else {
5625 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005626 }
5627 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 // The SIM language preferences only store a language (e.g. fr = French), not an
5630 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5631 // the SIM and carrier preferences does not include a country we add the country
5632 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005633 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005635 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 return mccLocale.toLanguageTag();
5637 }
5638
5639 if (DBG) log("No locale found - returning null");
5640 return null;
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005644 }
5645
5646 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005647 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005648 }
5649
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 /**
5651 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5652 */
5653 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005654 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005655 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005656
Chenjie Yu1ba97252018-01-11 18:16:20 -08005657 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005658 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005659
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005660 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005661 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5662 * representing the state of the modem.
5663 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005664 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5665 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005666 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005667 */
5668 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005669 public void requestModemActivityInfo(ResultReceiver result) {
5670 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005671 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672
5673 final long identity = Binder.clearCallingIdentity();
5674 try {
5675 ModemActivityInfo ret = null;
5676 synchronized (mLastModemActivityInfo) {
5677 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5678 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005679 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005680 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005682 int[] txTimeMs = info.getTransmitTimeMillis();
5683 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005684 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005685 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686 }
5687 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005688 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5689 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 mLastModemActivityInfo.setIdleTimeMillis(
5691 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005692 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5693 mLastModemActivityInfo.setReceiveTimeMillis(
5694 info.getReceiveTimeMillis() + mLastModemActivityInfo
5695 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005696 }
Chen Xud78231e2019-09-10 18:49:52 -07005697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005698 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5699 mLastModemActivityInfo.getSleepTimeMillis(),
5700 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005701 mLastModemActivityInfo.getTransmitTimeMillis(),
5702 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 Bundle bundle = new Bundle();
5705 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5706 result.send(0, bundle);
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005709 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005710 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005711
Siddharth Rayb8114062018-06-17 15:02:38 -07005712 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5713 // less than total activity duration.
5714 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5715 if (info == null) {
5716 return false;
5717 }
5718 int activityDurationMs =
5719 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5720 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005721 int[] txTimeMs = info.getTransmitTimeMillis();
5722 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5723 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005724 }
5725 return (info.isValid()
5726 && (info.getSleepTimeMillis() <= activityDurationMs)
5727 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005728 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005729 && (totalTxTimeMs <= activityDurationMs));
5730 }
5731
Jack Yu85bd38a2015-11-09 11:34:32 -08005732 /**
5733 * {@hide}
5734 * Returns the service state information on specified subscription.
5735 */
5736 @Override
5737 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005739 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005740 return null;
5741 }
5742
Hall Liuf19c44f2018-11-27 14:38:17 -08005743 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5744 LocationAccessPolicy.checkLocationPermission(mApp,
5745 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5746 .setCallingPackage(callingPackage)
5747 .setCallingPid(Binder.getCallingPid())
5748 .setCallingUid(Binder.getCallingUid())
5749 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005750 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5752 .build());
5753
5754 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5755 LocationAccessPolicy.checkLocationPermission(mApp,
5756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5757 .setCallingPackage(callingPackage)
5758 .setCallingPid(Binder.getCallingPid())
5759 .setCallingUid(Binder.getCallingUid())
5760 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005761 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005762 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5763 .build());
5764 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5765 boolean hasFinePermission =
5766 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5767 boolean hasCoarsePermission =
5768 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 final long identity = Binder.clearCallingIdentity();
5771 try {
5772 final Phone phone = getPhone(subId);
5773 if (phone == null) {
5774 return null;
5775 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005776
Hall Liuf19c44f2018-11-27 14:38:17 -08005777 ServiceState ss = phone.getServiceState();
5778
5779 // Scrub out the location info in ServiceState depending on what level of access
5780 // the caller has.
5781 if (hasFinePermission) return ss;
5782 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5783 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005787 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005788
5789 /**
5790 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5791 *
5792 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5793 * voicemail ringtone.
5794 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5795 * PhoneAccount.
5796 */
5797 @Override
5798 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005799 final long identity = Binder.clearCallingIdentity();
5800 try {
5801 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5802 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005803 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005804 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005805
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5807 } finally {
5808 Binder.restoreCallingIdentity(identity);
5809 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005810 }
5811
5812 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005813 * Sets the per-account voicemail ringtone.
5814 *
5815 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5816 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5817 *
5818 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5819 * voicemail ringtone.
5820 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5821 * PhoneAccount.
5822 */
5823 @Override
5824 public void setVoicemailRingtoneUri(String callingPackage,
5825 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005826 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005827 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5828 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005829 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5831 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5832 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005833 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
5837 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5838 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005839 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005840 }
5841 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5842 } finally {
5843 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005844 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005845 }
5846
5847 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005848 * Returns whether vibration is set for voicemail notification in Phone settings.
5849 *
5850 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5851 * voicemail vibration setting.
5852 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5853 */
5854 @Override
5855 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
5858 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5859 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005860 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005861 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005867 }
5868
Youhan Wange64578a2016-05-02 15:32:42 -07005869 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005870 * Sets the per-account voicemail vibration.
5871 *
5872 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5873 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5874 *
5875 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5876 * voicemail vibration setting.
5877 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5878 * specific PhoneAccount.
5879 */
5880 @Override
5881 public void setVoicemailVibrationEnabled(String callingPackage,
5882 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005883 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5885 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005886 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5888 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5889 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005890 }
5891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005892 final long identity = Binder.clearCallingIdentity();
5893 try {
5894 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5895 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005896 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005897 }
5898 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5899 } finally {
5900 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005901 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005902 }
5903
5904 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005905 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5906 *
5907 * @throws SecurityException if the caller does not have the required permission
5908 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005909 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005910 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005911 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005912 }
5913
5914 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005915 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5916 * permission.
5917 *
5918 * @throws SecurityException if the caller does not have the required permission
5919 */
5920 private void enforceSendSmsPermission() {
5921 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5922 }
5923
5924 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005925 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005926 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005927 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005928 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005929 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005930 final long identity = Binder.clearCallingIdentity();
5931 try {
5932 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005933 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005934 if (componentName == null) {
5935 throw new SecurityException(
5936 "Caller not current active visual voicemail package[null]");
5937 }
5938 String vvmPackage = componentName.getPackageName();
5939 if (!callingPackage.equals(vvmPackage)) {
5940 throw new SecurityException("Caller not current active visual voicemail package["
5941 + vvmPackage + "]");
5942 }
5943 } finally {
5944 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005945 }
5946 }
5947
5948 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005949 * Return the application ID for the app type.
5950 *
5951 * @param subId the subscription ID that this request applies to.
5952 * @param appType the uicc app type.
5953 * @return Application ID for specificied app type, or null if no uicc.
5954 */
5955 @Override
5956 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005957 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005958 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959
5960 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005961 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005962 if (phone == null) {
5963 return null;
5964 }
5965 String aid = null;
5966 try {
5967 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5968 .getApplicationByType(appType).getAid();
5969 } catch (Exception e) {
5970 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5971 }
5972 return aid;
5973 } finally {
5974 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005975 }
Youhan Wange64578a2016-05-02 15:32:42 -07005976 }
5977
Youhan Wang4001d252016-05-11 10:29:41 -07005978 /**
5979 * Return the Electronic Serial Number.
5980 *
5981 * @param subId the subscription ID that this request applies to.
5982 * @return ESN or null if error.
5983 */
5984 @Override
5985 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005986 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005987 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005990 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 if (phone == null) {
5992 return null;
5993 }
5994 String esn = null;
5995 try {
5996 esn = phone.getEsn();
5997 } catch (Exception e) {
5998 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5999 }
6000 return esn;
6001 } finally {
6002 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006003 }
Youhan Wang4001d252016-05-11 10:29:41 -07006004 }
6005
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006006 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006007 * Return the Preferred Roaming List Version.
6008 *
6009 * @param subId the subscription ID that this request applies to.
6010 * @return PRLVersion or null if error.
6011 */
6012 @Override
6013 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006014 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006015 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016
6017 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006018 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006019 if (phone == null) {
6020 return null;
6021 }
6022 String cdmaPrlVersion = null;
6023 try {
6024 cdmaPrlVersion = phone.getCdmaPrlVersion();
6025 } catch (Exception e) {
6026 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6027 }
6028 return cdmaPrlVersion;
6029 } finally {
6030 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006031 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006032 }
6033
6034 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006035 * Get snapshot of Telephony histograms
6036 * @return List of Telephony histograms
6037 * @hide
6038 */
6039 @Override
6040 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6042 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043
6044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 return RIL.getTelephonyRILTimingHistograms();
6047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006050 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006051
6052 /**
6053 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006054 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6055 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006056 * Require system privileges. In the future we may add this to carrier APIs.
6057 *
Michele Berionne482f8202018-11-27 18:57:59 -08006058 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006059 */
6060 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006061 @TelephonyManager.SetCarrierRestrictionResult
6062 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006063 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006065
Michele Berionne482f8202018-11-27 18:57:59 -08006066 if (carrierRestrictionRules == null) {
6067 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006068 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006069
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006070 final long identity = Binder.clearCallingIdentity();
6071 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006072 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006073 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 } finally {
6075 Binder.restoreCallingIdentity(identity);
6076 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006077 }
6078
6079 /**
6080 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006081 * Get the allowed carrier list and the excluded carrier list, including the priority between
6082 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006083 * Require system privileges. In the future we may add this to carrier APIs.
6084 *
Michele Berionne482f8202018-11-27 18:57:59 -08006085 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006086 */
6087 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006088 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006089 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006091
6092 final long identity = Binder.clearCallingIdentity();
6093 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006094 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6095 if (response instanceof CarrierRestrictionRules) {
6096 return (CarrierRestrictionRules) response;
6097 }
6098 // Response is an Exception of some kind,
6099 // which is signalled to the user as a NULL retval
6100 return null;
6101 } catch (Exception e) {
6102 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6103 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006104 } finally {
6105 Binder.restoreCallingIdentity(identity);
6106 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006107 }
6108
fionaxu59545b42016-05-25 15:53:37 -07006109 /**
6110 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6111 * @param subId the subscription ID that this action applies to.
6112 * @param enabled control enable or disable metered apns.
6113 * {@hide}
6114 */
6115 @Override
6116 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6117 enforceModifyPermission();
6118 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006119
6120 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006121 if (phone == null) {
6122 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6123 return;
6124 }
6125 try {
6126 phone.carrierActionSetMeteredApnsEnabled(enabled);
6127 } catch (Exception e) {
6128 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 } finally {
6130 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006131 }
6132 }
6133
6134 /**
6135 * Action set from carrier signalling broadcast receivers to enable/disable radio
6136 * @param subId the subscription ID that this action applies to.
6137 * @param enabled control enable or disable radio.
6138 * {@hide}
6139 */
6140 @Override
6141 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6142 enforceModifyPermission();
6143 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144
6145 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006146 if (phone == null) {
6147 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6148 return;
6149 }
6150 try {
6151 phone.carrierActionSetRadioEnabled(enabled);
6152 } catch (Exception e) {
6153 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154 } finally {
6155 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006156 }
6157 }
6158
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006159 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006160 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6161 * network status based on which carrier apps could apply actions accordingly,
6162 * enable/disable default url handler for example.
6163 *
6164 * @param subId the subscription ID that this action applies to.
6165 * @param report control start/stop reporting the default network status.
6166 * {@hide}
6167 */
6168 @Override
6169 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6170 enforceModifyPermission();
6171 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006172
6173 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006174 if (phone == null) {
6175 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6176 return;
6177 }
6178 try {
6179 phone.carrierActionReportDefaultNetworkStatus(report);
6180 } catch (Exception e) {
6181 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 } finally {
6183 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006184 }
6185 }
6186
6187 /**
fionaxud9622282017-07-17 17:51:30 -07006188 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6189 * @param subId the subscription ID that this action applies to.
6190 * {@hide}
6191 */
6192 @Override
6193 public void carrierActionResetAll(int subId) {
6194 enforceModifyPermission();
6195 final Phone phone = getPhone(subId);
6196 if (phone == null) {
6197 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6198 return;
6199 }
6200 try {
6201 phone.carrierActionResetAll();
6202 } catch (Exception e) {
6203 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6204 }
6205 }
6206
6207 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006208 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6209 * bug report is being generated.
6210 */
6211 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006212 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006213 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6214 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006215 writer.println("Permission Denial: can't dump Phone from pid="
6216 + Binder.getCallingPid()
6217 + ", uid=" + Binder.getCallingUid()
6218 + "without permission "
6219 + android.Manifest.permission.DUMP);
6220 return;
6221 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006222 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006223 }
Jack Yueb89b242016-06-22 13:27:47 -07006224
Brad Ebingerdac2f002018-04-03 15:17:52 -07006225 @Override
6226 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6227 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6228 throws RemoteException {
6229 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6230 }
6231
Jack Yueb89b242016-06-22 13:27:47 -07006232 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006233 * Get aggregated video call data usage since boot.
6234 *
6235 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6236 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006237 * {@hide}
6238 */
6239 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006240 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006241 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6242 null);
6243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 final long identity = Binder.clearCallingIdentity();
6245 try {
6246 // NetworkStatsService keeps tracking the active network interface and identity. It
6247 // records the delta with the corresponding network identity.
6248 // We just return the total video call data usage snapshot since boot.
6249 Phone phone = getPhone(subId);
6250 if (phone != null) {
6251 return phone.getVtDataUsage(perUidStats);
6252 }
6253 return null;
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006256 }
Jack Yueb89b242016-06-22 13:27:47 -07006257 }
Jack Yu75ab2952016-07-08 14:29:33 -07006258
6259 /**
6260 * Policy control of data connection. Usually used when data limit is passed.
6261 * @param enabled True if enabling the data, otherwise disabling.
6262 * @param subId Subscription index
6263 * {@hide}
6264 */
6265 @Override
6266 public void setPolicyDataEnabled(boolean enabled, int subId) {
6267 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268
6269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 Phone phone = getPhone(subId);
6272 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006273 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 }
6275 } finally {
6276 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006277 }
6278 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006279
6280 /**
6281 * Get Client request stats
6282 * @return List of Client Request Stats
6283 * @hide
6284 */
6285 @Override
6286 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006288 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006289 return null;
6290 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006291 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 if (phone != null) {
6296 return phone.getClientRequestStats();
6297 }
6298
6299 return null;
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006303 }
6304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006305 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006306 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006307 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006308 }
Jack Yueb4124c2017-02-16 15:32:43 -08006309
6310 /**
Grace Chen70990072017-03-24 17:21:30 -07006311 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006312 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006313 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006314 * @param state State of SIM (power down, power up, pass through)
6315 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6316 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6317 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006318 *
6319 **/
6320 @Override
Grace Chen70990072017-03-24 17:21:30 -07006321 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006322 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006323 Phone phone = PhoneFactory.getPhone(slotIndex);
6324
vagdeviaf9a5b92018-08-15 16:01:53 -07006325 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006330 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006331 }
6332 } finally {
6333 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006334 }
6335 }
Shuo Qiandd210312017-04-12 22:11:33 +00006336
Tyler Gunn65d45c22017-06-05 11:22:26 -07006337 private boolean isUssdApiAllowed(int subId) {
6338 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006340 if (configManager == null) {
6341 return false;
6342 }
6343 PersistableBundle pb = configManager.getConfigForSubId(subId);
6344 if (pb == null) {
6345 return false;
6346 }
6347 return pb.getBoolean(
6348 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6349 }
6350
Shuo Qiandd210312017-04-12 22:11:33 +00006351 /**
6352 * Check if phone is in emergency callback mode
6353 * @return true if phone is in emergency callback mode
6354 * @param subId sub id
6355 */
goneil9c5f4872017-12-05 14:07:56 -08006356 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006357 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006358 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006359 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 if (phone != null) {
6364 return phone.isInEcm();
6365 } else {
6366 return false;
6367 }
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006370 }
6371 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006372
6373 /**
6374 * Get the current signal strength information for the given subscription.
6375 * Because this information is not updated when the device is in a low power state
6376 * it should not be relied-upon to be current.
6377 * @param subId Subscription index
6378 * @return the most recent cached signal strength info from the modem
6379 */
6380 @Override
6381 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006382 final long identity = Binder.clearCallingIdentity();
6383 try {
6384 Phone p = getPhone(subId);
6385 if (p == null) {
6386 return null;
6387 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006388
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 return p.getSignalStrength();
6390 } finally {
6391 Binder.restoreCallingIdentity(identity);
6392 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006393 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006394
Pengquan Meng77b7f132018-08-22 14:49:57 -07006395 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006396 * Get the current modem radio state for the given slot.
6397 * @param slotIndex slot index.
6398 * @param callingPackage the name of the package making the call.
6399 * @return the current radio power state from the modem
6400 */
6401 @Override
6402 public int getRadioPowerState(int slotIndex, String callingPackage) {
6403 Phone phone = PhoneFactory.getPhone(slotIndex);
6404 if (phone != null) {
6405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6406 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6407 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6408 }
6409
6410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 return phone.getRadioPowerState();
6413 } finally {
6414 Binder.restoreCallingIdentity(identity);
6415 }
6416 }
6417 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6418 }
6419
6420 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006421 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6422 *
6423 * <p>Requires one of the following permissions:
6424 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6425 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6426 * privileges.
6427 *
6428 * @param subId subscription id
6429 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6430 * {@code false}.
6431 */
6432 @Override
6433 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006434 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6435 null /* message */);
6436
Pengquan Menga1bb6272018-09-06 09:59:22 -07006437 boolean isEnabled = false;
6438 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006439 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006440 Phone phone = getPhone(subId);
6441 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006442 } catch (Exception e) {
6443 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6444 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006445 } finally {
6446 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006447 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006448 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006449 }
6450
6451
6452 /**
6453 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6454 *
6455 * <p> Requires permission:
6456 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6457 * privileges.
6458 *
6459 * @param subId subscription id
6460 * @param isEnabled {@code true} means enable, {@code false} means disable.
6461 */
6462 @Override
6463 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6465 mApp, subId, "setDataRoamingEnabled");
6466
Pengquan Menga1bb6272018-09-06 09:59:22 -07006467 final long identity = Binder.clearCallingIdentity();
6468 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006469 Phone phone = getPhone(subId);
6470 if (phone != null) {
6471 phone.setDataRoamingEnabled(isEnabled);
6472 }
6473 } finally {
6474 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006475 }
6476 }
6477
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006478 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006479 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006480 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6481 mApp, subId, "isManualNetworkSelectionAllowed");
6482
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006483 boolean isAllowed = true;
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006486 Phone phone = getPhone(subId);
6487 if (phone != null) {
6488 isAllowed = phone.isCspPlmnEnabled();
6489 }
6490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
6493 return isAllowed;
6494 }
6495
6496 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006497 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006498 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006499 try {
6500 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006501 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006502 } catch (SecurityException e) {
6503 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6504 // has carrier privileges on an active UICC
6505 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6506 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006507 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006508 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006509 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006510
6511 final long identity = Binder.clearCallingIdentity();
6512 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006513 UiccController uiccController = UiccController.getInstance();
6514 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006515 if (hasReadPermission) {
6516 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006517 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006518
6519 // Remove private info if the caller doesn't have access
6520 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6521 for (UiccCardInfo cardInfo : cardInfos) {
6522 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6523 // is available
6524 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6525 if (card == null || card.getUiccProfile() == null) {
6526 // assume no access if the card or profile is unavailable
6527 filteredInfos.add(cardInfo.getUnprivileged());
6528 continue;
6529 }
6530 UiccProfile profile = card.getUiccProfile();
6531 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6532 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6533 filteredInfos.add(cardInfo);
6534 } else {
6535 filteredInfos.add(cardInfo.getUnprivileged());
6536 }
6537 }
6538 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 }
6543
6544 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006545 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006546 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006548 final long identity = Binder.clearCallingIdentity();
6549 try {
6550 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6551 if (slots == null) {
6552 Rlog.i(LOG_TAG, "slots is null.");
6553 return null;
6554 }
6555
6556 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6557 for (int i = 0; i < slots.length; i++) {
6558 UiccSlot slot = slots[i];
6559 if (slot == null) {
6560 continue;
6561 }
6562
Jordan Liu7be7e652019-05-06 18:55:02 +00006563 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006564 UiccCard card = slot.getUiccCard();
6565 if (card != null) {
6566 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006567 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006568 cardId = slot.getEid();
6569 if (TextUtils.isEmpty(cardId)) {
6570 cardId = slot.getIccId();
6571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 }
6573
Jordan Liu857451f2019-05-09 16:35:35 -07006574 if (cardId != null) {
6575 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6576 // if cardId is an EID, it's all digits so this is fine
6577 cardId = IccUtils.stripTrailingFs(cardId);
6578 }
6579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580 int cardState = 0;
6581 switch (slot.getCardState()) {
6582 case CARDSTATE_ABSENT:
6583 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6584 break;
6585 case CARDSTATE_PRESENT:
6586 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6587 break;
6588 case CARDSTATE_ERROR:
6589 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6590 break;
6591 case CARDSTATE_RESTRICTED:
6592 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6593 break;
6594 default:
6595 break;
6596
6597 }
6598
6599 infos[i] = new UiccSlotInfo(
6600 slot.isActive(),
6601 slot.isEuicc(),
6602 cardId,
6603 cardState,
6604 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006605 slot.isExtendedApduSupported(),
6606 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 }
6608 return infos;
6609 } finally {
6610 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006611 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006612 }
6613
6614 @Override
6615 public boolean switchSlots(int[] physicalSlots) {
6616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006617
6618 final long identity = Binder.clearCallingIdentity();
6619 try {
6620 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
6623 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006624 }
Jack Yu4c988042018-02-27 15:30:01 -08006625
6626 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006627 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006628 final long identity = Binder.clearCallingIdentity();
6629 try {
6630 return UiccController.getInstance().getCardIdForDefaultEuicc();
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
6633 }
6634 }
6635
6636 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006637 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6638 enforceModifyPermission();
6639 final Phone phone = getPhone(subId);
6640 if (phone == null) {
6641 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6642 return;
6643 }
6644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 phone.setRadioIndicationUpdateMode(filters, mode);
6648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
Jack Yu4c988042018-02-27 15:30:01 -08006651 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006652
6653 /**
goneil47ffb6e2018-04-06 15:40:58 -07006654 * A test API to reload the UICC profile.
6655 *
6656 * <p>Requires that the calling app has permission
6657 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6658 * @hide
6659 */
6660 @Override
6661 public void refreshUiccProfile(int subId) {
6662 enforceModifyPermission();
6663
6664 final long identity = Binder.clearCallingIdentity();
6665 try {
6666 Phone phone = getPhone(subId);
6667 if (phone == null) {
6668 return;
6669 }
6670 UiccCard uiccCard = phone.getUiccCard();
6671 if (uiccCard == null) {
6672 return;
6673 }
6674 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6675 if (uiccProfile == null) {
6676 return;
6677 }
6678 uiccProfile.refresh();
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
6684 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006685 * Returns false if the mobile data is disabled by default, otherwise return true.
6686 */
6687 private boolean getDefaultDataEnabled() {
6688 return "true".equalsIgnoreCase(
6689 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6690 }
6691
6692 /**
6693 * Returns true if the data roaming is enabled by default, i.e the system property
6694 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6695 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6696 */
6697 private boolean getDefaultDataRoamingEnabled(int subId) {
6698 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006699 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006700 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6701 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6702 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6703 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6704 return isDataRoamingEnabled;
6705 }
6706
6707 /**
6708 * Returns the default network type for the given {@code subId}, if the default network type is
6709 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6710 */
6711 private int getDefaultNetworkType(int subId) {
6712 return Integer.parseInt(
6713 TelephonyManager.getTelephonyProperty(
6714 mSubscriptionController.getPhoneId(subId),
6715 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6716 String.valueOf(Phone.PREFERRED_NT_MODE)));
6717 }
fionaxua13278b2018-03-21 00:08:13 -07006718
6719 @Override
6720 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006721 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006722 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
6726 final Phone phone = getPhone(subId);
6727 if (phone == null) {
6728 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6729 return;
6730 }
chen xueaba88a2019-03-15 13:15:10 -07006731 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6732 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 } finally {
6734 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006735 }
fionaxua13278b2018-03-21 00:08:13 -07006736 }
6737
6738 @Override
6739 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006740 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
6742 final long identity = Binder.clearCallingIdentity();
6743 try {
6744 final Phone phone = getPhone(subId);
6745 if (phone == null) {
6746 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6747 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6748 }
6749 return phone.getCarrierIdListVersion();
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006752 }
fionaxua13278b2018-03-21 00:08:13 -07006753 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006754
6755 @Override
6756 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6758 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6759 return -1;
6760 }
6761
6762 final long identity = Binder.clearCallingIdentity();
6763 try {
6764 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
6768 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006769
6770 @Override
6771 public int getCdmaRoamingMode(int subId) {
6772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6773 mApp, subId, "getCdmaRoamingMode");
6774
6775 final long identity = Binder.clearCallingIdentity();
6776 try {
6777 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6778 } finally {
6779 Binder.restoreCallingIdentity(identity);
6780 }
6781 }
6782
6783 @Override
6784 public boolean setCdmaRoamingMode(int subId, int mode) {
6785 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6786 mApp, subId, "setCdmaRoamingMode");
6787
6788 final long identity = Binder.clearCallingIdentity();
6789 try {
6790 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6791 } finally {
6792 Binder.restoreCallingIdentity(identity);
6793 }
6794 }
6795
6796 @Override
6797 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6799 mApp, subId, "setCdmaSubscriptionMode");
6800
6801 final long identity = Binder.clearCallingIdentity();
6802 try {
6803 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6804 } finally {
6805 Binder.restoreCallingIdentity(identity);
6806 }
6807 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006808
6809 private void ensureUserRunning(int userId) {
6810 if (!mUserManager.isUserRunning(userId)) {
6811 throw new IllegalStateException("User " + userId + " does not exist or not running");
6812 }
6813 }
6814
6815 /**
6816 * Returns a list of SMS apps on a given user.
6817 *
6818 * Only the shell user (UID 2000 or 0) can call it.
6819 * Target user must be running.
6820 */
6821 @Override
6822 public String[] getSmsApps(int userId) {
6823 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6824 ensureUserRunning(userId);
6825
6826 final Collection<SmsApplicationData> apps =
6827 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6828
6829 String[] ret = new String[apps.size()];
6830 int i = 0;
6831 for (SmsApplicationData app : apps) {
6832 ret[i++] = app.mPackageName;
6833 }
6834 return ret;
6835 }
6836
6837 /**
6838 * Returns the default SMS app package name on a given user.
6839 *
6840 * Only the shell user (UID 2000 or 0) can call it.
6841 * Target user must be running.
6842 */
6843 @Override
6844 public String getDefaultSmsApp(int userId) {
6845 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6846 ensureUserRunning(userId);
6847
6848 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6849 /* updateIfNeeded= */ true, userId);
6850 return cn == null ? null : cn.getPackageName();
6851 }
6852
6853 /**
6854 * Set a package as the default SMS app on a given user.
6855 *
6856 * Only the shell user (UID 2000 or 0) can call it.
6857 * Target user must be running.
6858 */
6859 @Override
6860 public void setDefaultSmsApp(int userId, String packageName) {
6861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6862 ensureUserRunning(userId);
6863
6864 boolean found = false;
6865 for (String pkg : getSmsApps(userId)) {
6866 if (TextUtils.equals(packageName, pkg)) {
6867 found = true;
6868 break;
6869 }
6870 }
6871 if (!found) {
6872 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6873 }
6874
6875 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6876 }
sqianc5eccab2018-10-19 18:46:41 -07006877
6878 @Override
sqian8c685422019-02-22 15:55:18 -08006879 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006880 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006881 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006882 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006883 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6884 }
6885 final long identity = Binder.clearCallingIdentity();
6886 try {
sqian854d44b2018-12-12 16:48:18 -08006887 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6888 for (Phone phone: PhoneFactory.getPhones()) {
6889 if (phone.getEmergencyNumberTracker() != null
6890 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6891 emergencyNumberListInternal.put(
6892 phone.getSubId(),
6893 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6894 }
sqian11b7a0e2018-12-05 18:48:28 -08006895 }
sqian854d44b2018-12-12 16:48:18 -08006896 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006897 } finally {
6898 Binder.restoreCallingIdentity(identity);
6899 }
sqianc5eccab2018-10-19 18:46:41 -07006900 }
6901
6902 @Override
sqian8c685422019-02-22 15:55:18 -08006903 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006904 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006905 if (!exactMatch) {
6906 TelephonyPermissions
6907 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006908 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006909 }
6910 final long identity = Binder.clearCallingIdentity();
6911 try {
sqian854d44b2018-12-12 16:48:18 -08006912 for (Phone phone: PhoneFactory.getPhones()) {
6913 if (phone.getEmergencyNumberTracker() != null
6914 && phone.getEmergencyNumberTracker() != null) {
6915 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6916 number, exactMatch)) {
6917 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006918 }
6919 }
sqian11b7a0e2018-12-05 18:48:28 -08006920 }
6921 return false;
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
sqianf4ca7ed2019-01-15 18:32:07 -08006927 /**
6928 * Update emergency number list for test mode.
6929 */
6930 @Override
6931 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6932 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6933 "updateEmergencyNumberListTestMode");
6934
6935 final long identity = Binder.clearCallingIdentity();
6936 try {
6937 for (Phone phone: PhoneFactory.getPhones()) {
6938 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6939 if (tracker != null) {
6940 tracker.executeEmergencyNumberTestModeCommand(action, num);
6941 }
6942 }
6943 } finally {
6944 Binder.restoreCallingIdentity(identity);
6945 }
6946 }
6947
6948 /**
6949 * Get the full emergency number list for test mode.
6950 */
6951 @Override
6952 public List<String> getEmergencyNumberListTestMode() {
6953 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6954 "getEmergencyNumberListTestMode");
6955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
6958 Set<String> emergencyNumbers = new HashSet<>();
6959 for (Phone phone: PhoneFactory.getPhones()) {
6960 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6961 if (tracker != null) {
6962 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6963 emergencyNumbers.add(num.getNumber());
6964 }
6965 }
6966 }
6967 return new ArrayList<>(emergencyNumbers);
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
chen xud6b45bd2018-10-30 22:27:10 -07006973 @Override
6974 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6975 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6976 Phone phone = getPhone(subId);
6977 if (phone == null) {
6978 return null;
6979 }
6980 final long identity = Binder.clearCallingIdentity();
6981 try {
6982 UiccProfile profile = UiccController.getInstance()
6983 .getUiccProfileForPhone(phone.getPhoneId());
6984 if (profile != null) {
6985 return profile.getCertsFromCarrierPrivilegeAccessRules();
6986 }
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
6989 }
6990 return null;
6991 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006992
6993 /**
6994 * Enable or disable a modem stack.
6995 */
6996 @Override
6997 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6998 enforceModifyPermission();
6999
7000 final long identity = Binder.clearCallingIdentity();
7001 try {
7002 Phone phone = PhoneFactory.getPhone(slotIndex);
7003 if (phone == null) {
7004 return false;
7005 } else {
7006 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7007 }
7008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
7011 }
Michelecea4cf22018-12-21 15:00:11 -08007012
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007013 /**
7014 * Whether a modem stack is enabled or not.
7015 */
7016 @Override
7017 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7018 Phone phone = PhoneFactory.getPhone(slotIndex);
7019 if (phone == null) return false;
7020
7021 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7022 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7023 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7024 }
7025
7026 final long identity = Binder.clearCallingIdentity();
7027 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007028 try {
7029 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7030 } catch (NoSuchElementException ex) {
7031 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7032 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
7036 }
7037
Michelecea4cf22018-12-21 15:00:11 -08007038 @Override
Michele0ea7d782019-03-19 14:58:42 -07007039 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007040 enforceModifyPermission();
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007045 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007046 .commit();
7047 } finally {
7048 Binder.restoreCallingIdentity(identity);
7049 }
7050 }
7051
7052 @Override
Michele0ea7d782019-03-19 14:58:42 -07007053 @TelephonyManager.IsMultiSimSupportedResult
7054 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007056 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7057 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007058 }
Michelecea4cf22018-12-21 15:00:11 -08007059
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
Michele0ea7d782019-03-19 14:58:42 -07007062 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007067
Michele0ea7d782019-03-19 14:58:42 -07007068 @TelephonyManager.IsMultiSimSupportedResult
7069 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007070 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7071 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7072 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007073 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7074 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007075 }
7076 // Check if the hardware supports multisim functionality. If usage of multisim is not
7077 // supported by the modem, indicate that it is restricted.
7078 PhoneCapability staticCapability =
7079 mPhoneConfigurationManager.getStaticPhoneCapability();
7080 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007081 loge("isMultiSimSupportedInternal: no static configuration available");
7082 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007083 }
7084 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007085 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7086 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007087 }
7088 // Check if support of multiple SIMs is restricted by carrier
7089 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007090 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007091 }
7092
Michele0ea7d782019-03-19 14:58:42 -07007093 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007094 }
7095
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007096 /**
7097 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007098 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7099 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7100 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007101 * @param numOfSims number of active sims we want to switch to
7102 */
7103 @Override
7104 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007105 if (numOfSims == 1) {
7106 enforceModifyPermission();
7107 } else {
7108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7109 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7110 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007111 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007112
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007113 try {
Michele30b57b22019-03-01 12:01:14 -08007114 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007115 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007116 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7117 return;
7118 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007119 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7120 } finally {
7121 Binder.restoreCallingIdentity(identity);
7122 }
7123 }
7124
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007125 @Override
7126 public boolean isApplicationOnUicc(int subId, int appType) {
7127 enforceReadPrivilegedPermission("isApplicationOnUicc");
7128 Phone phone = getPhone(subId);
7129 if (phone == null) {
7130 return false;
7131 }
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 UiccCard uiccCard = phone.getUiccCard();
7135 if (uiccCard == null) {
7136 return false;
7137 }
7138 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7139 if (uiccProfile == null) {
7140 return false;
7141 }
7142 if (TelephonyManager.APPTYPE_SIM <= appType
7143 && appType <= TelephonyManager.APPTYPE_ISIM) {
7144 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7145 }
7146 return false;
7147 } finally {
7148 Binder.restoreCallingIdentity(identity);
7149 }
7150 }
7151
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007152 /**
chen xub4baa772019-04-03 10:23:41 -07007153 * Get whether making changes to modem configurations will trigger reboot.
7154 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007155 */
7156 @Override
chen xub4baa772019-04-03 10:23:41 -07007157 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7159 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7160 return false;
7161 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007162 final long identity = Binder.clearCallingIdentity();
7163 try {
7164 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7165 } finally {
7166 Binder.restoreCallingIdentity(identity);
7167 }
7168 }
7169
Nathan Harold29f5f052019-02-15 13:41:57 -08007170 private void updateModemStateMetrics() {
7171 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7172 // TODO: check the state for each modem if the api is ready.
7173 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7174 }
7175
Pengquan Meng3889a572019-01-23 11:16:29 -08007176 @Override
7177 public int[] getSlotsMapping() {
7178 enforceReadPrivilegedPermission("getSlotsMapping");
7179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7183 // All logical slots should have a mapping to a physical slot.
7184 int[] logicalSlotsMapping = new int[phoneCount];
7185 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7186 for (int i = 0; i < slotInfos.length; i++) {
7187 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7188 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7189 }
7190 }
7191 return logicalSlotsMapping;
7192 } finally {
7193 Binder.restoreCallingIdentity(identity);
7194 }
7195 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007196
7197 /**
7198 * Get the IRadio HAL Version
7199 */
7200 @Override
7201 public int getRadioHalVersion() {
7202 Phone phone = getDefaultPhone();
7203 if (phone == null) return -1;
7204 HalVersion hv = phone.getHalVersion();
7205 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7206 return hv.major * 100 + hv.minor;
7207 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007208
7209 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007210 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7211 * corresponding network requests on a subId.
7212 *
7213 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007214 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007215 * 2) APN is un-metered for this subscription, or
7216 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7217 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7218 *
7219 * @return whether data is allowed for a apn type.
7220 *
7221 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007222 */
7223 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007224 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007226 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7227 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007228 }
7229
7230 // Now that all security checks passes, perform the operation as ourselves.
7231 final long identity = Binder.clearCallingIdentity();
7232 try {
7233 Phone phone = getPhone(subId);
7234 if (phone == null) return false;
7235
Jack Yu41407ee2019-05-13 16:54:09 -07007236 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007237 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7238 } finally {
7239 Binder.restoreCallingIdentity(identity);
7240 }
7241 }
7242
7243 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007244 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007245 enforceReadPrivilegedPermission("isApnMetered");
7246
7247 // Now that all security checks passes, perform the operation as ourselves.
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 Phone phone = getPhone(subId);
7251 if (phone == null) return true; // By default return true.
7252
Jack Yu41407ee2019-05-13 16:54:09 -07007253 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007258
7259 @Override
7260 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7261 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7262 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7263 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7264 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7265 }
7266 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7267 Intent intent = new Intent();
7268 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7269 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7270 // Bring up choose default SMS subscription dialog right now
7271 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7272 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7273 mApp.startActivity(intent);
7274 }
chen xud5ca2d52019-05-28 15:20:57 -07007275
7276 @Override
7277 public String getMmsUAProfUrl(int subId) {
7278 //TODO investigate if this API should require proper permission check in R b/133791609
7279 final long identity = Binder.clearCallingIdentity();
7280 try {
7281 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7282 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
7285 }
7286 }
7287
7288 @Override
7289 public String getMmsUserAgent(int subId) {
7290 //TODO investigate if this API should require proper permission check in R b/133791609
7291 final long identity = Binder.clearCallingIdentity();
7292 try {
7293 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7294 .getString(com.android.internal.R.string.config_mms_user_agent);
7295 } finally {
7296 Binder.restoreCallingIdentity(identity);
7297 }
7298 }
Jack Yub07d4972019-05-28 16:12:25 -07007299
7300 @Override
7301 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7302 enforceModifyPermission();
7303
7304 // Now that all security checks passes, perform the operation as ourselves.
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 Phone phone = getPhone(subId);
7308 if (phone == null) return false;
7309
7310 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7311 } finally {
7312 Binder.restoreCallingIdentity(identity);
7313 }
7314 }
7315
7316 @Override
7317 public boolean isDataAllowedInVoiceCall(int subId) {
7318 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7319
7320 // Now that all security checks passes, perform the operation as ourselves.
7321 final long identity = Binder.clearCallingIdentity();
7322 try {
7323 Phone phone = getPhone(subId);
7324 if (phone == null) return false;
7325
7326 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7327 } finally {
7328 Binder.restoreCallingIdentity(identity);
7329 }
7330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007331}