blob: 2211a4ac01344937e1eb6cf0a13cb8d9d5359c02 [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070027import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.content.Context;
29import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070030import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070031import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070032import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080033import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070034import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070035import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.net.Uri;
37import android.os.AsyncResult;
38import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080039import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.Bundle;
41import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070042import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Looper;
44import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070046import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080047import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070048import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070050import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070051import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070053import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070054import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080056import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070057import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080058import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080059import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070060import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070061import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080062import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070064import android.telephony.CellInfoGsm;
65import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070066import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070068import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070069import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080070import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070071import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080072import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070073import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080074import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080075import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070076import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080079import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070080import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080081import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070083import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080085import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000086import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070087import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070088import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070089import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080090import android.telephony.data.ApnSetting;
91import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080093import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -070094import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080095import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070096import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsMmTelFeature;
98import android.telephony.ims.aidl.IImsRcsFeature;
99import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.feature.MmTelFeature;
102import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800103import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800107import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800109
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700111import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800112import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700114import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700115import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800116import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700117import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800120import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800121import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800123import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700124import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100125import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700126import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700129import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800130import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700131import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700132import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700133import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700134import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700135import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700137import com.android.internal.telephony.SmsApplication;
138import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800139import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.TelephonyPermissions;
sqianf4ca7ed2019-01-15 18:32:07 -0800141import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700142import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800143import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800144import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.uicc.IccIoResult;
146import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800147import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700148import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800149import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000152import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700153import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800154import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700155import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800156import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700157import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700158import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800159
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700160import java.io.FileDescriptor;
161import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800164import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700165import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800166import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800167import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800168import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100169import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170import java.util.Map;
sqianf4ca7ed2019-01-15 18:32:07 -0800171import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172
173/**
174 * Implementation of the ITelephony interface.
175 */
Santos Cordon117fee72014-05-16 17:56:12 -0700176public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177 private static final String LOG_TAG = "PhoneInterfaceManager";
178 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
179 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182 // Message codes used with mMainThreadHandler
183 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700184 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
185 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186 private static final int CMD_OPEN_CHANNEL = 9;
187 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
188 private static final int CMD_CLOSE_CHANNEL = 11;
189 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800190 private static final int CMD_NV_READ_ITEM = 13;
191 private static final int EVENT_NV_READ_ITEM_DONE = 14;
192 private static final int CMD_NV_WRITE_ITEM = 15;
193 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
194 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
195 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700196 private static final int CMD_RESET_MODEM_CONFIG = 19;
197 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800198 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
199 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
200 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
201 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800202 private static final int CMD_SEND_ENVELOPE = 25;
203 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000204 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
205 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700206 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
207 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
208 private static final int CMD_EXCHANGE_SIM_IO = 31;
209 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800210 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
211 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700212 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
213 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700214 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
215 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700216 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
217 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
218 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
219 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700220 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
221 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
222 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
223 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700224 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
226 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000227 private static final int CMD_SWITCH_SLOTS = 50;
228 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700229 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
230 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
231 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
232 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
233 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
234 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
235 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
236 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700237 private static final int CMD_GET_ALL_CELL_INFO = 60;
238 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
239 private static final int CMD_GET_CELL_LOCATION = 62;
240 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700241 private static final int CMD_MODEM_REBOOT = 64;
242 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700243 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
244 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800245 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
246 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800248 // Parameters of select command.
249 private static final int SELECT_COMMAND = 0xA4;
250 private static final int SELECT_P1 = 0x04;
251 private static final int SELECT_P2 = 0;
252 private static final int SELECT_P3 = 0x10;
253
Pengquan Meng85728fb2018-03-12 16:31:21 -0700254 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
255 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
256 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
257
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 /** The singleton instance. */
259 private static PhoneInterfaceManager sInstance;
260
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800262 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700263 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private AppOpsManager mAppOps;
265 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800266 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800267 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700268 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Derek Tan97ebb422014-09-05 16:55:38 -0700270 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
271 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800272 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800273 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700274
Michelecea4cf22018-12-21 15:00:11 -0800275 // String to store multi SIM allowed
276 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
277
Derek Tan740e1672017-06-27 14:56:27 -0700278 // The AID of ISD-R.
279 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
280
yinxub1bed742017-04-17 11:45:04 -0700281 private NetworkScanRequestTracker mNetworkScanRequestTracker;
282
David Kelly5e06a7f2018-03-12 14:10:59 +0000283 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
284 private static final int MANUFACTURER_CODE_LENGTH = 8;
285
Derek Tan89e89d42014-07-08 17:00:10 -0700286 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class IccAPDUArgument {
290 public int channel, cla, command, p1, p2, p3;
291 public String data;
292
293 public IccAPDUArgument(int channel, int cla, int command,
294 int p1, int p2, int p3, String data) {
295 this.channel = channel;
296 this.cla = cla;
297 this.command = command;
298 this.p1 = p1;
299 this.p2 = p2;
300 this.p3 = p3;
301 this.data = data;
302 }
303 }
304
305 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700306 * A request object to use for transmitting data to an ICC.
307 */
308 private static final class ManualNetworkSelectionArgument {
309 public OperatorInfo operatorInfo;
310 public boolean persistSelection;
311
312 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
313 this.operatorInfo = operatorInfo;
314 this.persistSelection = persistSelection;
315 }
316 }
317
318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
320 * request after sending. The main thread will notify the request when it is complete.
321 */
322 private static final class MainThreadRequest {
323 /** The argument to use for the request */
324 public Object argument;
325 /** The result of the request that is run on the main thread */
326 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800327 // The subscriber id that this request applies to. Defaults to
328 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
329 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330
Nathan Harold92bed182018-10-12 18:16:49 -0700331 // In cases where subId is unavailable, the caller needs to specify the phone.
332 public Phone phone;
333
vagdeviaf9a5b92018-08-15 16:01:53 -0700334 public WorkSource workSource;
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 public MainThreadRequest(Object argument) {
337 this.argument = argument;
338 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800339
Nathan Harold92bed182018-10-12 18:16:49 -0700340 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
341 this.argument = argument;
342 if (phone != null) {
343 this.phone = phone;
344 }
345 this.workSource = workSource;
346 }
347
vagdeviaf9a5b92018-08-15 16:01:53 -0700348 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 if (subId != null) {
351 this.subId = subId;
352 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700353 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 }
356
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800357 private static final class IncomingThirdPartyCallArgs {
358 public final ComponentName component;
359 public final String callId;
360 public final String callerDisplayName;
361
362 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
363 String callerDisplayName) {
364 this.component = component;
365 this.callId = callId;
366 this.callerDisplayName = callerDisplayName;
367 }
368 }
369
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 /**
371 * A handler that processes messages on the main thread in the phone process. Since many
372 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
373 * inbound binder threads to the main thread in the phone process. The Binder thread
374 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
375 * on, which will be notified when the operation completes and will contain the result of the
376 * request.
377 *
378 * <p>If a MainThreadRequest object is provided in the msg.obj field,
379 * note that request.result must be set to something non-null for the calling thread to
380 * unblock.
381 */
382 private final class MainThreadHandler extends Handler {
383 @Override
384 public void handleMessage(Message msg) {
385 MainThreadRequest request;
386 Message onCompleted;
387 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800388 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700389 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800390 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
392 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700393 case CMD_HANDLE_USSD_REQUEST: {
394 request = (MainThreadRequest) msg.obj;
395 final Phone phone = getPhoneFromRequest(request);
396 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
397 String ussdRequest = ussdObject.first;
398 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700399
Pengquan Menga1bb6272018-09-06 09:59:22 -0700400 if (!isUssdApiAllowed(request.subId)) {
401 // Carrier does not support use of this API, return failure.
402 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
403 UssdResponse response = new UssdResponse(ussdRequest, null);
404 Bundle returnData = new Bundle();
405 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
406 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700407
Pengquan Menga1bb6272018-09-06 09:59:22 -0700408 request.result = true;
409 notifyRequester(request);
410 return;
411 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700412
Pengquan Menga1bb6272018-09-06 09:59:22 -0700413 try {
414 request.result = phone != null
415 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
416 } catch (CallStateException cse) {
417 request.result = false;
418 }
419 // Wake up the requesting thread
420 notifyRequester(request);
421 break;
pkanwar32d516d2016-10-14 19:37:38 -0700422 }
423
Yorke Lee716f67e2015-06-17 15:39:16 -0700424 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 final Phone phone = getPhoneFromRequest(request);
427 request.result = phone != null ?
428 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
429 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800438 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 if (uiccCard == null) {
440 loge("iccTransmitApduLogicalChannel: No UICC");
441 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700442 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
445 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 iccArgument.channel, iccArgument.cla, iccArgument.command,
448 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 ar = (AsyncResult) msg.obj;
455 request = (MainThreadRequest) ar.userObj;
456 if (ar.exception == null && ar.result != null) {
457 request.result = ar.result;
458 } else {
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
460 if (ar.result == null) {
461 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800462 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800464 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 } else {
466 loge("iccTransmitApduLogicalChannel: Unknown exception");
467 }
468 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 break;
471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
473 request = (MainThreadRequest) msg.obj;
474 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 if (uiccCard == null) {
477 loge("iccTransmitApduBasicChannel: No UICC");
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 } else {
481 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
482 request);
483 uiccCard.iccTransmitApduBasicChannel(
484 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
485 iccArgument.p3, iccArgument.data, onCompleted);
486 }
487 break;
488
489 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
490 ar = (AsyncResult) msg.obj;
491 request = (MainThreadRequest) ar.userObj;
492 if (ar.exception == null && ar.result != null) {
493 request.result = ar.result;
494 } else {
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
496 if (ar.result == null) {
497 loge("iccTransmitApduBasicChannel: Empty response");
498 } else if (ar.exception instanceof CommandException) {
499 loge("iccTransmitApduBasicChannel: CommandException: " +
500 ar.exception);
501 } else {
502 loge("iccTransmitApduBasicChannel: Unknown exception");
503 }
504 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 break;
507
508 case CMD_EXCHANGE_SIM_IO:
509 request = (MainThreadRequest) msg.obj;
510 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 if (uiccCard == null) {
513 loge("iccExchangeSimIO: No UICC");
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 } else {
517 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
518 request);
519 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
520 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
521 iccArgument.data, onCompleted);
522 }
523 break;
524
525 case EVENT_EXCHANGE_SIM_IO_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
530 } else {
531 request.result = new IccIoResult(0x6f, 0, (byte[])null);
532 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 break;
535
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 case CMD_SEND_ENVELOPE:
537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("sendEnvelopeWithStatus: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
545 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
549 case EVENT_SEND_ENVELOPE_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
556 if (ar.result == null) {
557 loge("sendEnvelopeWithStatus: Empty response");
558 } else if (ar.exception instanceof CommandException) {
559 loge("sendEnvelopeWithStatus: CommandException: " +
560 ar.exception);
561 } else {
562 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
563 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 break;
567
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 case CMD_OPEN_CHANNEL:
569 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800571 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 if (uiccCard == null) {
573 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800574 request.result = new IccOpenLogicalChannelResponse(-1,
575 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 } else {
578 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
580 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
584 case EVENT_OPEN_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 int[] result = (int[]) ar.result;
590 int channelId = result[0];
591 byte[] selectResponse = null;
592 if (result.length > 1) {
593 selectResponse = new byte[result.length - 1];
594 for (int i = 1; i < result.length; ++i) {
595 selectResponse[i - 1] = (byte) result[i];
596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.result == null) {
602 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (ar.exception != null) {
605 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
606 }
607
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700609 if (ar.exception instanceof CommandException) {
610 CommandException.Error error =
611 ((CommandException) (ar.exception)).getCommandError();
612 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700614 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 }
617 }
618 openChannelResp = new IccOpenLogicalChannelResponse(
619 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700621 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case CMD_CLOSE_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800627 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900630 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
634 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800639 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
640 break;
641
642 case CMD_NV_READ_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800645 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
646 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800647 break;
648
649 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 ar = (AsyncResult) msg.obj;
651 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800652 if (ar.exception == null && ar.result != null) {
653 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 request.result = "";
656 if (ar.result == null) {
657 loge("nvReadItem: Empty response");
658 } else if (ar.exception instanceof CommandException) {
659 loge("nvReadItem: CommandException: " +
660 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
664 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
Jake Hambye994d462014-02-03 13:10:13 -0800668 case CMD_NV_WRITE_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
671 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800672 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_WRITE_ITEM_DONE:
677 handleNullReturnEvent(msg, "nvWriteItem");
678 break;
679
680 case CMD_NV_WRITE_CDMA_PRL:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800683 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
686 case EVENT_NV_WRITE_CDMA_PRL_DONE:
687 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
688 break;
689
chen xu6dac5ab2018-10-26 17:39:23 -0700690 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800691 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700692 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800693 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
chen xu6dac5ab2018-10-26 17:39:23 -0700696 case EVENT_RESET_MODEM_CONFIG_DONE:
697 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 case CMD_GET_PREFERRED_NETWORK_TYPE:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result; // Integer
711 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800712 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 if (ar.result == null) {
714 loge("getPreferredNetworkType: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("getPreferredNetworkType: CommandException: " +
717 ar.exception);
718 } else {
719 loge("getPreferredNetworkType: Unknown exception");
720 }
721 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case CMD_SET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
728 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
733 handleNullReturnEvent(msg, "setPreferredNetworkType");
734 break;
735
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000736 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
737 request = (MainThreadRequest)msg.obj;
738 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 break;
741
742 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
743 ar = (AsyncResult)msg.obj;
744 request = (MainThreadRequest)ar.userObj;
745 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700746 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 break;
748
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800749 case CMD_SET_VOICEMAIL_NUMBER:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
752 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800753 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
754 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800755 break;
756
757 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
758 handleNullReturnEvent(msg, "setVoicemailNumber");
759 break;
760
Stuart Scott54788802015-03-30 13:18:01 -0700761 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
764 request);
765 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
766 break;
767
768 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
769 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
770 break;
771
Shishir Agrawal302c8692015-06-19 13:49:39 -0700772 case CMD_PERFORM_NETWORK_SCAN:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
775 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
776 break;
777
778 case EVENT_PERFORM_NETWORK_SCAN_DONE:
779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
781 CellNetworkScanResult cellScanResult;
782 if (ar.exception == null && ar.result != null) {
783 cellScanResult = new CellNetworkScanResult(
784 CellNetworkScanResult.STATUS_SUCCESS,
785 (List<OperatorInfo>) ar.result);
786 } else {
787 if (ar.result == null) {
788 loge("getCellNetworkScanResults: Empty response");
789 }
790 if (ar.exception != null) {
791 loge("getCellNetworkScanResults: Exception: " + ar.exception);
792 }
793 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
794 if (ar.exception instanceof CommandException) {
795 CommandException.Error error =
796 ((CommandException) (ar.exception)).getCommandError();
797 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
799 } else if (error == CommandException.Error.GENERIC_FAILURE) {
800 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
801 }
802 }
803 cellScanResult = new CellNetworkScanResult(errorCode, null);
804 }
805 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
809 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
810 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 ManualNetworkSelectionArgument selArg =
812 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
814 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
816 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null) {
823 request.result = true;
824 } else {
825 request.result = false;
826 loge("setNetworkSelectionModeManual " + ar.exception);
827 }
828 notifyRequester(request);
829 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 case CMD_GET_MODEM_ACTIVITY_INFO:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800835 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 break;
837
838 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 if (ar.exception == null && ar.result != null) {
842 request.result = ar.result;
843 } else {
844 if (ar.result == null) {
845 loge("queryModemActivityInfo: Empty response");
846 } else if (ar.exception instanceof CommandException) {
847 loge("queryModemActivityInfo: CommandException: " +
848 ar.exception);
849 } else {
850 loge("queryModemActivityInfo: Unknown exception");
851 }
852 }
Amit Mahajand4766222016-01-28 15:28:28 -0800853 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
854 if (request.result == null) {
855 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
856 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700857 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 break;
859
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 case CMD_SET_ALLOWED_CARRIERS:
861 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800862 CarrierRestrictionRules argument =
863 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800865 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
868 case EVENT_SET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800874 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
875 if (ar.exception instanceof CommandException) {
876 loge("setAllowedCarriers: CommandException: " + ar.exception);
877 CommandException.Error error =
878 ((CommandException) (ar.exception)).getCommandError();
879 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
880 request.result =
881 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
882 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 } else {
884 loge("setAllowedCarriers: Unknown exception");
885 }
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
890 case CMD_GET_ALLOWED_CARRIERS:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800893 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_GET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800902 request.result = new IllegalStateException(
903 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 if (ar.result == null) {
905 loge("getAllowedCarriers: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("getAllowedCarriers: CommandException: " +
908 ar.exception);
909 } else {
910 loge("getAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
922 request.result = new IllegalArgumentException(
923 "Failed to retrieve Forbidden Plmns");
924 if (ar.result == null) {
925 loge("getForbiddenPlmns: Empty response");
926 } else {
927 loge("getForbiddenPlmns: Unknown exception");
928 }
929 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932
933 case CMD_GET_FORBIDDEN_PLMNS:
934 request = (MainThreadRequest) msg.obj;
935 uiccCard = getUiccCardFromRequest(request);
936 if (uiccCard == null) {
937 loge("getForbiddenPlmns() UiccCard is null");
938 request.result = new IllegalArgumentException(
939 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700940 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 break;
942 }
943 Integer appType = (Integer) request.argument;
944 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
945 if (uiccApp == null) {
946 loge("getForbiddenPlmns() no app with specified type -- "
947 + appType);
948 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951 } else {
952 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
953 + " specified type -- " + appType);
954 }
955 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
956 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
957 onCompleted);
958 break;
959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000960 case CMD_SWITCH_SLOTS:
961 request = (MainThreadRequest) msg.obj;
962 int[] physicalSlots = (int[]) request.argument;
963 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
964 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
965 break;
966
967 case EVENT_SWITCH_SLOTS_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700971 notifyRequester(request);
972 break;
973 case CMD_GET_NETWORK_SELECTION_MODE:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
976 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
977 break;
978
979 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception != null) {
983 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
984 } else {
985 int mode = ((int[]) ar.result)[0];
986 if (mode == 0) {
987 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
988 } else {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000991 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700992 notifyRequester(request);
993 break;
994 case CMD_GET_CDMA_ROAMING_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
997 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
998 break;
999 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1004 } else {
1005 request.result = ((int[]) ar.result)[0];
1006 }
1007 notifyRequester(request);
1008 break;
1009 case CMD_SET_CDMA_ROAMING_MODE:
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1012 int mode = (int) request.argument;
1013 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1014 break;
1015 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 request.result = ar.exception == null;
1019 notifyRequester(request);
1020 break;
1021 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1024 int subscriptionMode = (int) request.argument;
1025 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1026 break;
1027 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 request.result = ar.exception == null;
1031 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001032 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001033 case CMD_GET_ALL_CELL_INFO:
1034 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001036 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 case EVENT_GET_ALL_CELL_INFO_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001041 // If a timeout occurs, the response will be null
1042 request.result = (ar.exception == null && ar.result != null)
1043 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 synchronized (request) {
1045 request.notifyAll();
1046 }
1047 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 case CMD_REQUEST_CELL_INFO_UPDATE:
1049 request = (MainThreadRequest) msg.obj;
1050 request.phone.requestCellInfoUpdate(request.workSource,
1051 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1052 break;
1053 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1057 try {
1058 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001060 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1061 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001064 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 } else {
1066 // use the result as returned
1067 cb.onCellInfo((List<CellInfo>) ar.result);
1068 }
1069 } catch (RemoteException re) {
1070 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1071 }
1072 break;
1073 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001074 request = (MainThreadRequest) msg.obj;
1075 WorkSource ws = (WorkSource) request.argument;
1076 Phone phone = getPhoneFromRequest(request);
1077 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1078 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 if (ar.exception == null) {
1083 request.result = ar.result;
1084 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1087 ? new CdmaCellLocation() : new GsmCellLocation();
1088 }
1089
1090 synchronized (request) {
1091 request.notifyAll();
1092 }
1093 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001094 case CMD_MODEM_REBOOT:
1095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001097 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001098 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001099 case EVENT_CMD_MODEM_REBOOT_DONE:
1100 handleNullReturnEvent(msg, "rebootModem");
1101 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001102 case CMD_REQUEST_ENABLE_MODEM:
1103 request = (MainThreadRequest) msg.obj;
1104 boolean enable = (boolean) request.argument;
1105 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001106 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001107 PhoneConfigurationManager.getInstance()
1108 .enablePhone(request.phone, enable, onCompleted);
1109 break;
1110 case EVENT_ENABLE_MODEM_DONE:
1111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 request.result = (ar.exception == null);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001114 //update the cache as modem status has changed
1115 mPhoneConfigurationManager.addToPhoneStatusCache(
1116 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -08001117 updateModemStateMetrics();
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001118 notifyRequester(request);
1119 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 default:
1121 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1122 break;
1123 }
1124 }
Jake Hambye994d462014-02-03 13:10:13 -08001125
Pengquan Menga1bb6272018-09-06 09:59:22 -07001126 private void notifyRequester(MainThreadRequest request) {
1127 synchronized (request) {
1128 request.notifyAll();
1129 }
1130 }
1131
Jake Hambye994d462014-02-03 13:10:13 -08001132 private void handleNullReturnEvent(Message msg, String command) {
1133 AsyncResult ar = (AsyncResult) msg.obj;
1134 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1135 if (ar.exception == null) {
1136 request.result = true;
1137 } else {
1138 request.result = false;
1139 if (ar.exception instanceof CommandException) {
1140 loge(command + ": CommandException: " + ar.exception);
1141 } else {
1142 loge(command + ": Unknown exception");
1143 }
1144 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001145 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 }
1148
1149 /**
1150 * Posts the specified command to be executed on the main thread,
1151 * waits for the request to complete, and returns the result.
1152 * @see #sendRequestAsync
1153 */
1154 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001155 return sendRequest(
1156 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
1164 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1165 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001166 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001167 }
1168
1169 /**
1170 * Posts the specified command to be executed on the main thread,
1171 * waits for the request to complete, and returns the result.
1172 * @see #sendRequestAsync
1173 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001174 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001175 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001176 }
1177
1178 /**
1179 * Posts the specified command to be executed on the main thread,
1180 * waits for the request to complete, and returns the result.
1181 * @see #sendRequestAsync
1182 */
Nathan Harold92bed182018-10-12 18:16:49 -07001183 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1184 return sendRequest(command, argument, subId, null, workSource);
1185 }
1186
1187 /**
1188 * Posts the specified command to be executed on the main thread,
1189 * waits for the request to complete, and returns the result.
1190 * @see #sendRequestAsync
1191 */
1192 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1193 return sendRequest(
1194 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1195 }
1196
1197 /**
1198 * Posts the specified command to be executed on the main thread,
1199 * waits for the request to complete, and returns the result.
1200 * @see #sendRequestAsync
1201 */
1202 private Object sendRequest(
1203 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1205 throw new RuntimeException("This method will deadlock if called from the main thread.");
1206 }
1207
Nathan Harold92bed182018-10-12 18:16:49 -07001208 MainThreadRequest request = null;
1209 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1210 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1211 } else if (phone != null) {
1212 request = new MainThreadRequest(argument, phone, workSource);
1213 } else {
1214 request = new MainThreadRequest(argument, subId, workSource);
1215 }
1216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 Message msg = mMainThreadHandler.obtainMessage(command, request);
1218 msg.sendToTarget();
1219
1220 // Wait for the request to complete
1221 synchronized (request) {
1222 while (request.result == null) {
1223 try {
1224 request.wait();
1225 } catch (InterruptedException e) {
1226 // Do nothing, go back and wait until the request is complete
1227 }
1228 }
1229 }
1230 return request.result;
1231 }
1232
1233 /**
1234 * Asynchronous ("fire and forget") version of sendRequest():
1235 * Posts the specified command to be executed on the main thread, and
1236 * returns immediately.
1237 * @see #sendRequest
1238 */
1239 private void sendRequestAsync(int command) {
1240 mMainThreadHandler.sendEmptyMessage(command);
1241 }
1242
1243 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001244 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 */
1247 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 sendRequestAsync(command, argument, null, null);
1249 }
1250
1251 /**
1252 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1253 * @see {@link #sendRequest(int,Object)}
1254 */
1255 private void sendRequestAsync(
1256 int command, Object argument, Phone phone, WorkSource workSource) {
1257 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001258 Message msg = mMainThreadHandler.obtainMessage(command, request);
1259 msg.sendToTarget();
1260 }
1261
1262 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 * Initialize the singleton PhoneInterfaceManager instance.
1264 * This is only done once, at startup, from PhoneApp.onCreate().
1265 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001266 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 synchronized (PhoneInterfaceManager.class) {
1268 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001269 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 } else {
1271 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1272 }
1273 return sInstance;
1274 }
1275 }
1276
1277 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001278 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001281 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1283 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001284 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001285 mTelephonySharedPreferences =
1286 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001287 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001288 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 publish();
1291 }
1292
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001293 private Phone getDefaultPhone() {
1294 Phone thePhone = getPhone(getDefaultSubscription());
1295 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1296 }
1297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 private void publish() {
1299 if (DBG) log("publish: " + this);
1300
1301 ServiceManager.addService("phone", this);
1302 }
1303
Stuart Scott584921c2015-01-15 17:10:34 -08001304 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001305 if (request.phone != null) {
1306 return request.phone;
1307 } else {
1308 return getPhoneFromSubId(request.subId);
1309 }
1310 }
1311
1312 private Phone getPhoneFromSubId(int subId) {
1313 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1314 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001315 }
1316
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001317 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1318 Phone phone = getPhoneFromRequest(request);
1319 return phone == null ? null :
1320 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1321 }
1322
Wink Saville36469e72014-06-11 15:17:00 -07001323 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001324 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001325 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327
1328 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 if (DBG) log("dial: " + number);
1334 // No permission check needed here: This is just a wrapper around the
1335 // ACTION_DIAL intent, which is available to any app since it puts up
1336 // the UI before it does anything.
1337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001338 final long identity = Binder.clearCallingIdentity();
1339 try {
1340 String url = createTelUrl(number);
1341 if (url == null) {
1342 return;
1343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001345 // PENDING: should we just silently fail if phone is offhook or ringing?
1346 PhoneConstants.State state = mCM.getState(subId);
1347 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1348 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1349 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1350 mApp.startActivity(intent);
1351 }
1352 } finally {
1353 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354 }
1355 }
1356
1357 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001358 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
Wink Savilleb564aae2014-10-23 10:18:09 -07001361 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 if (DBG) log("call: " + number);
1363
1364 // This is just a wrapper around the ACTION_CALL intent, but we still
1365 // need to do a permission check since we're calling startActivity()
1366 // from the context of the phone app.
1367 enforceCallPermission();
1368
1369 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1370 != AppOpsManager.MODE_ALLOWED) {
1371 return;
1372 }
1373
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001374 final long identity = Binder.clearCallingIdentity();
1375 try {
1376 String url = createTelUrl(number);
1377 if (url == null) {
1378 return;
1379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001381 boolean isValid = false;
1382 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1383 if (slist != null) {
1384 for (SubscriptionInfo subInfoRecord : slist) {
1385 if (subInfoRecord.getSubscriptionId() == subId) {
1386 isValid = true;
1387 break;
1388 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001389 }
Wink Saville08874612014-08-31 19:19:58 -07001390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001391 if (!isValid) {
1392 return;
1393 }
Wink Saville08874612014-08-31 19:19:58 -07001394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001395 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1396 intent.putExtra(SUBSCRIPTION_KEY, subId);
1397 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1398 mApp.startActivity(intent);
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
1401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001409 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001410 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1411 }
1412
1413 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001415 }
1416
Wink Savilleb564aae2014-10-23 10:18:09 -07001417 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001418 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001419 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1420 }
1421
1422 /** {@hide} */
1423 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001429
1430 final long identity = Binder.clearCallingIdentity();
1431 try {
1432 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1433 checkSimPin.start();
1434 return checkSimPin.unlockSim(null, pin);
1435 } finally {
1436 Binder.restoreCallingIdentity(identity);
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
Wink Saville9de0f752013-10-22 19:04:03 -07001440 /** {@hide} */
1441 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001442 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001443 }
1444
Wink Savilleb564aae2014-10-23 10:18:09 -07001445 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001447
1448 final long identity = Binder.clearCallingIdentity();
1449 try {
1450 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1451 checkSimPuk.start();
1452 return checkSimPuk.unlockSim(puk, pin);
1453 } finally {
1454 Binder.restoreCallingIdentity(identity);
1455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457
1458 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001459 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 * a synchronous one.
1461 */
1462 private static class UnlockSim extends Thread {
1463
1464 private final IccCard mSimCard;
1465
1466 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001467 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1468 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
1470 // For replies from SimCard interface
1471 private Handler mHandler;
1472
1473 // For async handler to identify request type
1474 private static final int SUPPLY_PIN_COMPLETE = 100;
1475
1476 public UnlockSim(IccCard simCard) {
1477 mSimCard = simCard;
1478 }
1479
1480 @Override
1481 public void run() {
1482 Looper.prepare();
1483 synchronized (UnlockSim.this) {
1484 mHandler = new Handler() {
1485 @Override
1486 public void handleMessage(Message msg) {
1487 AsyncResult ar = (AsyncResult) msg.obj;
1488 switch (msg.what) {
1489 case SUPPLY_PIN_COMPLETE:
1490 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1491 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001492 mRetryCount = msg.arg1;
1493 if (ar.exception != null) {
1494 if (ar.exception instanceof CommandException &&
1495 ((CommandException)(ar.exception)).getCommandError()
1496 == CommandException.Error.PASSWORD_INCORRECT) {
1497 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1498 } else {
1499 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1500 }
1501 } else {
1502 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 mDone = true;
1505 UnlockSim.this.notifyAll();
1506 }
1507 break;
1508 }
1509 }
1510 };
1511 UnlockSim.this.notifyAll();
1512 }
1513 Looper.loop();
1514 }
1515
1516 /*
1517 * Use PIN or PUK to unlock SIM card
1518 *
1519 * If PUK is null, unlock SIM card with PIN
1520 *
1521 * If PUK is not null, unlock SIM card with PUK and set PIN code
1522 */
Wink Saville9de0f752013-10-22 19:04:03 -07001523 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524
1525 while (mHandler == null) {
1526 try {
1527 wait();
1528 } catch (InterruptedException e) {
1529 Thread.currentThread().interrupt();
1530 }
1531 }
1532 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1533
1534 if (puk == null) {
1535 mSimCard.supplyPin(pin, callback);
1536 } else {
1537 mSimCard.supplyPuk(puk, pin, callback);
1538 }
1539
1540 while (!mDone) {
1541 try {
1542 Log.d(LOG_TAG, "wait for done");
1543 wait();
1544 } catch (InterruptedException e) {
1545 // Restore the interrupted status
1546 Thread.currentThread().interrupt();
1547 }
1548 }
1549 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001550 int[] resultArray = new int[2];
1551 resultArray[0] = mResult;
1552 resultArray[1] = mRetryCount;
1553 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555 }
1556
1557 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001558 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001559
1560 }
1561
Wink Savilleb564aae2014-10-23 10:18:09 -07001562 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 // No permission check needed here: this call is harmless, and it's
1564 // needed for the ServiceState.requestStateUpdate() call (which is
1565 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001566 final long identity = Binder.clearCallingIdentity();
1567 try {
1568 final Phone phone = getPhone(subId);
1569 if (phone != null) {
1570 phone.updateServiceLocation();
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
1576
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001577 @Override
1578 public boolean isRadioOn(String callingPackage) {
1579 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001580 }
1581
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001582 @Override
1583 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001585 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001586 return false;
1587 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001588
1589 final long identity = Binder.clearCallingIdentity();
1590 try {
1591 return isRadioOnForSubscriber(subId);
1592 } finally {
1593 Binder.restoreCallingIdentity(identity);
1594 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001595 }
1596
1597 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
1602 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1603 } else {
1604 return false;
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
1610
1611 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001612 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
Wink Saville36469e72014-06-11 15:17:00 -07001614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone != null) {
1622 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1623 }
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 }
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
1629 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001631 }
1632
Wink Savilleb564aae2014-10-23 10:18:09 -07001633 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001634 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001635
1636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 final Phone phone = getPhone(subId);
1639 if (phone == null) {
1640 return false;
1641 }
1642 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1643 toggleRadioOnOffForSubscriber(subId);
1644 }
1645 return true;
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
Wink Saville36469e72014-06-11 15:17:00 -07001650
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 public boolean needMobileRadioShutdown() {
1652 /*
1653 * If any of the Radios are available, it will need to be
1654 * shutdown. So return true if any Radio is available.
1655 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001656 final long identity = Binder.clearCallingIdentity();
1657 try {
1658 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1659 Phone phone = PhoneFactory.getPhone(i);
1660 if (phone != null && phone.isRadioAvailable()) return true;
1661 }
1662 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1663 return false;
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 }
1668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001669 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001671 enforceModifyPermission();
1672
1673 final long identity = Binder.clearCallingIdentity();
1674 try {
1675 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1676 logv("Shutting down Phone " + i);
1677 shutdownRadioUsingPhoneId(i);
1678 }
1679 } finally {
1680 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001681 }
1682 }
1683
1684 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001685 Phone phone = PhoneFactory.getPhone(phoneId);
1686 if (phone != null && phone.isRadioAvailable()) {
1687 phone.shutdownRadio();
1688 }
1689 }
1690
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001692 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1697 if (defaultPhone != null) {
1698 defaultPhone.setRadioPower(turnOn);
1699 return true;
1700 } else {
1701 loge("There's no default phone.");
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001706 }
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.setRadioPower(turnOn);
1717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Wink Saville36469e72014-06-11 15:17:00 -07001726 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public boolean enableDataConnectivity() {
1729 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001736 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001737 return true;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Wink Saville36469e72014-06-11 15:17:00 -07001746 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 public boolean disableDataConnectivity() {
1749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001750
1751 final long identity = Binder.clearCallingIdentity();
1752 try {
1753 int subId = mSubscriptionController.getDefaultDataSubId();
1754 final Phone phone = getPhone(subId);
1755 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001756 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757 return true;
1758 } else {
1759 return false;
1760 }
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001767 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001772 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001773 } else {
1774 return false;
1775 }
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
1781 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001782 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001783 }
1784
pkanwarae03a6b2016-11-06 20:37:09 -08001785 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 enforceCallPermission();
1787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1791 return;
1792 }
1793 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1794 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1795 } finally {
1796 Binder.restoreCallingIdentity(identity);
1797 }
pkanwar32d516d2016-10-14 19:37:38 -07001798 };
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1806 return false;
1807 }
1808 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001815 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001816 }
1817
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001818 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819 final long identity = Binder.clearCallingIdentity();
1820 try {
1821 Phone phone = PhoneFactory.getPhone(slotIndex);
1822 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1823 PhoneConstantConversions.convertCallState(phone.getState());
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
1826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 public int getDataState() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1834 if (phone != null) {
1835 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1836 } else {
1837 return PhoneConstantConversions.convertDataState(
1838 PhoneConstants.DataState.DISCONNECTED);
1839 }
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public int getDataActivity() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1850 if (phone != null) {
1851 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1852 } else {
1853 return TelephonyManager.DATA_ACTIVITY_NONE;
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
1860 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001861 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001862 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001863 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001864
1865 LocationAccessPolicy.LocationPermissionResult locationResult =
1866 LocationAccessPolicy.checkLocationPermission(mApp,
1867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1868 .setCallingPackage(callingPackage)
1869 .setCallingPid(Binder.getCallingPid())
1870 .setCallingUid(Binder.getCallingUid())
1871 .setMethod("getCellLocation")
1872 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1873 .build());
1874 switch (locationResult) {
1875 case DENIED_HARD:
1876 throw new SecurityException("Not allowed to access cell location");
1877 case DENIED_SOFT:
1878 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 }
1880
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001881 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 if (DBG_LOC) log("getCellLocation: is active user");
1885 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001886 int subId = mSubscriptionController.getDefaultDataSubId();
1887 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1888 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001889 return data;
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
1892 }
Svetoslav64fad262015-04-14 14:35:21 -07001893 }
1894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001896 public String getNetworkCountryIsoForPhone(int phoneId) {
1897 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1898 // registered cell info, so return a NULL country instead.
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001901 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1902 // Get default phone in this case.
1903 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1904 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001905 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001906 // Todo: fix this when we can get the actual cellular network info when the device
1907 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001908 if (TelephonyManager.NETWORK_TYPE_IWLAN
1909 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1910 return "";
1911 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001912 Phone phone = PhoneFactory.getPhone(phoneId);
1913 if (phone != null) {
1914 ServiceStateTracker sst = phone.getServiceStateTracker();
1915 if (sst != null) {
1916 LocaleTracker lt = sst.getLocaleTracker();
1917 if (lt != null) {
1918 return lt.getCurrentCountry();
1919 }
1920 }
1921 }
1922 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001926 }
1927
1928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001930 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001931 }
1932
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001934 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 mApp.enforceCallingOrSelfPermission(
1936 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937
1938 final long identity = Binder.clearCallingIdentity();
1939 try {
1940 final Phone phone = getPhone(subId);
1941 if (phone != null) {
1942 phone.enableLocationUpdates();
1943 }
1944 } finally {
1945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 @Override
1950 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001951 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952 }
1953
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001955 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 mApp.enforceCallingOrSelfPermission(
1957 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 phone.disableLocationUpdates();
1964 }
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Nathan Harold31d7ff32018-10-15 20:20:30 -07001970 /**
1971 * Returns the target SDK version number for a given package name.
1972 *
1973 * @return target SDK if the package is found or INT_MAX.
1974 */
1975 private int getTargetSdk(String packageName) {
1976 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001977 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1978 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001979 if (ai != null) return ai.targetSdkVersion;
1980 } catch (PackageManager.NameNotFoundException unexpected) {
1981 }
1982 return Integer.MAX_VALUE;
1983 }
1984
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 @Override
1986 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001987 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1988 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001989 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1990 throw new SecurityException(
1991 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1992 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001993
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1995 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1996 return null;
1997 }
Svetoslav64fad262015-04-14 14:35:21 -07001998
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001999 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000
Nathan Haroldf180aac2018-06-01 18:43:55 -07002001 List<CellInfo> info = getAllCellInfo(callingPackage);
2002 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003
Nathan Haroldf180aac2018-06-01 18:43:55 -07002004 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2005 for (CellInfo ci : info) {
2006 if (ci instanceof CellInfoGsm) {
2007 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2008 } else if (ci instanceof CellInfoWcdma) {
2009 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002012 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002015 private List<CellInfo> getCachedCellInfo() {
2016 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2017 for (Phone phone : PhoneFactory.getPhones()) {
2018 List<CellInfo> info = phone.getAllCellInfo();
2019 if (info != null) cellInfos.addAll(info);
2020 }
2021 return cellInfos;
2022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023
2024 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002025 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002026 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002027 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002028
2029 LocationAccessPolicy.LocationPermissionResult locationResult =
2030 LocationAccessPolicy.checkLocationPermission(mApp,
2031 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2032 .setCallingPackage(callingPackage)
2033 .setCallingPid(Binder.getCallingPid())
2034 .setCallingUid(Binder.getCallingUid())
2035 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002036 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002037 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2038 .build());
2039 switch (locationResult) {
2040 case DENIED_HARD:
2041 throw new SecurityException("Not allowed to access cell info");
2042 case DENIED_SOFT:
2043 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 }
2045
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002046 final int targetSdk = getTargetSdk(callingPackage);
2047 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2048 return getCachedCellInfo();
2049 }
2050
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002051 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002053 final long identity = Binder.clearCallingIdentity();
2054 try {
2055 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2056 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002057 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002058 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059 if (info != null) cellInfos.addAll(info);
2060 }
2061 return cellInfos;
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 }
2065 }
2066
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002067 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002068 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2069 requestCellInfoUpdateInternal(
2070 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2071 }
2072
2073 @Override
2074 public void requestCellInfoUpdateWithWorkSource(
2075 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2076 enforceModifyPermission();
2077 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2078 }
2079
2080 private void requestCellInfoUpdateInternal(
2081 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002082 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002084
2085 LocationAccessPolicy.LocationPermissionResult locationResult =
2086 LocationAccessPolicy.checkLocationPermission(mApp,
2087 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2088 .setCallingPackage(callingPackage)
2089 .setCallingPid(Binder.getCallingPid())
2090 .setCallingUid(Binder.getCallingUid())
2091 .setMethod("requestCellInfoUpdate")
2092 .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;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002099 }
2100
2101 final Phone phone = getPhone(subId);
2102 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2103
2104 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2105 }
2106
2107 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002109 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002114 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115 } finally {
2116 Binder.restoreCallingIdentity(identity);
2117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Shishir Agrawala9f32182016-04-12 12:00:16 -07002120 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002121 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002122 Phone phone = PhoneFactory.getPhone(slotIndex);
2123 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002124 return null;
2125 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002126 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002127 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2128 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002129 return null;
2130 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 return phone.getImei();
2135 } finally {
2136 Binder.restoreCallingIdentity(identity);
2137 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002138 }
2139
2140 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002141 public String getTypeAllocationCodeForSlot(int slotIndex) {
2142 Phone phone = PhoneFactory.getPhone(slotIndex);
2143 String tac = null;
2144 if (phone != null) {
2145 String imei = phone.getImei();
2146 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2147 }
2148 return tac;
2149 }
2150
2151 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002152 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002153 Phone phone = PhoneFactory.getPhone(slotIndex);
2154 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002155 return null;
2156 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002157
Jeff Davidson913390f2018-02-23 17:11:49 -08002158 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002159 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2160 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002161 return null;
2162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 return phone.getMeid();
2167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
Jack Yu2af8d712017-03-15 17:14:14 -07002170 }
2171
2172 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002173 public String getManufacturerCodeForSlot(int slotIndex) {
2174 Phone phone = PhoneFactory.getPhone(slotIndex);
2175 String manufacturerCode = null;
2176 if (phone != null) {
2177 String meid = phone.getMeid();
2178 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2179 }
2180 return manufacturerCode;
2181 }
2182
2183 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002184 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002185 Phone phone = PhoneFactory.getPhone(slotIndex);
2186 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002187 return null;
2188 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002189 int subId = phone.getSubId();
2190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2191 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2192 return null;
2193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 return phone.getDeviceSvn();
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002201 }
2202
fionaxu43304da2017-11-27 22:51:16 -08002203 @Override
2204 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
fionaxu43304da2017-11-27 22:51:16 -08002212 }
2213
2214 @Override
2215 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 final Phone phone = getPhone(subId);
2219 return phone == null ? null : phone.getCarrierName();
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
fionaxu43304da2017-11-27 22:51:16 -08002223 }
2224
calvinpanffe225e2018-11-01 19:43:06 +08002225 @Override
chen xu0026ca62019-03-06 15:28:50 -08002226 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 final Phone phone = getPhone(subId);
2230 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002231 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
2235 }
2236
2237 @Override
chen xu0026ca62019-03-06 15:28:50 -08002238 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002242 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002243 } finally {
2244 Binder.restoreCallingIdentity(identity);
2245 }
2246 }
2247
chen xu651eec72018-11-11 19:03:44 -08002248 @Override
chen xu864e11c2018-12-06 22:10:03 -08002249 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2250 if (!isSubscriptionMccMnc) {
2251 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2252 }
chen xu651eec72018-11-11 19:03:44 -08002253 final Phone phone = PhoneFactory.getPhone(slotIndex);
2254 if (phone == null) {
2255 return TelephonyManager.UNKNOWN_CARRIER_ID;
2256 }
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
2263 }
2264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 //
2266 // Internal helper methods.
2267 //
2268
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002269 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2271 *
2272 * @throws SecurityException if the caller does not have the required permission
2273 */
2274 private void enforceModifyPermission() {
2275 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2276 }
2277
2278 /**
2279 * Make sure the caller has the CALL_PHONE permission.
2280 *
2281 * @throws SecurityException if the caller does not have the required permission
2282 */
2283 private void enforceCallPermission() {
2284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2285 }
2286
Stuart Scott8eef64f2015-04-08 15:13:54 -07002287 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002288 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002289 "ConnectivityService");
2290 }
2291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 private String createTelUrl(String number) {
2293 if (TextUtils.isEmpty(number)) {
2294 return null;
2295 }
2296
Jake Hambye994d462014-02-03 13:10:13 -08002297 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Ihab Awadf9e92732013-12-05 18:02:52 -08002300 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2302 }
2303
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002304 private static void logv(String msg) {
2305 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2306 }
2307
Ihab Awadf9e92732013-12-05 18:02:52 -08002308 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2310 }
2311
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002314 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002318 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 final Phone phone = PhoneFactory.getPhone(slotIndex);
2322 if (phone == null) {
2323 return PhoneConstants.PHONE_TYPE_NONE;
2324 } else {
2325 return phone.getPhoneType();
2326 }
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
2332 /**
2333 * Returns the CDMA ERI icon index to display
2334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 @Override
2336 public int getCdmaEriIconIndex(String callingPackage) {
2337 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002341 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002344 return -1;
2345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
2350 if (phone != null) {
2351 return phone.getCdmaEriIconIndex();
2352 } else {
2353 return -1;
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 }
2359
2360 /**
2361 * Returns the CDMA ERI icon mode,
2362 * 0 - ON
2363 * 1 - FLASHING
2364 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002365 @Override
2366 public int getCdmaEriIconMode(String callingPackage) {
2367 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
2369
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002371 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002374 return -1;
2375 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 if (phone != null) {
2381 return phone.getCdmaEriIconMode();
2382 } else {
2383 return -1;
2384 }
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
2389
2390 /**
2391 * Returns the CDMA ERI text,
2392 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002393 @Override
2394 public String getCdmaEriText(String callingPackage) {
2395 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002396 }
2397
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002401 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 return null;
2403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
2408 if (phone != null) {
2409 return phone.getCdmaEriText();
2410 } else {
2411 return null;
2412 }
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417
2418 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002419 * Returns the CDMA MDN.
2420 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002422 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2424 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002429 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 return phone.getLine1Number();
2431 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002432 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433 return null;
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002437 }
2438 }
2439
2440 /**
2441 * Returns the CDMA MIN.
2442 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002444 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2446 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = getPhone(subId);
2451 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2452 return phone.getCdmaMin();
2453 } else {
2454 return null;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002458 }
2459 }
2460
Hall Liud892bec2018-11-30 14:51:45 -08002461 @Override
2462 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2463 INumberVerificationCallback callback, String callingPackage) {
2464 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2465 != PERMISSION_GRANTED) {
2466 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2467 }
2468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2469
2470 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2471 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2472 throw new SecurityException("Calling package must be configured in the device config");
2473 }
2474
2475 if (range == null) {
2476 throw new NullPointerException("Range must be non-null");
2477 }
2478
2479 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002480 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002481
2482 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2483 }
2484
Junda Liuca05d5d2014-08-14 22:36:34 -07002485 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 * Returns true if CDMA provisioning needs to run.
2487 */
2488 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002491 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496
2497 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002498 * Sets the voice mail number of a given subId.
2499 */
2500 @Override
2501 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002502 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2507 new Pair<String, String>(alphaTag, number), new Integer(subId));
2508 return success;
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002512 }
2513
Ta-wei Yen87c49842016-05-13 21:19:52 -07002514 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002515 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002517 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002518 if (!TextUtils.equals(callingPackage, systemDialer)) {
2519 throw new SecurityException("caller must be system dialer");
2520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2525 if (phoneAccountHandle == null) {
2526 return null;
2527 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002528 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002531 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002532 }
2533
2534 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002535 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002539 return null;
2540 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002542 final long identity = Binder.clearCallingIdentity();
2543 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002544 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002548 }
2549
2550 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002551 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2552 VisualVoicemailSmsFilterSettings settings) {
2553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002558 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002562 }
2563
2564 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002565 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002571 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002575 }
2576
2577 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002578 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2579 String callingPackage, int subId) {
2580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002585 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002589 }
2590
2591 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002592 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002593 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002598 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002602 }
2603
2604 @Override
2605 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2606 String number, int port, String text, PendingIntent sentIntent) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002608 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002609 enforceSendSmsPermission();
2610 // Make the calls as the phone process.
2611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2614 if (port == 0) {
2615 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2616 sentIntent, null, false);
2617 } else {
2618 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2619 smsManager.sendDataMessageWithSelfPermissions(number, null,
2620 (short) port, data, sentIntent, null);
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002625 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002626 /**
fionaxu0152e512016-11-14 13:36:14 -08002627 * Sets the voice activation state of a given subId.
2628 */
2629 @Override
2630 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2632 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = getPhone(subId);
2637 if (phone != null) {
2638 phone.setVoiceActivationState(activationState);
2639 } else {
2640 loge("setVoiceActivationState fails with invalid subId: " + subId);
2641 }
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002644 }
2645 }
2646
2647 /**
2648 * Sets the data activation state of a given subId.
2649 */
2650 @Override
2651 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2653 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
2659 phone.setDataActivationState(activationState);
2660 } else {
2661 loge("setVoiceActivationState fails with invalid subId: " + subId);
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002665 }
2666 }
2667
2668 /**
2669 * Returns the voice activation state of a given subId.
2670 */
2671 @Override
2672 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002673 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002674
fionaxu0152e512016-11-14 13:36:14 -08002675 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 if (phone != null) {
2679 return phone.getVoiceActivationState();
2680 } else {
2681 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Returns the data activation state of a given subId.
2690 */
2691 @Override
2692 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002693 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002694
fionaxu0152e512016-11-14 13:36:14 -08002695 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 if (phone != null) {
2699 return phone.getDataActivationState();
2700 } else {
2701 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002705 }
2706 }
2707
2708 /**
Wink Saville36469e72014-06-11 15:17:00 -07002709 * Returns the unread count of voicemails for a subId
2710 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002712 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2714 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2715 return 0;
2716 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 final Phone phone = getPhone(subId);
2720 if (phone != null) {
2721 return phone.getVoiceMessageCount();
2722 } else {
2723 return 0;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 }
2729
2730 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002731 * returns true, if the device is in a state where both voice and data
2732 * are supported simultaneously. This can change based on location or network condition.
2733 */
2734 @Override
2735 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 final Phone phone = getPhone(subId);
2739 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002743 }
2744
2745 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002746 * Send the dialer code if called from the current default dialer or the caller has
2747 * carrier privilege.
2748 * @param inputCode The dialer code to send
2749 */
2750 @Override
2751 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002754 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2755 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002756 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002757 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2758 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002759 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002763 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
fionaxu235cc5e2017-03-06 22:25:57 -08002767 }
2768
2769 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002770 * Returns the data network type.
2771 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 *
2773 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2774 */
2775 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002776 public int getNetworkType() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(getDefaultSubscription());
2780 if (phone != null) {
2781 return phone.getServiceState().getDataNetworkType();
2782 } else {
2783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002787 }
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Pengquan Menga1bb6272018-09-06 09:59:22 -07002790 @Override
2791 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002792 if (!isActiveSubscription(subId)) {
2793 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2794 }
2795
Pengquan Menga1bb6272018-09-06 09:59:22 -07002796 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2797 }
2798
Brad Ebinger35c841c2018-10-01 10:40:55 -07002799 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002800 public boolean isInEmergencySmsMode() {
2801 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2802 final long identity = Binder.clearCallingIdentity();
2803 try {
2804 for (Phone phone : PhoneFactory.getPhones()) {
2805 if (phone.isInEmergencySmsMode()) {
2806 return true;
2807 }
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
2811 }
2812 return false;
2813 }
2814
2815 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002816 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2817 throws RemoteException {
2818 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002819 final long token = Binder.clearCallingIdentity();
2820 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002822 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002823 .addRegistrationCallbackForSubscription(c, subId);
2824 } finally {
2825 Binder.restoreCallingIdentity(token);
2826 }
2827 }
2828
2829 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002830 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2831 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002832 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2833 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2834 }
2835 Binder.withCleanCallingIdentity(() -> {
2836 try {
2837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002838 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002839 .removeRegistrationCallbackForSubscription(c, subId);
2840 } catch (IllegalArgumentException e) {
2841 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2842 + "is inactive, ignoring unregister.");
2843 // If the subscription is no longer active, just return, since the callback
2844 // will already have been removed internally.
2845 }
2846 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002847 }
2848
2849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002850 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2851 throws RemoteException {
2852 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2854 final long token = Binder.clearCallingIdentity();
2855 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 .addCapabilitiesCallbackForSubscription(c, subId);
2858 } finally {
2859 Binder.restoreCallingIdentity(token);
2860 }
2861 }
2862
2863 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002864 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2865 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002866
2867 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2868 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2869 }
2870 Binder.withCleanCallingIdentity(() -> {
2871 try {
2872 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002873 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002874 .removeCapabilitiesCallbackForSubscription(c, subId);
2875 } catch (IllegalArgumentException e) {
2876 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2877 + "is inactive, ignoring unregister.");
2878 // If the subscription is no longer active, just return, since the callback
2879 // will already have been removed internally.
2880 }
2881 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002882 }
2883
2884 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002885 public boolean isCapable(int subId, int capability, int regTech) {
2886 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2888 final long token = Binder.clearCallingIdentity();
2889 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002890 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002891 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2892 } catch (ImsException e) {
2893 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2894 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002895 } catch (IllegalArgumentException e) {
2896 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2897 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 } finally {
2899 Binder.restoreCallingIdentity(token);
2900 }
2901 }
2902
2903 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002904 public boolean isAvailable(int subId, int capability, int regTech) {
2905 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002906 final long token = Binder.clearCallingIdentity();
2907 try {
2908 Phone phone = getPhone(subId);
2909 if (phone == null) return false;
2910 return phone.isImsCapabilityAvailable(capability, regTech);
2911 } finally {
2912 Binder.restoreCallingIdentity(token);
2913 }
2914 }
2915
2916 @Override
2917 public boolean isAdvancedCallingSettingEnabled(int subId) {
2918 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2920 final long token = Binder.clearCallingIdentity();
2921 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2924 } finally {
2925 Binder.restoreCallingIdentity(token);
2926 }
2927 }
2928
2929 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002930 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002932 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002944 public boolean isVtSettingEnabled(int subId) {
2945 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002949 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002950 getSlotIndexOrException(subId)).isVtEnabledByUser();
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002957 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002959 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002963 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public boolean isVoWiFiSettingEnabled(int subId) {
2971 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002975 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002976 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2977 } finally {
2978 Binder.restoreCallingIdentity(identity);
2979 }
2980 }
2981
2982 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002983 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002985 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 }
2994
2995 @Override
2996 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2997 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003001 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003002 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3003 } finally {
3004 Binder.restoreCallingIdentity(identity);
3005 }
3006 }
3007
3008 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003009 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003011 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003015 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003016 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 @Override
3023 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3025 "setVoWiFiNonPersistent");
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003029 boolean isRoaming = TelephonyManager.from(
3030 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003032 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
3036 }
3037
3038 @Override
3039 public int getVoWiFiModeSetting(int subId) {
3040 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3041 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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 @Override
3052 public void setVoWiFiModeSetting(int subId, int mode) {
3053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3054 "setVoWiFiModeSetting");
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 Ebinger35c841c2018-10-01 10:40:55 -07003059 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
3066 public int getVoWiFiRoamingModeSetting(int subId) {
3067 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
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(true /*isRoaming*/);
3073 } finally {
3074 Binder.restoreCallingIdentity(identity);
3075 }
3076 }
3077
3078 @Override
3079 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3081 "setVoWiFiRoamingModeSetting");
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, true /*isRoaming*/);
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
3092 @Override
3093 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3095 "setRttCapabilityEnabled");
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003099 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003100 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public boolean isTtyOverVolteEnabled(int subId) {
3108 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
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 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003113 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003119 @Override
3120 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3121 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3122 final long identity = Binder.clearCallingIdentity();
3123 try {
3124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003126 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003127 } finally {
3128 Binder.restoreCallingIdentity(identity);
3129 }
3130 }
3131
3132 @Override
3133 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3134 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3135 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003136 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3137 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3138 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003139 try {
3140 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003142 .removeProvisioningCallbackForSubscription(callback, subId);
3143 } catch (IllegalArgumentException e) {
3144 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3145 + "is inactive, ignoring unregister.");
3146 // If the subscription is no longer active, just return, since the callback will already
3147 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 }
3152
3153 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003154 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3155 boolean isProvisioned) {
3156 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3157 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3158 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3159 }
3160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3161 "setProvisioningStatusForCapability");
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3165 Phone phone = getPhone(subId);
3166 if (phone == null) {
3167 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3168 + subId);
3169 return;
3170 }
3171 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3172 return;
3173 }
3174
3175 // this capability requires provisioning, route to the correct API.
3176 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3177 switch (capability) {
3178 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3179 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3180 ims.setVolteProvisioned(isProvisioned);
3181 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3182 ims.setWfcProvisioned(isProvisioned);
3183 }
3184 break;
3185 }
3186 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3187 // There is currently no difference in VT provisioning type.
3188 ims.setVtProvisioned(isProvisioned);
3189 break;
3190 }
3191 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3192 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3193 // change the capability of the feature instead if needed.
3194 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3195 == isProvisioned) {
3196 // No change in provisioning.
3197 return;
3198 }
3199 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3200 try {
3201 ims.changeMmTelCapability(capability, tech, isProvisioned);
3202 } catch (ImsException e) {
3203 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3204 + ", Exception" + e.getMessage());
3205 }
3206 break;
3207 }
3208 default: {
3209 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3210 + capability + "', which does not require provisioning.");
3211 }
3212 }
3213
3214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
3220 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3221 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3222 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3223 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3224 }
3225 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3229 Phone phone = getPhone(subId);
3230 if (phone == null) {
3231 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3232 + subId);
3233 // We will fail with "true" as the provisioning status because this is the default
3234 // if we do not require provisioning.
3235 return true;
3236 }
3237
3238 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3239 return true;
3240 }
3241
3242 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3243 switch (capability) {
3244 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3245 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3246 return ims.isVolteProvisionedOnDevice();
3247 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3248 return ims.isWfcProvisionedOnDevice();
3249 }
3250 // This should never happen, since we are checking tech above to make sure it
3251 // is either LTE or IWLAN.
3252 throw new IllegalArgumentException("Invalid radio technology for voice "
3253 + "capability.");
3254 }
3255 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3256 // There is currently no difference in VT provisioning type.
3257 return ims.isVtProvisionedOnDevice();
3258 }
3259 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3260 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3261 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3262 }
3263 default: {
3264 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3265 + capability + "', which does not require provisioning.");
3266 }
3267 }
3268
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
3272 }
3273
3274 @Override
3275 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3276 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3277 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3278 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3279 }
3280 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3281 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3282 return (provisionedBits & capability) > 0;
3283 }
3284
3285 @Override
3286 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3287 boolean isProvisioned) {
3288 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3289 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3290 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3291 }
3292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3293 "setProvisioningStatusForCapability");
3294 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3295 // If the current provisioning status for capability already matches isProvisioned,
3296 // do nothing.
3297 if (((provisionedBits & capability) > 0) == isProvisioned) {
3298 return;
3299 }
3300 if (isProvisioned) {
3301 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3302 } else {
3303 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3304 }
3305 }
3306
3307 /**
3308 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3309 * technology. The bitfield should mirror the bitfield defined by
3310 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3311 */
3312 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3313 String key = getMmTelProvisioningKey(subId, tech);
3314 // Default is no capabilities are provisioned.
3315 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3316 }
3317
3318 /**
3319 * Sets the MmTel capability provisioning bitfield (defined by
3320 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3321 * technology specified.
3322 *
3323 * Note: This is a synchronous command and should not be called on UI thread.
3324 */
3325 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3326 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3327 String key = getMmTelProvisioningKey(subId, tech);
3328 editor.putInt(key, newField);
3329 editor.commit();
3330 }
3331
3332 private static String getMmTelProvisioningKey(int subId, int tech) {
3333 // resulting key is provision_ims_mmtel_{subId}_{tech}
3334 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3335 }
3336
3337 /**
3338 * Query CarrierConfig to see if the specified capability requires provisioning for the
3339 * carrier associated with the subscription id.
3340 */
3341 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3342 int capability) {
3343 CarrierConfigManager configManager = new CarrierConfigManager(context);
3344 PersistableBundle c = configManager.getConfigForSubId(subId);
3345 boolean requireUtProvisioning = c.getBoolean(
3346 // By default, this config is true (even if there is no SIM). We also check to make
3347 // sure the subscription needs provisioning here, so we do not need to check for
3348 // the no-SIM case, where we would normally shortcut this to false.
3349 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3350 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3351 false);
3352 boolean requireVoiceVtProvisioning = c.getBoolean(
3353 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3354
3355 // First check to make sure that the capability requires provisioning.
3356 switch (capability) {
3357 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3358 // intentional fallthrough
3359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3360 if (requireVoiceVtProvisioning) {
3361 // Voice and Video requires provisioning
3362 return true;
3363 }
3364 break;
3365 }
3366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3367 if (requireUtProvisioning) {
3368 // UT requires provisioning
3369 return true;
3370 }
3371 break;
3372 }
3373 }
3374 return false;
3375 }
3376
3377 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003378 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003379 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3380 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3381 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003382 enforceReadPrivilegedPermission("getImsProvisioningInt");
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003386 int slotId = getSlotIndex(subId);
3387 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3388 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3389 + subId + "' for key:" + key);
3390 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3391 }
3392 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003393 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003394 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3395 + subId + "' for key:" + key);
3396 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
3403 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003404 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3405 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3406 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003407 enforceReadPrivilegedPermission("getImsProvisioningString");
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 int slotId = getSlotIndex(subId);
3412 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3413 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3414 + subId + "' for key:" + key);
3415 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3416 }
3417 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003419 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3420 + subId + "' for key:" + key);
3421 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
3427 @Override
3428 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3430 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3431 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3433 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 int slotId = getSlotIndex(subId);
3438 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3439 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3440 + subId + "' for key:" + key);
3441 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3442 }
3443 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003445 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3446 + "' for key:" + key);
3447 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
3453 @Override
3454 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3456 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3457 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3459 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003463 int slotId = getSlotIndex(subId);
3464 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3465 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3466 + subId + "' for key:" + key);
3467 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3468 }
3469 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3472 + "' for key:" + key);
3473 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003474 } finally {
3475 Binder.restoreCallingIdentity(identity);
3476 }
3477 }
3478
Brad Ebinger35c841c2018-10-01 10:40:55 -07003479 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3480 int slotId = SubscriptionManager.getSlotIndex(subId);
3481 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003482 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003483 }
3484 return slotId;
3485 }
3486
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003487 private int getSlotIndex(int subId) {
3488 int slotId = SubscriptionManager.getSlotIndex(subId);
3489 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3490 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3491 }
3492 return slotId;
3493 }
3494
Wink Saville36469e72014-06-11 15:17:00 -07003495 /**
3496 * Returns the network type for a subId
3497 */
3498 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003501 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3503 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003504
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 final Phone phone = getPhone(subId);
3508 if (phone != null) {
3509 return phone.getServiceState().getDataNetworkType();
3510 } else {
3511 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3512 }
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 }
3517
3518 /**
3519 * Returns the data network type
3520 */
3521 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 public int getDataNetworkType(String callingPackage) {
3523 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003524 }
3525
3526 /**
3527 * Returns the data network type for a subId
3528 */
3529 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003530 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003532 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003533 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3534 }
3535
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003536 final long identity = Binder.clearCallingIdentity();
3537 try {
3538 final Phone phone = getPhone(subId);
3539 if (phone != null) {
3540 return phone.getServiceState().getDataNetworkType();
3541 } else {
3542 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3543 }
3544 } finally {
3545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003547 }
3548
3549 /**
Wink Saville36469e72014-06-11 15:17:00 -07003550 * Returns the Voice network type for a subId
3551 */
3552 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003553 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003554 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003555 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003556 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3557 }
3558
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = getPhone(subId);
3562 if (phone != null) {
3563 return phone.getServiceState().getVoiceNetworkType();
3564 } else {
3565 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3566 }
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003570 }
3571
3572 /**
3573 * @return true if a ICC card is present
3574 */
3575 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003576 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003577 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3578 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003579 }
3580
3581 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003582 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003583 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003585 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 final Phone phone = PhoneFactory.getPhone(slotIndex);
3589 if (phone != null) {
3590 return phone.getIccCard().hasIccCard();
3591 } else {
3592 return false;
3593 }
3594 } finally {
3595 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003596 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003597 }
3598
3599 /**
3600 * Return if the current radio is LTE on CDMA. This
3601 * is a tri-state return value as for a period of time
3602 * the mode may be unknown.
3603 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003604 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003605 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003606 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003608 @Override
3609 public int getLteOnCdmaMode(String callingPackage) {
3610 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003611 }
3612
Sanket Padawe356d7632015-06-22 14:03:32 -07003613 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003614 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003616 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003617 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3618 }
3619
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 final Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3625 } else {
3626 return phone.getLteOnCdmaMode();
3627 }
3628 } finally {
3629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003630 }
Wink Saville36469e72014-06-11 15:17:00 -07003631 }
3632
Wink Saville36469e72014-06-11 15:17:00 -07003633 /**
3634 * {@hide}
3635 * Returns Default subId, 0 in the case of single standby.
3636 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003637 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003638 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003639 }
3640
Shishir Agrawala9f32182016-04-12 12:00:16 -07003641 private int getSlotForDefaultSubscription() {
3642 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3643 }
3644
Wink Savilleb564aae2014-10-23 10:18:09 -07003645 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003646 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003647 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003648
Pengquan Menge92a50d2018-09-21 15:54:48 -07003649 private boolean isActiveSubscription(int subId) {
3650 return mSubscriptionController.isActiveSubId(subId);
3651 }
3652
Ihab Awadf2177b72013-11-25 13:33:23 -08003653 /**
3654 * @see android.telephony.TelephonyManager.WifiCallingChoices
3655 */
3656 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657 final long identity = Binder.clearCallingIdentity();
3658 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003659 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003660 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3661 getWhenToMakeWifiCallsDefaultPreference());
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003665 }
3666
3667 /**
3668 * @see android.telephony.TelephonyManager.WifiCallingChoices
3669 */
3670 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003675 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003679 }
3680
Sailesh Nepald1e68152013-12-12 19:08:02 -08003681 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003682 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003683 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003684 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003685
Jordan Liu4c733742019-02-28 12:03:40 -08003686 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3687 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3688 if (phoneId == -1) {
3689 throw new IllegalArgumentException("Given slot index: " + slotIndex
3690 + " does not correspond to an active phone");
3691 }
3692 return PhoneFactory.getPhone(phoneId);
3693 }
3694
Shishir Agrawal566b7612013-10-28 14:41:00 -07003695 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003696 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3697 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3699 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003700 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003701 if (DBG) {
3702 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3703 }
3704 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3705 p2);
3706 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003707
Jordan Liu4c733742019-02-28 12:03:40 -08003708
3709 @Override
3710 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3711 int slotIndex, String callingPackage, String aid, int p2) {
3712 enforceModifyPermission();
3713 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3714 if (DBG) {
3715 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3716 }
3717 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3718 callingPackage, aid, p2);
3719 }
3720
3721 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3722 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003723 final long identity = Binder.clearCallingIdentity();
3724 try {
3725 if (TextUtils.equals(ISDR_AID, aid)) {
3726 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3728 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 if (bestComponent == null
3730 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3731 loge("The calling package is not allowed to access ISD-R.");
3732 throw new SecurityException(
3733 "The calling package is not allowed to access ISD-R.");
3734 }
Derek Tan740e1672017-06-27 14:56:27 -07003735 }
Derek Tan740e1672017-06-27 14:56:27 -07003736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003737 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003738 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3739 null /* workSource */);
3740 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003741 return response;
3742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003745 }
3746
3747 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003748 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3750 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003751 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3752 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3753 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003754
Jordan Liu4c733742019-02-28 12:03:40 -08003755 @Override
3756 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3757 enforceModifyPermission();
3758 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3759 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3760 channel);
3761 }
3762
3763 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003764 final long identity = Binder.clearCallingIdentity();
3765 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003766 if (channel < 0) {
3767 return false;
3768 }
Jordan Liu4c733742019-02-28 12:03:40 -08003769 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3770 null /* workSource */);
3771 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 return success;
3773 } finally {
3774 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003775 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003776 }
3777
3778 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003779 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003780 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003781 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3782 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003783 if (DBG) {
3784 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3785 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3786 + p3 + " data=" + data);
3787 }
3788 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3789 command, p1, p2, p3, data);
3790 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003791
Jordan Liu4c733742019-02-28 12:03:40 -08003792 @Override
3793 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3794 int command, int p1, int p2, int p3, String data) {
3795 enforceModifyPermission();
3796 if (DBG) {
3797 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3798 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3799 + p3 + " data=" + data);
3800 }
3801 return iccTransmitApduLogicalChannelWithPermission(
3802 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3803 data);
3804 }
3805
3806 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3807 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003810 if (channel < 0) {
3811 return "";
3812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003814 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003815 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3816 null /* workSource */);
3817 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003818
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003819 // Append the returned status code to the end of the response payload.
3820 String s = Integer.toHexString(
3821 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3822 if (response.payload != null) {
3823 s = IccUtils.bytesToHexString(response.payload) + s;
3824 }
3825 return s;
3826 } finally {
3827 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003828 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003829 }
Jake Hambye994d462014-02-03 13:10:13 -08003830
Evan Charltonc66da362014-05-16 14:06:40 -07003831 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003832 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3833 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3835 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003836 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003837 if (DBG) {
3838 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3839 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3840 }
3841 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3842 cla, command, p1, p2, p3, data);
3843 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003844
Jordan Liu4c733742019-02-28 12:03:40 -08003845 @Override
3846 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3847 int command, int p1, int p2, int p3, String data) {
3848 enforceModifyPermission();
3849 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3850 if (DBG) {
3851 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3852 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3853 + " data=" + data);
3854 }
3855
3856 return iccTransmitApduBasicChannelWithPermission(
3857 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3858 p2, p3, data);
3859 }
3860
3861 // open APDU basic channel assuming the caller has sufficient permissions
3862 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3863 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3867 && TextUtils.equals(ISDR_AID, data)) {
3868 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3870 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003871 if (bestComponent == null
3872 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3873 loge("The calling package is not allowed to select ISD-R.");
3874 throw new SecurityException(
3875 "The calling package is not allowed to select ISD-R.");
3876 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003877 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003880 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3881 null /* workSource */);
3882 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003883
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003884 // Append the returned status code to the end of the response payload.
3885 String s = Integer.toHexString(
3886 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3887 if (response.payload != null) {
3888 s = IccUtils.bytesToHexString(response.payload) + s;
3889 }
3890 return s;
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003893 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003894 }
3895
3896 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003897 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003898 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3900 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003901
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 if (DBG) {
3905 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3906 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3907 }
3908
3909 IccIoResult response =
3910 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3911 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3912 subId);
3913
3914 if (DBG) {
3915 log("Exchange SIM_IO [R]" + response);
3916 }
3917
3918 byte[] result = null;
3919 int length = 2;
3920 if (response.payload != null) {
3921 length = 2 + response.payload.length;
3922 result = new byte[length];
3923 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3924 } else {
3925 result = new byte[length];
3926 }
3927
3928 result[length - 1] = (byte) response.sw2;
3929 result[length - 2] = (byte) response.sw1;
3930 return result;
3931 } finally {
3932 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003933 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003934 }
3935
Nathan Haroldb3014052017-01-25 15:57:32 -08003936 /**
3937 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3938 * on a particular subscription
3939 */
sqianb6e41952018-03-12 14:54:01 -07003940 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3942 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3943 return null;
3944 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003945
3946 final long identity = Binder.clearCallingIdentity();
3947 try {
3948 if (appType != TelephonyManager.APPTYPE_USIM
3949 && appType != TelephonyManager.APPTYPE_SIM) {
3950 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3951 return null;
3952 }
3953 Object response = sendRequest(
3954 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3955 if (response instanceof String[]) {
3956 return (String[]) response;
3957 }
3958 // Response is an Exception of some kind,
3959 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003960 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003963 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003964 }
3965
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003966 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003967 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3969 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003970
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003971 final long identity = Binder.clearCallingIdentity();
3972 try {
3973 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3974 if (response.payload == null) {
3975 return "";
3976 }
Evan Charltonc66da362014-05-16 14:06:40 -07003977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 // Append the returned status code to the end of the response payload.
3979 String s = Integer.toHexString(
3980 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3981 s = IccUtils.bytesToHexString(response.payload) + s;
3982 return s;
3983 } finally {
3984 Binder.restoreCallingIdentity(identity);
3985 }
Evan Charltonc66da362014-05-16 14:06:40 -07003986 }
3987
Jake Hambye994d462014-02-03 13:10:13 -08003988 /**
3989 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3990 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3991 *
3992 * @param itemID the ID of the item to read
3993 * @return the NV item as a String, or null on error.
3994 */
3995 @Override
3996 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003997 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3999 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004000
4001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004004 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004005 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4006 return value;
4007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
Jake Hambye994d462014-02-03 13:10:13 -08004010 }
4011
4012 /**
4013 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4014 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4015 *
4016 * @param itemID the ID of the item to read
4017 * @param itemValue the value to write, as a String
4018 * @return true on success; false on any failure
4019 */
4020 @Override
4021 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004022 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004023 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4024 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004025
4026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4029 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004030 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004031 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4032 return success;
4033 } finally {
4034 Binder.restoreCallingIdentity(identity);
4035 }
Jake Hambye994d462014-02-03 13:10:13 -08004036 }
4037
4038 /**
4039 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4040 * Used for device configuration by some CDMA operators.
4041 *
4042 * @param preferredRoamingList byte array containing the new PRL
4043 * @return true on success; false on any failure
4044 */
4045 @Override
4046 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4048 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004049
4050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4053 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4054 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4055 return success;
4056 } finally {
4057 Binder.restoreCallingIdentity(identity);
4058 }
Jake Hambye994d462014-02-03 13:10:13 -08004059 }
4060
4061 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004062 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004063 * Used for device configuration by some CDMA operators.
4064 *
chen xu6dac5ab2018-10-26 17:39:23 -07004065 * @param slotIndex - device slot.
4066 *
Jake Hambye994d462014-02-03 13:10:13 -08004067 * @return true on success; false on any failure
4068 */
4069 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004070 public boolean resetModemConfig(int slotIndex) {
4071 Phone phone = PhoneFactory.getPhone(slotIndex);
4072 if (phone != null) {
4073 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4074 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004075
chen xu6dac5ab2018-10-26 17:39:23 -07004076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4079 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4080 return success;
4081 } finally {
4082 Binder.restoreCallingIdentity(identity);
4083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004084 }
chen xu6dac5ab2018-10-26 17:39:23 -07004085 return false;
4086 }
4087
4088 /**
4089 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4090 *
4091 * @param slotIndex - device slot.
4092 *
4093 * @return true on success; false on any failure
4094 */
4095 @Override
4096 public boolean rebootModem(int slotIndex) {
4097 Phone phone = PhoneFactory.getPhone(slotIndex);
4098 if (phone != null) {
4099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4100 mApp, phone.getSubId(), "rebootModem");
4101
4102 final long identity = Binder.clearCallingIdentity();
4103 try {
4104 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4105 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4106 return success;
4107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
4110 }
4111 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004112 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004113
Svet Ganovb320e182015-04-16 12:30:10 -07004114 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004118 return new String[0];
4119 }
4120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004121 final long identity = Binder.clearCallingIdentity();
4122 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Wink Saville36469e72014-06-11 15:17:00 -07004127 }
4128
Brad Ebinger51f743a2017-01-23 13:50:20 -08004129 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004130 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4131 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004132 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004133 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004138 ImsResolver resolver = PhoneFactory.getImsResolver();
4139 if (resolver == null) {
4140 // may happen if the device does not support IMS.
4141 return;
4142 }
4143 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004147 }
4148
4149 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004150 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4151 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004152 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004153 public void disableIms(int slotId) {
4154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155
4156 final long identity = Binder.clearCallingIdentity();
4157 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004158 ImsResolver resolver = PhoneFactory.getImsResolver();
4159 if (resolver == null) {
4160 // may happen if the device does not support IMS.
4161 return;
4162 }
4163 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004164 } finally {
4165 Binder.restoreCallingIdentity(identity);
4166 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004167 }
4168
4169 /**
4170 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4171 * feature or {@link null} if the service is not available. If the feature is available, the
4172 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4173 */
4174 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004175 IImsServiceFeatureCallback callback) {
4176 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004177
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004180 ImsResolver resolver = PhoneFactory.getImsResolver();
4181 if (resolver == null) {
4182 // may happen if the device does not support IMS.
4183 return null;
4184 }
4185 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004189 }
4190
4191 /**
4192 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4193 * feature during emergency calling or {@link null} if the service is not available. If the
4194 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4195 * listener for feature updates.
4196 */
4197 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4198 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004199
4200 final long identity = Binder.clearCallingIdentity();
4201 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004202 ImsResolver resolver = PhoneFactory.getImsResolver();
4203 if (resolver == null) {
4204 // may happen if the device does not support IMS.
4205 return null;
4206 }
4207 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004211 }
4212
Brad Ebinger5f64b052017-12-14 14:26:15 -08004213 /**
4214 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004215 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004216 */
4217 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4218 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004219
4220 final long identity = Binder.clearCallingIdentity();
4221 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004222 ImsResolver resolver = PhoneFactory.getImsResolver();
4223 if (resolver == null) {
4224 // may happen if the device does not support IMS.
4225 return null;
4226 }
4227 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004231 }
4232
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004233 /**
4234 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004235 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004236 */
4237 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4238 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004239
4240 final long identity = Binder.clearCallingIdentity();
4241 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004242 ImsResolver resolver = PhoneFactory.getImsResolver();
4243 if (resolver == null) {
4244 // may happen if the device does not support IMS.
4245 return null;
4246 }
4247 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004248 } finally {
4249 Binder.restoreCallingIdentity(identity);
4250 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004251 }
4252
Brad Ebinger884c07b2018-02-15 16:17:40 -08004253 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004254 * Sets the ImsService Package Name that Telephony will bind to.
4255 *
4256 * @param slotId the slot ID that the ImsService should bind for.
4257 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4258 * ImsService is the device default ImsService.
4259 * @param packageName The package name of the application that contains the ImsService to bind
4260 * to.
4261 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4262 * @hide
4263 */
4264 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004265 int[] subIds = SubscriptionManager.getSubId(slotId);
4266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4267 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4268 "setImsService");
4269
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004270 final long identity = Binder.clearCallingIdentity();
4271 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004272 ImsResolver resolver = PhoneFactory.getImsResolver();
4273 if (resolver == null) {
4274 // may happen if the device does not support IMS.
4275 return false;
4276 }
4277 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4278 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279 } finally {
4280 Binder.restoreCallingIdentity(identity);
4281 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004282 }
4283
4284 /**
4285 * Return the ImsService configuration.
4286 *
4287 * @param slotId The slot that the ImsService is associated with.
4288 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4289 * the device default.
4290 * @return the package name of the ImsService configuration.
4291 */
4292 public String getImsService(int slotId, boolean isCarrierImsService) {
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 "getImsService");
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 "";
4304 }
4305 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 } finally {
4307 Binder.restoreCallingIdentity(identity);
4308 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004309 }
4310
Wink Saville36469e72014-06-11 15:17:00 -07004311 public void setImsRegistrationState(boolean registered) {
4312 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004313
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004316 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004317 } finally {
4318 Binder.restoreCallingIdentity(identity);
4319 }
Wink Saville36469e72014-06-11 15:17:00 -07004320 }
4321
4322 /**
Stuart Scott54788802015-03-30 13:18:01 -07004323 * Set the network selection mode to automatic.
4324 *
4325 */
4326 @Override
4327 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4329 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330
Pengquan Menge92a50d2018-09-21 15:54:48 -07004331 if (!isActiveSubscription(subId)) {
4332 return;
4333 }
4334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004335 final long identity = Binder.clearCallingIdentity();
4336 try {
4337 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4338 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4339 } finally {
4340 Binder.restoreCallingIdentity(identity);
4341 }
Stuart Scott54788802015-03-30 13:18:01 -07004342 }
4343
Pengquan Mengea84e042018-09-20 14:57:26 -07004344 /**
4345 * Ask the radio to connect to the input network and change selection mode to manual.
4346 *
4347 * @param subId the id of the subscription.
4348 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4349 * the operator to attach to.
4350 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4351 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4352 * normal network selection next time.
4353 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004354 */
4355 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004356 public boolean setNetworkSelectionModeManual(
4357 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4359 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004360
4361 if (!isActiveSubscription(subId)) {
4362 return false;
4363 }
4364
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365 final long identity = Binder.clearCallingIdentity();
4366 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004367 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004368 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004369 if (DBG) {
4370 log("setNetworkSelectionModeManual: subId: " + subId
4371 + " operator: " + operatorInfo);
4372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004373 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004377 }
4378
4379 /**
4380 * Scans for available networks.
4381 */
4382 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004383 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4385 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004386 LocationAccessPolicy.LocationPermissionResult locationResult =
4387 LocationAccessPolicy.checkLocationPermission(mApp,
4388 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4389 .setCallingPackage(callingPackage)
4390 .setCallingPid(Binder.getCallingPid())
4391 .setCallingUid(Binder.getCallingUid())
4392 .setMethod("getCellNetworkScanResults")
4393 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4394 .build());
4395 switch (locationResult) {
4396 case DENIED_HARD:
4397 throw new SecurityException("Not allowed to access scan results -- location");
4398 case DENIED_SOFT:
4399 return null;
4400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401
Pengquan Menga1bb6272018-09-06 09:59:22 -07004402 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 try {
4404 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004405 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004410 }
4411
4412 /**
yinxub1bed742017-04-17 11:45:04 -07004413 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004414 *
yinxub1bed742017-04-17 11:45:04 -07004415 * @param subId id of the subscription
4416 * @param request contains the radio access networks with bands/channels to scan
4417 * @param messenger callback messenger for scan results or errors
4418 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004419 * @return the id of the requested scan which can be used to stop the scan.
4420 */
4421 @Override
4422 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004423 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4425 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426
Hall Liuf19c44f2018-11-27 14:38:17 -08004427 LocationAccessPolicy.LocationPermissionResult locationResult =
4428 LocationAccessPolicy.checkLocationPermission(mApp,
4429 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4430 .setCallingPackage(callingPackage)
4431 .setCallingPid(Binder.getCallingPid())
4432 .setCallingUid(Binder.getCallingUid())
4433 .setMethod("requestNetworkScan")
4434 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4435 .build());
4436 switch (locationResult) {
4437 case DENIED_HARD:
4438 throw new SecurityException("Not allowed to request network scan -- location");
4439 case DENIED_SOFT:
4440 return -1;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004442
4443 return mNetworkScanRequestTracker.startNetworkScan(
4444 request, messenger, binder, getPhone(subId),
4445 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004446 }
4447
4448 /**
4449 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004450 *
4451 * @param subId id of the subscription
4452 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004453 */
4454 @Override
4455 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004456 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4457 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004458
4459 final long identity = Binder.clearCallingIdentity();
4460 try {
4461 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
4464 }
yinxu504e1392017-04-12 16:03:22 -07004465 }
4466
4467 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004468 * Get the calculated preferred network type.
4469 * Used for debugging incorrect network type.
4470 *
4471 * @return the preferred network type, defined in RILConstants.java.
4472 */
4473 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004474 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004475 final Phone defaultPhone = getDefaultPhone();
4476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4477 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004478 return RILConstants.PREFERRED_NETWORK_MODE;
4479 }
4480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004481 final long identity = Binder.clearCallingIdentity();
4482 try {
4483 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004484 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 } finally {
4486 Binder.restoreCallingIdentity(identity);
4487 }
Junda Liu84d15a22014-07-02 11:21:04 -07004488 }
4489
4490 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004491 * Get the preferred network type.
4492 * Used for device configuration by some CDMA operators.
4493 *
4494 * @return the preferred network type, defined in RILConstants.java.
4495 */
4496 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004497 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004498 TelephonyPermissions
4499 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4500 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004501
4502 final long identity = Binder.clearCallingIdentity();
4503 try {
4504 if (DBG) log("getPreferredNetworkType");
4505 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4506 int networkType = (result != null ? result[0] : -1);
4507 if (DBG) log("getPreferredNetworkType: " + networkType);
4508 return networkType;
4509 } finally {
4510 Binder.restoreCallingIdentity(identity);
4511 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004512 }
4513
4514 /**
4515 * Set the preferred network type.
4516 * Used for device configuration by some CDMA operators.
4517 *
4518 * @param networkType the preferred network type, defined in RILConstants.java.
4519 * @return true on success; false on any failure.
4520 */
4521 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004522 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
4528 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4529 Boolean success = (Boolean) sendRequest(
4530 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4531 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4532 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004533 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4535 }
4536 return success;
4537 } finally {
4538 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004539 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004540 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004541
4542 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004543 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004544 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004545 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004546 * @hide
4547 */
4548 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004549 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004550 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004551 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004552 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004554 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004555 } finally {
4556 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004557 }
Junda Liu475951f2014-11-07 16:45:03 -08004558 }
4559
4560 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004561 * Set mobile data enabled
4562 * Used by the user through settings etc to turn on/off mobile data
4563 *
4564 * @param enable {@code true} turn turn data on, else {@code false}
4565 */
4566 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004567 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004568 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4569 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 int phoneId = mSubscriptionController.getPhoneId(subId);
4574 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4575 Phone phone = PhoneFactory.getPhone(phoneId);
4576 if (phone != null) {
4577 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004578 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004579 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004580 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 }
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004584 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004585 }
4586
4587 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004588 * Get the user enabled state of Mobile Data.
4589 *
4590 * TODO: remove and use isUserDataEnabled.
4591 * This can't be removed now because some vendor codes
4592 * calls through ITelephony directly while they should
4593 * use TelephonyManager.
4594 *
4595 * @return true on enabled
4596 */
4597 @Override
4598 public boolean getDataEnabled(int subId) {
4599 return isUserDataEnabled(subId);
4600 }
4601
4602 /**
4603 * Get whether mobile data is enabled per user setting.
4604 *
4605 * There are other factors deciding whether mobile data is actually enabled, but they are
4606 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004607 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004608 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004609 *
4610 * @return {@code true} if data is enabled else {@code false}
4611 */
4612 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004613 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004614 try {
4615 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4616 null);
4617 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4619 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004620 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004621
4622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 int phoneId = mSubscriptionController.getPhoneId(subId);
4625 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4626 Phone phone = PhoneFactory.getPhone(phoneId);
4627 if (phone != null) {
4628 boolean retVal = phone.isUserDataEnabled();
4629 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4630 return retVal;
4631 } else {
4632 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4633 return false;
4634 }
4635 } finally {
4636 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004637 }
4638 }
4639
4640 /**
4641 * Get whether mobile data is enabled.
4642 *
4643 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4644 * whether mobile data is actually enabled.
4645 *
4646 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4647 *
4648 * @return {@code true} if data is enabled else {@code false}
4649 */
4650 @Override
4651 public boolean isDataEnabled(int subId) {
4652 try {
4653 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4654 null);
4655 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004656 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4657 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659
4660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 int phoneId = mSubscriptionController.getPhoneId(subId);
4663 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4664 Phone phone = PhoneFactory.getPhone(phoneId);
4665 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004666 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004667 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4668 return retVal;
4669 } else {
4670 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4671 return false;
4672 }
4673 } finally {
4674 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004675 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004676 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004677
4678 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004679 public int getCarrierPrivilegeStatus(int subId) {
4680 final Phone phone = getPhone(subId);
4681 if (phone == null) {
4682 loge("getCarrierPrivilegeStatus: Invalid subId");
4683 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4684 }
4685 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004686 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004687 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004688 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4689 }
4690 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004691 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004692 }
Junda Liu29340342014-07-10 15:23:27 -07004693
4694 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004695 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4696 final Phone phone = getPhone(subId);
4697 if (phone == null) {
4698 loge("getCarrierPrivilegeStatus: Invalid subId");
4699 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4700 }
4701 UiccProfile profile =
4702 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4703 if (profile == null) {
4704 loge("getCarrierPrivilegeStatus: No UICC");
4705 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4706 }
4707 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4708 }
4709
4710 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004711 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004712 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004713 if (TextUtils.isEmpty(pkgName))
4714 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004715 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004716 if (card == null) {
4717 loge("checkCarrierPrivilegesForPackage: No UICC");
4718 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4719 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004720 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4721 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004722 }
4723
4724 @Override
4725 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004726 if (TextUtils.isEmpty(pkgName))
4727 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004728 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4729 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4730 UiccCard card = UiccController.getInstance().getUiccCard(i);
4731 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004732 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004733 continue;
4734 }
4735
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004736 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004737 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4738 break;
4739 }
4740 }
4741
4742 return result;
Junda Liu29340342014-07-10 15:23:27 -07004743 }
Derek Tan89e89d42014-07-08 17:00:10 -07004744
4745 @Override
Junda Liue64de782015-04-16 17:19:16 -07004746 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4747 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4748 loge("phoneId " + phoneId + " is not valid.");
4749 return null;
4750 }
4751 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004752 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004753 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004754 return null ;
4755 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004756 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004757 }
4758
Amith Yamasani6e118872016-02-19 12:53:51 -08004759 @Override
4760 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004761 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004762 List<String> privilegedPackages = new ArrayList<>();
4763 List<PackageInfo> packages = null;
4764 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4765 UiccCard card = UiccController.getInstance().getUiccCard(i);
4766 if (card == null) {
4767 // No UICC in that slot.
4768 continue;
4769 }
4770 if (card.hasCarrierPrivilegeRules()) {
4771 if (packages == null) {
4772 // Only check packages in user 0 for now
4773 packages = pm.getInstalledPackagesAsUser(
4774 PackageManager.MATCH_DISABLED_COMPONENTS
4775 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4776 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4777 }
4778 for (int p = packages.size() - 1; p >= 0; p--) {
4779 PackageInfo pkgInfo = packages.get(p);
4780 if (pkgInfo != null && pkgInfo.packageName != null
4781 && card.getCarrierPrivilegeStatus(pkgInfo)
4782 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4783 privilegedPackages.add(pkgInfo.packageName);
4784 }
4785 }
4786 }
4787 }
4788 return privilegedPackages;
4789 }
4790
Wink Savilleb564aae2014-10-23 10:18:09 -07004791 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004792 final Phone phone = getPhone(subId);
4793 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004794 if (card == null) {
4795 loge("getIccId: No UICC");
4796 return null;
4797 }
4798 String iccId = card.getIccId();
4799 if (TextUtils.isEmpty(iccId)) {
4800 loge("getIccId: ICC ID is null or empty.");
4801 return null;
4802 }
4803 return iccId;
4804 }
4805
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004806 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004807 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4808 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4810 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004811
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004812 final long identity = Binder.clearCallingIdentity();
4813 try {
4814 final String iccId = getIccId(subId);
4815 final Phone phone = getPhone(subId);
4816 if (phone == null) {
4817 return false;
4818 }
4819 final String subscriberId = phone.getSubscriberId();
4820
4821 if (DBG_MERGE) {
4822 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4823 + subscriberId + " to " + number);
4824 }
4825
4826 if (TextUtils.isEmpty(iccId)) {
4827 return false;
4828 }
4829
4830 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4831
4832 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4833 if (alphaTag == null) {
4834 editor.remove(alphaTagPrefKey);
4835 } else {
4836 editor.putString(alphaTagPrefKey, alphaTag);
4837 }
4838
4839 // Record both the line number and IMSI for this ICCID, since we need to
4840 // track all merged IMSIs based on line number
4841 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4842 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4843 if (number == null) {
4844 editor.remove(numberPrefKey);
4845 editor.remove(subscriberPrefKey);
4846 } else {
4847 editor.putString(numberPrefKey, number);
4848 editor.putString(subscriberPrefKey, subscriberId);
4849 }
4850
4851 editor.commit();
4852 return true;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004855 }
Derek Tan7226c842014-07-02 17:42:23 -07004856 }
4857
4858 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004859 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004860 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004862 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004863 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004864 return null;
4865 }
Derek Tan97ebb422014-09-05 16:55:38 -07004866
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867 final long identity = Binder.clearCallingIdentity();
4868 try {
4869 String iccId = getIccId(subId);
4870 if (iccId != null) {
4871 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4872 if (DBG_MERGE) {
4873 log("getLine1NumberForDisplay returning "
4874 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4875 }
4876 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4879 return null;
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004882 }
Derek Tan7226c842014-07-02 17:42:23 -07004883 }
4884
4885 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004886 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004888 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004889 return null;
4890 }
Derek Tan97ebb422014-09-05 16:55:38 -07004891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 final long identity = Binder.clearCallingIdentity();
4893 try {
4894 String iccId = getIccId(subId);
4895 if (iccId != null) {
4896 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4897 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4898 }
4899 return null;
4900 } finally {
4901 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004902 }
Derek Tan7226c842014-07-02 17:42:23 -07004903 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004904
4905 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004906 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004907 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4908 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004910 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4911 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004912 return null;
4913 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004914
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004915 final long identity = Binder.clearCallingIdentity();
4916 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004917 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004918 final TelephonyManager tele = TelephonyManager.from(context);
4919 final SubscriptionManager sub = SubscriptionManager.from(context);
4920
4921 // Figure out what subscribers are currently active
4922 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4923 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4924 // the process, where TelephonyManager was instantiated.
4925 // Otherwise AppOps check will fail.
4926
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004927 final int[] subIds = sub.getActiveSubscriptionIdList();
4928 for (int subId : subIds) {
4929 activeSubscriberIds.add(tele.getSubscriberId(subId));
4930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931
4932 // First pass, find a number override for an active subscriber
4933 String mergeNumber = null;
4934 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4935 for (String key : prefs.keySet()) {
4936 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4937 final String subscriberId = (String) prefs.get(key);
4938 if (activeSubscriberIds.contains(subscriberId)) {
4939 final String iccId = key.substring(
4940 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4941 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4942 mergeNumber = (String) prefs.get(numberKey);
4943 if (DBG_MERGE) {
4944 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4945 + " for active subscriber " + subscriberId);
4946 }
4947 if (!TextUtils.isEmpty(mergeNumber)) {
4948 break;
4949 }
4950 }
4951 }
4952 }
4953
4954 // Shortcut when no active merged subscribers
4955 if (TextUtils.isEmpty(mergeNumber)) {
4956 return null;
4957 }
4958
4959 // Second pass, find all subscribers under that line override
4960 final ArraySet<String> result = new ArraySet<>();
4961 for (String key : prefs.keySet()) {
4962 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4963 final String number = (String) prefs.get(key);
4964 if (mergeNumber.equals(number)) {
4965 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4966 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4967 final String subscriberId = (String) prefs.get(subscriberKey);
4968 if (!TextUtils.isEmpty(subscriberId)) {
4969 result.add(subscriberId);
4970 }
4971 }
4972 }
4973 }
4974
4975 final String[] resultArray = result.toArray(new String[result.size()]);
4976 Arrays.sort(resultArray);
4977 if (DBG_MERGE) {
4978 Slog.d(LOG_TAG,
4979 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4980 }
4981 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004982 } finally {
4983 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004984 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004985 }
4986
4987 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004988 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4990 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
4994 final Phone phone = getPhone(subId);
4995 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004999 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005000
5001 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005002 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005003 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5004 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005005 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 final Phone phone = getPhone(subId);
5010 if (phone == null) {
5011 return false;
5012 }
5013 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5014 cdmaNonRoamingList);
5015 } finally {
5016 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005017 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005018 }
5019
5020 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005021 @Deprecated
5022 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5023 enforceModifyPermission();
5024
5025 int returnValue = 0;
5026 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005027 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005028 if(result.exception == null) {
5029 if (result.result != null) {
5030 byte[] responseData = (byte[])(result.result);
5031 if(responseData.length > oemResp.length) {
5032 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5033 responseData.length + "bytes. Buffer Size is " +
5034 oemResp.length + "bytes.");
5035 }
5036 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5037 returnValue = responseData.length;
5038 }
5039 } else {
5040 CommandException ex = (CommandException) result.exception;
5041 returnValue = ex.getCommandError().ordinal();
5042 if(returnValue > 0) returnValue *= -1;
5043 }
5044 } catch (RuntimeException e) {
5045 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5046 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5047 if(returnValue > 0) returnValue *= -1;
5048 }
5049
5050 return returnValue;
5051 }
5052
5053 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005054 public void setRadioCapability(RadioAccessFamily[] rafs) {
5055 try {
5056 ProxyController.getInstance().setRadioCapability(rafs);
5057 } catch (RuntimeException e) {
5058 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5059 }
5060 }
5061
5062 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005063 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005064 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005065 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005066 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005067 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005068 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069 final long identity = Binder.clearCallingIdentity();
5070 try {
chen xub97461a2018-10-26 14:17:57 -07005071 TelephonyPermissions
5072 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5073 mApp, phone.getSubId(), "getRadioAccessFamily");
5074 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 } finally {
5076 Binder.restoreCallingIdentity(identity);
5077 }
chen xub97461a2018-10-26 14:17:57 -07005078 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005079 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005080
5081 @Override
5082 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005083 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005084 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085
5086 final long identity = Binder.clearCallingIdentity();
5087 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005088 ImsManager.getInstance(defaultPhone.getContext(),
5089 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005093 }
5094
5095 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005096 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005097 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005099 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005100 return false;
5101 }
Svet Ganovb320e182015-04-16 12:30:10 -07005102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
5105 // Check the user preference and the system-level IMS setting. Even if the user has
5106 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5107 // In the long run, we may instead need to check if there exists a connection service
5108 // which can support video calling.
5109 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005110 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111 return imsManager.isVtEnabledByPlatform()
5112 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5113 && imsManager.isVtEnabledByUser();
5114 } finally {
5115 Binder.restoreCallingIdentity(identity);
5116 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005117 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005118
Andrew Leea1239f22015-03-02 17:44:07 -08005119 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5122 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5123 return false;
5124 }
5125
5126 final long identity = Binder.clearCallingIdentity();
5127 try {
5128 CarrierConfigManager configManager =
5129 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005130 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005131 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5132 } finally {
5133 Binder.restoreCallingIdentity(identity);
5134 }
Andrew Leea1239f22015-03-02 17:44:07 -08005135 }
5136
5137 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 public boolean isWorldPhone(int subId, String callingPackage) {
5139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5140 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5141 return false;
5142 }
5143
5144 final long identity = Binder.clearCallingIdentity();
5145 try {
5146 CarrierConfigManager configManager =
5147 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005148 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Andrew Leea1239f22015-03-02 17:44:07 -08005153 }
5154
Andrew Lee9431b832015-03-09 18:46:45 -07005155 @Override
5156 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005157 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005158 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005159 }
5160
5161 @Override
5162 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005165 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 } finally {
5167 Binder.restoreCallingIdentity(identity);
5168 }
Andrew Lee9431b832015-03-09 18:46:45 -07005169 }
5170
Hall Liuf6668912018-10-31 17:05:23 -07005171 /**
5172 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5173 * support for the feature and device firmware support.
5174 *
5175 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5176 */
5177 @Override
5178 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005179 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005180 final Phone phone = getPhone(subscriptionId);
5181 if (phone == null) {
5182 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5183 return false;
5184 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005186 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5188 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005189 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005190 return isCarrierSupported && isDeviceSupported;
5191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Hall Liu98187582018-01-22 19:15:32 -08005194 }
5195
Hall Liuf6668912018-10-31 17:05:23 -07005196 /**
5197 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5198 * both also support RTT.
5199 */
5200 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005201 final long identity = Binder.clearCallingIdentity();
5202 try {
Hall Liuf6668912018-10-31 17:05:23 -07005203 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005204 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 } finally {
5206 Binder.restoreCallingIdentity(identity);
5207 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005208 }
5209
Sanket Padawe7310cc72015-01-14 09:53:20 -08005210 /**
5211 * Returns the unique device ID of phone, for example, the IMEI for
5212 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5213 *
5214 * <p>Requires Permission:
5215 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5216 */
5217 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005218 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005219 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005220 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005221 return null;
5222 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005223 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005224 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5225 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005226 return null;
5227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228
5229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 return phone.getDeviceId();
5232 } finally {
5233 Binder.restoreCallingIdentity(identity);
5234 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005235 }
5236
Ping Sunc67b7c22016-03-02 19:16:45 +08005237 /**
5238 * {@hide}
5239 * Returns the IMS Registration Status on a particular subid
5240 *
5241 * @param subId
5242 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005243 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005244 Phone phone = getPhone(subId);
5245 if (phone != null) {
5246 return phone.isImsRegistered();
5247 } else {
5248 return false;
5249 }
5250 }
5251
Santos Cordon7a1885b2015-02-03 11:15:19 -08005252 @Override
5253 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005254 final long identity = Binder.clearCallingIdentity();
5255 try {
5256 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5257 } finally {
5258 Binder.restoreCallingIdentity(identity);
5259 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005260 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005261
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005262 /**
5263 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005264 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005265 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 Phone phone = getPhone(subId);
5269 if (phone != null) {
5270 return phone.isWifiCallingEnabled();
5271 } else {
5272 return false;
5273 }
5274 } finally {
5275 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005276 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005277 }
5278
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005279 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005280 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005281 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005282 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
5285 Phone phone = getPhone(subId);
5286 if (phone != null) {
5287 return phone.isVideoEnabled();
5288 } else {
5289 return false;
5290 }
5291 } finally {
5292 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005293 }
5294 }
5295
5296 /**
5297 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5298 * defined in {@link ImsRegistrationImplBase}.
5299 */
5300 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 Phone phone = getPhone(subId);
5304 if (phone != null) {
5305 return phone.getImsRegistrationTech();
5306 } else {
5307 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5308 }
5309 } finally {
5310 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005311 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005312 }
5313
Stuart Scott8eef64f2015-04-08 15:13:54 -07005314 @Override
5315 public void factoryReset(int subId) {
5316 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005317 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5318 return;
5319 }
5320
Svet Ganovcc087f82015-05-12 20:35:54 -07005321 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005322
Svet Ganovcc087f82015-05-12 20:35:54 -07005323 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005324 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5325 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005326 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005327 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005328 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005329 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5330 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005331 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005332 // There has been issues when Sms raw table somehow stores orphan
5333 // fragments. They lead to garbled message when new fragments come
5334 // in and combined with those stale ones. In case this happens again,
5335 // user can reset all network settings which will clean up this table.
5336 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005337 } finally {
5338 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005339 }
5340 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005341
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005342 private void cleanUpSmsRawTable(Context context) {
5343 ContentResolver resolver = context.getContentResolver();
5344 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5345 resolver.delete(uri, null, null);
5346 }
5347
Narayan Kamath1c496c22015-04-16 14:40:19 +01005348 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005349 public String getSimLocaleForSubscriber(int subId) {
5350 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5351 final Phone phone = getPhone(subId);
5352 if (phone == null) {
5353 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005354 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005355 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005356 final long identity = Binder.clearCallingIdentity();
5357 try {
chen xu5d3637b2019-01-21 23:31:38 -08005358 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5359 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005360 if (info == null) {
5361 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5362 return null;
5363 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005364 // Try and fetch the locale from the carrier properties or from the SIM language
5365 // preferences (EF-PL and EF-LI)...
5366 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005368 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5369 if (localeFromDefaultSim != null) {
5370 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5371 if (DBG) log("Using locale from subId: " + subId + " locale: "
5372 + localeFromDefaultSim);
5373 return localeFromDefaultSim.toLanguageTag();
5374 } else {
5375 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 }
5377 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 // The SIM language preferences only store a language (e.g. fr = French), not an
5380 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5381 // the SIM and carrier preferences does not include a country we add the country
5382 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005383 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005385 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005386 return mccLocale.toLanguageTag();
5387 }
5388
5389 if (DBG) log("No locale found - returning null");
5390 return null;
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005394 }
5395
5396 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005397 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005398 }
5399
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005400 /**
5401 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5402 */
5403 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005404 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005405 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005406
Chenjie Yu1ba97252018-01-11 18:16:20 -08005407 private final ModemActivityInfo mLastModemActivityInfo =
5408 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5409
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005410 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005411 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5412 * representing the state of the modem.
5413 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005414 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5415 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005416 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005417 */
5418 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005419 public void requestModemActivityInfo(ResultReceiver result) {
5420 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005421 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422
5423 final long identity = Binder.clearCallingIdentity();
5424 try {
5425 ModemActivityInfo ret = null;
5426 synchronized (mLastModemActivityInfo) {
5427 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5428 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005429 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005430 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5432 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005433 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5434 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 }
5436 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5438 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005439 mLastModemActivityInfo.setIdleTimeMillis(
5440 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5441 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5442 mLastModemActivityInfo.setRxTimeMillis(
5443 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5444 mLastModemActivityInfo.setEnergyUsed(
5445 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5448 mLastModemActivityInfo.getSleepTimeMillis(),
5449 mLastModemActivityInfo.getIdleTimeMillis(),
5450 mLastModemActivityInfo.getTxTimeMillis(),
5451 mLastModemActivityInfo.getRxTimeMillis(),
5452 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 Bundle bundle = new Bundle();
5455 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5456 result.send(0, bundle);
5457 } finally {
5458 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005459 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005460 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005461
Siddharth Rayb8114062018-06-17 15:02:38 -07005462 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5463 // less than total activity duration.
5464 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5465 if (info == null) {
5466 return false;
5467 }
5468 int activityDurationMs =
5469 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5470 int totalTxTimeMs = 0;
5471 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5472 totalTxTimeMs += info.getTxTimeMillis()[i];
5473 }
5474 return (info.isValid()
5475 && (info.getSleepTimeMillis() <= activityDurationMs)
5476 && (info.getIdleTimeMillis() <= activityDurationMs)
5477 && (info.getRxTimeMillis() <= activityDurationMs)
5478 && (totalTxTimeMs <= activityDurationMs));
5479 }
5480
Jack Yu85bd38a2015-11-09 11:34:32 -08005481 /**
5482 * {@hide}
5483 * Returns the service state information on specified subscription.
5484 */
5485 @Override
5486 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005488 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005489 return null;
5490 }
5491
Hall Liuf19c44f2018-11-27 14:38:17 -08005492 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5493 LocationAccessPolicy.checkLocationPermission(mApp,
5494 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5495 .setCallingPackage(callingPackage)
5496 .setCallingPid(Binder.getCallingPid())
5497 .setCallingUid(Binder.getCallingUid())
5498 .setMethod("getServiceStateForSubscriber")
5499 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5500 .build());
5501
5502 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5503 LocationAccessPolicy.checkLocationPermission(mApp,
5504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5505 .setCallingPackage(callingPackage)
5506 .setCallingPid(Binder.getCallingPid())
5507 .setCallingUid(Binder.getCallingUid())
5508 .setMethod("getServiceStateForSubscriber")
5509 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5510 .build());
5511 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5512 boolean hasFinePermission =
5513 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5514 boolean hasCoarsePermission =
5515 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5516
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 final Phone phone = getPhone(subId);
5520 if (phone == null) {
5521 return null;
5522 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005523
Hall Liuf19c44f2018-11-27 14:38:17 -08005524 ServiceState ss = phone.getServiceState();
5525
5526 // Scrub out the location info in ServiceState depending on what level of access
5527 // the caller has.
5528 if (hasFinePermission) return ss;
5529 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5530 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005534 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005535
5536 /**
5537 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5538 *
5539 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5540 * voicemail ringtone.
5541 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5542 * PhoneAccount.
5543 */
5544 @Override
5545 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 final long identity = Binder.clearCallingIdentity();
5547 try {
5548 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5549 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005550 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5554 } finally {
5555 Binder.restoreCallingIdentity(identity);
5556 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005557 }
5558
5559 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005560 * Sets the per-account voicemail ringtone.
5561 *
5562 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5563 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5564 *
5565 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5566 * voicemail ringtone.
5567 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5568 * PhoneAccount.
5569 */
5570 @Override
5571 public void setVoicemailRingtoneUri(String callingPackage,
5572 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005573 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005574 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5575 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005576 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005577 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5578 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5579 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005581
5582 final long identity = Binder.clearCallingIdentity();
5583 try {
5584 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5585 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005586 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005587 }
5588 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5589 } finally {
5590 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005591 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005592 }
5593
5594 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005595 * Returns whether vibration is set for voicemail notification in Phone settings.
5596 *
5597 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5598 * voicemail vibration setting.
5599 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5600 */
5601 @Override
5602 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005603 final long identity = Binder.clearCallingIdentity();
5604 try {
5605 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5606 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005607 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5611 } finally {
5612 Binder.restoreCallingIdentity(identity);
5613 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005614 }
5615
Youhan Wange64578a2016-05-02 15:32:42 -07005616 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005617 * Sets the per-account voicemail vibration.
5618 *
5619 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5620 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5621 *
5622 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5623 * voicemail vibration setting.
5624 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5625 * specific PhoneAccount.
5626 */
5627 @Override
5628 public void setVoicemailVibrationEnabled(String callingPackage,
5629 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005630 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005631 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5632 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005633 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005634 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5635 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5636 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005637 }
5638
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
5641 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5642 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005643 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 }
5645 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005648 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005649 }
5650
5651 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005652 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5653 *
5654 * @throws SecurityException if the caller does not have the required permission
5655 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005656 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005657 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005658 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005659 }
5660
5661 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005662 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5663 * permission.
5664 *
5665 * @throws SecurityException if the caller does not have the required permission
5666 */
5667 private void enforceSendSmsPermission() {
5668 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5669 }
5670
5671 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005672 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005673 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005674 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005675 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005676 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 final long identity = Binder.clearCallingIdentity();
5678 try {
5679 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 if (componentName == null) {
5682 throw new SecurityException(
5683 "Caller not current active visual voicemail package[null]");
5684 }
5685 String vvmPackage = componentName.getPackageName();
5686 if (!callingPackage.equals(vvmPackage)) {
5687 throw new SecurityException("Caller not current active visual voicemail package["
5688 + vvmPackage + "]");
5689 }
5690 } finally {
5691 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005692 }
5693 }
5694
5695 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005696 * Return the application ID for the app type.
5697 *
5698 * @param subId the subscription ID that this request applies to.
5699 * @param appType the uicc app type.
5700 * @return Application ID for specificied app type, or null if no uicc.
5701 */
5702 @Override
5703 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005704 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005705 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706
5707 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005708 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 if (phone == null) {
5710 return null;
5711 }
5712 String aid = null;
5713 try {
5714 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5715 .getApplicationByType(appType).getAid();
5716 } catch (Exception e) {
5717 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5718 }
5719 return aid;
5720 } finally {
5721 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005722 }
Youhan Wange64578a2016-05-02 15:32:42 -07005723 }
5724
Youhan Wang4001d252016-05-11 10:29:41 -07005725 /**
5726 * Return the Electronic Serial Number.
5727 *
5728 * @param subId the subscription ID that this request applies to.
5729 * @return ESN or null if error.
5730 */
5731 @Override
5732 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005733 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005734 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735
5736 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005737 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 if (phone == null) {
5739 return null;
5740 }
5741 String esn = null;
5742 try {
5743 esn = phone.getEsn();
5744 } catch (Exception e) {
5745 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5746 }
5747 return esn;
5748 } finally {
5749 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005750 }
Youhan Wang4001d252016-05-11 10:29:41 -07005751 }
5752
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005753 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005754 * Return the Preferred Roaming List Version.
5755 *
5756 * @param subId the subscription ID that this request applies to.
5757 * @return PRLVersion or null if error.
5758 */
5759 @Override
5760 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005761 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005762 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005763
5764 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005765 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005766 if (phone == null) {
5767 return null;
5768 }
5769 String cdmaPrlVersion = null;
5770 try {
5771 cdmaPrlVersion = phone.getCdmaPrlVersion();
5772 } catch (Exception e) {
5773 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5774 }
5775 return cdmaPrlVersion;
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005778 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005779 }
5780
5781 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005782 * Get snapshot of Telephony histograms
5783 * @return List of Telephony histograms
5784 * @hide
5785 */
5786 @Override
5787 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5789 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 return RIL.getTelephonyRILTimingHistograms();
5794 } finally {
5795 Binder.restoreCallingIdentity(identity);
5796 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005797 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005798
5799 /**
5800 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005801 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5802 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005803 * Require system privileges. In the future we may add this to carrier APIs.
5804 *
Michele Berionne482f8202018-11-27 18:57:59 -08005805 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005806 */
5807 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005808 @TelephonyManager.SetCarrierRestrictionResult
5809 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005810 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005811 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005812
Michele Berionne482f8202018-11-27 18:57:59 -08005813 if (carrierRestrictionRules == null) {
5814 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005815 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005816
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005817 final long identity = Binder.clearCallingIdentity();
5818 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005819 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005820 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 } finally {
5822 Binder.restoreCallingIdentity(identity);
5823 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005824 }
5825
5826 /**
5827 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005828 * Get the allowed carrier list and the excluded carrier list, including the priority between
5829 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005830 * Require system privileges. In the future we may add this to carrier APIs.
5831 *
Michele Berionne482f8202018-11-27 18:57:59 -08005832 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005833 */
5834 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005835 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005836 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005837 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005841 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5842 if (response instanceof CarrierRestrictionRules) {
5843 return (CarrierRestrictionRules) response;
5844 }
5845 // Response is an Exception of some kind,
5846 // which is signalled to the user as a NULL retval
5847 return null;
5848 } catch (Exception e) {
5849 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5850 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005854 }
5855
fionaxu59545b42016-05-25 15:53:37 -07005856 /**
5857 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5858 * @param subId the subscription ID that this action applies to.
5859 * @param enabled control enable or disable metered apns.
5860 * {@hide}
5861 */
5862 @Override
5863 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5864 enforceModifyPermission();
5865 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866
5867 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005868 if (phone == null) {
5869 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5870 return;
5871 }
5872 try {
5873 phone.carrierActionSetMeteredApnsEnabled(enabled);
5874 } catch (Exception e) {
5875 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 } finally {
5877 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005878 }
5879 }
5880
5881 /**
5882 * Action set from carrier signalling broadcast receivers to enable/disable radio
5883 * @param subId the subscription ID that this action applies to.
5884 * @param enabled control enable or disable radio.
5885 * {@hide}
5886 */
5887 @Override
5888 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5889 enforceModifyPermission();
5890 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891
5892 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005893 if (phone == null) {
5894 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5895 return;
5896 }
5897 try {
5898 phone.carrierActionSetRadioEnabled(enabled);
5899 } catch (Exception e) {
5900 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005901 } finally {
5902 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005903 }
5904 }
5905
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005906 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005907 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5908 * network status based on which carrier apps could apply actions accordingly,
5909 * enable/disable default url handler for example.
5910 *
5911 * @param subId the subscription ID that this action applies to.
5912 * @param report control start/stop reporting the default network status.
5913 * {@hide}
5914 */
5915 @Override
5916 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5917 enforceModifyPermission();
5918 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005919
5920 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005921 if (phone == null) {
5922 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5923 return;
5924 }
5925 try {
5926 phone.carrierActionReportDefaultNetworkStatus(report);
5927 } catch (Exception e) {
5928 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 } finally {
5930 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005931 }
5932 }
5933
5934 /**
fionaxud9622282017-07-17 17:51:30 -07005935 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5936 * @param subId the subscription ID that this action applies to.
5937 * {@hide}
5938 */
5939 @Override
5940 public void carrierActionResetAll(int subId) {
5941 enforceModifyPermission();
5942 final Phone phone = getPhone(subId);
5943 if (phone == null) {
5944 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5945 return;
5946 }
5947 try {
5948 phone.carrierActionResetAll();
5949 } catch (Exception e) {
5950 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5951 }
5952 }
5953
5954 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005955 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5956 * bug report is being generated.
5957 */
5958 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005959 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5961 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005962 writer.println("Permission Denial: can't dump Phone from pid="
5963 + Binder.getCallingPid()
5964 + ", uid=" + Binder.getCallingUid()
5965 + "without permission "
5966 + android.Manifest.permission.DUMP);
5967 return;
5968 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005969 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005970 }
Jack Yueb89b242016-06-22 13:27:47 -07005971
Brad Ebingerdac2f002018-04-03 15:17:52 -07005972 @Override
5973 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5974 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5975 throws RemoteException {
5976 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5977 }
5978
Jack Yueb89b242016-06-22 13:27:47 -07005979 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005980 * Get aggregated video call data usage since boot.
5981 *
5982 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5983 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005984 * {@hide}
5985 */
5986 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005987 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005988 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5989 null);
5990
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 // NetworkStatsService keeps tracking the active network interface and identity. It
5994 // records the delta with the corresponding network identity.
5995 // We just return the total video call data usage snapshot since boot.
5996 Phone phone = getPhone(subId);
5997 if (phone != null) {
5998 return phone.getVtDataUsage(perUidStats);
5999 }
6000 return null;
6001 } finally {
6002 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006003 }
Jack Yueb89b242016-06-22 13:27:47 -07006004 }
Jack Yu75ab2952016-07-08 14:29:33 -07006005
6006 /**
6007 * Policy control of data connection. Usually used when data limit is passed.
6008 * @param enabled True if enabling the data, otherwise disabling.
6009 * @param subId Subscription index
6010 * {@hide}
6011 */
6012 @Override
6013 public void setPolicyDataEnabled(boolean enabled, int subId) {
6014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015
6016 final long identity = Binder.clearCallingIdentity();
6017 try {
6018 Phone phone = getPhone(subId);
6019 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006020 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006021 }
6022 } finally {
6023 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006024 }
6025 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006026
6027 /**
6028 * Get Client request stats
6029 * @return List of Client Request Stats
6030 * @hide
6031 */
6032 @Override
6033 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006034 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006035 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006036 return null;
6037 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006038 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 if (phone != null) {
6043 return phone.getClientRequestStats();
6044 }
6045
6046 return null;
6047 } finally {
6048 Binder.restoreCallingIdentity(identity);
6049 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006050 }
6051
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006052 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006053 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006054 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006055 }
Jack Yueb4124c2017-02-16 15:32:43 -08006056
6057 /**
Grace Chen70990072017-03-24 17:21:30 -07006058 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006059 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006060 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006061 * @param state State of SIM (power down, power up, pass through)
6062 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6063 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6064 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006065 *
6066 **/
6067 @Override
Grace Chen70990072017-03-24 17:21:30 -07006068 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006069 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006070 Phone phone = PhoneFactory.getPhone(slotIndex);
6071
vagdeviaf9a5b92018-08-15 16:01:53 -07006072 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006074 final long identity = Binder.clearCallingIdentity();
6075 try {
6076 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006077 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 }
6079 } finally {
6080 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006081 }
6082 }
Shuo Qiandd210312017-04-12 22:11:33 +00006083
Tyler Gunn65d45c22017-06-05 11:22:26 -07006084 private boolean isUssdApiAllowed(int subId) {
6085 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006086 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006087 if (configManager == null) {
6088 return false;
6089 }
6090 PersistableBundle pb = configManager.getConfigForSubId(subId);
6091 if (pb == null) {
6092 return false;
6093 }
6094 return pb.getBoolean(
6095 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6096 }
6097
Shuo Qiandd210312017-04-12 22:11:33 +00006098 /**
6099 * Check if phone is in emergency callback mode
6100 * @return true if phone is in emergency callback mode
6101 * @param subId sub id
6102 */
goneil9c5f4872017-12-05 14:07:56 -08006103 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006104 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006105 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006106 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107
6108 final long identity = Binder.clearCallingIdentity();
6109 try {
6110 if (phone != null) {
6111 return phone.isInEcm();
6112 } else {
6113 return false;
6114 }
6115 } finally {
6116 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006117 }
6118 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006119
6120 /**
6121 * Get the current signal strength information for the given subscription.
6122 * Because this information is not updated when the device is in a low power state
6123 * it should not be relied-upon to be current.
6124 * @param subId Subscription index
6125 * @return the most recent cached signal strength info from the modem
6126 */
6127 @Override
6128 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 Phone p = getPhone(subId);
6132 if (p == null) {
6133 return null;
6134 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006135
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006136 return p.getSignalStrength();
6137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006140 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006141
Pengquan Meng77b7f132018-08-22 14:49:57 -07006142 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006143 * Get the current modem radio state for the given slot.
6144 * @param slotIndex slot index.
6145 * @param callingPackage the name of the package making the call.
6146 * @return the current radio power state from the modem
6147 */
6148 @Override
6149 public int getRadioPowerState(int slotIndex, String callingPackage) {
6150 Phone phone = PhoneFactory.getPhone(slotIndex);
6151 if (phone != null) {
6152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6153 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6154 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6155 }
6156
6157 final long identity = Binder.clearCallingIdentity();
6158 try {
6159 return phone.getRadioPowerState();
6160 } finally {
6161 Binder.restoreCallingIdentity(identity);
6162 }
6163 }
6164 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6165 }
6166
6167 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006168 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6169 *
6170 * <p>Requires one of the following permissions:
6171 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6172 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6173 * privileges.
6174 *
6175 * @param subId subscription id
6176 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6177 * {@code false}.
6178 */
6179 @Override
6180 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006181 boolean isEnabled = false;
6182 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006183 try {
6184 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07006185 null /* message */);
6186 Phone phone = getPhone(subId);
6187 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006188 } catch (Exception e) {
6189 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6190 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006191 } finally {
6192 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006193 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006194 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006195 }
6196
6197
6198 /**
6199 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6200 *
6201 * <p> Requires permission:
6202 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6203 * privileges.
6204 *
6205 * @param subId subscription id
6206 * @param isEnabled {@code true} means enable, {@code false} means disable.
6207 */
6208 @Override
6209 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6213 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07006214
Pengquan Menga1bb6272018-09-06 09:59:22 -07006215 Phone phone = getPhone(subId);
6216 if (phone != null) {
6217 phone.setDataRoamingEnabled(isEnabled);
6218 }
6219 } finally {
6220 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006221 }
6222 }
6223
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006224 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006225 public boolean isManualNetworkSelectionAllowed(int subId) {
6226 boolean isAllowed = true;
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6230 mApp, subId, "isManualNetworkSelectionAllowed");
6231 Phone phone = getPhone(subId);
6232 if (phone != null) {
6233 isAllowed = phone.isCspPlmnEnabled();
6234 }
6235 } finally {
6236 Binder.restoreCallingIdentity(identity);
6237 }
6238 return isAllowed;
6239 }
6240
6241 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006242 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liuc65bc952019-02-12 17:54:02 -08006243 try {
6244 enforceReadPrivilegedPermission("getUiccCardsInfo");
6245 } catch (SecurityException e) {
6246 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6247 // has carrier privileges on an active UICC
6248 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6249 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6250 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6251 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006252 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006253
6254 final long identity = Binder.clearCallingIdentity();
6255 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006256 UiccController uiccController = UiccController.getInstance();
6257 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6258
6259 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6260 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6261 // Remove private info if the caller doesn't have access
6262 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6263 for (UiccCardInfo cardInfo : cardInfos) {
6264 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6265 UiccProfile profile = card.getUiccProfile();
6266 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6267 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6268 filteredInfos.add(cardInfo.getUnprivileged());
6269 } else {
6270 filteredInfos.add(cardInfo);
6271 }
6272 }
6273 return filteredInfos;
6274 }
6275 return cardInfos;
6276 } catch (PackageManager.NameNotFoundException e) {
6277 // This should not happen since we pass the package info in from TelephonyManager
6278 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006279 } finally {
6280 Binder.restoreCallingIdentity(identity);
6281 }
6282 }
6283
6284 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006285 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006286 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006287
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288 final long identity = Binder.clearCallingIdentity();
6289 try {
6290 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6291 if (slots == null) {
6292 Rlog.i(LOG_TAG, "slots is null.");
6293 return null;
6294 }
6295
6296 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6297 for (int i = 0; i < slots.length; i++) {
6298 UiccSlot slot = slots[i];
6299 if (slot == null) {
6300 continue;
6301 }
6302
6303 String cardId;
6304 UiccCard card = slot.getUiccCard();
6305 if (card != null) {
6306 cardId = card.getCardId();
6307 } else {
6308 cardId = slot.getIccId();
6309 }
6310
6311 int cardState = 0;
6312 switch (slot.getCardState()) {
6313 case CARDSTATE_ABSENT:
6314 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6315 break;
6316 case CARDSTATE_PRESENT:
6317 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6318 break;
6319 case CARDSTATE_ERROR:
6320 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6321 break;
6322 case CARDSTATE_RESTRICTED:
6323 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6324 break;
6325 default:
6326 break;
6327
6328 }
6329
6330 infos[i] = new UiccSlotInfo(
6331 slot.isActive(),
6332 slot.isEuicc(),
6333 cardId,
6334 cardState,
6335 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006336 slot.isExtendedApduSupported(),
6337 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006338 }
6339 return infos;
6340 } finally {
6341 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006342 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006343 }
6344
6345 @Override
6346 public boolean switchSlots(int[] physicalSlots) {
6347 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006348
6349 final long identity = Binder.clearCallingIdentity();
6350 try {
6351 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006355 }
Jack Yu4c988042018-02-27 15:30:01 -08006356
6357 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006358 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006359 final long identity = Binder.clearCallingIdentity();
6360 try {
6361 return UiccController.getInstance().getCardIdForDefaultEuicc();
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
6365 }
6366
6367 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006368 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6369 enforceModifyPermission();
6370 final Phone phone = getPhone(subId);
6371 if (phone == null) {
6372 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6373 return;
6374 }
6375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 phone.setRadioIndicationUpdateMode(filters, mode);
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
Jack Yu4c988042018-02-27 15:30:01 -08006382 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006383
6384 /**
goneil47ffb6e2018-04-06 15:40:58 -07006385 * A test API to reload the UICC profile.
6386 *
6387 * <p>Requires that the calling app has permission
6388 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6389 * @hide
6390 */
6391 @Override
6392 public void refreshUiccProfile(int subId) {
6393 enforceModifyPermission();
6394
6395 final long identity = Binder.clearCallingIdentity();
6396 try {
6397 Phone phone = getPhone(subId);
6398 if (phone == null) {
6399 return;
6400 }
6401 UiccCard uiccCard = phone.getUiccCard();
6402 if (uiccCard == null) {
6403 return;
6404 }
6405 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6406 if (uiccProfile == null) {
6407 return;
6408 }
6409 uiccProfile.refresh();
6410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
6413 }
6414
6415 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006416 * Returns false if the mobile data is disabled by default, otherwise return true.
6417 */
6418 private boolean getDefaultDataEnabled() {
6419 return "true".equalsIgnoreCase(
6420 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6421 }
6422
6423 /**
6424 * Returns true if the data roaming is enabled by default, i.e the system property
6425 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6426 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6427 */
6428 private boolean getDefaultDataRoamingEnabled(int subId) {
6429 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006430 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006431 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6432 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6433 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6434 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6435 return isDataRoamingEnabled;
6436 }
6437
6438 /**
6439 * Returns the default network type for the given {@code subId}, if the default network type is
6440 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6441 */
6442 private int getDefaultNetworkType(int subId) {
6443 return Integer.parseInt(
6444 TelephonyManager.getTelephonyProperty(
6445 mSubscriptionController.getPhoneId(subId),
6446 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6447 String.valueOf(Phone.PREFERRED_NT_MODE)));
6448 }
fionaxua13278b2018-03-21 00:08:13 -07006449
6450 @Override
6451 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006452 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006453 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454
6455 final long identity = Binder.clearCallingIdentity();
6456 try {
6457 final Phone phone = getPhone(subId);
6458 if (phone == null) {
6459 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6460 return;
6461 }
chen xueaba88a2019-03-15 13:15:10 -07006462 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6463 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 } finally {
6465 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006466 }
fionaxua13278b2018-03-21 00:08:13 -07006467 }
6468
6469 @Override
6470 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006471 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
6475 final Phone phone = getPhone(subId);
6476 if (phone == null) {
6477 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6478 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6479 }
6480 return phone.getCarrierIdListVersion();
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006483 }
fionaxua13278b2018-03-21 00:08:13 -07006484 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006485
6486 @Override
6487 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6489 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6490 return -1;
6491 }
6492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6496 } finally {
6497 Binder.restoreCallingIdentity(identity);
6498 }
6499 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006500
6501 @Override
6502 public int getCdmaRoamingMode(int subId) {
6503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6504 mApp, subId, "getCdmaRoamingMode");
6505
6506 final long identity = Binder.clearCallingIdentity();
6507 try {
6508 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6509 } finally {
6510 Binder.restoreCallingIdentity(identity);
6511 }
6512 }
6513
6514 @Override
6515 public boolean setCdmaRoamingMode(int subId, int mode) {
6516 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6517 mApp, subId, "setCdmaRoamingMode");
6518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
6521 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
6525 }
6526
6527 @Override
6528 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6530 mApp, subId, "setCdmaSubscriptionMode");
6531
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6535 } finally {
6536 Binder.restoreCallingIdentity(identity);
6537 }
6538 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006539
6540 private void ensureUserRunning(int userId) {
6541 if (!mUserManager.isUserRunning(userId)) {
6542 throw new IllegalStateException("User " + userId + " does not exist or not running");
6543 }
6544 }
6545
6546 /**
6547 * Returns a list of SMS apps on a given user.
6548 *
6549 * Only the shell user (UID 2000 or 0) can call it.
6550 * Target user must be running.
6551 */
6552 @Override
6553 public String[] getSmsApps(int userId) {
6554 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6555 ensureUserRunning(userId);
6556
6557 final Collection<SmsApplicationData> apps =
6558 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6559
6560 String[] ret = new String[apps.size()];
6561 int i = 0;
6562 for (SmsApplicationData app : apps) {
6563 ret[i++] = app.mPackageName;
6564 }
6565 return ret;
6566 }
6567
6568 /**
6569 * Returns the default SMS app package name on a given user.
6570 *
6571 * Only the shell user (UID 2000 or 0) can call it.
6572 * Target user must be running.
6573 */
6574 @Override
6575 public String getDefaultSmsApp(int userId) {
6576 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6577 ensureUserRunning(userId);
6578
6579 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6580 /* updateIfNeeded= */ true, userId);
6581 return cn == null ? null : cn.getPackageName();
6582 }
6583
6584 /**
6585 * Set a package as the default SMS app on a given user.
6586 *
6587 * Only the shell user (UID 2000 or 0) can call it.
6588 * Target user must be running.
6589 */
6590 @Override
6591 public void setDefaultSmsApp(int userId, String packageName) {
6592 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6593 ensureUserRunning(userId);
6594
6595 boolean found = false;
6596 for (String pkg : getSmsApps(userId)) {
6597 if (TextUtils.equals(packageName, pkg)) {
6598 found = true;
6599 break;
6600 }
6601 }
6602 if (!found) {
6603 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6604 }
6605
6606 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6607 }
sqianc5eccab2018-10-19 18:46:41 -07006608
6609 @Override
sqian8c685422019-02-22 15:55:18 -08006610 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006611 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006612 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006613 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006614 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6615 }
6616 final long identity = Binder.clearCallingIdentity();
6617 try {
sqian854d44b2018-12-12 16:48:18 -08006618 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6619 for (Phone phone: PhoneFactory.getPhones()) {
6620 if (phone.getEmergencyNumberTracker() != null
6621 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6622 emergencyNumberListInternal.put(
6623 phone.getSubId(),
6624 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6625 }
sqian11b7a0e2018-12-05 18:48:28 -08006626 }
sqian854d44b2018-12-12 16:48:18 -08006627 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006628 } finally {
6629 Binder.restoreCallingIdentity(identity);
6630 }
sqianc5eccab2018-10-19 18:46:41 -07006631 }
6632
6633 @Override
sqian8c685422019-02-22 15:55:18 -08006634 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006635 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006636 if (!exactMatch) {
6637 TelephonyPermissions
6638 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006639 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006640 }
6641 final long identity = Binder.clearCallingIdentity();
6642 try {
sqian854d44b2018-12-12 16:48:18 -08006643 for (Phone phone: PhoneFactory.getPhones()) {
6644 if (phone.getEmergencyNumberTracker() != null
6645 && phone.getEmergencyNumberTracker() != null) {
6646 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6647 number, exactMatch)) {
6648 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006649 }
6650 }
sqian11b7a0e2018-12-05 18:48:28 -08006651 }
6652 return false;
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
6655 }
6656 }
6657
sqianf4ca7ed2019-01-15 18:32:07 -08006658 /**
6659 * Update emergency number list for test mode.
6660 */
6661 @Override
6662 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6663 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6664 "updateEmergencyNumberListTestMode");
6665
6666 final long identity = Binder.clearCallingIdentity();
6667 try {
6668 for (Phone phone: PhoneFactory.getPhones()) {
6669 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6670 if (tracker != null) {
6671 tracker.executeEmergencyNumberTestModeCommand(action, num);
6672 }
6673 }
6674 } finally {
6675 Binder.restoreCallingIdentity(identity);
6676 }
6677 }
6678
6679 /**
6680 * Get the full emergency number list for test mode.
6681 */
6682 @Override
6683 public List<String> getEmergencyNumberListTestMode() {
6684 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6685 "getEmergencyNumberListTestMode");
6686
6687 final long identity = Binder.clearCallingIdentity();
6688 try {
6689 Set<String> emergencyNumbers = new HashSet<>();
6690 for (Phone phone: PhoneFactory.getPhones()) {
6691 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6692 if (tracker != null) {
6693 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6694 emergencyNumbers.add(num.getNumber());
6695 }
6696 }
6697 }
6698 return new ArrayList<>(emergencyNumbers);
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
6702 }
6703
chen xud6b45bd2018-10-30 22:27:10 -07006704 @Override
6705 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6706 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6707 Phone phone = getPhone(subId);
6708 if (phone == null) {
6709 return null;
6710 }
6711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 UiccProfile profile = UiccController.getInstance()
6714 .getUiccProfileForPhone(phone.getPhoneId());
6715 if (profile != null) {
6716 return profile.getCertsFromCarrierPrivilegeAccessRules();
6717 }
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
6721 return null;
6722 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006723
6724 /**
6725 * Enable or disable a modem stack.
6726 */
6727 @Override
6728 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6729 enforceModifyPermission();
6730
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 Phone phone = PhoneFactory.getPhone(slotIndex);
6734 if (phone == null) {
6735 return false;
6736 } else {
6737 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6738 }
6739 } finally {
6740 Binder.restoreCallingIdentity(identity);
6741 }
6742 }
Michelecea4cf22018-12-21 15:00:11 -08006743
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006744 /**
6745 * Whether a modem stack is enabled or not.
6746 */
6747 @Override
6748 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6749 Phone phone = PhoneFactory.getPhone(slotIndex);
6750 if (phone == null) return false;
6751
6752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6753 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6754 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6755 }
6756
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
6759 return PhoneConfigurationManager.getInstance().getPhoneStatus(phone);
6760 } finally {
6761 Binder.restoreCallingIdentity(identity);
6762 }
6763 }
6764
Michelecea4cf22018-12-21 15:00:11 -08006765 @Override
Michele0ea7d782019-03-19 14:58:42 -07006766 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006767 enforceModifyPermission();
6768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
6771 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006772 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006773 .commit();
6774 } finally {
6775 Binder.restoreCallingIdentity(identity);
6776 }
6777 }
6778
6779 @Override
Michele0ea7d782019-03-19 14:58:42 -07006780 @TelephonyManager.IsMultiSimSupportedResult
6781 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006783 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6784 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006785 }
Michelecea4cf22018-12-21 15:00:11 -08006786
6787 final long identity = Binder.clearCallingIdentity();
6788 try {
Michele0ea7d782019-03-19 14:58:42 -07006789 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006794
Michele0ea7d782019-03-19 14:58:42 -07006795 @TelephonyManager.IsMultiSimSupportedResult
6796 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006797 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6798 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6799 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006800 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6801 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006802 }
6803 // Check if the hardware supports multisim functionality. If usage of multisim is not
6804 // supported by the modem, indicate that it is restricted.
6805 PhoneCapability staticCapability =
6806 mPhoneConfigurationManager.getStaticPhoneCapability();
6807 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07006808 loge("isMultiSimSupportedInternal: no static configuration available");
6809 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006810 }
6811 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006812 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6813 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006814 }
6815 // Check if support of multiple SIMs is restricted by carrier
6816 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07006817 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006818 }
6819
Michele0ea7d782019-03-19 14:58:42 -07006820 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006821 }
6822
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006823 /**
6824 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006825 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6826 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6827 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006828 * @param numOfSims number of active sims we want to switch to
6829 */
6830 @Override
6831 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006832 if (numOfSims == 1) {
6833 enforceModifyPermission();
6834 } else {
6835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6836 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6837 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006838 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006839
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006840 try {
Michele30b57b22019-03-01 12:01:14 -08006841 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07006842 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006843 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6844 return;
6845 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006846 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
6850 }
6851
6852 /**
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006853 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006854 * Return value defaults to true
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006855 */
6856 @Override
6857 public boolean isRebootRequiredForModemConfigChange() {
6858 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6859 final long identity = Binder.clearCallingIdentity();
6860 try {
6861 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6862 } finally {
6863 Binder.restoreCallingIdentity(identity);
6864 }
6865 }
6866
Nathan Harold29f5f052019-02-15 13:41:57 -08006867 private void updateModemStateMetrics() {
6868 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6869 // TODO: check the state for each modem if the api is ready.
6870 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6871 }
6872
Pengquan Meng3889a572019-01-23 11:16:29 -08006873 @Override
6874 public int[] getSlotsMapping() {
6875 enforceReadPrivilegedPermission("getSlotsMapping");
6876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6880 // All logical slots should have a mapping to a physical slot.
6881 int[] logicalSlotsMapping = new int[phoneCount];
6882 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6883 for (int i = 0; i < slotInfos.length; i++) {
6884 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6885 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6886 }
6887 }
6888 return logicalSlotsMapping;
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
6892 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006893
6894 /**
6895 * Get the IRadio HAL Version
6896 */
6897 @Override
6898 public int getRadioHalVersion() {
6899 Phone phone = getDefaultPhone();
6900 if (phone == null) return -1;
6901 HalVersion hv = phone.getHalVersion();
6902 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6903 return hv.major * 100 + hv.minor;
6904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006905}