blob: 7a20d8b5b88b5ada2fde07f55907c7edfe064293 [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 Ebingerdac2f002018-04-03 15:17:52 -070052import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070053import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080058import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070059import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080060import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080061import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070062import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070063import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080064import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070065import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070066import android.telephony.CellInfoGsm;
67import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070068import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070069import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070070import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070071import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080072import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070073import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080074import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070075import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080076import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080077import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070078import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080079import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070080import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070081import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080082import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080083import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080084import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070085import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080088import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000089import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070090import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070091import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080093import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070094import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080095import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080097import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700100import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsMmTelFeature;
102import android.telephony.ims.aidl.IImsRcsFeature;
103import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800105import android.telephony.ims.feature.MmTelFeature;
106import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800107import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800109import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800111import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800112import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800113
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700115import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800116import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700117import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700118import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700119import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800120import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700121import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800124import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700125import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800126import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800128import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700129import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100130import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700131import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700132import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700134import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800135import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700136import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700137import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700138import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700139import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700140import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700142import com.android.internal.telephony.SmsApplication;
143import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700144import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700145import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800146import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800147import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700148import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800149import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700150import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800151import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800152import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700153import com.android.internal.telephony.uicc.IccIoResult;
154import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800155import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700156import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800157import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800159import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000160import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700161import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800162import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700164import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800165import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700166import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700167import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800168
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700169import java.io.FileDescriptor;
170import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700173import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800174import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800175import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800176import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100177import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700179import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182/**
183 * Implementation of the ITelephony interface.
184 */
Santos Cordon117fee72014-05-16 17:56:12 -0700185public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186 private static final String LOG_TAG = "PhoneInterfaceManager";
187 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
188 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700190
191 // Message codes used with mMainThreadHandler
192 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700193 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
194 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700195 private static final int CMD_OPEN_CHANNEL = 9;
196 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
197 private static final int CMD_CLOSE_CHANNEL = 11;
198 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800199 private static final int CMD_NV_READ_ITEM = 13;
200 private static final int EVENT_NV_READ_ITEM_DONE = 14;
201 private static final int CMD_NV_WRITE_ITEM = 15;
202 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
203 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
204 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700205 private static final int CMD_RESET_MODEM_CONFIG = 19;
206 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800207 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
208 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
209 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
210 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800211 private static final int CMD_SEND_ENVELOPE = 25;
212 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000213 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
214 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700215 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
216 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
217 private static final int CMD_EXCHANGE_SIM_IO = 31;
218 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800219 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
220 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700221 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
222 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700223 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
224 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700225 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
226 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
227 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
228 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700229 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
230 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
231 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
232 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700233 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800234 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
235 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000236 private static final int CMD_SWITCH_SLOTS = 50;
237 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700238 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
239 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
240 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
241 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
242 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
243 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
244 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
245 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700246 private static final int CMD_GET_ALL_CELL_INFO = 60;
247 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
248 private static final int CMD_GET_CELL_LOCATION = 62;
249 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700250 private static final int CMD_MODEM_REBOOT = 64;
251 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700252 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
253 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800254 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
255 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700256 private static final int CMD_GET_MODEM_STATUS = 70;
257 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800259 // Parameters of select command.
260 private static final int SELECT_COMMAND = 0xA4;
261 private static final int SELECT_P1 = 0x04;
262 private static final int SELECT_P2 = 0;
263 private static final int SELECT_P3 = 0x10;
264
Pengquan Meng85728fb2018-03-12 16:31:21 -0700265 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
266 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
267 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
268
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269 /** The singleton instance. */
270 private static PhoneInterfaceManager sInstance;
271
Wink Saville3ab207e2014-11-20 13:07:20 -0800272 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700274 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800275 private AppOpsManager mAppOps;
276 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800277 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700279 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700280
Derek Tan97ebb422014-09-05 16:55:38 -0700281 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
282 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800283 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800284 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700285
Michelecea4cf22018-12-21 15:00:11 -0800286 // String to store multi SIM allowed
287 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
288
Derek Tan740e1672017-06-27 14:56:27 -0700289 // The AID of ISD-R.
290 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
291
yinxub1bed742017-04-17 11:45:04 -0700292 private NetworkScanRequestTracker mNetworkScanRequestTracker;
293
David Kelly5e06a7f2018-03-12 14:10:59 +0000294 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
295 private static final int MANUFACTURER_CODE_LENGTH = 8;
296
Derek Tan89e89d42014-07-08 17:00:10 -0700297 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700298 * A request object to use for transmitting data to an ICC.
299 */
300 private static final class IccAPDUArgument {
301 public int channel, cla, command, p1, p2, p3;
302 public String data;
303
304 public IccAPDUArgument(int channel, int cla, int command,
305 int p1, int p2, int p3, String data) {
306 this.channel = channel;
307 this.cla = cla;
308 this.command = command;
309 this.p1 = p1;
310 this.p2 = p2;
311 this.p3 = p3;
312 this.data = data;
313 }
314 }
315
316 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700317 * A request object to use for transmitting data to an ICC.
318 */
319 private static final class ManualNetworkSelectionArgument {
320 public OperatorInfo operatorInfo;
321 public boolean persistSelection;
322
323 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
324 this.operatorInfo = operatorInfo;
325 this.persistSelection = persistSelection;
326 }
327 }
328
329 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
331 * request after sending. The main thread will notify the request when it is complete.
332 */
333 private static final class MainThreadRequest {
334 /** The argument to use for the request */
335 public Object argument;
336 /** The result of the request that is run on the main thread */
337 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800338 // The subscriber id that this request applies to. Defaults to
339 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
340 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 // In cases where subId is unavailable, the caller needs to specify the phone.
343 public Phone phone;
344
vagdeviaf9a5b92018-08-15 16:01:53 -0700345 public WorkSource workSource;
346
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700347 public MainThreadRequest(Object argument) {
348 this.argument = argument;
349 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800350
Nathan Harold92bed182018-10-12 18:16:49 -0700351 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
352 this.argument = argument;
353 if (phone != null) {
354 this.phone = phone;
355 }
356 this.workSource = workSource;
357 }
358
vagdeviaf9a5b92018-08-15 16:01:53 -0700359 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800360 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800361 if (subId != null) {
362 this.subId = subId;
363 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700364 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800365 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 }
367
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800368 private static final class IncomingThirdPartyCallArgs {
369 public final ComponentName component;
370 public final String callId;
371 public final String callerDisplayName;
372
373 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
374 String callerDisplayName) {
375 this.component = component;
376 this.callId = callId;
377 this.callerDisplayName = callerDisplayName;
378 }
379 }
380
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700381 /**
382 * A handler that processes messages on the main thread in the phone process. Since many
383 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
384 * inbound binder threads to the main thread in the phone process. The Binder thread
385 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
386 * on, which will be notified when the operation completes and will contain the result of the
387 * request.
388 *
389 * <p>If a MainThreadRequest object is provided in the msg.obj field,
390 * note that request.result must be set to something non-null for the calling thread to
391 * unblock.
392 */
393 private final class MainThreadHandler extends Handler {
394 @Override
395 public void handleMessage(Message msg) {
396 MainThreadRequest request;
397 Message onCompleted;
398 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800399 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700400 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800401 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402
403 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700404 case CMD_HANDLE_USSD_REQUEST: {
405 request = (MainThreadRequest) msg.obj;
406 final Phone phone = getPhoneFromRequest(request);
407 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
408 String ussdRequest = ussdObject.first;
409 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 if (!isUssdApiAllowed(request.subId)) {
412 // Carrier does not support use of this API, return failure.
413 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
414 UssdResponse response = new UssdResponse(ussdRequest, null);
415 Bundle returnData = new Bundle();
416 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
417 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700418
Pengquan Menga1bb6272018-09-06 09:59:22 -0700419 request.result = true;
420 notifyRequester(request);
421 return;
422 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700423
Pengquan Menga1bb6272018-09-06 09:59:22 -0700424 try {
425 request.result = phone != null
426 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
427 } catch (CallStateException cse) {
428 request.result = false;
429 }
430 // Wake up the requesting thread
431 notifyRequester(request);
432 break;
pkanwar32d516d2016-10-14 19:37:38 -0700433 }
434
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700437 final Phone phone = getPhoneFromRequest(request);
438 request.result = phone != null ?
439 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
440 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700448 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800449 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 if (uiccCard == null) {
451 loge("iccTransmitApduLogicalChannel: No UICC");
452 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700454 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
456 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 iccArgument.channel, iccArgument.cla, iccArgument.command,
459 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 break;
463
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700464 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 ar = (AsyncResult) msg.obj;
466 request = (MainThreadRequest) ar.userObj;
467 if (ar.exception == null && ar.result != null) {
468 request.result = ar.result;
469 } else {
470 request.result = new IccIoResult(0x6F, 0, (byte[])null);
471 if (ar.result == null) {
472 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800473 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800475 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 } else {
477 loge("iccTransmitApduLogicalChannel: Unknown exception");
478 }
479 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 break;
482
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
484 request = (MainThreadRequest) msg.obj;
485 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800486 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 if (uiccCard == null) {
488 loge("iccTransmitApduBasicChannel: No UICC");
489 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 } else {
492 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
493 request);
494 uiccCard.iccTransmitApduBasicChannel(
495 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
496 iccArgument.p3, iccArgument.data, onCompleted);
497 }
498 break;
499
500 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduBasicChannel: Empty response");
509 } else if (ar.exception instanceof CommandException) {
510 loge("iccTransmitApduBasicChannel: CommandException: " +
511 ar.exception);
512 } else {
513 loge("iccTransmitApduBasicChannel: Unknown exception");
514 }
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 break;
518
519 case CMD_EXCHANGE_SIM_IO:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccExchangeSimIO: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
529 request);
530 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
531 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
532 iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_EXCHANGE_SIM_IO_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6f, 0, (byte[])null);
543 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700545 break;
546
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 case CMD_SEND_ENVELOPE:
548 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800549 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700550 if (uiccCard == null) {
551 loge("sendEnvelopeWithStatus: No UICC");
552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700553 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700554 } else {
555 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
556 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
557 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800558 break;
559
560 case EVENT_SEND_ENVELOPE_DONE:
561 ar = (AsyncResult) msg.obj;
562 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700563 if (ar.exception == null && ar.result != null) {
564 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
567 if (ar.result == null) {
568 loge("sendEnvelopeWithStatus: Empty response");
569 } else if (ar.exception instanceof CommandException) {
570 loge("sendEnvelopeWithStatus: CommandException: " +
571 ar.exception);
572 } else {
573 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
574 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800575 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 break;
578
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 case CMD_OPEN_CHANNEL:
580 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800581 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800582 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 if (uiccCard == null) {
584 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800585 request.result = new IccOpenLogicalChannelResponse(-1,
586 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700588 } else {
589 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800590 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
591 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700592 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700593 break;
594
595 case EVENT_OPEN_CHANNEL_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700598 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700600 int[] result = (int[]) ar.result;
601 int channelId = result[0];
602 byte[] selectResponse = null;
603 if (result.length > 1) {
604 selectResponse = new byte[result.length - 1];
605 for (int i = 1; i < result.length; ++i) {
606 selectResponse[i - 1] = (byte) result[i];
607 }
608 }
609 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 if (ar.result == null) {
613 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 if (ar.exception != null) {
616 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
617 }
618
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700619 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700620 if (ar.exception instanceof CommandException) {
621 CommandException.Error error =
622 ((CommandException) (ar.exception)).getCommandError();
623 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700624 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700625 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 }
628 }
629 openChannelResp = new IccOpenLogicalChannelResponse(
630 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700631 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700632 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case CMD_CLOSE_CHANNEL:
637 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800638 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700639 if (uiccCard == null) {
640 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900641 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700642 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700643 } else {
644 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
645 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
646 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 break;
648
649 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800650 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
651 break;
652
653 case CMD_NV_READ_ITEM:
654 request = (MainThreadRequest) msg.obj;
655 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800656 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
657 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800658 break;
659
660 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 ar = (AsyncResult) msg.obj;
662 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800663 if (ar.exception == null && ar.result != null) {
664 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800666 request.result = "";
667 if (ar.result == null) {
668 loge("nvReadItem: Empty response");
669 } else if (ar.exception instanceof CommandException) {
670 loge("nvReadItem: CommandException: " +
671 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
675 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
Jake Hambye994d462014-02-03 13:10:13 -0800679 case CMD_NV_WRITE_ITEM:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
682 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700684 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800685 break;
686
687 case EVENT_NV_WRITE_ITEM_DONE:
688 handleNullReturnEvent(msg, "nvWriteItem");
689 break;
690
691 case CMD_NV_WRITE_CDMA_PRL:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800694 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
697 case EVENT_NV_WRITE_CDMA_PRL_DONE:
698 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
699 break;
700
chen xu6dac5ab2018-10-26 17:39:23 -0700701 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800702 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700703 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800704 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800705 break;
706
chen xu6dac5ab2018-10-26 17:39:23 -0700707 case EVENT_RESET_MODEM_CONFIG_DONE:
708 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800709 break;
710
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 case CMD_GET_PREFERRED_NETWORK_TYPE:
712 request = (MainThreadRequest) msg.obj;
713 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700714 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 break;
716
717 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
718 ar = (AsyncResult) msg.obj;
719 request = (MainThreadRequest) ar.userObj;
720 if (ar.exception == null && ar.result != null) {
721 request.result = ar.result; // Integer
722 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800723 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800724 if (ar.result == null) {
725 loge("getPreferredNetworkType: Empty response");
726 } else if (ar.exception instanceof CommandException) {
727 loge("getPreferredNetworkType: CommandException: " +
728 ar.exception);
729 } else {
730 loge("getPreferredNetworkType: Unknown exception");
731 }
732 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700733 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800734 break;
735
736 case CMD_SET_PREFERRED_NETWORK_TYPE:
737 request = (MainThreadRequest) msg.obj;
738 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
739 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700740 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
744 handleNullReturnEvent(msg, "setPreferredNetworkType");
745 break;
746
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
748 request = (MainThreadRequest)msg.obj;
749 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800750 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000751 break;
752
753 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
754 ar = (AsyncResult)msg.obj;
755 request = (MainThreadRequest)ar.userObj;
756 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700757 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800760 case CMD_SET_VOICEMAIL_NUMBER:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
763 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800764 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
765 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800766 break;
767
768 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
769 handleNullReturnEvent(msg, "setVoicemailNumber");
770 break;
771
Stuart Scott54788802015-03-30 13:18:01 -0700772 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
775 request);
776 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
777 break;
778
779 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
780 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
781 break;
782
Shishir Agrawal302c8692015-06-19 13:49:39 -0700783 case CMD_PERFORM_NETWORK_SCAN:
784 request = (MainThreadRequest) msg.obj;
785 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
786 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
787 break;
788
789 case EVENT_PERFORM_NETWORK_SCAN_DONE:
790 ar = (AsyncResult) msg.obj;
791 request = (MainThreadRequest) ar.userObj;
792 CellNetworkScanResult cellScanResult;
793 if (ar.exception == null && ar.result != null) {
794 cellScanResult = new CellNetworkScanResult(
795 CellNetworkScanResult.STATUS_SUCCESS,
796 (List<OperatorInfo>) ar.result);
797 } else {
798 if (ar.result == null) {
799 loge("getCellNetworkScanResults: Empty response");
800 }
801 if (ar.exception != null) {
802 loge("getCellNetworkScanResults: Exception: " + ar.exception);
803 }
804 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
805 if (ar.exception instanceof CommandException) {
806 CommandException.Error error =
807 ((CommandException) (ar.exception)).getCommandError();
808 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
809 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
810 } else if (error == CommandException.Error.GENERIC_FAILURE) {
811 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
812 }
813 }
814 cellScanResult = new CellNetworkScanResult(errorCode, null);
815 }
816 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700817 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700818 break;
819
820 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
821 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700822 ManualNetworkSelectionArgument selArg =
823 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
825 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700826 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
827 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
830 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700831 ar = (AsyncResult) msg.obj;
832 request = (MainThreadRequest) ar.userObj;
833 if (ar.exception == null) {
834 request.result = true;
835 } else {
836 request.result = false;
837 loge("setNetworkSelectionModeManual " + ar.exception);
838 }
839 notifyRequester(request);
840 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700841 break;
842
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700843 case CMD_GET_MODEM_ACTIVITY_INFO:
844 request = (MainThreadRequest) msg.obj;
845 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700846 if (defaultPhone != null) {
847 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
848 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700849 break;
850
851 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
852 ar = (AsyncResult) msg.obj;
853 request = (MainThreadRequest) ar.userObj;
854 if (ar.exception == null && ar.result != null) {
855 request.result = ar.result;
856 } else {
857 if (ar.result == null) {
858 loge("queryModemActivityInfo: Empty response");
859 } else if (ar.exception instanceof CommandException) {
860 loge("queryModemActivityInfo: CommandException: " +
861 ar.exception);
862 } else {
863 loge("queryModemActivityInfo: Unknown exception");
864 }
865 }
Amit Mahajand4766222016-01-28 15:28:28 -0800866 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
867 if (request.result == null) {
868 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
869 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700870 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700871 break;
872
Meng Wang1a7c35a2016-05-05 20:56:15 -0700873 case CMD_SET_ALLOWED_CARRIERS:
874 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800875 CarrierRestrictionRules argument =
876 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700877 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800878 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700879 break;
880
881 case EVENT_SET_ALLOWED_CARRIERS_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result;
886 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800887 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
888 if (ar.exception instanceof CommandException) {
889 loge("setAllowedCarriers: CommandException: " + ar.exception);
890 CommandException.Error error =
891 ((CommandException) (ar.exception)).getCommandError();
892 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
893 request.result =
894 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
895 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 } else {
897 loge("setAllowedCarriers: Unknown exception");
898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 break;
902
903 case CMD_GET_ALLOWED_CARRIERS:
904 request = (MainThreadRequest) msg.obj;
905 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800906 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700907 break;
908
909 case EVENT_GET_ALLOWED_CARRIERS_DONE:
910 ar = (AsyncResult) msg.obj;
911 request = (MainThreadRequest) ar.userObj;
912 if (ar.exception == null && ar.result != null) {
913 request.result = ar.result;
914 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800915 request.result = new IllegalStateException(
916 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700917 if (ar.result == null) {
918 loge("getAllowedCarriers: Empty response");
919 } else if (ar.exception instanceof CommandException) {
920 loge("getAllowedCarriers: CommandException: " +
921 ar.exception);
922 } else {
923 loge("getAllowedCarriers: Unknown exception");
924 }
925 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700926 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700927 break;
928
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
930 ar = (AsyncResult) msg.obj;
931 request = (MainThreadRequest) ar.userObj;
932 if (ar.exception == null && ar.result != null) {
933 request.result = ar.result;
934 } else {
935 request.result = new IllegalArgumentException(
936 "Failed to retrieve Forbidden Plmns");
937 if (ar.result == null) {
938 loge("getForbiddenPlmns: Empty response");
939 } else {
940 loge("getForbiddenPlmns: Unknown exception");
941 }
942 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700943 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800944 break;
945
946 case CMD_GET_FORBIDDEN_PLMNS:
947 request = (MainThreadRequest) msg.obj;
948 uiccCard = getUiccCardFromRequest(request);
949 if (uiccCard == null) {
950 loge("getForbiddenPlmns() UiccCard is null");
951 request.result = new IllegalArgumentException(
952 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700953 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800954 break;
955 }
956 Integer appType = (Integer) request.argument;
957 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
958 if (uiccApp == null) {
959 loge("getForbiddenPlmns() no app with specified type -- "
960 + appType);
961 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700962 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800963 break;
964 } else {
965 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
966 + " specified type -- " + appType);
967 }
968 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
969 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
970 onCompleted);
971 break;
972
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000973 case CMD_SWITCH_SLOTS:
974 request = (MainThreadRequest) msg.obj;
975 int[] physicalSlots = (int[]) request.argument;
976 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
977 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
978 break;
979
980 case EVENT_SWITCH_SLOTS_DONE:
981 ar = (AsyncResult) msg.obj;
982 request = (MainThreadRequest) ar.userObj;
983 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700984 notifyRequester(request);
985 break;
986 case CMD_GET_NETWORK_SELECTION_MODE:
987 request = (MainThreadRequest) msg.obj;
988 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
989 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
990 break;
991
992 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 if (ar.exception != null) {
996 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
997 } else {
998 int mode = ((int[]) ar.result)[0];
999 if (mode == 0) {
1000 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1001 } else {
1002 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1003 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001004 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001005 notifyRequester(request);
1006 break;
1007 case CMD_GET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1010 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1011 break;
1012 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 if (ar.exception != null) {
1016 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1017 } else {
1018 request.result = ((int[]) ar.result)[0];
1019 }
1020 notifyRequester(request);
1021 break;
1022 case CMD_SET_CDMA_ROAMING_MODE:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1025 int mode = (int) request.argument;
1026 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1027 break;
1028 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1029 ar = (AsyncResult) msg.obj;
1030 request = (MainThreadRequest) ar.userObj;
1031 request.result = ar.exception == null;
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1037 int subscriptionMode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001045 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 case CMD_GET_ALL_CELL_INFO:
1047 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001048 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001049 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001050 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 case EVENT_GET_ALL_CELL_INFO_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001054 // If a timeout occurs, the response will be null
1055 request.result = (ar.exception == null && ar.result != null)
1056 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 synchronized (request) {
1058 request.notifyAll();
1059 }
1060 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 case CMD_REQUEST_CELL_INFO_UPDATE:
1062 request = (MainThreadRequest) msg.obj;
1063 request.phone.requestCellInfoUpdate(request.workSource,
1064 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1065 break;
1066 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1067 ar = (AsyncResult) msg.obj;
1068 request = (MainThreadRequest) ar.userObj;
1069 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1070 try {
1071 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001072 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001073 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1074 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001075 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001077 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 } else {
1079 // use the result as returned
1080 cb.onCellInfo((List<CellInfo>) ar.result);
1081 }
1082 } catch (RemoteException re) {
1083 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1084 }
1085 break;
1086 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001087 request = (MainThreadRequest) msg.obj;
1088 WorkSource ws = (WorkSource) request.argument;
1089 Phone phone = getPhoneFromRequest(request);
1090 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1091 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null) {
1096 request.result = ar.result;
1097 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001098 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001099 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1100 ? new CdmaCellLocation() : new GsmCellLocation();
1101 }
1102
1103 synchronized (request) {
1104 request.notifyAll();
1105 }
1106 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001107 case CMD_MODEM_REBOOT:
1108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001110 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001111 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001112 case EVENT_CMD_MODEM_REBOOT_DONE:
1113 handleNullReturnEvent(msg, "rebootModem");
1114 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001115 case CMD_REQUEST_ENABLE_MODEM:
1116 request = (MainThreadRequest) msg.obj;
1117 boolean enable = (boolean) request.argument;
1118 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001119 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001120 PhoneConfigurationManager.getInstance()
1121 .enablePhone(request.phone, enable, onCompleted);
1122 break;
1123 case EVENT_ENABLE_MODEM_DONE:
1124 ar = (AsyncResult) msg.obj;
1125 request = (MainThreadRequest) ar.userObj;
1126 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001127 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001129 if ((boolean) request.result) {
1130 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1131 updateModemStateMetrics();
1132 } else {
1133 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1134 + ar.exception);
1135 }
1136 notifyRequester(request);
1137 break;
1138 case CMD_GET_MODEM_STATUS:
1139 request = (MainThreadRequest) msg.obj;
1140 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1141 PhoneConfigurationManager.getInstance()
1142 .getPhoneStatusFromModem(request.phone, onCompleted);
1143 break;
1144 case EVENT_GET_MODEM_STATUS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 int id = request.phone.getPhoneId();
1148 if (ar.exception == null && ar.result != null) {
1149 request.result = ar.result;
1150 //update the cache as modem status has changed
1151 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1152 (boolean) request.result);
1153 } else {
1154 // Return true if modem status cannot be retrieved. For most cases,
1155 // modem status is on. And for older version modems, GET_MODEM_STATUS
1156 // and disable modem are not supported. Modem is always on.
1157 // TODO: this should be fixed in R to support a third
1158 // status UNKNOWN b/131631629
1159 request.result = true;
1160 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1161 + ar.exception);
1162 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001163 notifyRequester(request);
1164 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001165 default:
1166 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1167 break;
1168 }
1169 }
Jake Hambye994d462014-02-03 13:10:13 -08001170
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 private void notifyRequester(MainThreadRequest request) {
1172 synchronized (request) {
1173 request.notifyAll();
1174 }
1175 }
1176
Jake Hambye994d462014-02-03 13:10:13 -08001177 private void handleNullReturnEvent(Message msg, String command) {
1178 AsyncResult ar = (AsyncResult) msg.obj;
1179 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1180 if (ar.exception == null) {
1181 request.result = true;
1182 } else {
1183 request.result = false;
1184 if (ar.exception instanceof CommandException) {
1185 loge(command + ": CommandException: " + ar.exception);
1186 } else {
1187 loge(command + ": Unknown exception");
1188 }
1189 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001190 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001191 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001200 return sendRequest(
1201 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001202 }
1203
1204 /**
1205 * Posts the specified command to be executed on the main thread,
1206 * waits for the request to complete, and returns the result.
1207 * @see #sendRequestAsync
1208 */
1209 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1210 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001211 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001212 }
1213
1214 /**
1215 * Posts the specified command to be executed on the main thread,
1216 * waits for the request to complete, and returns the result.
1217 * @see #sendRequestAsync
1218 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001219 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001220 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001221 }
1222
1223 /**
1224 * Posts the specified command to be executed on the main thread,
1225 * waits for the request to complete, and returns the result.
1226 * @see #sendRequestAsync
1227 */
Nathan Harold92bed182018-10-12 18:16:49 -07001228 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1229 return sendRequest(command, argument, subId, null, workSource);
1230 }
1231
1232 /**
1233 * Posts the specified command to be executed on the main thread,
1234 * waits for the request to complete, and returns the result.
1235 * @see #sendRequestAsync
1236 */
1237 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1238 return sendRequest(
1239 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1240 }
1241
1242 /**
1243 * Posts the specified command to be executed on the main thread,
1244 * waits for the request to complete, and returns the result.
1245 * @see #sendRequestAsync
1246 */
1247 private Object sendRequest(
1248 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001249 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1250 throw new RuntimeException("This method will deadlock if called from the main thread.");
1251 }
1252
Nathan Harold92bed182018-10-12 18:16:49 -07001253 MainThreadRequest request = null;
1254 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1255 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1256 } else if (phone != null) {
1257 request = new MainThreadRequest(argument, phone, workSource);
1258 } else {
1259 request = new MainThreadRequest(argument, subId, workSource);
1260 }
1261
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 Message msg = mMainThreadHandler.obtainMessage(command, request);
1263 msg.sendToTarget();
1264
1265 // Wait for the request to complete
1266 synchronized (request) {
1267 while (request.result == null) {
1268 try {
1269 request.wait();
1270 } catch (InterruptedException e) {
1271 // Do nothing, go back and wait until the request is complete
1272 }
1273 }
1274 }
1275 return request.result;
1276 }
1277
1278 /**
1279 * Asynchronous ("fire and forget") version of sendRequest():
1280 * Posts the specified command to be executed on the main thread, and
1281 * returns immediately.
1282 * @see #sendRequest
1283 */
1284 private void sendRequestAsync(int command) {
1285 mMainThreadHandler.sendEmptyMessage(command);
1286 }
1287
1288 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001289 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001291 */
1292 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 sendRequestAsync(command, argument, null, null);
1294 }
1295
1296 /**
1297 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1298 * @see {@link #sendRequest(int,Object)}
1299 */
1300 private void sendRequestAsync(
1301 int command, Object argument, Phone phone, WorkSource workSource) {
1302 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001303 Message msg = mMainThreadHandler.obtainMessage(command, request);
1304 msg.sendToTarget();
1305 }
1306
1307 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001308 * Initialize the singleton PhoneInterfaceManager instance.
1309 * This is only done once, at startup, from PhoneApp.onCreate().
1310 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001311 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312 synchronized (PhoneInterfaceManager.class) {
1313 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001314 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 } else {
1316 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1317 }
1318 return sInstance;
1319 }
1320 }
1321
1322 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001323 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001324 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001326 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1328 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001329 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 mTelephonySharedPreferences =
1331 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001332 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001333 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001334
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 publish();
1336 }
1337
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001338 private Phone getDefaultPhone() {
1339 Phone thePhone = getPhone(getDefaultSubscription());
1340 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1341 }
1342
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 private void publish() {
1344 if (DBG) log("publish: " + this);
1345
1346 ServiceManager.addService("phone", this);
1347 }
1348
Stuart Scott584921c2015-01-15 17:10:34 -08001349 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001350 if (request.phone != null) {
1351 return request.phone;
1352 } else {
1353 return getPhoneFromSubId(request.subId);
1354 }
1355 }
1356
1357 private Phone getPhoneFromSubId(int subId) {
1358 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1359 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001360 }
1361
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001362 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1363 Phone phone = getPhoneFromRequest(request);
1364 return phone == null ? null :
1365 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1366 }
1367
Wink Saville36469e72014-06-11 15:17:00 -07001368 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001369 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001370 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001371 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001372
1373 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001374 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001375 }
1376
Wink Savilleb564aae2014-10-23 10:18:09 -07001377 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 if (DBG) log("dial: " + number);
1379 // No permission check needed here: This is just a wrapper around the
1380 // ACTION_DIAL intent, which is available to any app since it puts up
1381 // the UI before it does anything.
1382
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001383 final long identity = Binder.clearCallingIdentity();
1384 try {
1385 String url = createTelUrl(number);
1386 if (url == null) {
1387 return;
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001390 // PENDING: should we just silently fail if phone is offhook or ringing?
1391 PhoneConstants.State state = mCM.getState(subId);
1392 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1393 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1394 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1395 mApp.startActivity(intent);
1396 }
1397 } finally {
1398 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001399 }
1400 }
1401
1402 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001407 if (DBG) log("call: " + number);
1408
1409 // This is just a wrapper around the ACTION_CALL intent, but we still
1410 // need to do a permission check since we're calling startActivity()
1411 // from the context of the phone app.
1412 enforceCallPermission();
1413
1414 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1415 != AppOpsManager.MODE_ALLOWED) {
1416 return;
1417 }
1418
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 String url = createTelUrl(number);
1422 if (url == null) {
1423 return;
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001426 boolean isValid = false;
1427 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1428 if (slist != null) {
1429 for (SubscriptionInfo subInfoRecord : slist) {
1430 if (subInfoRecord.getSubscriptionId() == subId) {
1431 isValid = true;
1432 break;
1433 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001434 }
Wink Saville08874612014-08-31 19:19:58 -07001435 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 if (!isValid) {
1437 return;
1438 }
Wink Saville08874612014-08-31 19:19:58 -07001439
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001440 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1441 intent.putExtra(SUBSCRIPTION_KEY, subId);
1442 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1443 mApp.startActivity(intent);
1444 } finally {
1445 Binder.restoreCallingIdentity(identity);
1446 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 }
1448
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001450 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001451 }
1452
Wink Savilleb564aae2014-10-23 10:18:09 -07001453 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001454 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001455 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1456 }
1457
1458 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001459 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001460 }
1461
Wink Savilleb564aae2014-10-23 10:18:09 -07001462 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001463 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001464 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1465 }
1466
1467 /** {@hide} */
1468 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001469 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001470 }
1471
Wink Savilleb564aae2014-10-23 10:18:09 -07001472 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001473 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001474
1475 final long identity = Binder.clearCallingIdentity();
1476 try {
1477 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1478 checkSimPin.start();
1479 return checkSimPin.unlockSim(null, pin);
1480 } finally {
1481 Binder.restoreCallingIdentity(identity);
1482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001483 }
1484
Wink Saville9de0f752013-10-22 19:04:03 -07001485 /** {@hide} */
1486 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001487 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001488 }
1489
Wink Savilleb564aae2014-10-23 10:18:09 -07001490 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001492
1493 final long identity = Binder.clearCallingIdentity();
1494 try {
1495 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1496 checkSimPuk.start();
1497 return checkSimPuk.unlockSim(puk, pin);
1498 } finally {
1499 Binder.restoreCallingIdentity(identity);
1500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001501 }
1502
1503 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001504 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001505 * a synchronous one.
1506 */
1507 private static class UnlockSim extends Thread {
1508
1509 private final IccCard mSimCard;
1510
1511 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001512 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1513 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 // For replies from SimCard interface
1516 private Handler mHandler;
1517
1518 // For async handler to identify request type
1519 private static final int SUPPLY_PIN_COMPLETE = 100;
1520
1521 public UnlockSim(IccCard simCard) {
1522 mSimCard = simCard;
1523 }
1524
1525 @Override
1526 public void run() {
1527 Looper.prepare();
1528 synchronized (UnlockSim.this) {
1529 mHandler = new Handler() {
1530 @Override
1531 public void handleMessage(Message msg) {
1532 AsyncResult ar = (AsyncResult) msg.obj;
1533 switch (msg.what) {
1534 case SUPPLY_PIN_COMPLETE:
1535 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1536 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001537 mRetryCount = msg.arg1;
1538 if (ar.exception != null) {
1539 if (ar.exception instanceof CommandException &&
1540 ((CommandException)(ar.exception)).getCommandError()
1541 == CommandException.Error.PASSWORD_INCORRECT) {
1542 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1543 } else {
1544 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1545 }
1546 } else {
1547 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001549 mDone = true;
1550 UnlockSim.this.notifyAll();
1551 }
1552 break;
1553 }
1554 }
1555 };
1556 UnlockSim.this.notifyAll();
1557 }
1558 Looper.loop();
1559 }
1560
1561 /*
1562 * Use PIN or PUK to unlock SIM card
1563 *
1564 * If PUK is null, unlock SIM card with PIN
1565 *
1566 * If PUK is not null, unlock SIM card with PUK and set PIN code
1567 */
Wink Saville9de0f752013-10-22 19:04:03 -07001568 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569
1570 while (mHandler == null) {
1571 try {
1572 wait();
1573 } catch (InterruptedException e) {
1574 Thread.currentThread().interrupt();
1575 }
1576 }
1577 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1578
1579 if (puk == null) {
1580 mSimCard.supplyPin(pin, callback);
1581 } else {
1582 mSimCard.supplyPuk(puk, pin, callback);
1583 }
1584
1585 while (!mDone) {
1586 try {
1587 Log.d(LOG_TAG, "wait for done");
1588 wait();
1589 } catch (InterruptedException e) {
1590 // Restore the interrupted status
1591 Thread.currentThread().interrupt();
1592 }
1593 }
1594 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001595 int[] resultArray = new int[2];
1596 resultArray[0] = mResult;
1597 resultArray[1] = mRetryCount;
1598 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600 }
1601
1602 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001603 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001604
1605 }
1606
Wink Savilleb564aae2014-10-23 10:18:09 -07001607 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001608 // No permission check needed here: this call is harmless, and it's
1609 // needed for the ServiceState.requestStateUpdate() call (which is
1610 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001611 final long identity = Binder.clearCallingIdentity();
1612 try {
1613 final Phone phone = getPhone(subId);
1614 if (phone != null) {
1615 phone.updateServiceLocation();
1616 }
1617 } finally {
1618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001619 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001620 }
1621
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001622 @Override
1623 public boolean isRadioOn(String callingPackage) {
1624 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001625 }
1626
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001627 @Override
1628 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001629 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001630 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001631 return false;
1632 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001633
1634 final long identity = Binder.clearCallingIdentity();
1635 try {
1636 return isRadioOnForSubscriber(subId);
1637 } finally {
1638 Binder.restoreCallingIdentity(identity);
1639 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001640 }
1641
1642 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 final Phone phone = getPhone(subId);
1646 if (phone != null) {
1647 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1648 } else {
1649 return false;
1650 }
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001653 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 }
1655
1656 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001657 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 }
Wink Saville36469e72014-06-11 15:17:00 -07001659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 final Phone phone = getPhone(subId);
1666 if (phone != null) {
1667 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001671 }
Wink Saville36469e72014-06-11 15:17:00 -07001672 }
1673
1674 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001675 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001676 }
1677
Wink Savilleb564aae2014-10-23 10:18:09 -07001678 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone phone = getPhone(subId);
1684 if (phone == null) {
1685 return false;
1686 }
1687 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1688 toggleRadioOnOffForSubscriber(subId);
1689 }
1690 return true;
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 }
Wink Saville36469e72014-06-11 15:17:00 -07001695
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001696 public boolean needMobileRadioShutdown() {
1697 /*
1698 * If any of the Radios are available, it will need to be
1699 * shutdown. So return true if any Radio is available.
1700 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1704 Phone phone = PhoneFactory.getPhone(i);
1705 if (phone != null && phone.isRadioAvailable()) return true;
1706 }
1707 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1708 return false;
1709 } finally {
1710 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001711 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
1713
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001714 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001715 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001716 enforceModifyPermission();
1717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1721 logv("Shutting down Phone " + i);
1722 shutdownRadioUsingPhoneId(i);
1723 }
1724 } finally {
1725 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001726 }
1727 }
1728
1729 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001730 Phone phone = PhoneFactory.getPhone(phoneId);
1731 if (phone != null && phone.isRadioAvailable()) {
1732 phone.shutdownRadio();
1733 }
1734 }
1735
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001736 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001737 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738
1739 final long identity = Binder.clearCallingIdentity();
1740 try {
1741 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1742 if (defaultPhone != null) {
1743 defaultPhone.setRadioPower(turnOn);
1744 return true;
1745 } else {
1746 loge("There's no default phone.");
1747 return false;
1748 }
1749 } finally {
1750 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001751 }
Wink Saville36469e72014-06-11 15:17:00 -07001752 }
1753
Wink Savilleb564aae2014-10-23 10:18:09 -07001754 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001755 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001756
1757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
1761 phone.setRadioPower(turnOn);
1762 return true;
1763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
Wink Saville36469e72014-06-11 15:17:00 -07001771 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001772 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001773 public boolean enableDataConnectivity() {
1774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 int subId = mSubscriptionController.getDefaultDataSubId();
1779 final Phone phone = getPhone(subId);
1780 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001781 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 return true;
1783 } else {
1784 return false;
1785 }
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
1790
Wink Saville36469e72014-06-11 15:17:00 -07001791 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001792 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 public boolean disableDataConnectivity() {
1794 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795
1796 final long identity = Binder.clearCallingIdentity();
1797 try {
1798 int subId = mSubscriptionController.getDefaultDataSubId();
1799 final Phone phone = getPhone(subId);
1800 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001801 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 return true;
1803 } else {
1804 return false;
1805 }
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001812 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001813 final long identity = Binder.clearCallingIdentity();
1814 try {
1815 final Phone phone = getPhone(subId);
1816 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001817 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001818 } else {
1819 return false;
1820 }
1821 } finally {
1822 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001823 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001824 }
1825
1826 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001827 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001828 }
1829
pkanwarae03a6b2016-11-06 20:37:09 -08001830 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 enforceCallPermission();
1832
1833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1836 return;
1837 }
1838 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1839 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
1842 }
pkanwar32d516d2016-10-14 19:37:38 -07001843 };
1844
Wink Savilleb564aae2014-10-23 10:18:09 -07001845 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847
1848 final long identity = Binder.clearCallingIdentity();
1849 try {
1850 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1851 return false;
1852 }
1853 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1854 } finally {
1855 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001856 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857 }
1858
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001859 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001860 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001861 }
1862
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001863 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001864 final long identity = Binder.clearCallingIdentity();
1865 try {
1866 Phone phone = PhoneFactory.getPhone(slotIndex);
1867 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1868 PhoneConstantConversions.convertCallState(phone.getState());
1869 } finally {
1870 Binder.restoreCallingIdentity(identity);
1871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001872 }
1873
Sanket Padawe356d7632015-06-22 14:03:32 -07001874 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001875 public int getDataState() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001876 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1877 }
1878
1879 @Override
1880 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001881 final long identity = Binder.clearCallingIdentity();
1882 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001883 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 if (phone != null) {
1885 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1886 } else {
1887 return PhoneConstantConversions.convertDataState(
1888 PhoneConstants.DataState.DISCONNECTED);
1889 }
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 }
1894
Sanket Padawe356d7632015-06-22 14:03:32 -07001895 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 public int getDataActivity() {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001897 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1898 }
1899
1900 @Override
1901 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001902 final long identity = Binder.clearCallingIdentity();
1903 try {
Nathan Haroldcbce7262019-06-14 16:58:30 -07001904 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001905 if (phone != null) {
1906 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1907 } else {
1908 return TelephonyManager.DATA_ACTIVITY_NONE;
1909 }
1910 } finally {
1911 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001912 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913 }
1914
1915 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001916 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001917 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001918 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001919
1920 LocationAccessPolicy.LocationPermissionResult locationResult =
1921 LocationAccessPolicy.checkLocationPermission(mApp,
1922 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1923 .setCallingPackage(callingPackage)
1924 .setCallingPid(Binder.getCallingPid())
1925 .setCallingUid(Binder.getCallingUid())
1926 .setMethod("getCellLocation")
1927 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1928 .build());
1929 switch (locationResult) {
1930 case DENIED_HARD:
1931 throw new SecurityException("Not allowed to access cell location");
1932 case DENIED_SOFT:
1933 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001936 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 final long identity = Binder.clearCallingIdentity();
1938 try {
1939 if (DBG_LOC) log("getCellLocation: is active user");
1940 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001941 int subId = mSubscriptionController.getDefaultDataSubId();
1942 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1943 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001944 return data;
1945 } finally {
1946 Binder.restoreCallingIdentity(identity);
1947 }
Svetoslav64fad262015-04-14 14:35:21 -07001948 }
1949
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001950 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001951 public String getNetworkCountryIsoForPhone(int phoneId) {
1952 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1953 // registered cell info, so return a NULL country instead.
1954 final long identity = Binder.clearCallingIdentity();
1955 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001956 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1957 // Get default phone in this case.
1958 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1959 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001960 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001961 // Todo: fix this when we can get the actual cellular network info when the device
1962 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001963 if (TelephonyManager.NETWORK_TYPE_IWLAN
1964 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1965 return "";
1966 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001967 Phone phone = PhoneFactory.getPhone(phoneId);
1968 if (phone != null) {
1969 ServiceStateTracker sst = phone.getServiceStateTracker();
1970 if (sst != null) {
1971 LocaleTracker lt = sst.getLocaleTracker();
1972 if (lt != null) {
1973 return lt.getCurrentCountry();
1974 }
1975 }
1976 }
1977 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001978 } finally {
1979 Binder.restoreCallingIdentity(identity);
1980 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001981 }
1982
1983 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001985 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001986 }
1987
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001989 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990 mApp.enforceCallingOrSelfPermission(
1991 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992
1993 final long identity = Binder.clearCallingIdentity();
1994 try {
1995 final Phone phone = getPhone(subId);
1996 if (phone != null) {
1997 phone.enableLocationUpdates();
1998 }
1999 } finally {
2000 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002001 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
2004 @Override
2005 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002006 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002007 }
2008
Sanket Padawe356d7632015-06-22 14:03:32 -07002009 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002010 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 mApp.enforceCallingOrSelfPermission(
2012 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002013
2014 final long identity = Binder.clearCallingIdentity();
2015 try {
2016 final Phone phone = getPhone(subId);
2017 if (phone != null) {
2018 phone.disableLocationUpdates();
2019 }
2020 } finally {
2021 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023 }
2024
Nathan Harold31d7ff32018-10-15 20:20:30 -07002025 /**
2026 * Returns the target SDK version number for a given package name.
2027 *
2028 * @return target SDK if the package is found or INT_MAX.
2029 */
2030 private int getTargetSdk(String packageName) {
2031 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002032 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
2033 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07002034 if (ai != null) return ai.targetSdkVersion;
2035 } catch (PackageManager.NameNotFoundException unexpected) {
2036 }
2037 return Integer.MAX_VALUE;
2038 }
2039
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 @Override
2041 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002042 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2043 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002044 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2045 throw new SecurityException(
2046 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2047 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002048
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
2050 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2051 return null;
2052 }
Svetoslav64fad262015-04-14 14:35:21 -07002053
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002054 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055
Nathan Haroldf180aac2018-06-01 18:43:55 -07002056 List<CellInfo> info = getAllCellInfo(callingPackage);
2057 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058
Nathan Haroldf180aac2018-06-01 18:43:55 -07002059 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2060 for (CellInfo ci : info) {
2061 if (ci instanceof CellInfoGsm) {
2062 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2063 } else if (ci instanceof CellInfoWcdma) {
2064 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2065 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002067 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 }
2069
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 private List<CellInfo> getCachedCellInfo() {
2071 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2072 for (Phone phone : PhoneFactory.getPhones()) {
2073 List<CellInfo> info = phone.getAllCellInfo();
2074 if (info != null) cellInfos.addAll(info);
2075 }
2076 return cellInfos;
2077 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078
2079 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002080 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002081 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002082 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002083
2084 LocationAccessPolicy.LocationPermissionResult locationResult =
2085 LocationAccessPolicy.checkLocationPermission(mApp,
2086 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2087 .setCallingPackage(callingPackage)
2088 .setCallingPid(Binder.getCallingPid())
2089 .setCallingUid(Binder.getCallingUid())
2090 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002091 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002092 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2093 .build());
2094 switch (locationResult) {
2095 case DENIED_HARD:
2096 throw new SecurityException("Not allowed to access cell info");
2097 case DENIED_SOFT:
2098 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002099 }
2100
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002101 final int targetSdk = getTargetSdk(callingPackage);
2102 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2103 return getCachedCellInfo();
2104 }
2105
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002106 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002107 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 final long identity = Binder.clearCallingIdentity();
2109 try {
2110 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2111 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002112 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002113 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002114 if (info != null) cellInfos.addAll(info);
2115 }
2116 return cellInfos;
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 }
2120 }
2121
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002122 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002123 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2124 requestCellInfoUpdateInternal(
2125 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2126 }
2127
2128 @Override
2129 public void requestCellInfoUpdateWithWorkSource(
2130 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2131 enforceModifyPermission();
2132 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2133 }
2134
2135 private void requestCellInfoUpdateInternal(
2136 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002137 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002138 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002139
2140 LocationAccessPolicy.LocationPermissionResult locationResult =
2141 LocationAccessPolicy.checkLocationPermission(mApp,
2142 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2143 .setCallingPackage(callingPackage)
2144 .setCallingPid(Binder.getCallingPid())
2145 .setCallingUid(Binder.getCallingUid())
2146 .setMethod("requestCellInfoUpdate")
2147 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2148 .build());
2149 switch (locationResult) {
2150 case DENIED_HARD:
2151 throw new SecurityException("Not allowed to access cell info");
2152 case DENIED_SOFT:
Nathan Haroldb3c5da42019-05-09 10:26:08 -07002153 try {
2154 cb.onCellInfo(new ArrayList<CellInfo>());
2155 } catch (RemoteException re) {
2156 // Drop without consequences
2157 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002158 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002159 }
2160
Nathan Harold32e84c42019-05-09 10:13:47 -07002161
2162 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002163 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2164
2165 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2166 }
2167
2168 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002170 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002171 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002172
2173 final long identity = Binder.clearCallingIdentity();
2174 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002175 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 } finally {
2177 Binder.restoreCallingIdentity(identity);
2178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002179 }
2180
Shishir Agrawala9f32182016-04-12 12:00:16 -07002181 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002182 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002183 Phone phone = PhoneFactory.getPhone(slotIndex);
2184 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002185 return null;
2186 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002187 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002188 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2189 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002190 return null;
2191 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 return phone.getImei();
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002199 }
2200
2201 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002202 public String getTypeAllocationCodeForSlot(int slotIndex) {
2203 Phone phone = PhoneFactory.getPhone(slotIndex);
2204 String tac = null;
2205 if (phone != null) {
2206 String imei = phone.getImei();
2207 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2208 }
2209 return tac;
2210 }
2211
2212 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002213 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002214 Phone phone = PhoneFactory.getPhone(slotIndex);
2215 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002216 return null;
2217 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002218
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002220 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2221 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002222 return null;
2223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224
2225 final long identity = Binder.clearCallingIdentity();
2226 try {
2227 return phone.getMeid();
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
Jack Yu2af8d712017-03-15 17:14:14 -07002231 }
2232
2233 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002234 public String getManufacturerCodeForSlot(int slotIndex) {
2235 Phone phone = PhoneFactory.getPhone(slotIndex);
2236 String manufacturerCode = null;
2237 if (phone != null) {
2238 String meid = phone.getMeid();
2239 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2240 }
2241 return manufacturerCode;
2242 }
2243
2244 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002245 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002246 Phone phone = PhoneFactory.getPhone(slotIndex);
2247 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002248 return null;
2249 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002250 int subId = phone.getSubId();
2251 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2252 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2253 return null;
2254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002255
2256 final long identity = Binder.clearCallingIdentity();
2257 try {
2258 return phone.getDeviceSvn();
2259 } finally {
2260 Binder.restoreCallingIdentity(identity);
2261 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002262 }
2263
fionaxu43304da2017-11-27 22:51:16 -08002264 @Override
2265 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002266 final long identity = Binder.clearCallingIdentity();
2267 try {
2268 final Phone phone = getPhone(subId);
2269 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
fionaxu43304da2017-11-27 22:51:16 -08002273 }
2274
2275 @Override
2276 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
2279 final Phone phone = getPhone(subId);
2280 return phone == null ? null : phone.getCarrierName();
2281 } finally {
2282 Binder.restoreCallingIdentity(identity);
2283 }
fionaxu43304da2017-11-27 22:51:16 -08002284 }
2285
calvinpanffe225e2018-11-01 19:43:06 +08002286 @Override
chen xu0026ca62019-03-06 15:28:50 -08002287 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002288 final long identity = Binder.clearCallingIdentity();
2289 try {
2290 final Phone phone = getPhone(subId);
2291 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002292 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002293 } finally {
2294 Binder.restoreCallingIdentity(identity);
2295 }
2296 }
2297
2298 @Override
chen xu0026ca62019-03-06 15:28:50 -08002299 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002303 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002304 } finally {
2305 Binder.restoreCallingIdentity(identity);
2306 }
2307 }
2308
chen xu651eec72018-11-11 19:03:44 -08002309 @Override
chen xu864e11c2018-12-06 22:10:03 -08002310 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2311 if (!isSubscriptionMccMnc) {
2312 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2313 }
chen xu651eec72018-11-11 19:03:44 -08002314 final Phone phone = PhoneFactory.getPhone(slotIndex);
2315 if (phone == null) {
2316 return TelephonyManager.UNKNOWN_CARRIER_ID;
2317 }
2318 final long identity = Binder.clearCallingIdentity();
2319 try {
2320 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2321 } finally {
2322 Binder.restoreCallingIdentity(identity);
2323 }
2324 }
2325
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002326 //
2327 // Internal helper methods.
2328 //
2329
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002330 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2332 *
2333 * @throws SecurityException if the caller does not have the required permission
2334 */
2335 private void enforceModifyPermission() {
2336 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2337 }
2338
2339 /**
2340 * Make sure the caller has the CALL_PHONE permission.
2341 *
2342 * @throws SecurityException if the caller does not have the required permission
2343 */
2344 private void enforceCallPermission() {
2345 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2346 }
2347
Stuart Scott8eef64f2015-04-08 15:13:54 -07002348 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002349 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002350 "ConnectivityService");
2351 }
2352
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 private String createTelUrl(String number) {
2354 if (TextUtils.isEmpty(number)) {
2355 return null;
2356 }
2357
Jake Hambye994d462014-02-03 13:10:13 -08002358 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002359 }
2360
Ihab Awadf9e92732013-12-05 18:02:52 -08002361 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2363 }
2364
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002365 private static void logv(String msg) {
2366 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2367 }
2368
Ihab Awadf9e92732013-12-05 18:02:52 -08002369 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002370 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2371 }
2372
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002375 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002376 }
2377
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002379 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002380 final long identity = Binder.clearCallingIdentity();
2381 try {
2382 final Phone phone = PhoneFactory.getPhone(slotIndex);
2383 if (phone == null) {
2384 return PhoneConstants.PHONE_TYPE_NONE;
2385 } else {
2386 return phone.getPhoneType();
2387 }
2388 } finally {
2389 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 }
2392
2393 /**
2394 * Returns the CDMA ERI icon index to display
2395 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002396 @Override
2397 public int getCdmaEriIconIndex(String callingPackage) {
2398 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002399 }
2400
Sanket Padawe356d7632015-06-22 14:03:32 -07002401 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002404 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 return -1;
2406 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002407
2408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 if (phone != null) {
2412 return phone.getCdmaEriIconIndex();
2413 } else {
2414 return -1;
2415 }
2416 } finally {
2417 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002418 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419 }
2420
2421 /**
2422 * Returns the CDMA ERI icon mode,
2423 * 0 - ON
2424 * 1 - FLASHING
2425 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002426 @Override
2427 public int getCdmaEriIconMode(String callingPackage) {
2428 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002429 }
2430
Sanket Padawe356d7632015-06-22 14:03:32 -07002431 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002432 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002434 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002435 return -1;
2436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 final Phone phone = getPhone(subId);
2441 if (phone != null) {
2442 return phone.getCdmaEriIconMode();
2443 } else {
2444 return -1;
2445 }
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
2450
2451 /**
2452 * Returns the CDMA ERI text,
2453 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002454 @Override
2455 public String getCdmaEriText(String callingPackage) {
2456 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002457 }
2458
Sanket Padawe356d7632015-06-22 14:03:32 -07002459 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002460 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002461 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002462 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002463 return null;
2464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002465
2466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 final Phone phone = getPhone(subId);
2469 if (phone != null) {
2470 return phone.getCdmaEriText();
2471 } else {
2472 return null;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
2479 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002480 * Returns the CDMA MDN.
2481 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002482 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002483 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2485 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486
2487 final long identity = Binder.clearCallingIdentity();
2488 try {
2489 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002490 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 return phone.getLine1Number();
2492 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002493 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002494 return null;
2495 }
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002498 }
2499 }
2500
2501 /**
2502 * Returns the CDMA MIN.
2503 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002505 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002506 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2507 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2513 return phone.getCdmaMin();
2514 } else {
2515 return null;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002519 }
2520 }
2521
Hall Liud892bec2018-11-30 14:51:45 -08002522 @Override
2523 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2524 INumberVerificationCallback callback, String callingPackage) {
2525 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2526 != PERMISSION_GRANTED) {
2527 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2528 }
2529 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2530
2531 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2532 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2533 throw new SecurityException("Calling package must be configured in the device config");
2534 }
2535
2536 if (range == null) {
2537 throw new NullPointerException("Range must be non-null");
2538 }
2539
2540 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002541 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002542
2543 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2544 }
2545
Junda Liuca05d5d2014-08-14 22:36:34 -07002546 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 * Returns true if CDMA provisioning needs to run.
2548 */
2549 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550 final long identity = Binder.clearCallingIdentity();
2551 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002552 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002553 } finally {
2554 Binder.restoreCallingIdentity(identity);
2555 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 }
2557
2558 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002559 * Sets the voice mail number of a given subId.
2560 */
2561 @Override
2562 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002563 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564
2565 final long identity = Binder.clearCallingIdentity();
2566 try {
2567 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2568 new Pair<String, String>(alphaTag, number), new Integer(subId));
2569 return success;
2570 } finally {
2571 Binder.restoreCallingIdentity(identity);
2572 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002573 }
2574
Ta-wei Yen87c49842016-05-13 21:19:52 -07002575 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002576 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2577 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002578 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002579 if (!TextUtils.equals(callingPackage, systemDialer)) {
2580 throw new SecurityException("caller must be system dialer");
2581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002582
2583 final long identity = Binder.clearCallingIdentity();
2584 try {
2585 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2586 if (phoneAccountHandle == null) {
2587 return null;
2588 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002589 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002590 } finally {
2591 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002592 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002593 }
2594
2595 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002596 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002598 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002599 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002600 return null;
2601 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002603 final long identity = Binder.clearCallingIdentity();
2604 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002605 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002606 } finally {
2607 Binder.restoreCallingIdentity(identity);
2608 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002609 }
2610
2611 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002612 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2613 VisualVoicemailSmsFilterSettings settings) {
2614 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615
2616 final long identity = Binder.clearCallingIdentity();
2617 try {
2618 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002619 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 } finally {
2621 Binder.restoreCallingIdentity(identity);
2622 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002623 }
2624
2625 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002626 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2627 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002632 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633 } finally {
2634 Binder.restoreCallingIdentity(identity);
2635 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002636 }
2637
2638 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002639 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2640 String callingPackage, int subId) {
2641 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642
2643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002646 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002650 }
2651
2652 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002653 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002654 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655
2656 final long identity = Binder.clearCallingIdentity();
2657 try {
2658 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002659 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } finally {
2661 Binder.restoreCallingIdentity(identity);
2662 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002663 }
2664
2665 @Override
2666 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2667 String number, int port, String text, PendingIntent sentIntent) {
2668 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002669 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002670 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002671 SmsController smsController = PhoneFactory.getSmsController();
2672 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2673 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002674 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002675
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002676 /**
fionaxu0152e512016-11-14 13:36:14 -08002677 * Sets the voice activation state of a given subId.
2678 */
2679 @Override
2680 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2682 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
2684 final long identity = Binder.clearCallingIdentity();
2685 try {
2686 final Phone phone = getPhone(subId);
2687 if (phone != null) {
2688 phone.setVoiceActivationState(activationState);
2689 } else {
2690 loge("setVoiceActivationState fails with invalid subId: " + subId);
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002694 }
2695 }
2696
2697 /**
2698 * Sets the data activation state of a given subId.
2699 */
2700 @Override
2701 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2703 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002704
2705 final long identity = Binder.clearCallingIdentity();
2706 try {
2707 final Phone phone = getPhone(subId);
2708 if (phone != null) {
2709 phone.setDataActivationState(activationState);
2710 } else {
2711 loge("setVoiceActivationState fails with invalid subId: " + subId);
2712 }
2713 } finally {
2714 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002715 }
2716 }
2717
2718 /**
2719 * Returns the voice activation state of a given subId.
2720 */
2721 @Override
2722 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002723 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724
fionaxu0152e512016-11-14 13:36:14 -08002725 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 if (phone != null) {
2729 return phone.getVoiceActivationState();
2730 } else {
2731 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2732 }
2733 } finally {
2734 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002735 }
2736 }
2737
2738 /**
2739 * Returns the data activation state of a given subId.
2740 */
2741 @Override
2742 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002743 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002744
fionaxu0152e512016-11-14 13:36:14 -08002745 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002746 final long identity = Binder.clearCallingIdentity();
2747 try {
2748 if (phone != null) {
2749 return phone.getDataActivationState();
2750 } else {
2751 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2752 }
2753 } finally {
2754 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002755 }
2756 }
2757
2758 /**
Wink Saville36469e72014-06-11 15:17:00 -07002759 * Returns the unread count of voicemails for a subId
2760 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002761 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002762 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2763 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2764 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2765 return 0;
2766 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 return phone.getVoiceMessageCount();
2772 } else {
2773 return 0;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002781 * returns true, if the device is in a state where both voice and data
2782 * are supported simultaneously. This can change based on location or network condition.
2783 */
2784 @Override
2785 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = getPhone(subId);
2789 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
2792 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002793 }
2794
2795 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002796 * Send the dialer code if called from the current default dialer or the caller has
2797 * carrier privilege.
2798 * @param inputCode The dialer code to send
2799 */
2800 @Override
2801 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002802 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002803 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002804 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2805 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002806 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002807 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2808 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002809 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002810
2811 final long identity = Binder.clearCallingIdentity();
2812 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002813 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814 } finally {
2815 Binder.restoreCallingIdentity(identity);
2816 }
fionaxu235cc5e2017-03-06 22:25:57 -08002817 }
2818
Pengquan Menga1bb6272018-09-06 09:59:22 -07002819 @Override
2820 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002821 if (!isActiveSubscription(subId)) {
2822 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2823 }
2824
Pengquan Menga1bb6272018-09-06 09:59:22 -07002825 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2826 }
2827
Brad Ebinger35c841c2018-10-01 10:40:55 -07002828 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002829 public boolean isInEmergencySmsMode() {
2830 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2831 final long identity = Binder.clearCallingIdentity();
2832 try {
2833 for (Phone phone : PhoneFactory.getPhones()) {
2834 if (phone.isInEmergencySmsMode()) {
2835 return true;
2836 }
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
2840 }
2841 return false;
2842 }
2843
2844 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002845 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2846 throws RemoteException {
2847 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002848 final long token = Binder.clearCallingIdentity();
2849 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002850 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002851 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002852 .addRegistrationCallbackForSubscription(c, subId);
2853 } finally {
2854 Binder.restoreCallingIdentity(token);
2855 }
2856 }
2857
2858 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002859 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2860 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002861 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2862 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2863 }
2864 Binder.withCleanCallingIdentity(() -> {
2865 try {
2866 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002867 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868 .removeRegistrationCallbackForSubscription(c, subId);
2869 } catch (IllegalArgumentException e) {
2870 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2871 + "is inactive, ignoring unregister.");
2872 // If the subscription is no longer active, just return, since the callback
2873 // will already have been removed internally.
2874 }
2875 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002876 }
2877
2878 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002879 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2880 throws RemoteException {
2881 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2883 final long token = Binder.clearCallingIdentity();
2884 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002886 .addCapabilitiesCallbackForSubscription(c, subId);
2887 } finally {
2888 Binder.restoreCallingIdentity(token);
2889 }
2890 }
2891
2892 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002893 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2894 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002895
2896 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2897 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2898 }
2899 Binder.withCleanCallingIdentity(() -> {
2900 try {
2901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002902 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002903 .removeCapabilitiesCallbackForSubscription(c, subId);
2904 } catch (IllegalArgumentException e) {
2905 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2906 + "is inactive, ignoring unregister.");
2907 // If the subscription is no longer active, just return, since the callback
2908 // will already have been removed internally.
2909 }
2910 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002911 }
2912
2913 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002914 public boolean isCapable(int subId, int capability, int regTech) {
2915 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2917 final long token = Binder.clearCallingIdentity();
2918 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002919 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2921 } catch (ImsException e) {
2922 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2923 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002924 } catch (IllegalArgumentException e) {
2925 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2926 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002927 } finally {
2928 Binder.restoreCallingIdentity(token);
2929 }
2930 }
2931
2932 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002933 public boolean isAvailable(int subId, int capability, int regTech) {
2934 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002935 final long token = Binder.clearCallingIdentity();
2936 try {
2937 Phone phone = getPhone(subId);
2938 if (phone == null) return false;
2939 return phone.isImsCapabilityAvailable(capability, regTech);
2940 } finally {
2941 Binder.restoreCallingIdentity(token);
2942 }
2943 }
2944
2945 @Override
2946 public boolean isAdvancedCallingSettingEnabled(int subId) {
2947 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2949 final long token = Binder.clearCallingIdentity();
2950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2953 } finally {
2954 Binder.restoreCallingIdentity(token);
2955 }
2956 }
2957
2958 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002959 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002961 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002973 public boolean isVtSettingEnabled(int subId) {
2974 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002978 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002979 getSlotIndexOrException(subId)).isVtEnabledByUser();
2980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002986 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002988 "setVtSettingEnabled");
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, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
2995 }
2996 }
2997
2998 @Override
2999 public boolean isVoWiFiSettingEnabled(int subId) {
3000 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003005 getSlotIndexOrException(subId)).isWfcEnabledByUser();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003012 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003014 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3026 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3027 final long identity = Binder.clearCallingIdentity();
3028 try {
3029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003030 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
3035 }
3036
3037 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003038 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003040 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 @Override
3052 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3054 "setVoWiFiNonPersistent");
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003059 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
3066 public int getVoWiFiModeSetting(int subId) {
3067 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
3079 public void setVoWiFiModeSetting(int subId, int mode) {
3080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3081 "setVoWiFiModeSetting");
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
3092 @Override
3093 public int getVoWiFiRoamingModeSetting(int subId) {
3094 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
3106 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3108 "setVoWiFiRoamingModeSetting");
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003112 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
3119 @Override
3120 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3122 "setRttCapabilityEnabled");
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003126 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
3131 }
3132
3133 @Override
3134 public boolean isTtyOverVolteEnabled(int subId) {
3135 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
3143 }
3144 }
3145
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003146 @Override
3147 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3148 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
3151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003152 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003153 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003154 } finally {
3155 Binder.restoreCallingIdentity(identity);
3156 }
3157 }
3158
3159 @Override
3160 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3161 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3162 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003163 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3164 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3165 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003166 try {
3167 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003168 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003169 .removeProvisioningCallbackForSubscription(callback, subId);
3170 } catch (IllegalArgumentException e) {
3171 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3172 + "is inactive, ignoring unregister.");
3173 // If the subscription is no longer active, just return, since the callback will already
3174 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
3178 }
3179
3180 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003181 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3182 boolean isProvisioned) {
3183 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3184 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3185 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3186 }
3187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3188 "setProvisioningStatusForCapability");
3189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3192 Phone phone = getPhone(subId);
3193 if (phone == null) {
3194 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3195 + subId);
3196 return;
3197 }
3198 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3199 return;
3200 }
3201
3202 // this capability requires provisioning, route to the correct API.
3203 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3204 switch (capability) {
3205 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3206 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3207 ims.setVolteProvisioned(isProvisioned);
3208 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3209 ims.setWfcProvisioned(isProvisioned);
3210 }
3211 break;
3212 }
3213 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3214 // There is currently no difference in VT provisioning type.
3215 ims.setVtProvisioned(isProvisioned);
3216 break;
3217 }
3218 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3219 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3220 // change the capability of the feature instead if needed.
3221 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3222 == isProvisioned) {
3223 // No change in provisioning.
3224 return;
3225 }
3226 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3227 try {
3228 ims.changeMmTelCapability(capability, tech, isProvisioned);
3229 } catch (ImsException e) {
3230 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3231 + ", Exception" + e.getMessage());
3232 }
3233 break;
3234 }
3235 default: {
3236 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3237 + capability + "', which does not require provisioning.");
3238 }
3239 }
3240
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 }
3245
3246 @Override
3247 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3248 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3249 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3250 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3251 }
3252 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3253 final long identity = Binder.clearCallingIdentity();
3254 try {
3255 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3256 Phone phone = getPhone(subId);
3257 if (phone == null) {
3258 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3259 + subId);
3260 // We will fail with "true" as the provisioning status because this is the default
3261 // if we do not require provisioning.
3262 return true;
3263 }
3264
3265 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3266 return true;
3267 }
3268
3269 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3270 switch (capability) {
3271 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3272 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3273 return ims.isVolteProvisionedOnDevice();
3274 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3275 return ims.isWfcProvisionedOnDevice();
3276 }
3277 // This should never happen, since we are checking tech above to make sure it
3278 // is either LTE or IWLAN.
3279 throw new IllegalArgumentException("Invalid radio technology for voice "
3280 + "capability.");
3281 }
3282 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3283 // There is currently no difference in VT provisioning type.
3284 return ims.isVtProvisionedOnDevice();
3285 }
3286 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3287 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3288 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3289 }
3290 default: {
3291 throw new IllegalArgumentException("Tried to get 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 isMmTelCapabilityProvisionedInCache(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("isMmTelCapabilityProvisionedInCache");
3308 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3309 return (provisionedBits & capability) > 0;
3310 }
3311
3312 @Override
3313 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3314 boolean isProvisioned) {
3315 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3316 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3317 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3318 }
3319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3320 "setProvisioningStatusForCapability");
3321 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3322 // If the current provisioning status for capability already matches isProvisioned,
3323 // do nothing.
3324 if (((provisionedBits & capability) > 0) == isProvisioned) {
3325 return;
3326 }
3327 if (isProvisioned) {
3328 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3329 } else {
3330 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3331 }
3332 }
3333
3334 /**
3335 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3336 * technology. The bitfield should mirror the bitfield defined by
3337 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3338 */
3339 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3340 String key = getMmTelProvisioningKey(subId, tech);
3341 // Default is no capabilities are provisioned.
3342 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3343 }
3344
3345 /**
3346 * Sets the MmTel capability provisioning bitfield (defined by
3347 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3348 * technology specified.
3349 *
3350 * Note: This is a synchronous command and should not be called on UI thread.
3351 */
3352 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3353 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3354 String key = getMmTelProvisioningKey(subId, tech);
3355 editor.putInt(key, newField);
3356 editor.commit();
3357 }
3358
3359 private static String getMmTelProvisioningKey(int subId, int tech) {
3360 // resulting key is provision_ims_mmtel_{subId}_{tech}
3361 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3362 }
3363
3364 /**
3365 * Query CarrierConfig to see if the specified capability requires provisioning for the
3366 * carrier associated with the subscription id.
3367 */
3368 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3369 int capability) {
3370 CarrierConfigManager configManager = new CarrierConfigManager(context);
3371 PersistableBundle c = configManager.getConfigForSubId(subId);
3372 boolean requireUtProvisioning = c.getBoolean(
3373 // By default, this config is true (even if there is no SIM). We also check to make
3374 // sure the subscription needs provisioning here, so we do not need to check for
3375 // the no-SIM case, where we would normally shortcut this to false.
3376 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3377 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3378 false);
3379 boolean requireVoiceVtProvisioning = c.getBoolean(
3380 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3381
3382 // First check to make sure that the capability requires provisioning.
3383 switch (capability) {
3384 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3385 // intentional fallthrough
3386 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3387 if (requireVoiceVtProvisioning) {
3388 // Voice and Video requires provisioning
3389 return true;
3390 }
3391 break;
3392 }
3393 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3394 if (requireUtProvisioning) {
3395 // UT requires provisioning
3396 return true;
3397 }
3398 break;
3399 }
3400 }
3401 return false;
3402 }
3403
3404 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003405 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3407 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3408 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 enforceReadPrivilegedPermission("getImsProvisioningInt");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 int slotId = getSlotIndex(subId);
3414 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3415 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3416 + subId + "' for key:" + key);
3417 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3418 }
3419 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3422 + subId + "' for key:" + key);
3423 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3433 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 enforceReadPrivilegedPermission("getImsProvisioningString");
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003438 int slotId = getSlotIndex(subId);
3439 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3440 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3441 + subId + "' for key:" + key);
3442 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3443 }
3444 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003446 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3447 + subId + "' for key:" + key);
3448 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
3452 }
3453
3454 @Override
3455 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3457 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3458 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3460 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003464 int slotId = getSlotIndex(subId);
3465 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3466 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3467 + subId + "' for key:" + key);
3468 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3469 }
3470 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003471 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003472 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3473 + "' for key:" + key);
3474 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003475 } finally {
3476 Binder.restoreCallingIdentity(identity);
3477 }
3478 }
3479
3480 @Override
3481 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3483 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3484 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3486 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003487 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, "setImsProvisioningString: called with an inactive subscription id '"
3493 + subId + "' for key:" + key);
3494 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3495 }
3496 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003498 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3499 + "' for key:" + key);
3500 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003501 } finally {
3502 Binder.restoreCallingIdentity(identity);
3503 }
3504 }
3505
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3507 int slotId = SubscriptionManager.getSlotIndex(subId);
3508 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003509 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 }
3511 return slotId;
3512 }
3513
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003514 private int getSlotIndex(int subId) {
3515 int slotId = SubscriptionManager.getSlotIndex(subId);
3516 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3517 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3518 }
3519 return slotId;
3520 }
3521
Wink Saville36469e72014-06-11 15:17:00 -07003522 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003523 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003524 */
3525 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003526 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Harold9042f0b2019-05-21 15:51:27 -07003527 if (getTargetSdk(callingPackage) >= android.os.Build.VERSION_CODES.Q
3528 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3529 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3531 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = getPhone(subId);
3536 if (phone != null) {
3537 return phone.getServiceState().getDataNetworkType();
3538 } else {
3539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3540 }
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
3545
3546 /**
3547 * Returns the data network type
3548 */
3549 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003550 public int getDataNetworkType(String callingPackage) {
3551 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
3554 /**
3555 * Returns the data network type for a subId
3556 */
3557 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003558 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003559 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003560 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003561 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3562 }
3563
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003564 final long identity = Binder.clearCallingIdentity();
3565 try {
3566 final Phone phone = getPhone(subId);
3567 if (phone != null) {
3568 return phone.getServiceState().getDataNetworkType();
3569 } else {
3570 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3571 }
3572 } finally {
3573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003575 }
3576
3577 /**
Wink Saville36469e72014-06-11 15:17:00 -07003578 * Returns the Voice network type for a subId
3579 */
3580 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003581 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003583 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003584 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3585 }
3586
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003587 final long identity = Binder.clearCallingIdentity();
3588 try {
3589 final Phone phone = getPhone(subId);
3590 if (phone != null) {
3591 return phone.getServiceState().getVoiceNetworkType();
3592 } else {
3593 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3594 }
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003598 }
3599
3600 /**
3601 * @return true if a ICC card is present
3602 */
3603 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003604 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003605 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3606 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003607 }
3608
3609 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003610 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003611 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003613 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 final Phone phone = PhoneFactory.getPhone(slotIndex);
3617 if (phone != null) {
3618 return phone.getIccCard().hasIccCard();
3619 } else {
3620 return false;
3621 }
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 }
3626
3627 /**
3628 * Return if the current radio is LTE on CDMA. This
3629 * is a tri-state return value as for a period of time
3630 * the mode may be unknown.
3631 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003632 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003633 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003634 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003635 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003636 @Override
3637 public int getLteOnCdmaMode(String callingPackage) {
3638 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003639 }
3640
Sanket Padawe356d7632015-06-22 14:03:32 -07003641 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003642 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003643 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003644 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003645 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3646 }
3647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 final long identity = Binder.clearCallingIdentity();
3649 try {
3650 final Phone phone = getPhone(subId);
3651 if (phone == null) {
3652 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3653 } else {
3654 return phone.getLteOnCdmaMode();
3655 }
3656 } finally {
3657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003658 }
Wink Saville36469e72014-06-11 15:17:00 -07003659 }
3660
Wink Saville36469e72014-06-11 15:17:00 -07003661 /**
3662 * {@hide}
3663 * Returns Default subId, 0 in the case of single standby.
3664 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003665 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003666 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003667 }
3668
Shishir Agrawala9f32182016-04-12 12:00:16 -07003669 private int getSlotForDefaultSubscription() {
3670 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3671 }
3672
Wink Savilleb564aae2014-10-23 10:18:09 -07003673 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003674 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003675 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003676
Pengquan Menge92a50d2018-09-21 15:54:48 -07003677 private boolean isActiveSubscription(int subId) {
3678 return mSubscriptionController.isActiveSubId(subId);
3679 }
3680
Ihab Awadf2177b72013-11-25 13:33:23 -08003681 /**
3682 * @see android.telephony.TelephonyManager.WifiCallingChoices
3683 */
3684 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003685 final long identity = Binder.clearCallingIdentity();
3686 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3689 getWhenToMakeWifiCallsDefaultPreference());
3690 } finally {
3691 Binder.restoreCallingIdentity(identity);
3692 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003693 }
3694
3695 /**
3696 * @see android.telephony.TelephonyManager.WifiCallingChoices
3697 */
3698 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003699 final long identity = Binder.clearCallingIdentity();
3700 try {
3701 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003702 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003703 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
3706 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003707 }
3708
Sailesh Nepald1e68152013-12-12 19:08:02 -08003709 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003710 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003711 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003712 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003713
Jordan Liu4c733742019-02-28 12:03:40 -08003714 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3715 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3716 if (phoneId == -1) {
3717 throw new IllegalArgumentException("Given slot index: " + slotIndex
3718 + " does not correspond to an active phone");
3719 }
3720 return PhoneFactory.getPhone(phoneId);
3721 }
3722
Shishir Agrawal566b7612013-10-28 14:41:00 -07003723 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003724 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3725 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003726 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3727 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003729 if (DBG) {
3730 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3731 }
3732 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3733 p2);
3734 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003735
Jordan Liu4c733742019-02-28 12:03:40 -08003736
3737 @Override
3738 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3739 int slotIndex, String callingPackage, String aid, int p2) {
3740 enforceModifyPermission();
3741 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3742 if (DBG) {
3743 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3744 }
3745 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3746 callingPackage, aid, p2);
3747 }
3748
3749 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3750 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 if (TextUtils.equals(ISDR_AID, aid)) {
3754 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003755 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3756 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003757 if (bestComponent == null
3758 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3759 loge("The calling package is not allowed to access ISD-R.");
3760 throw new SecurityException(
3761 "The calling package is not allowed to access ISD-R.");
3762 }
Derek Tan740e1672017-06-27 14:56:27 -07003763 }
Derek Tan740e1672017-06-27 14:56:27 -07003764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003765 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003766 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3767 null /* workSource */);
3768 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003769 return response;
3770 } finally {
3771 Binder.restoreCallingIdentity(identity);
3772 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003773 }
3774
3775 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003776 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003777 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3778 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003779 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3780 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3781 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782
Jordan Liu4c733742019-02-28 12:03:40 -08003783 @Override
3784 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3785 enforceModifyPermission();
3786 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3787 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3788 channel);
3789 }
3790
3791 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 if (channel < 0) {
3795 return false;
3796 }
Jordan Liu4c733742019-02-28 12:03:40 -08003797 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3798 null /* workSource */);
3799 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003800 return success;
3801 } finally {
3802 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003803 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003804 }
3805
3806 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003807 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003808 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3810 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003811 if (DBG) {
3812 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3813 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3814 + p3 + " data=" + data);
3815 }
3816 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3817 command, p1, p2, p3, data);
3818 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003819
Jordan Liu4c733742019-02-28 12:03:40 -08003820 @Override
3821 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3822 int command, int p1, int p2, int p3, String data) {
3823 enforceModifyPermission();
3824 if (DBG) {
3825 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3826 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3827 + p3 + " data=" + data);
3828 }
3829 return iccTransmitApduLogicalChannelWithPermission(
3830 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3831 data);
3832 }
3833
3834 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3835 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 final long identity = Binder.clearCallingIdentity();
3837 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003838 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003839 return "";
3840 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003842 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003843 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3844 null /* workSource */);
3845 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003846
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003847 // Append the returned status code to the end of the response payload.
3848 String s = Integer.toHexString(
3849 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3850 if (response.payload != null) {
3851 s = IccUtils.bytesToHexString(response.payload) + s;
3852 }
3853 return s;
3854 } finally {
3855 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003856 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003857 }
Jake Hambye994d462014-02-03 13:10:13 -08003858
Evan Charltonc66da362014-05-16 14:06:40 -07003859 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003860 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3861 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003862 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3863 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003865 if (DBG) {
3866 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3867 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3868 }
3869 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3870 cla, command, p1, p2, p3, data);
3871 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003872
Jordan Liu4c733742019-02-28 12:03:40 -08003873 @Override
3874 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3875 int command, int p1, int p2, int p3, String data) {
3876 enforceModifyPermission();
3877 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3878 if (DBG) {
3879 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3880 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3881 + " data=" + data);
3882 }
3883
3884 return iccTransmitApduBasicChannelWithPermission(
3885 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3886 p2, p3, data);
3887 }
3888
3889 // open APDU basic channel assuming the caller has sufficient permissions
3890 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3891 int cla, 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 {
3894 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3895 && TextUtils.equals(ISDR_AID, data)) {
3896 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003897 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3898 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003899 if (bestComponent == null
3900 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3901 loge("The calling package is not allowed to select ISD-R.");
3902 throw new SecurityException(
3903 "The calling package is not allowed to select ISD-R.");
3904 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003905 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003906
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003907 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003908 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3909 null /* workSource */);
3910 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003911
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003912 // Append the returned status code to the end of the response payload.
3913 String s = Integer.toHexString(
3914 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3915 if (response.payload != null) {
3916 s = IccUtils.bytesToHexString(response.payload) + s;
3917 }
3918 return s;
3919 } finally {
3920 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003921 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003922 }
3923
3924 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003925 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003926 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3928 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003929
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 if (DBG) {
3933 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3934 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3935 }
3936
3937 IccIoResult response =
3938 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3939 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3940 subId);
3941
3942 if (DBG) {
3943 log("Exchange SIM_IO [R]" + response);
3944 }
3945
3946 byte[] result = null;
3947 int length = 2;
3948 if (response.payload != null) {
3949 length = 2 + response.payload.length;
3950 result = new byte[length];
3951 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3952 } else {
3953 result = new byte[length];
3954 }
3955
3956 result[length - 1] = (byte) response.sw2;
3957 result[length - 2] = (byte) response.sw1;
3958 return result;
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003961 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003962 }
3963
Nathan Haroldb3014052017-01-25 15:57:32 -08003964 /**
3965 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3966 * on a particular subscription
3967 */
sqianb6e41952018-03-12 14:54:01 -07003968 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3970 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3971 return null;
3972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003973
3974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 if (appType != TelephonyManager.APPTYPE_USIM
3977 && appType != TelephonyManager.APPTYPE_SIM) {
3978 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3979 return null;
3980 }
3981 Object response = sendRequest(
3982 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3983 if (response instanceof String[]) {
3984 return (String[]) response;
3985 }
3986 // Response is an Exception of some kind,
3987 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003988 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003989 } finally {
3990 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003991 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003992 }
3993
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003994 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003995 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003996 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3997 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003998
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4002 if (response.payload == null) {
4003 return "";
4004 }
Evan Charltonc66da362014-05-16 14:06:40 -07004005
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004006 // Append the returned status code to the end of the response payload.
4007 String s = Integer.toHexString(
4008 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4009 s = IccUtils.bytesToHexString(response.payload) + s;
4010 return s;
4011 } finally {
4012 Binder.restoreCallingIdentity(identity);
4013 }
Evan Charltonc66da362014-05-16 14:06:40 -07004014 }
4015
Jake Hambye994d462014-02-03 13:10:13 -08004016 /**
4017 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4018 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4019 *
4020 * @param itemID the ID of the item to read
4021 * @return the NV item as a String, or null on error.
4022 */
4023 @Override
4024 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004025 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4027 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004032 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004033 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4034 return value;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Jake Hambye994d462014-02-03 13:10:13 -08004038 }
4039
4040 /**
4041 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4042 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4043 *
4044 * @param itemID the ID of the item to read
4045 * @param itemValue the value to write, as a String
4046 * @return true on success; false on any failure
4047 */
4048 @Override
4049 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004050 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4052 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004053
4054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4057 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004058 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4060 return success;
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Jake Hambye994d462014-02-03 13:10:13 -08004064 }
4065
4066 /**
4067 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4068 * Used for device configuration by some CDMA operators.
4069 *
4070 * @param preferredRoamingList byte array containing the new PRL
4071 * @return true on success; false on any failure
4072 */
4073 @Override
4074 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004077
4078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4081 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4082 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4083 return success;
4084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
Jake Hambye994d462014-02-03 13:10:13 -08004087 }
4088
4089 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004090 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004091 * Used for device configuration by some CDMA operators.
4092 *
chen xu6dac5ab2018-10-26 17:39:23 -07004093 * @param slotIndex - device slot.
4094 *
Jake Hambye994d462014-02-03 13:10:13 -08004095 * @return true on success; false on any failure
4096 */
4097 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004098 public boolean resetModemConfig(int slotIndex) {
4099 Phone phone = PhoneFactory.getPhone(slotIndex);
4100 if (phone != null) {
4101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004103
chen xu6dac5ab2018-10-26 17:39:23 -07004104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4107 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004112 }
chen xu6dac5ab2018-10-26 17:39:23 -07004113 return false;
4114 }
4115
4116 /**
4117 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4118 *
4119 * @param slotIndex - device slot.
4120 *
4121 * @return true on success; false on any failure
4122 */
4123 @Override
4124 public boolean rebootModem(int slotIndex) {
4125 Phone phone = PhoneFactory.getPhone(slotIndex);
4126 if (phone != null) {
4127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4128 mApp, phone.getSubId(), "rebootModem");
4129
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4133 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4134 return success;
4135 } finally {
4136 Binder.restoreCallingIdentity(identity);
4137 }
4138 }
4139 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004140 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004141
Svet Ganovb320e182015-04-16 12:30:10 -07004142 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004143 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004145 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004146 return new String[0];
4147 }
4148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004149 final long identity = Binder.clearCallingIdentity();
4150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004151 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Wink Saville36469e72014-06-11 15:17:00 -07004155 }
4156
Brad Ebinger51f743a2017-01-23 13:50:20 -08004157 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004158 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4159 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004160 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004161 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004162 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163
4164 final long identity = Binder.clearCallingIdentity();
4165 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004166 ImsResolver resolver = PhoneFactory.getImsResolver();
4167 if (resolver == null) {
4168 // may happen if the device does not support IMS.
4169 return;
4170 }
4171 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004175 }
4176
4177 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004178 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4179 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004180 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004181 public void disableIms(int slotId) {
4182 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004186 ImsResolver resolver = PhoneFactory.getImsResolver();
4187 if (resolver == null) {
4188 // may happen if the device does not support IMS.
4189 return;
4190 }
4191 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004195 }
4196
4197 /**
4198 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4199 * feature or {@link null} if the service is not available. If the feature is available, the
4200 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4201 */
4202 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004203 IImsServiceFeatureCallback callback) {
4204 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004205
4206 final long identity = Binder.clearCallingIdentity();
4207 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004208 ImsResolver resolver = PhoneFactory.getImsResolver();
4209 if (resolver == null) {
4210 // may happen if the device does not support IMS.
4211 return null;
4212 }
4213 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004217 }
4218
4219 /**
4220 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4221 * feature during emergency calling or {@link null} if the service is not available. If the
4222 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4223 * listener for feature updates.
4224 */
4225 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4226 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004227
4228 final long identity = Binder.clearCallingIdentity();
4229 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004230 ImsResolver resolver = PhoneFactory.getImsResolver();
4231 if (resolver == null) {
4232 // may happen if the device does not support IMS.
4233 return null;
4234 }
4235 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004236 } finally {
4237 Binder.restoreCallingIdentity(identity);
4238 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004239 }
4240
Brad Ebinger5f64b052017-12-14 14:26:15 -08004241 /**
4242 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004243 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004244 */
4245 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4246 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247
4248 final long identity = Binder.clearCallingIdentity();
4249 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004250 ImsResolver resolver = PhoneFactory.getImsResolver();
4251 if (resolver == null) {
4252 // may happen if the device does not support IMS.
4253 return null;
4254 }
4255 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004259 }
4260
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004261 /**
4262 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004263 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004264 */
4265 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267
4268 final long identity = Binder.clearCallingIdentity();
4269 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004270 ImsResolver resolver = PhoneFactory.getImsResolver();
4271 if (resolver == null) {
4272 // may happen if the device does not support IMS.
4273 return null;
4274 }
4275 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004279 }
4280
Brad Ebinger884c07b2018-02-15 16:17:40 -08004281 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004282 * Sets the ImsService Package Name that Telephony will bind to.
4283 *
4284 * @param slotId the slot ID that the ImsService should bind for.
4285 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4286 * ImsService is the device default ImsService.
4287 * @param packageName The package name of the application that contains the ImsService to bind
4288 * to.
4289 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4290 * @hide
4291 */
4292 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004293 int[] subIds = SubscriptionManager.getSubId(slotId);
4294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4295 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4296 "setImsService");
4297
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004298 final long identity = Binder.clearCallingIdentity();
4299 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004300 ImsResolver resolver = PhoneFactory.getImsResolver();
4301 if (resolver == null) {
4302 // may happen if the device does not support IMS.
4303 return false;
4304 }
4305 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4306 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 } finally {
4308 Binder.restoreCallingIdentity(identity);
4309 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004310 }
4311
4312 /**
4313 * Return the ImsService configuration.
4314 *
4315 * @param slotId The slot that the ImsService is associated with.
4316 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4317 * the device default.
4318 * @return the package name of the ImsService configuration.
4319 */
4320 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004321 int[] subIds = SubscriptionManager.getSubId(slotId);
4322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4323 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4324 "getImsService");
4325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004326 final long identity = Binder.clearCallingIdentity();
4327 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004328 ImsResolver resolver = PhoneFactory.getImsResolver();
4329 if (resolver == null) {
4330 // may happen if the device does not support IMS.
4331 return "";
4332 }
4333 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004337 }
4338
Wink Saville36469e72014-06-11 15:17:00 -07004339 public void setImsRegistrationState(boolean registered) {
4340 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341
4342 final long identity = Binder.clearCallingIdentity();
4343 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004344 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 } finally {
4346 Binder.restoreCallingIdentity(identity);
4347 }
Wink Saville36469e72014-06-11 15:17:00 -07004348 }
4349
4350 /**
Stuart Scott54788802015-03-30 13:18:01 -07004351 * Set the network selection mode to automatic.
4352 *
4353 */
4354 @Override
4355 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004356 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4357 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004358
Pengquan Menge92a50d2018-09-21 15:54:48 -07004359 if (!isActiveSubscription(subId)) {
4360 return;
4361 }
4362
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004363 final long identity = Binder.clearCallingIdentity();
4364 try {
4365 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4366 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
4369 }
Stuart Scott54788802015-03-30 13:18:01 -07004370 }
4371
Pengquan Mengea84e042018-09-20 14:57:26 -07004372 /**
4373 * Ask the radio to connect to the input network and change selection mode to manual.
4374 *
4375 * @param subId the id of the subscription.
4376 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4377 * the operator to attach to.
4378 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4379 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4380 * normal network selection next time.
4381 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004382 */
4383 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004384 public boolean setNetworkSelectionModeManual(
4385 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4387 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004388
4389 if (!isActiveSubscription(subId)) {
4390 return false;
4391 }
4392
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004393 final long identity = Binder.clearCallingIdentity();
4394 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004395 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004397 if (DBG) {
4398 log("setNetworkSelectionModeManual: subId: " + subId
4399 + " operator: " + operatorInfo);
4400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004405 }
4406
4407 /**
4408 * Scans for available networks.
4409 */
4410 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004411 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4413 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004414 LocationAccessPolicy.LocationPermissionResult locationResult =
4415 LocationAccessPolicy.checkLocationPermission(mApp,
4416 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4417 .setCallingPackage(callingPackage)
4418 .setCallingPid(Binder.getCallingPid())
4419 .setCallingUid(Binder.getCallingUid())
4420 .setMethod("getCellNetworkScanResults")
4421 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4422 .build());
4423 switch (locationResult) {
4424 case DENIED_HARD:
4425 throw new SecurityException("Not allowed to access scan results -- location");
4426 case DENIED_SOFT:
4427 return null;
4428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004429
Pengquan Menga1bb6272018-09-06 09:59:22 -07004430 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 try {
4432 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004433 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004438 }
4439
4440 /**
yinxub1bed742017-04-17 11:45:04 -07004441 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004442 *
yinxub1bed742017-04-17 11:45:04 -07004443 * @param subId id of the subscription
4444 * @param request contains the radio access networks with bands/channels to scan
4445 * @param messenger callback messenger for scan results or errors
4446 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004447 * @return the id of the requested scan which can be used to stop the scan.
4448 */
4449 @Override
4450 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004451 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4453 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004454 LocationAccessPolicy.LocationPermissionResult locationResult =
4455 LocationAccessPolicy.checkLocationPermission(mApp,
4456 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4457 .setCallingPackage(callingPackage)
4458 .setCallingPid(Binder.getCallingPid())
4459 .setCallingUid(Binder.getCallingUid())
4460 .setMethod("requestNetworkScan")
4461 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4462 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004463 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004464 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004465 if (e != null) {
4466 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4467 throw e;
4468 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004469 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004470 return TelephonyScanManager.INVALID_SCAN_ID;
4471 }
4472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004473 }
Hall Liu912dfd32019-04-25 14:02:26 -07004474 int callingUid = Binder.getCallingUid();
4475 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004476 final long identity = Binder.clearCallingIdentity();
4477 try {
4478 return mNetworkScanRequestTracker.startNetworkScan(
4479 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004480 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004481 } finally {
4482 Binder.restoreCallingIdentity(identity);
4483 }
yinxu504e1392017-04-12 16:03:22 -07004484 }
4485
Hall Liub2ac8ef2019-02-28 15:56:23 -08004486 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004487 NetworkScanRequest request, int subId) {
4488 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4489 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4490 boolean hasNetworkScanPermission =
4491 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4492 == PERMISSION_GRANTED;
4493
4494 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4495 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4496 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004497 }
4498
4499 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4500 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004501 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4502 return new SecurityException("Specific channels must not be"
4503 + " scanned without location access.");
4504 }
4505 }
4506 }
4507
Hall Liub2ac8ef2019-02-28 15:56:23 -08004508 return null;
4509 }
4510
yinxu504e1392017-04-12 16:03:22 -07004511 /**
4512 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004513 *
4514 * @param subId id of the subscription
4515 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004516 */
4517 @Override
4518 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4520 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521
Hall Liu912dfd32019-04-25 14:02:26 -07004522 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 final long identity = Binder.clearCallingIdentity();
4524 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004525 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 } finally {
4527 Binder.restoreCallingIdentity(identity);
4528 }
yinxu504e1392017-04-12 16:03:22 -07004529 }
4530
4531 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004532 * Get the calculated preferred network type.
4533 * Used for debugging incorrect network type.
4534 *
4535 * @return the preferred network type, defined in RILConstants.java.
4536 */
4537 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004538 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004539 final Phone defaultPhone = getDefaultPhone();
4540 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4541 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004542 return RILConstants.PREFERRED_NETWORK_MODE;
4543 }
4544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004545 final long identity = Binder.clearCallingIdentity();
4546 try {
4547 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004548 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 } finally {
4550 Binder.restoreCallingIdentity(identity);
4551 }
Junda Liu84d15a22014-07-02 11:21:04 -07004552 }
4553
4554 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004555 * Get the preferred network type.
4556 * Used for device configuration by some CDMA operators.
4557 *
4558 * @return the preferred network type, defined in RILConstants.java.
4559 */
4560 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004561 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004562 TelephonyPermissions
4563 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4564 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565
4566 final long identity = Binder.clearCallingIdentity();
4567 try {
4568 if (DBG) log("getPreferredNetworkType");
4569 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4570 int networkType = (result != null ? result[0] : -1);
4571 if (DBG) log("getPreferredNetworkType: " + networkType);
4572 return networkType;
4573 } finally {
4574 Binder.restoreCallingIdentity(identity);
4575 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004576 }
4577
4578 /**
4579 * Set the preferred network type.
4580 * Used for device configuration by some CDMA operators.
4581 *
4582 * @param networkType the preferred network type, defined in RILConstants.java.
4583 * @return true on success; false on any failure.
4584 */
4585 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004586 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004587 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4588 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589
4590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4593 Boolean success = (Boolean) sendRequest(
4594 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4595 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4596 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004597 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4599 }
4600 return success;
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004603 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004604 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004605
4606 /**
Miaoa84611c2019-03-15 09:21:10 +08004607 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004608 *
Miaoa84611c2019-03-15 09:21:10 +08004609 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004610 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004611 * @hide
4612 */
4613 @Override
Miaoa84611c2019-03-15 09:21:10 +08004614 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004615 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004616 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004617 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004618 try {
Miaoa84611c2019-03-15 09:21:10 +08004619 if (phone != null) {
4620 return phone.hasMatchedTetherApnSetting();
4621 } else {
4622 return false;
4623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004624 } finally {
4625 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004626 }
Junda Liu475951f2014-11-07 16:45:03 -08004627 }
4628
4629 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004630 * Set mobile data enabled
4631 * Used by the user through settings etc to turn on/off mobile data
4632 *
4633 * @param enable {@code true} turn turn data on, else {@code false}
4634 */
4635 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004636 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4638 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639
4640 final long identity = Binder.clearCallingIdentity();
4641 try {
4642 int phoneId = mSubscriptionController.getPhoneId(subId);
4643 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4644 Phone phone = PhoneFactory.getPhone(phoneId);
4645 if (phone != null) {
4646 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004647 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004649 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004650 }
4651 } finally {
4652 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004653 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004654 }
4655
4656 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004657 * Get the user enabled state of Mobile Data.
4658 *
4659 * TODO: remove and use isUserDataEnabled.
4660 * This can't be removed now because some vendor codes
4661 * calls through ITelephony directly while they should
4662 * use TelephonyManager.
4663 *
4664 * @return true on enabled
4665 */
4666 @Override
4667 public boolean getDataEnabled(int subId) {
4668 return isUserDataEnabled(subId);
4669 }
4670
4671 /**
4672 * Get whether mobile data is enabled per user setting.
4673 *
4674 * There are other factors deciding whether mobile data is actually enabled, but they are
4675 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004676 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004677 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004678 *
4679 * @return {@code true} if data is enabled else {@code false}
4680 */
4681 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004682 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004683 try {
4684 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4685 null);
4686 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4688 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690
4691 final long identity = Binder.clearCallingIdentity();
4692 try {
4693 int phoneId = mSubscriptionController.getPhoneId(subId);
4694 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4695 Phone phone = PhoneFactory.getPhone(phoneId);
4696 if (phone != null) {
4697 boolean retVal = phone.isUserDataEnabled();
4698 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4699 return retVal;
4700 } else {
4701 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4702 return false;
4703 }
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004706 }
4707 }
4708
4709 /**
4710 * Get whether mobile data is enabled.
4711 *
4712 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4713 * whether mobile data is actually enabled.
4714 *
4715 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4716 *
4717 * @return {@code true} if data is enabled else {@code false}
4718 */
4719 @Override
4720 public boolean isDataEnabled(int subId) {
4721 try {
4722 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4723 null);
4724 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004725 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4726 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004728
4729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 int phoneId = mSubscriptionController.getPhoneId(subId);
4732 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4733 Phone phone = PhoneFactory.getPhone(phoneId);
4734 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004735 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004736 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4737 return retVal;
4738 } else {
4739 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4740 return false;
4741 }
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004744 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004745 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004746
4747 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004748 public int getCarrierPrivilegeStatus(int subId) {
4749 final Phone phone = getPhone(subId);
4750 if (phone == null) {
4751 loge("getCarrierPrivilegeStatus: Invalid subId");
4752 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4753 }
4754 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004755 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004756 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4758 }
4759 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004760 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004761 }
Junda Liu29340342014-07-10 15:23:27 -07004762
4763 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004764 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4765 final Phone phone = getPhone(subId);
4766 if (phone == null) {
4767 loge("getCarrierPrivilegeStatus: Invalid subId");
4768 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4769 }
4770 UiccProfile profile =
4771 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4772 if (profile == null) {
4773 loge("getCarrierPrivilegeStatus: No UICC");
4774 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4775 }
4776 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4777 }
4778
4779 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004780 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4781 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004782 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004783 }
4784
4785 int phoneId = SubscriptionManager.getPhoneId(subId);
4786 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004787 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004788 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004789 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4790 }
chen xuf7e9fe82019-05-09 19:31:02 -07004791
4792 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004793 }
4794
4795 @Override
4796 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004797 if (TextUtils.isEmpty(pkgName))
4798 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004799 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4800 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4801 UiccCard card = UiccController.getInstance().getUiccCard(i);
4802 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004803 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004804 continue;
4805 }
4806
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004807 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004808 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4809 break;
4810 }
4811 }
4812
4813 return result;
Junda Liu29340342014-07-10 15:23:27 -07004814 }
Derek Tan89e89d42014-07-08 17:00:10 -07004815
4816 @Override
Junda Liue64de782015-04-16 17:19:16 -07004817 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4818 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4819 loge("phoneId " + phoneId + " is not valid.");
4820 return null;
4821 }
4822 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004823 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004824 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004825 return null ;
4826 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004827 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004828 }
4829
Amith Yamasani6e118872016-02-19 12:53:51 -08004830 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004831 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004832 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004833 List<String> privilegedPackages = new ArrayList<>();
4834 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004835 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4836 // has UICC in that slot.
4837 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004838 if (card.hasCarrierPrivilegeRules()) {
4839 if (packages == null) {
4840 // Only check packages in user 0 for now
4841 packages = pm.getInstalledPackagesAsUser(
4842 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004843 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4844 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004845 }
4846 for (int p = packages.size() - 1; p >= 0; p--) {
4847 PackageInfo pkgInfo = packages.get(p);
4848 if (pkgInfo != null && pkgInfo.packageName != null
4849 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004850 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004851 privilegedPackages.add(pkgInfo.packageName);
4852 }
4853 }
4854 }
4855 }
4856 return privilegedPackages;
4857 }
4858
chen xuf7e9fe82019-05-09 19:31:02 -07004859 @Override
4860 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4861 List<String> privilegedPackages = new ArrayList<>();
4862 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4863 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4864 }
4865 return privilegedPackages;
4866 }
4867
Wink Savilleb564aae2014-10-23 10:18:09 -07004868 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004869 final Phone phone = getPhone(subId);
4870 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004871 if (card == null) {
4872 loge("getIccId: No UICC");
4873 return null;
4874 }
4875 String iccId = card.getIccId();
4876 if (TextUtils.isEmpty(iccId)) {
4877 loge("getIccId: ICC ID is null or empty.");
4878 return null;
4879 }
4880 return iccId;
4881 }
4882
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004883 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004884 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4885 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004886 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4887 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004888
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 final long identity = Binder.clearCallingIdentity();
4890 try {
4891 final String iccId = getIccId(subId);
4892 final Phone phone = getPhone(subId);
4893 if (phone == null) {
4894 return false;
4895 }
4896 final String subscriberId = phone.getSubscriberId();
4897
4898 if (DBG_MERGE) {
4899 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4900 + subscriberId + " to " + number);
4901 }
4902
4903 if (TextUtils.isEmpty(iccId)) {
4904 return false;
4905 }
4906
4907 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4908
4909 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4910 if (alphaTag == null) {
4911 editor.remove(alphaTagPrefKey);
4912 } else {
4913 editor.putString(alphaTagPrefKey, alphaTag);
4914 }
4915
4916 // Record both the line number and IMSI for this ICCID, since we need to
4917 // track all merged IMSIs based on line number
4918 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4919 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4920 if (number == null) {
4921 editor.remove(numberPrefKey);
4922 editor.remove(subscriberPrefKey);
4923 } else {
4924 editor.putString(numberPrefKey, number);
4925 editor.putString(subscriberPrefKey, subscriberId);
4926 }
4927
4928 editor.commit();
4929 return true;
4930 } finally {
4931 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004932 }
Derek Tan7226c842014-07-02 17:42:23 -07004933 }
4934
4935 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004936 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004937 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004939 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004940 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004941 return null;
4942 }
Derek Tan97ebb422014-09-05 16:55:38 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 final long identity = Binder.clearCallingIdentity();
4945 try {
4946 String iccId = getIccId(subId);
4947 if (iccId != null) {
4948 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4949 if (DBG_MERGE) {
4950 log("getLine1NumberForDisplay returning "
4951 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4952 }
4953 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004954 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004955 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4956 return null;
4957 } finally {
4958 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004959 }
Derek Tan7226c842014-07-02 17:42:23 -07004960 }
4961
4962 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004963 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004964 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004965 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004966 return null;
4967 }
Derek Tan97ebb422014-09-05 16:55:38 -07004968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 final long identity = Binder.clearCallingIdentity();
4970 try {
4971 String iccId = getIccId(subId);
4972 if (iccId != null) {
4973 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4974 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4975 }
4976 return null;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004979 }
Derek Tan7226c842014-07-02 17:42:23 -07004980 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004981
4982 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07004983 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004984 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4985 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004987 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4988 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004989 return null;
4990 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004991
Jordan Liub49b04b2019-05-06 14:45:15 -07004992 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4993 // the process, where TelephonyManager was instantiated.
4994 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004995 final long identity = Binder.clearCallingIdentity();
4996 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004997 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004998 final TelephonyManager tele = TelephonyManager.from(context);
4999 final SubscriptionManager sub = SubscriptionManager.from(context);
5000
5001 // Figure out what subscribers are currently active
5002 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005003
Jordan Liub49b04b2019-05-06 14:45:15 -07005004 // Only consider subs which match the current subId
5005 // This logic can be simplified. See b/131189269 for progress.
5006 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005007 activeSubscriberIds.add(tele.getSubscriberId(subId));
5008 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009
5010 // First pass, find a number override for an active subscriber
5011 String mergeNumber = null;
5012 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5013 for (String key : prefs.keySet()) {
5014 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5015 final String subscriberId = (String) prefs.get(key);
5016 if (activeSubscriberIds.contains(subscriberId)) {
5017 final String iccId = key.substring(
5018 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5019 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5020 mergeNumber = (String) prefs.get(numberKey);
5021 if (DBG_MERGE) {
5022 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5023 + " for active subscriber " + subscriberId);
5024 }
5025 if (!TextUtils.isEmpty(mergeNumber)) {
5026 break;
5027 }
5028 }
5029 }
5030 }
5031
5032 // Shortcut when no active merged subscribers
5033 if (TextUtils.isEmpty(mergeNumber)) {
5034 return null;
5035 }
5036
5037 // Second pass, find all subscribers under that line override
5038 final ArraySet<String> result = new ArraySet<>();
5039 for (String key : prefs.keySet()) {
5040 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5041 final String number = (String) prefs.get(key);
5042 if (mergeNumber.equals(number)) {
5043 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5044 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5045 final String subscriberId = (String) prefs.get(subscriberKey);
5046 if (!TextUtils.isEmpty(subscriberId)) {
5047 result.add(subscriberId);
5048 }
5049 }
5050 }
5051 }
5052
5053 final String[] resultArray = result.toArray(new String[result.size()]);
5054 Arrays.sort(resultArray);
5055 if (DBG_MERGE) {
5056 Slog.d(LOG_TAG,
5057 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5058 }
5059 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005062 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005063 }
5064
5065 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005066 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5067 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5068
5069 final long identity = Binder.clearCallingIdentity();
5070 try {
5071 final TelephonyManager telephonyManager = mApp.getSystemService(
5072 TelephonyManager.class);
5073 String subscriberId = telephonyManager.getSubscriberId(subId);
5074 if (subscriberId == null) {
5075 if (DBG) {
5076 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5077 + subId);
5078 }
5079 return null;
5080 }
5081
5082 final SubscriptionInfo info = SubscriptionController.getInstance()
5083 .getSubscriptionInfo(subId);
5084 final ParcelUuid groupUuid = info.getGroupUuid();
5085 // If it doesn't belong to any group, return just subscriberId of itself.
5086 if (groupUuid == null) {
5087 return new String[]{subscriberId};
5088 }
5089
5090 // Get all subscriberIds from the group.
5091 final List<String> mergedSubscriberIds = new ArrayList<>();
5092 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5093 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5094 for (SubscriptionInfo subInfo : groupInfos) {
5095 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5096 if (subscriberId != null) {
5097 mergedSubscriberIds.add(subscriberId);
5098 }
5099 }
5100
5101 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5102 } finally {
5103 Binder.restoreCallingIdentity(identity);
5104
5105 }
5106 }
5107
5108 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005109 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005110 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5111 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005112
5113 final long identity = Binder.clearCallingIdentity();
5114 try {
5115 final Phone phone = getPhone(subId);
5116 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5117 } finally {
5118 Binder.restoreCallingIdentity(identity);
5119 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005120 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005121
5122 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005123 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005124 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5125 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005126 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 final Phone phone = getPhone(subId);
5131 if (phone == null) {
5132 return false;
5133 }
5134 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5135 cdmaNonRoamingList);
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005138 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005139 }
5140
5141 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005142 @Deprecated
5143 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5144 enforceModifyPermission();
5145
5146 int returnValue = 0;
5147 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005148 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005149 if(result.exception == null) {
5150 if (result.result != null) {
5151 byte[] responseData = (byte[])(result.result);
5152 if(responseData.length > oemResp.length) {
5153 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5154 responseData.length + "bytes. Buffer Size is " +
5155 oemResp.length + "bytes.");
5156 }
5157 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5158 returnValue = responseData.length;
5159 }
5160 } else {
5161 CommandException ex = (CommandException) result.exception;
5162 returnValue = ex.getCommandError().ordinal();
5163 if(returnValue > 0) returnValue *= -1;
5164 }
5165 } catch (RuntimeException e) {
5166 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5167 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5168 if(returnValue > 0) returnValue *= -1;
5169 }
5170
5171 return returnValue;
5172 }
5173
5174 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005175 public void setRadioCapability(RadioAccessFamily[] rafs) {
5176 try {
5177 ProxyController.getInstance().setRadioCapability(rafs);
5178 } catch (RuntimeException e) {
5179 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5180 }
5181 }
5182
5183 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005184 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005185 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005186 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005187 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005188 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 final long identity = Binder.clearCallingIdentity();
5191 try {
chen xub97461a2018-10-26 14:17:57 -07005192 TelephonyPermissions
5193 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5194 mApp, phone.getSubId(), "getRadioAccessFamily");
5195 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
chen xub97461a2018-10-26 14:17:57 -07005199 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005200 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005201
5202 @Override
5203 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005204 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206
5207 final long identity = Binder.clearCallingIdentity();
5208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005209 ImsManager.getInstance(defaultPhone.getContext(),
5210 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 } finally {
5212 Binder.restoreCallingIdentity(identity);
5213 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005214 }
5215
5216 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005217 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005218 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005219 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005220 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005221 return false;
5222 }
Svet Ganovb320e182015-04-16 12:30:10 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 final long identity = Binder.clearCallingIdentity();
5225 try {
5226 // Check the user preference and the system-level IMS setting. Even if the user has
5227 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5228 // In the long run, we may instead need to check if there exists a connection service
5229 // which can support video calling.
5230 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005231 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005232 return imsManager.isVtEnabledByPlatform()
5233 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5234 && imsManager.isVtEnabledByUser();
5235 } finally {
5236 Binder.restoreCallingIdentity(identity);
5237 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005238 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005239
Andrew Leea1239f22015-03-02 17:44:07 -08005240 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5242 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5243 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5244 return false;
5245 }
5246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 CarrierConfigManager configManager =
5250 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005251 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Andrew Leea1239f22015-03-02 17:44:07 -08005256 }
5257
5258 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 public boolean isWorldPhone(int subId, String callingPackage) {
5260 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5261 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5262 return false;
5263 }
5264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 CarrierConfigManager configManager =
5268 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005269 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5271 } finally {
5272 Binder.restoreCallingIdentity(identity);
5273 }
Andrew Leea1239f22015-03-02 17:44:07 -08005274 }
5275
Andrew Lee9431b832015-03-09 18:46:45 -07005276 @Override
5277 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005278 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005279 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005280 }
5281
5282 @Override
5283 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005284 final long identity = Binder.clearCallingIdentity();
5285 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005286 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Andrew Lee9431b832015-03-09 18:46:45 -07005290 }
5291
Hall Liuf6668912018-10-31 17:05:23 -07005292 /**
5293 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5294 * support for the feature and device firmware support.
5295 *
5296 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5297 */
5298 @Override
5299 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005301 final Phone phone = getPhone(subscriptionId);
5302 if (phone == null) {
5303 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5304 return false;
5305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005307 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5309 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005310 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 return isCarrierSupported && isDeviceSupported;
5312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
Hall Liu98187582018-01-22 19:15:32 -08005315 }
5316
Hall Liuf6668912018-10-31 17:05:23 -07005317 /**
5318 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5319 * both also support RTT.
5320 */
5321 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322 final long identity = Binder.clearCallingIdentity();
5323 try {
Hall Liuf6668912018-10-31 17:05:23 -07005324 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005325 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005329 }
5330
Sanket Padawe7310cc72015-01-14 09:53:20 -08005331 /**
5332 * Returns the unique device ID of phone, for example, the IMEI for
5333 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5334 *
5335 * <p>Requires Permission:
5336 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5337 */
5338 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005339 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005340 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005341 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005342 return null;
5343 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005344 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005345 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5346 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005347 return null;
5348 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005349
5350 final long identity = Binder.clearCallingIdentity();
5351 try {
5352 return phone.getDeviceId();
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005356 }
5357
Ping Sunc67b7c22016-03-02 19:16:45 +08005358 /**
5359 * {@hide}
5360 * Returns the IMS Registration Status on a particular subid
5361 *
5362 * @param subId
5363 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005364 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005365 Phone phone = getPhone(subId);
5366 if (phone != null) {
5367 return phone.isImsRegistered();
5368 } else {
5369 return false;
5370 }
5371 }
5372
Santos Cordon7a1885b2015-02-03 11:15:19 -08005373 @Override
5374 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005375 final long identity = Binder.clearCallingIdentity();
5376 try {
5377 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005381 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005382
Tyler Gunnf70ed162019-04-03 15:28:53 -07005383 @Override
5384 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 Phone phone = getPhone(subscriptionId);
5388 if (phone == null) {
5389 return null;
5390 }
5391 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
5394 }
5395 }
5396
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005397 /**
5398 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005399 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005400 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 final long identity = Binder.clearCallingIdentity();
5402 try {
5403 Phone phone = getPhone(subId);
5404 if (phone != null) {
5405 return phone.isWifiCallingEnabled();
5406 } else {
5407 return false;
5408 }
5409 } finally {
5410 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005411 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005412 }
5413
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005414 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005415 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005416 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005417 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 Phone phone = getPhone(subId);
5421 if (phone != null) {
5422 return phone.isVideoEnabled();
5423 } else {
5424 return false;
5425 }
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005428 }
5429 }
5430
5431 /**
5432 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5433 * defined in {@link ImsRegistrationImplBase}.
5434 */
5435 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005436 final long identity = Binder.clearCallingIdentity();
5437 try {
5438 Phone phone = getPhone(subId);
5439 if (phone != null) {
5440 return phone.getImsRegistrationTech();
5441 } else {
5442 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5443 }
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005446 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005447 }
5448
Stuart Scott8eef64f2015-04-08 15:13:54 -07005449 @Override
5450 public void factoryReset(int subId) {
5451 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005452 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5453 return;
5454 }
5455
Svet Ganovcc087f82015-05-12 20:35:54 -07005456 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005457
Svet Ganovcc087f82015-05-12 20:35:54 -07005458 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005459 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5460 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005461 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005462 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005463 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005464 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5465 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005466 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005467 // There has been issues when Sms raw table somehow stores orphan
5468 // fragments. They lead to garbled message when new fragments come
5469 // in and combined with those stale ones. In case this happens again,
5470 // user can reset all network settings which will clean up this table.
5471 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005474 }
5475 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005476
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005477 private void cleanUpSmsRawTable(Context context) {
5478 ContentResolver resolver = context.getContentResolver();
5479 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5480 resolver.delete(uri, null, null);
5481 }
5482
Narayan Kamath1c496c22015-04-16 14:40:19 +01005483 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005484 public String getSimLocaleForSubscriber(int subId) {
5485 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5486 final Phone phone = getPhone(subId);
5487 if (phone == null) {
5488 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005489 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
chen xu5d3637b2019-01-21 23:31:38 -08005493 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5494 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005495 if (info == null) {
5496 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5497 return null;
5498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005499 // Try and fetch the locale from the carrier properties or from the SIM language
5500 // preferences (EF-PL and EF-LI)...
5501 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005503 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5504 if (localeFromDefaultSim != null) {
5505 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5506 if (DBG) log("Using locale from subId: " + subId + " locale: "
5507 + localeFromDefaultSim);
5508 return localeFromDefaultSim.toLanguageTag();
5509 } else {
5510 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511 }
5512 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005514 // The SIM language preferences only store a language (e.g. fr = French), not an
5515 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5516 // the SIM and carrier preferences does not include a country we add the country
5517 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005518 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005520 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 return mccLocale.toLanguageTag();
5522 }
5523
5524 if (DBG) log("No locale found - returning null");
5525 return null;
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005529 }
5530
5531 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005532 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005533 }
5534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005535 /**
5536 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5537 */
5538 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005539 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005540 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005541
Chenjie Yu1ba97252018-01-11 18:16:20 -08005542 private final ModemActivityInfo mLastModemActivityInfo =
5543 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5544
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005545 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005546 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5547 * representing the state of the modem.
5548 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005549 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5550 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005551 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005552 */
5553 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005554 public void requestModemActivityInfo(ResultReceiver result) {
5555 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005556 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557
5558 final long identity = Binder.clearCallingIdentity();
5559 try {
5560 ModemActivityInfo ret = null;
5561 synchronized (mLastModemActivityInfo) {
5562 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5563 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005564 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005565 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5567 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005568 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5569 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 }
5571 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5573 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 mLastModemActivityInfo.setIdleTimeMillis(
5575 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5576 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5577 mLastModemActivityInfo.setRxTimeMillis(
5578 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5579 mLastModemActivityInfo.setEnergyUsed(
5580 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005581 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5583 mLastModemActivityInfo.getSleepTimeMillis(),
5584 mLastModemActivityInfo.getIdleTimeMillis(),
5585 mLastModemActivityInfo.getTxTimeMillis(),
5586 mLastModemActivityInfo.getRxTimeMillis(),
5587 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005588 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 Bundle bundle = new Bundle();
5590 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5591 result.send(0, bundle);
5592 } finally {
5593 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005594 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005595 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005596
Siddharth Rayb8114062018-06-17 15:02:38 -07005597 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5598 // less than total activity duration.
5599 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5600 if (info == null) {
5601 return false;
5602 }
5603 int activityDurationMs =
5604 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5605 int totalTxTimeMs = 0;
5606 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5607 totalTxTimeMs += info.getTxTimeMillis()[i];
5608 }
5609 return (info.isValid()
5610 && (info.getSleepTimeMillis() <= activityDurationMs)
5611 && (info.getIdleTimeMillis() <= activityDurationMs)
5612 && (info.getRxTimeMillis() <= activityDurationMs)
5613 && (totalTxTimeMs <= activityDurationMs));
5614 }
5615
Jack Yu85bd38a2015-11-09 11:34:32 -08005616 /**
5617 * {@hide}
5618 * Returns the service state information on specified subscription.
5619 */
5620 @Override
5621 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005623 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005624 return null;
5625 }
5626
Hall Liuf19c44f2018-11-27 14:38:17 -08005627 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5628 LocationAccessPolicy.checkLocationPermission(mApp,
5629 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5630 .setCallingPackage(callingPackage)
5631 .setCallingPid(Binder.getCallingPid())
5632 .setCallingUid(Binder.getCallingUid())
5633 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005634 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005635 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5636 .build());
5637
5638 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5639 LocationAccessPolicy.checkLocationPermission(mApp,
5640 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5641 .setCallingPackage(callingPackage)
5642 .setCallingPid(Binder.getCallingPid())
5643 .setCallingUid(Binder.getCallingUid())
5644 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005645 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005646 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5647 .build());
5648 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5649 boolean hasFinePermission =
5650 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5651 boolean hasCoarsePermission =
5652 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 final long identity = Binder.clearCallingIdentity();
5655 try {
5656 final Phone phone = getPhone(subId);
5657 if (phone == null) {
5658 return null;
5659 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005660
Hall Liuf19c44f2018-11-27 14:38:17 -08005661 ServiceState ss = phone.getServiceState();
5662
5663 // Scrub out the location info in ServiceState depending on what level of access
5664 // the caller has.
5665 if (hasFinePermission) return ss;
5666 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5667 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005671 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005672
5673 /**
5674 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5675 *
5676 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5677 * voicemail ringtone.
5678 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5679 * PhoneAccount.
5680 */
5681 @Override
5682 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 final long identity = Binder.clearCallingIdentity();
5684 try {
5685 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5686 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005687 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005688 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005690 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5691 } finally {
5692 Binder.restoreCallingIdentity(identity);
5693 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005694 }
5695
5696 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005697 * Sets the per-account voicemail ringtone.
5698 *
5699 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5700 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5701 *
5702 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5703 * voicemail ringtone.
5704 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5705 * PhoneAccount.
5706 */
5707 @Override
5708 public void setVoicemailRingtoneUri(String callingPackage,
5709 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005710 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5712 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005713 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5715 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5716 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005717 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718
5719 final long identity = Binder.clearCallingIdentity();
5720 try {
5721 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5722 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005723 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 }
5725 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5726 } finally {
5727 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005728 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005729 }
5730
5731 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005732 * Returns whether vibration is set for voicemail notification in Phone settings.
5733 *
5734 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5735 * voicemail vibration setting.
5736 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5737 */
5738 @Override
5739 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5743 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005744 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005745 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005746
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005747 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
5750 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005751 }
5752
Youhan Wange64578a2016-05-02 15:32:42 -07005753 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005754 * Sets the per-account voicemail vibration.
5755 *
5756 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5757 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5758 *
5759 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5760 * voicemail vibration setting.
5761 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5762 * specific PhoneAccount.
5763 */
5764 @Override
5765 public void setVoicemailVibrationEnabled(String callingPackage,
5766 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005767 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5769 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005770 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5773 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005774 }
5775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 final long identity = Binder.clearCallingIdentity();
5777 try {
5778 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5779 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005780 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005781 }
5782 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5783 } finally {
5784 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005785 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005786 }
5787
5788 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005789 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5790 *
5791 * @throws SecurityException if the caller does not have the required permission
5792 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005793 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005794 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005795 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005796 }
5797
5798 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005799 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5800 * permission.
5801 *
5802 * @throws SecurityException if the caller does not have the required permission
5803 */
5804 private void enforceSendSmsPermission() {
5805 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5806 }
5807
5808 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005809 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005810 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005811 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005812 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005813 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005817 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005818 if (componentName == null) {
5819 throw new SecurityException(
5820 "Caller not current active visual voicemail package[null]");
5821 }
5822 String vvmPackage = componentName.getPackageName();
5823 if (!callingPackage.equals(vvmPackage)) {
5824 throw new SecurityException("Caller not current active visual voicemail package["
5825 + vvmPackage + "]");
5826 }
5827 } finally {
5828 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005829 }
5830 }
5831
5832 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005833 * Return the application ID for the app type.
5834 *
5835 * @param subId the subscription ID that this request applies to.
5836 * @param appType the uicc app type.
5837 * @return Application ID for specificied app type, or null if no uicc.
5838 */
5839 @Override
5840 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005841 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005842 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005843
5844 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005845 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005846 if (phone == null) {
5847 return null;
5848 }
5849 String aid = null;
5850 try {
5851 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5852 .getApplicationByType(appType).getAid();
5853 } catch (Exception e) {
5854 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5855 }
5856 return aid;
5857 } finally {
5858 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005859 }
Youhan Wange64578a2016-05-02 15:32:42 -07005860 }
5861
Youhan Wang4001d252016-05-11 10:29:41 -07005862 /**
5863 * Return the Electronic Serial Number.
5864 *
5865 * @param subId the subscription ID that this request applies to.
5866 * @return ESN or null if error.
5867 */
5868 @Override
5869 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005870 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005871 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872
5873 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005874 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005875 if (phone == null) {
5876 return null;
5877 }
5878 String esn = null;
5879 try {
5880 esn = phone.getEsn();
5881 } catch (Exception e) {
5882 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5883 }
5884 return esn;
5885 } finally {
5886 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005887 }
Youhan Wang4001d252016-05-11 10:29:41 -07005888 }
5889
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005890 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005891 * Return the Preferred Roaming List Version.
5892 *
5893 * @param subId the subscription ID that this request applies to.
5894 * @return PRLVersion or null if error.
5895 */
5896 @Override
5897 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005898 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005899 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900
5901 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005902 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005903 if (phone == null) {
5904 return null;
5905 }
5906 String cdmaPrlVersion = null;
5907 try {
5908 cdmaPrlVersion = phone.getCdmaPrlVersion();
5909 } catch (Exception e) {
5910 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5911 }
5912 return cdmaPrlVersion;
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005915 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005916 }
5917
5918 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005919 * Get snapshot of Telephony histograms
5920 * @return List of Telephony histograms
5921 * @hide
5922 */
5923 @Override
5924 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5926 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005927
5928 final long identity = Binder.clearCallingIdentity();
5929 try {
5930 return RIL.getTelephonyRILTimingHistograms();
5931 } finally {
5932 Binder.restoreCallingIdentity(identity);
5933 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005934 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005935
5936 /**
5937 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005938 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5939 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005940 * Require system privileges. In the future we may add this to carrier APIs.
5941 *
Michele Berionne482f8202018-11-27 18:57:59 -08005942 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005943 */
5944 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005945 @TelephonyManager.SetCarrierRestrictionResult
5946 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005947 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005948 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005949
Michele Berionne482f8202018-11-27 18:57:59 -08005950 if (carrierRestrictionRules == null) {
5951 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005952 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005953
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005954 final long identity = Binder.clearCallingIdentity();
5955 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005956 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005957 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 } finally {
5959 Binder.restoreCallingIdentity(identity);
5960 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005961 }
5962
5963 /**
5964 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005965 * Get the allowed carrier list and the excluded carrier list, including the priority between
5966 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005967 * Require system privileges. In the future we may add this to carrier APIs.
5968 *
Michele Berionne482f8202018-11-27 18:57:59 -08005969 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005970 */
5971 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005972 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005973 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005978 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5979 if (response instanceof CarrierRestrictionRules) {
5980 return (CarrierRestrictionRules) response;
5981 }
5982 // Response is an Exception of some kind,
5983 // which is signalled to the user as a NULL retval
5984 return null;
5985 } catch (Exception e) {
5986 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5987 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005991 }
5992
fionaxu59545b42016-05-25 15:53:37 -07005993 /**
5994 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5995 * @param subId the subscription ID that this action applies to.
5996 * @param enabled control enable or disable metered apns.
5997 * {@hide}
5998 */
5999 @Override
6000 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6001 enforceModifyPermission();
6002 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003
6004 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006005 if (phone == null) {
6006 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6007 return;
6008 }
6009 try {
6010 phone.carrierActionSetMeteredApnsEnabled(enabled);
6011 } catch (Exception e) {
6012 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 } finally {
6014 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006015 }
6016 }
6017
6018 /**
6019 * Action set from carrier signalling broadcast receivers to enable/disable radio
6020 * @param subId the subscription ID that this action applies to.
6021 * @param enabled control enable or disable radio.
6022 * {@hide}
6023 */
6024 @Override
6025 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6026 enforceModifyPermission();
6027 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028
6029 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006030 if (phone == null) {
6031 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6032 return;
6033 }
6034 try {
6035 phone.carrierActionSetRadioEnabled(enabled);
6036 } catch (Exception e) {
6037 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006038 } finally {
6039 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006040 }
6041 }
6042
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006043 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006044 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6045 * network status based on which carrier apps could apply actions accordingly,
6046 * enable/disable default url handler for example.
6047 *
6048 * @param subId the subscription ID that this action applies to.
6049 * @param report control start/stop reporting the default network status.
6050 * {@hide}
6051 */
6052 @Override
6053 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6054 enforceModifyPermission();
6055 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006056
6057 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006058 if (phone == null) {
6059 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6060 return;
6061 }
6062 try {
6063 phone.carrierActionReportDefaultNetworkStatus(report);
6064 } catch (Exception e) {
6065 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006066 } finally {
6067 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006068 }
6069 }
6070
6071 /**
fionaxud9622282017-07-17 17:51:30 -07006072 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6073 * @param subId the subscription ID that this action applies to.
6074 * {@hide}
6075 */
6076 @Override
6077 public void carrierActionResetAll(int subId) {
6078 enforceModifyPermission();
6079 final Phone phone = getPhone(subId);
6080 if (phone == null) {
6081 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6082 return;
6083 }
6084 try {
6085 phone.carrierActionResetAll();
6086 } catch (Exception e) {
6087 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6088 }
6089 }
6090
6091 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006092 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6093 * bug report is being generated.
6094 */
6095 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006096 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006097 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6098 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006099 writer.println("Permission Denial: can't dump Phone from pid="
6100 + Binder.getCallingPid()
6101 + ", uid=" + Binder.getCallingUid()
6102 + "without permission "
6103 + android.Manifest.permission.DUMP);
6104 return;
6105 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006107 }
Jack Yueb89b242016-06-22 13:27:47 -07006108
Brad Ebingerdac2f002018-04-03 15:17:52 -07006109 @Override
6110 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6111 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6112 throws RemoteException {
6113 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6114 }
6115
Jack Yueb89b242016-06-22 13:27:47 -07006116 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006117 * Get aggregated video call data usage since boot.
6118 *
6119 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6120 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006121 * {@hide}
6122 */
6123 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006124 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006125 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6126 null);
6127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 // NetworkStatsService keeps tracking the active network interface and identity. It
6131 // records the delta with the corresponding network identity.
6132 // We just return the total video call data usage snapshot since boot.
6133 Phone phone = getPhone(subId);
6134 if (phone != null) {
6135 return phone.getVtDataUsage(perUidStats);
6136 }
6137 return null;
6138 } finally {
6139 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006140 }
Jack Yueb89b242016-06-22 13:27:47 -07006141 }
Jack Yu75ab2952016-07-08 14:29:33 -07006142
6143 /**
6144 * Policy control of data connection. Usually used when data limit is passed.
6145 * @param enabled True if enabling the data, otherwise disabling.
6146 * @param subId Subscription index
6147 * {@hide}
6148 */
6149 @Override
6150 public void setPolicyDataEnabled(boolean enabled, int subId) {
6151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152
6153 final long identity = Binder.clearCallingIdentity();
6154 try {
6155 Phone phone = getPhone(subId);
6156 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006157 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 }
6159 } finally {
6160 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006161 }
6162 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006163
6164 /**
6165 * Get Client request stats
6166 * @return List of Client Request Stats
6167 * @hide
6168 */
6169 @Override
6170 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006172 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006173 return null;
6174 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006175 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 final long identity = Binder.clearCallingIdentity();
6178 try {
6179 if (phone != null) {
6180 return phone.getClientRequestStats();
6181 }
6182
6183 return null;
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006187 }
6188
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006189 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006191 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006192 }
Jack Yueb4124c2017-02-16 15:32:43 -08006193
6194 /**
Grace Chen70990072017-03-24 17:21:30 -07006195 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006196 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006197 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006198 * @param state State of SIM (power down, power up, pass through)
6199 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6200 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6201 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006202 *
6203 **/
6204 @Override
Grace Chen70990072017-03-24 17:21:30 -07006205 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006206 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006207 Phone phone = PhoneFactory.getPhone(slotIndex);
6208
vagdeviaf9a5b92018-08-15 16:01:53 -07006209 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 final long identity = Binder.clearCallingIdentity();
6212 try {
6213 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006214 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006215 }
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006218 }
6219 }
Shuo Qiandd210312017-04-12 22:11:33 +00006220
Tyler Gunn65d45c22017-06-05 11:22:26 -07006221 private boolean isUssdApiAllowed(int subId) {
6222 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006223 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006224 if (configManager == null) {
6225 return false;
6226 }
6227 PersistableBundle pb = configManager.getConfigForSubId(subId);
6228 if (pb == null) {
6229 return false;
6230 }
6231 return pb.getBoolean(
6232 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6233 }
6234
Shuo Qiandd210312017-04-12 22:11:33 +00006235 /**
6236 * Check if phone is in emergency callback mode
6237 * @return true if phone is in emergency callback mode
6238 * @param subId sub id
6239 */
goneil9c5f4872017-12-05 14:07:56 -08006240 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006241 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006242 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006243 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244
6245 final long identity = Binder.clearCallingIdentity();
6246 try {
6247 if (phone != null) {
6248 return phone.isInEcm();
6249 } else {
6250 return false;
6251 }
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006254 }
6255 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006256
6257 /**
6258 * Get the current signal strength information for the given subscription.
6259 * Because this information is not updated when the device is in a low power state
6260 * it should not be relied-upon to be current.
6261 * @param subId Subscription index
6262 * @return the most recent cached signal strength info from the modem
6263 */
6264 @Override
6265 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 final long identity = Binder.clearCallingIdentity();
6267 try {
6268 Phone p = getPhone(subId);
6269 if (p == null) {
6270 return null;
6271 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006273 return p.getSignalStrength();
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
6276 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006277 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006278
Pengquan Meng77b7f132018-08-22 14:49:57 -07006279 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006280 * Get the current modem radio state for the given slot.
6281 * @param slotIndex slot index.
6282 * @param callingPackage the name of the package making the call.
6283 * @return the current radio power state from the modem
6284 */
6285 @Override
6286 public int getRadioPowerState(int slotIndex, String callingPackage) {
6287 Phone phone = PhoneFactory.getPhone(slotIndex);
6288 if (phone != null) {
6289 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6290 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6291 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6292 }
6293
6294 final long identity = Binder.clearCallingIdentity();
6295 try {
6296 return phone.getRadioPowerState();
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
6300 }
6301 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6302 }
6303
6304 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006305 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6306 *
6307 * <p>Requires one of the following permissions:
6308 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6309 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6310 * privileges.
6311 *
6312 * @param subId subscription id
6313 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6314 * {@code false}.
6315 */
6316 @Override
6317 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006318 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6319 null /* message */);
6320
Pengquan Menga1bb6272018-09-06 09:59:22 -07006321 boolean isEnabled = false;
6322 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006323 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006324 Phone phone = getPhone(subId);
6325 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006326 } catch (Exception e) {
6327 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6328 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006329 } finally {
6330 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006331 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006332 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006333 }
6334
6335
6336 /**
6337 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6338 *
6339 * <p> Requires permission:
6340 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6341 * privileges.
6342 *
6343 * @param subId subscription id
6344 * @param isEnabled {@code true} means enable, {@code false} means disable.
6345 */
6346 @Override
6347 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006348 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6349 mApp, subId, "setDataRoamingEnabled");
6350
Pengquan Menga1bb6272018-09-06 09:59:22 -07006351 final long identity = Binder.clearCallingIdentity();
6352 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006353 Phone phone = getPhone(subId);
6354 if (phone != null) {
6355 phone.setDataRoamingEnabled(isEnabled);
6356 }
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006359 }
6360 }
6361
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006362 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006363 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006364 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6365 mApp, subId, "isManualNetworkSelectionAllowed");
6366
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006367 boolean isAllowed = true;
6368 final long identity = Binder.clearCallingIdentity();
6369 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006370 Phone phone = getPhone(subId);
6371 if (phone != null) {
6372 isAllowed = phone.isCspPlmnEnabled();
6373 }
6374 } finally {
6375 Binder.restoreCallingIdentity(identity);
6376 }
6377 return isAllowed;
6378 }
6379
6380 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006381 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006382 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006383 try {
6384 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006385 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006386 } catch (SecurityException e) {
6387 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6388 // has carrier privileges on an active UICC
6389 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6390 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006391 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006392 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006393 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006397 UiccController uiccController = UiccController.getInstance();
6398 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006399 if (hasReadPermission) {
6400 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006401 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006402
6403 // Remove private info if the caller doesn't have access
6404 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6405 for (UiccCardInfo cardInfo : cardInfos) {
6406 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6407 // is available
6408 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6409 if (card == null || card.getUiccProfile() == null) {
6410 // assume no access if the card or profile is unavailable
6411 filteredInfos.add(cardInfo.getUnprivileged());
6412 continue;
6413 }
6414 UiccProfile profile = card.getUiccProfile();
6415 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6416 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6417 filteredInfos.add(cardInfo);
6418 } else {
6419 filteredInfos.add(cardInfo.getUnprivileged());
6420 }
6421 }
6422 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006423 } finally {
6424 Binder.restoreCallingIdentity(identity);
6425 }
6426 }
6427
6428 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006429 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006430 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006431
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6435 if (slots == null) {
6436 Rlog.i(LOG_TAG, "slots is null.");
6437 return null;
6438 }
6439
6440 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6441 for (int i = 0; i < slots.length; i++) {
6442 UiccSlot slot = slots[i];
6443 if (slot == null) {
6444 continue;
6445 }
6446
Jordan Liu7be7e652019-05-06 18:55:02 +00006447 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 UiccCard card = slot.getUiccCard();
6449 if (card != null) {
6450 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006451 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006452 cardId = slot.getIccId();
6453 }
6454
6455 int cardState = 0;
6456 switch (slot.getCardState()) {
6457 case CARDSTATE_ABSENT:
6458 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6459 break;
6460 case CARDSTATE_PRESENT:
6461 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6462 break;
6463 case CARDSTATE_ERROR:
6464 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6465 break;
6466 case CARDSTATE_RESTRICTED:
6467 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6468 break;
6469 default:
6470 break;
6471
6472 }
6473
6474 infos[i] = new UiccSlotInfo(
6475 slot.isActive(),
6476 slot.isEuicc(),
6477 cardId,
6478 cardState,
6479 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006480 slot.isExtendedApduSupported(),
6481 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 }
6483 return infos;
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006486 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006487 }
6488
6489 @Override
6490 public boolean switchSlots(int[] physicalSlots) {
6491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006499 }
Jack Yu4c988042018-02-27 15:30:01 -08006500
6501 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006502 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006503 final long identity = Binder.clearCallingIdentity();
6504 try {
6505 return UiccController.getInstance().getCardIdForDefaultEuicc();
6506 } finally {
6507 Binder.restoreCallingIdentity(identity);
6508 }
6509 }
6510
6511 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006512 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6513 enforceModifyPermission();
6514 final Phone phone = getPhone(subId);
6515 if (phone == null) {
6516 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6517 return;
6518 }
6519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 final long identity = Binder.clearCallingIdentity();
6521 try {
6522 phone.setRadioIndicationUpdateMode(filters, mode);
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Jack Yu4c988042018-02-27 15:30:01 -08006526 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006527
6528 /**
goneil47ffb6e2018-04-06 15:40:58 -07006529 * A test API to reload the UICC profile.
6530 *
6531 * <p>Requires that the calling app has permission
6532 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6533 * @hide
6534 */
6535 @Override
6536 public void refreshUiccProfile(int subId) {
6537 enforceModifyPermission();
6538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 Phone phone = getPhone(subId);
6542 if (phone == null) {
6543 return;
6544 }
6545 UiccCard uiccCard = phone.getUiccCard();
6546 if (uiccCard == null) {
6547 return;
6548 }
6549 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6550 if (uiccProfile == null) {
6551 return;
6552 }
6553 uiccProfile.refresh();
6554 } finally {
6555 Binder.restoreCallingIdentity(identity);
6556 }
6557 }
6558
6559 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006560 * Returns false if the mobile data is disabled by default, otherwise return true.
6561 */
6562 private boolean getDefaultDataEnabled() {
6563 return "true".equalsIgnoreCase(
6564 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6565 }
6566
6567 /**
6568 * Returns true if the data roaming is enabled by default, i.e the system property
6569 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6570 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6571 */
6572 private boolean getDefaultDataRoamingEnabled(int subId) {
6573 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006574 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006575 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6576 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6577 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6578 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6579 return isDataRoamingEnabled;
6580 }
6581
6582 /**
6583 * Returns the default network type for the given {@code subId}, if the default network type is
6584 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6585 */
6586 private int getDefaultNetworkType(int subId) {
6587 return Integer.parseInt(
6588 TelephonyManager.getTelephonyProperty(
6589 mSubscriptionController.getPhoneId(subId),
6590 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6591 String.valueOf(Phone.PREFERRED_NT_MODE)));
6592 }
fionaxua13278b2018-03-21 00:08:13 -07006593
6594 @Override
6595 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006596 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006597 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598
6599 final long identity = Binder.clearCallingIdentity();
6600 try {
6601 final Phone phone = getPhone(subId);
6602 if (phone == null) {
6603 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6604 return;
6605 }
chen xueaba88a2019-03-15 13:15:10 -07006606 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6607 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006608 } finally {
6609 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006610 }
fionaxua13278b2018-03-21 00:08:13 -07006611 }
6612
6613 @Override
6614 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006615 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006616
6617 final long identity = Binder.clearCallingIdentity();
6618 try {
6619 final Phone phone = getPhone(subId);
6620 if (phone == null) {
6621 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6622 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6623 }
6624 return phone.getCarrierIdListVersion();
6625 } finally {
6626 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006627 }
fionaxua13278b2018-03-21 00:08:13 -07006628 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006629
6630 @Override
6631 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6633 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6634 return -1;
6635 }
6636
6637 final long identity = Binder.clearCallingIdentity();
6638 try {
6639 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6640 } finally {
6641 Binder.restoreCallingIdentity(identity);
6642 }
6643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006644
6645 @Override
6646 public int getCdmaRoamingMode(int subId) {
6647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6648 mApp, subId, "getCdmaRoamingMode");
6649
6650 final long identity = Binder.clearCallingIdentity();
6651 try {
6652 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
6655 }
6656 }
6657
6658 @Override
6659 public boolean setCdmaRoamingMode(int subId, int mode) {
6660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6661 mApp, subId, "setCdmaRoamingMode");
6662
6663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
6669 }
6670
6671 @Override
6672 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6674 mApp, subId, "setCdmaSubscriptionMode");
6675
6676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006683
6684 private void ensureUserRunning(int userId) {
6685 if (!mUserManager.isUserRunning(userId)) {
6686 throw new IllegalStateException("User " + userId + " does not exist or not running");
6687 }
6688 }
6689
6690 /**
6691 * Returns a list of SMS apps on a given user.
6692 *
6693 * Only the shell user (UID 2000 or 0) can call it.
6694 * Target user must be running.
6695 */
6696 @Override
6697 public String[] getSmsApps(int userId) {
6698 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6699 ensureUserRunning(userId);
6700
6701 final Collection<SmsApplicationData> apps =
6702 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6703
6704 String[] ret = new String[apps.size()];
6705 int i = 0;
6706 for (SmsApplicationData app : apps) {
6707 ret[i++] = app.mPackageName;
6708 }
6709 return ret;
6710 }
6711
6712 /**
6713 * Returns the default SMS app package name on a given user.
6714 *
6715 * Only the shell user (UID 2000 or 0) can call it.
6716 * Target user must be running.
6717 */
6718 @Override
6719 public String getDefaultSmsApp(int userId) {
6720 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6721 ensureUserRunning(userId);
6722
6723 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6724 /* updateIfNeeded= */ true, userId);
6725 return cn == null ? null : cn.getPackageName();
6726 }
6727
6728 /**
6729 * Set a package as the default SMS app on a given user.
6730 *
6731 * Only the shell user (UID 2000 or 0) can call it.
6732 * Target user must be running.
6733 */
6734 @Override
6735 public void setDefaultSmsApp(int userId, String packageName) {
6736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6737 ensureUserRunning(userId);
6738
6739 boolean found = false;
6740 for (String pkg : getSmsApps(userId)) {
6741 if (TextUtils.equals(packageName, pkg)) {
6742 found = true;
6743 break;
6744 }
6745 }
6746 if (!found) {
6747 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6748 }
6749
6750 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6751 }
sqianc5eccab2018-10-19 18:46:41 -07006752
6753 @Override
sqian8c685422019-02-22 15:55:18 -08006754 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006755 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006757 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006758 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6759 }
6760 final long identity = Binder.clearCallingIdentity();
6761 try {
sqian854d44b2018-12-12 16:48:18 -08006762 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6763 for (Phone phone: PhoneFactory.getPhones()) {
6764 if (phone.getEmergencyNumberTracker() != null
6765 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6766 emergencyNumberListInternal.put(
6767 phone.getSubId(),
6768 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6769 }
sqian11b7a0e2018-12-05 18:48:28 -08006770 }
sqian854d44b2018-12-12 16:48:18 -08006771 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006772 } finally {
6773 Binder.restoreCallingIdentity(identity);
6774 }
sqianc5eccab2018-10-19 18:46:41 -07006775 }
6776
6777 @Override
sqian8c685422019-02-22 15:55:18 -08006778 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006779 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006780 if (!exactMatch) {
6781 TelephonyPermissions
6782 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006783 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006784 }
6785 final long identity = Binder.clearCallingIdentity();
6786 try {
sqian854d44b2018-12-12 16:48:18 -08006787 for (Phone phone: PhoneFactory.getPhones()) {
6788 if (phone.getEmergencyNumberTracker() != null
6789 && phone.getEmergencyNumberTracker() != null) {
6790 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6791 number, exactMatch)) {
6792 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006793 }
6794 }
sqian11b7a0e2018-12-05 18:48:28 -08006795 }
6796 return false;
6797 } finally {
6798 Binder.restoreCallingIdentity(identity);
6799 }
6800 }
6801
sqianf4ca7ed2019-01-15 18:32:07 -08006802 /**
6803 * Update emergency number list for test mode.
6804 */
6805 @Override
6806 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6807 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6808 "updateEmergencyNumberListTestMode");
6809
6810 final long identity = Binder.clearCallingIdentity();
6811 try {
6812 for (Phone phone: PhoneFactory.getPhones()) {
6813 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6814 if (tracker != null) {
6815 tracker.executeEmergencyNumberTestModeCommand(action, num);
6816 }
6817 }
6818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
6821 }
6822
6823 /**
6824 * Get the full emergency number list for test mode.
6825 */
6826 @Override
6827 public List<String> getEmergencyNumberListTestMode() {
6828 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6829 "getEmergencyNumberListTestMode");
6830
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
6833 Set<String> emergencyNumbers = new HashSet<>();
6834 for (Phone phone: PhoneFactory.getPhones()) {
6835 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6836 if (tracker != null) {
6837 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6838 emergencyNumbers.add(num.getNumber());
6839 }
6840 }
6841 }
6842 return new ArrayList<>(emergencyNumbers);
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
6846 }
6847
chen xud6b45bd2018-10-30 22:27:10 -07006848 @Override
6849 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6850 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6851 Phone phone = getPhone(subId);
6852 if (phone == null) {
6853 return null;
6854 }
6855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 UiccProfile profile = UiccController.getInstance()
6858 .getUiccProfileForPhone(phone.getPhoneId());
6859 if (profile != null) {
6860 return profile.getCertsFromCarrierPrivilegeAccessRules();
6861 }
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
6865 return null;
6866 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006867
6868 /**
6869 * Enable or disable a modem stack.
6870 */
6871 @Override
6872 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6873 enforceModifyPermission();
6874
6875 final long identity = Binder.clearCallingIdentity();
6876 try {
6877 Phone phone = PhoneFactory.getPhone(slotIndex);
6878 if (phone == null) {
6879 return false;
6880 } else {
6881 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6882 }
6883 } finally {
6884 Binder.restoreCallingIdentity(identity);
6885 }
6886 }
Michelecea4cf22018-12-21 15:00:11 -08006887
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006888 /**
6889 * Whether a modem stack is enabled or not.
6890 */
6891 @Override
6892 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6893 Phone phone = PhoneFactory.getPhone(slotIndex);
6894 if (phone == null) return false;
6895
6896 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6897 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6898 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6899 }
6900
6901 final long identity = Binder.clearCallingIdentity();
6902 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006903 try {
6904 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6905 } catch (NoSuchElementException ex) {
6906 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6907 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006908 } finally {
6909 Binder.restoreCallingIdentity(identity);
6910 }
6911 }
6912
Michelecea4cf22018-12-21 15:00:11 -08006913 @Override
Michele0ea7d782019-03-19 14:58:42 -07006914 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006915 enforceModifyPermission();
6916
6917 final long identity = Binder.clearCallingIdentity();
6918 try {
6919 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006920 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006921 .commit();
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
6925 }
6926
6927 @Override
Michele0ea7d782019-03-19 14:58:42 -07006928 @TelephonyManager.IsMultiSimSupportedResult
6929 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006931 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6932 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006933 }
Michelecea4cf22018-12-21 15:00:11 -08006934
6935 final long identity = Binder.clearCallingIdentity();
6936 try {
Michele0ea7d782019-03-19 14:58:42 -07006937 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006938 } finally {
6939 Binder.restoreCallingIdentity(identity);
6940 }
6941 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006942
Michele0ea7d782019-03-19 14:58:42 -07006943 @TelephonyManager.IsMultiSimSupportedResult
6944 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006945 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6946 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6947 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006948 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6949 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006950 }
6951 // Check if the hardware supports multisim functionality. If usage of multisim is not
6952 // supported by the modem, indicate that it is restricted.
6953 PhoneCapability staticCapability =
6954 mPhoneConfigurationManager.getStaticPhoneCapability();
6955 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006956 loge("isMultiSimSupportedInternal: no static configuration available");
6957 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006958 }
6959 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006960 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6961 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006962 }
6963 // Check if support of multiple SIMs is restricted by carrier
6964 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006965 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006966 }
6967
Michele0ea7d782019-03-19 14:58:42 -07006968 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006969 }
6970
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006971 /**
6972 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006973 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6974 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6975 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006976 * @param numOfSims number of active sims we want to switch to
6977 */
6978 @Override
6979 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006980 if (numOfSims == 1) {
6981 enforceModifyPermission();
6982 } else {
6983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6984 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6985 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006986 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006987
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006988 try {
Michele30b57b22019-03-01 12:01:14 -08006989 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006990 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006991 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6992 return;
6993 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006994 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
6998 }
6999
7000 /**
chen xub4baa772019-04-03 10:23:41 -07007001 * Get whether making changes to modem configurations will trigger reboot.
7002 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007003 */
7004 @Override
chen xub4baa772019-04-03 10:23:41 -07007005 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7007 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7008 return false;
7009 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007010 final long identity = Binder.clearCallingIdentity();
7011 try {
7012 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
7016 }
7017
Nathan Harold29f5f052019-02-15 13:41:57 -08007018 private void updateModemStateMetrics() {
7019 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7020 // TODO: check the state for each modem if the api is ready.
7021 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7022 }
7023
Pengquan Meng3889a572019-01-23 11:16:29 -08007024 @Override
7025 public int[] getSlotsMapping() {
7026 enforceReadPrivilegedPermission("getSlotsMapping");
7027
7028 final long identity = Binder.clearCallingIdentity();
7029 try {
7030 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7031 // All logical slots should have a mapping to a physical slot.
7032 int[] logicalSlotsMapping = new int[phoneCount];
7033 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7034 for (int i = 0; i < slotInfos.length; i++) {
7035 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7036 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7037 }
7038 }
7039 return logicalSlotsMapping;
7040 } finally {
7041 Binder.restoreCallingIdentity(identity);
7042 }
7043 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007044
7045 /**
7046 * Get the IRadio HAL Version
7047 */
7048 @Override
7049 public int getRadioHalVersion() {
7050 Phone phone = getDefaultPhone();
7051 if (phone == null) return -1;
7052 HalVersion hv = phone.getHalVersion();
7053 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7054 return hv.major * 100 + hv.minor;
7055 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007056
7057 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007058 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7059 * corresponding network requests on a subId.
7060 *
7061 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007062 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007063 * 2) APN is un-metered for this subscription, or
7064 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7065 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7066 *
7067 * @return whether data is allowed for a apn type.
7068 *
7069 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007070 */
7071 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007072 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007073 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007074 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7075 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007076 }
7077
7078 // Now that all security checks passes, perform the operation as ourselves.
7079 final long identity = Binder.clearCallingIdentity();
7080 try {
7081 Phone phone = getPhone(subId);
7082 if (phone == null) return false;
7083
Jack Yu41407ee2019-05-13 16:54:09 -07007084 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007085 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
7089 }
7090
7091 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007092 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007093 enforceReadPrivilegedPermission("isApnMetered");
7094
7095 // Now that all security checks passes, perform the operation as ourselves.
7096 final long identity = Binder.clearCallingIdentity();
7097 try {
7098 Phone phone = getPhone(subId);
7099 if (phone == null) return true; // By default return true.
7100
Jack Yu41407ee2019-05-13 16:54:09 -07007101 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007102 } finally {
7103 Binder.restoreCallingIdentity(identity);
7104 }
7105 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007106
7107 @Override
7108 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7109 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7110 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7111 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7112 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7113 }
7114 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7115 Intent intent = new Intent();
7116 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7117 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7118 // Bring up choose default SMS subscription dialog right now
7119 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7120 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7121 mApp.startActivity(intent);
7122 }
chen xud5ca2d52019-05-28 15:20:57 -07007123
7124 @Override
7125 public String getMmsUAProfUrl(int subId) {
7126 //TODO investigate if this API should require proper permission check in R b/133791609
7127 final long identity = Binder.clearCallingIdentity();
7128 try {
7129 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7130 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
7134 }
7135
7136 @Override
7137 public String getMmsUserAgent(int subId) {
7138 //TODO investigate if this API should require proper permission check in R b/133791609
7139 final long identity = Binder.clearCallingIdentity();
7140 try {
7141 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7142 .getString(com.android.internal.R.string.config_mms_user_agent);
7143 } finally {
7144 Binder.restoreCallingIdentity(identity);
7145 }
7146 }
Jack Yub07d4972019-05-28 16:12:25 -07007147
7148 @Override
7149 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7150 enforceModifyPermission();
7151
7152 // Now that all security checks passes, perform the operation as ourselves.
7153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 Phone phone = getPhone(subId);
7156 if (phone == null) return false;
7157
7158 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
7162 }
7163
7164 @Override
7165 public boolean isDataAllowedInVoiceCall(int subId) {
7166 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7167
7168 // Now that all security checks passes, perform the operation as ourselves.
7169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 Phone phone = getPhone(subId);
7172 if (phone == null) return false;
7173
7174 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
7178 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007179}