blob: bb6c8fff1d6c146ed4d390cabc9011a258bb6b4d [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 Berionne0963c862018-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;
Michelebcb01bc2019-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 Yu311536f2018-11-26 11:20:48 -080090import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080091import 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 Ebinger4c460712018-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 Ebinger4c460712018-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 Ebinger4c460712018-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 xu02581692018-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 Chenf144d942018-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;
sqian2fff4a32018-11-05 14:18:37 -0800137import 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;
sqian9d4df8b2019-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;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800143import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700144import com.android.internal.telephony.uicc.IccIoResult;
145import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800146import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700147import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800148import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700149import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000151import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700152import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800153import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700154import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800155import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700156import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700157import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800158
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700159import java.io.FileDescriptor;
160import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700162import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800163import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800164import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800165import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800166import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800167import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100168import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800169import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800170import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700171
172/**
173 * Implementation of the ITelephony interface.
174 */
Santos Cordon117fee72014-05-16 17:56:12 -0700175public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700176 private static final String LOG_TAG = "PhoneInterfaceManager";
177 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
178 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700180
181 // Message codes used with mMainThreadHandler
182 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700183 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
184 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700185 private static final int CMD_OPEN_CHANNEL = 9;
186 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
187 private static final int CMD_CLOSE_CHANNEL = 11;
188 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800189 private static final int CMD_NV_READ_ITEM = 13;
190 private static final int EVENT_NV_READ_ITEM_DONE = 14;
191 private static final int CMD_NV_WRITE_ITEM = 15;
192 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
193 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
194 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700195 private static final int CMD_RESET_MODEM_CONFIG = 19;
196 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800197 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
198 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
199 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
200 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800201 private static final int CMD_SEND_ENVELOPE = 25;
202 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000203 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
204 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700205 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
206 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
207 private static final int CMD_EXCHANGE_SIM_IO = 31;
208 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800209 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
210 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700211 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
212 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700213 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
214 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700215 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
216 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
217 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
218 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700219 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
220 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
221 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
222 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700223 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800224 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
225 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000226 private static final int CMD_SWITCH_SLOTS = 50;
227 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700228 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
229 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
230 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
231 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
232 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
233 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
234 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
235 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700236 private static final int CMD_GET_ALL_CELL_INFO = 60;
237 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
238 private static final int CMD_GET_CELL_LOCATION = 62;
239 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700240 private static final int CMD_MODEM_REBOOT = 64;
241 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700242 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
243 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800244 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
245 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700246
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800247 // Parameters of select command.
248 private static final int SELECT_COMMAND = 0xA4;
249 private static final int SELECT_P1 = 0x04;
250 private static final int SELECT_P2 = 0;
251 private static final int SELECT_P3 = 0x10;
252
Pengquan Meng85728fb2018-03-12 16:31:21 -0700253 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
254 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
255 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
256
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700257 /** The singleton instance. */
258 private static PhoneInterfaceManager sInstance;
259
Wink Saville3ab207e2014-11-20 13:07:20 -0800260 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700262 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private AppOpsManager mAppOps;
264 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800265 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800266 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700267 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700268
Derek Tan97ebb422014-09-05 16:55:38 -0700269 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
270 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800271 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800272 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700273
Micheled3107c52018-12-21 15:00:11 -0800274 // String to store multi SIM allowed
275 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
276
Derek Tan740e1672017-06-27 14:56:27 -0700277 // The AID of ISD-R.
278 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
279
yinxub1bed742017-04-17 11:45:04 -0700280 private NetworkScanRequestTracker mNetworkScanRequestTracker;
281
David Kelly5e06a7f2018-03-12 14:10:59 +0000282 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
283 private static final int MANUFACTURER_CODE_LENGTH = 8;
284
Derek Tan89e89d42014-07-08 17:00:10 -0700285 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700286 * A request object to use for transmitting data to an ICC.
287 */
288 private static final class IccAPDUArgument {
289 public int channel, cla, command, p1, p2, p3;
290 public String data;
291
292 public IccAPDUArgument(int channel, int cla, int command,
293 int p1, int p2, int p3, String data) {
294 this.channel = channel;
295 this.cla = cla;
296 this.command = command;
297 this.p1 = p1;
298 this.p2 = p2;
299 this.p3 = p3;
300 this.data = data;
301 }
302 }
303
304 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700305 * A request object to use for transmitting data to an ICC.
306 */
307 private static final class ManualNetworkSelectionArgument {
308 public OperatorInfo operatorInfo;
309 public boolean persistSelection;
310
311 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
312 this.operatorInfo = operatorInfo;
313 this.persistSelection = persistSelection;
314 }
315 }
316
317 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700318 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
319 * request after sending. The main thread will notify the request when it is complete.
320 */
321 private static final class MainThreadRequest {
322 /** The argument to use for the request */
323 public Object argument;
324 /** The result of the request that is run on the main thread */
325 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800326 // The subscriber id that this request applies to. Defaults to
327 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
328 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700329
Nathan Harold92bed182018-10-12 18:16:49 -0700330 // In cases where subId is unavailable, the caller needs to specify the phone.
331 public Phone phone;
332
vagdevie435a3e2018-08-15 16:01:53 -0700333 public WorkSource workSource;
334
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335 public MainThreadRequest(Object argument) {
336 this.argument = argument;
337 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800338
Nathan Harold92bed182018-10-12 18:16:49 -0700339 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
340 this.argument = argument;
341 if (phone != null) {
342 this.phone = phone;
343 }
344 this.workSource = workSource;
345 }
346
vagdevie435a3e2018-08-15 16:01:53 -0700347 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800348 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800349 if (subId != null) {
350 this.subId = subId;
351 }
vagdevie435a3e2018-08-15 16:01:53 -0700352 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 }
355
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800356 private static final class IncomingThirdPartyCallArgs {
357 public final ComponentName component;
358 public final String callId;
359 public final String callerDisplayName;
360
361 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
362 String callerDisplayName) {
363 this.component = component;
364 this.callId = callId;
365 this.callerDisplayName = callerDisplayName;
366 }
367 }
368
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 /**
370 * A handler that processes messages on the main thread in the phone process. Since many
371 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
372 * inbound binder threads to the main thread in the phone process. The Binder thread
373 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
374 * on, which will be notified when the operation completes and will contain the result of the
375 * request.
376 *
377 * <p>If a MainThreadRequest object is provided in the msg.obj field,
378 * note that request.result must be set to something non-null for the calling thread to
379 * unblock.
380 */
381 private final class MainThreadHandler extends Handler {
382 @Override
383 public void handleMessage(Message msg) {
384 MainThreadRequest request;
385 Message onCompleted;
386 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800387 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700388 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800389 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390
391 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700392 case CMD_HANDLE_USSD_REQUEST: {
393 request = (MainThreadRequest) msg.obj;
394 final Phone phone = getPhoneFromRequest(request);
395 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
396 String ussdRequest = ussdObject.first;
397 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700398
Pengquan Meng0c05b502018-09-06 09:59:22 -0700399 if (!isUssdApiAllowed(request.subId)) {
400 // Carrier does not support use of this API, return failure.
401 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
402 UssdResponse response = new UssdResponse(ussdRequest, null);
403 Bundle returnData = new Bundle();
404 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
405 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700406
Pengquan Meng0c05b502018-09-06 09:59:22 -0700407 request.result = true;
408 notifyRequester(request);
409 return;
410 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700411
Pengquan Meng0c05b502018-09-06 09:59:22 -0700412 try {
413 request.result = phone != null
414 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
415 } catch (CallStateException cse) {
416 request.result = false;
417 }
418 // Wake up the requesting thread
419 notifyRequester(request);
420 break;
pkanwar32d516d2016-10-14 19:37:38 -0700421 }
422
Yorke Lee716f67e2015-06-17 15:39:16 -0700423 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700425 final Phone phone = getPhoneFromRequest(request);
426 request.result = phone != null ?
427 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
428 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700430 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700432 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700433
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700435 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800437 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700438 if (uiccCard == null) {
439 loge("iccTransmitApduLogicalChannel: No UICC");
440 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700441 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700442 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
444 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700445 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 iccArgument.channel, iccArgument.cla, iccArgument.command,
447 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700449 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700450 break;
451
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700452 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 ar = (AsyncResult) msg.obj;
454 request = (MainThreadRequest) ar.userObj;
455 if (ar.exception == null && ar.result != null) {
456 request.result = ar.result;
457 } else {
458 request.result = new IccIoResult(0x6F, 0, (byte[])null);
459 if (ar.result == null) {
460 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800461 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800463 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700464 } else {
465 loge("iccTransmitApduLogicalChannel: Unknown exception");
466 }
467 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700468 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 break;
470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
472 request = (MainThreadRequest) msg.obj;
473 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800474 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 if (uiccCard == null) {
476 loge("iccTransmitApduBasicChannel: No UICC");
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700478 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 } else {
480 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
481 request);
482 uiccCard.iccTransmitApduBasicChannel(
483 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
484 iccArgument.p3, iccArgument.data, onCompleted);
485 }
486 break;
487
488 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
489 ar = (AsyncResult) msg.obj;
490 request = (MainThreadRequest) ar.userObj;
491 if (ar.exception == null && ar.result != null) {
492 request.result = ar.result;
493 } else {
494 request.result = new IccIoResult(0x6F, 0, (byte[])null);
495 if (ar.result == null) {
496 loge("iccTransmitApduBasicChannel: Empty response");
497 } else if (ar.exception instanceof CommandException) {
498 loge("iccTransmitApduBasicChannel: CommandException: " +
499 ar.exception);
500 } else {
501 loge("iccTransmitApduBasicChannel: Unknown exception");
502 }
503 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700504 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 break;
506
507 case CMD_EXCHANGE_SIM_IO:
508 request = (MainThreadRequest) msg.obj;
509 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800510 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700511 if (uiccCard == null) {
512 loge("iccExchangeSimIO: No UICC");
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700514 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 } else {
516 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
517 request);
518 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
519 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
520 iccArgument.data, onCompleted);
521 }
522 break;
523
524 case EVENT_EXCHANGE_SIM_IO_DONE:
525 ar = (AsyncResult) msg.obj;
526 request = (MainThreadRequest) ar.userObj;
527 if (ar.exception == null && ar.result != null) {
528 request.result = ar.result;
529 } else {
530 request.result = new IccIoResult(0x6f, 0, (byte[])null);
531 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 break;
534
Derek Tan4d5e5c12014-02-04 11:54:58 -0800535 case CMD_SEND_ENVELOPE:
536 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800537 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700538 if (uiccCard == null) {
539 loge("sendEnvelopeWithStatus: No UICC");
540 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700541 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700542 } else {
543 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
544 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
545 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800546 break;
547
548 case EVENT_SEND_ENVELOPE_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800553 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
555 if (ar.result == null) {
556 loge("sendEnvelopeWithStatus: Empty response");
557 } else if (ar.exception instanceof CommandException) {
558 loge("sendEnvelopeWithStatus: CommandException: " +
559 ar.exception);
560 } else {
561 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
562 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700564 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 break;
566
Shishir Agrawal566b7612013-10-28 14:41:00 -0700567 case CMD_OPEN_CHANNEL:
568 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800569 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800570 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700571 if (uiccCard == null) {
572 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800573 request.result = new IccOpenLogicalChannelResponse(-1,
574 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700575 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700576 } else {
577 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800578 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
579 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700580 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700581 break;
582
583 case EVENT_OPEN_CHANNEL_DONE:
584 ar = (AsyncResult) msg.obj;
585 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700587 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 int[] result = (int[]) ar.result;
589 int channelId = result[0];
590 byte[] selectResponse = null;
591 if (result.length > 1) {
592 selectResponse = new byte[result.length - 1];
593 for (int i = 1; i < result.length; ++i) {
594 selectResponse[i - 1] = (byte) result[i];
595 }
596 }
597 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700598 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 if (ar.result == null) {
601 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 if (ar.exception != null) {
604 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
605 }
606
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700607 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700608 if (ar.exception instanceof CommandException) {
609 CommandException.Error error =
610 ((CommandException) (ar.exception)).getCommandError();
611 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700613 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700614 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700615 }
616 }
617 openChannelResp = new IccOpenLogicalChannelResponse(
618 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700620 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case CMD_CLOSE_CHANNEL:
625 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800626 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 if (uiccCard == null) {
628 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900629 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
633 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
634 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800638 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
639 break;
640
641 case CMD_NV_READ_ITEM:
642 request = (MainThreadRequest) msg.obj;
643 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800644 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
645 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800646 break;
647
648 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 ar = (AsyncResult) msg.obj;
650 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800651 if (ar.exception == null && ar.result != null) {
652 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800654 request.result = "";
655 if (ar.result == null) {
656 loge("nvReadItem: Empty response");
657 } else if (ar.exception instanceof CommandException) {
658 loge("nvReadItem: CommandException: " +
659 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800661 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 }
663 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700664 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 break;
666
Jake Hambye994d462014-02-03 13:10:13 -0800667 case CMD_NV_WRITE_ITEM:
668 request = (MainThreadRequest) msg.obj;
669 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
670 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800671 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700672 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800673 break;
674
675 case EVENT_NV_WRITE_ITEM_DONE:
676 handleNullReturnEvent(msg, "nvWriteItem");
677 break;
678
679 case CMD_NV_WRITE_CDMA_PRL:
680 request = (MainThreadRequest) msg.obj;
681 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800682 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800683 break;
684
685 case EVENT_NV_WRITE_CDMA_PRL_DONE:
686 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
687 break;
688
chen xu1cc0abe2018-10-26 17:39:23 -0700689 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800690 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700691 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800692 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
chen xu1cc0abe2018-10-26 17:39:23 -0700695 case EVENT_RESET_MODEM_CONFIG_DONE:
696 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
Jake Hamby7c27be32014-03-03 13:25:59 -0800699 case CMD_GET_PREFERRED_NETWORK_TYPE:
700 request = (MainThreadRequest) msg.obj;
701 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700702 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800703 break;
704
705 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
706 ar = (AsyncResult) msg.obj;
707 request = (MainThreadRequest) ar.userObj;
708 if (ar.exception == null && ar.result != null) {
709 request.result = ar.result; // Integer
710 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800711 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 if (ar.result == null) {
713 loge("getPreferredNetworkType: Empty response");
714 } else if (ar.exception instanceof CommandException) {
715 loge("getPreferredNetworkType: CommandException: " +
716 ar.exception);
717 } else {
718 loge("getPreferredNetworkType: Unknown exception");
719 }
720 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700721 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case CMD_SET_PREFERRED_NETWORK_TYPE:
725 request = (MainThreadRequest) msg.obj;
726 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
727 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700728 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800729 break;
730
731 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
732 handleNullReturnEvent(msg, "setPreferredNetworkType");
733 break;
734
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000735 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
736 request = (MainThreadRequest)msg.obj;
737 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800738 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000739 break;
740
741 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
742 ar = (AsyncResult)msg.obj;
743 request = (MainThreadRequest)ar.userObj;
744 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700745 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000746 break;
747
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800748 case CMD_SET_VOICEMAIL_NUMBER:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
751 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800752 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
753 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800754 break;
755
756 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
757 handleNullReturnEvent(msg, "setVoicemailNumber");
758 break;
759
Stuart Scott54788802015-03-30 13:18:01 -0700760 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
763 request);
764 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
765 break;
766
767 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
768 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
769 break;
770
Shishir Agrawal302c8692015-06-19 13:49:39 -0700771 case CMD_PERFORM_NETWORK_SCAN:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
774 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
775 break;
776
777 case EVENT_PERFORM_NETWORK_SCAN_DONE:
778 ar = (AsyncResult) msg.obj;
779 request = (MainThreadRequest) ar.userObj;
780 CellNetworkScanResult cellScanResult;
781 if (ar.exception == null && ar.result != null) {
782 cellScanResult = new CellNetworkScanResult(
783 CellNetworkScanResult.STATUS_SUCCESS,
784 (List<OperatorInfo>) ar.result);
785 } else {
786 if (ar.result == null) {
787 loge("getCellNetworkScanResults: Empty response");
788 }
789 if (ar.exception != null) {
790 loge("getCellNetworkScanResults: Exception: " + ar.exception);
791 }
792 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
793 if (ar.exception instanceof CommandException) {
794 CommandException.Error error =
795 ((CommandException) (ar.exception)).getCommandError();
796 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
797 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
798 } else if (error == CommandException.Error.GENERIC_FAILURE) {
799 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
800 }
801 }
802 cellScanResult = new CellNetworkScanResult(errorCode, null);
803 }
804 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700805 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700806 break;
807
808 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
809 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700810 ManualNetworkSelectionArgument selArg =
811 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
813 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700814 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
815 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700816 break;
817
818 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700819 ar = (AsyncResult) msg.obj;
820 request = (MainThreadRequest) ar.userObj;
821 if (ar.exception == null) {
822 request.result = true;
823 } else {
824 request.result = false;
825 loge("setNetworkSelectionModeManual " + ar.exception);
826 }
827 notifyRequester(request);
828 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 break;
830
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700831 case CMD_GET_MODEM_ACTIVITY_INFO:
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800834 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700835 break;
836
837 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null && ar.result != null) {
841 request.result = ar.result;
842 } else {
843 if (ar.result == null) {
844 loge("queryModemActivityInfo: Empty response");
845 } else if (ar.exception instanceof CommandException) {
846 loge("queryModemActivityInfo: CommandException: " +
847 ar.exception);
848 } else {
849 loge("queryModemActivityInfo: Unknown exception");
850 }
851 }
Amit Mahajand4766222016-01-28 15:28:28 -0800852 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
853 if (request.result == null) {
854 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
855 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700856 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700857 break;
858
Meng Wang1a7c35a2016-05-05 20:56:15 -0700859 case CMD_SET_ALLOWED_CARRIERS:
860 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800861 CarrierRestrictionRules argument =
862 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800864 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700865 break;
866
867 case EVENT_SET_ALLOWED_CARRIERS_DONE:
868 ar = (AsyncResult) msg.obj;
869 request = (MainThreadRequest) ar.userObj;
870 if (ar.exception == null && ar.result != null) {
871 request.result = ar.result;
872 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800873 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
874 if (ar.exception instanceof CommandException) {
875 loge("setAllowedCarriers: CommandException: " + ar.exception);
876 CommandException.Error error =
877 ((CommandException) (ar.exception)).getCommandError();
878 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
879 request.result =
880 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
881 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700882 } else {
883 loge("setAllowedCarriers: Unknown exception");
884 }
885 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700886 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700887 break;
888
889 case CMD_GET_ALLOWED_CARRIERS:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800892 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700893 break;
894
895 case EVENT_GET_ALLOWED_CARRIERS_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null && ar.result != null) {
899 request.result = ar.result;
900 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800901 request.result = new IllegalStateException(
902 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 if (ar.result == null) {
904 loge("getAllowedCarriers: Empty response");
905 } else if (ar.exception instanceof CommandException) {
906 loge("getAllowedCarriers: CommandException: " +
907 ar.exception);
908 } else {
909 loge("getAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
Nathan Haroldb3014052017-01-25 15:57:32 -0800915 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
916 ar = (AsyncResult) msg.obj;
917 request = (MainThreadRequest) ar.userObj;
918 if (ar.exception == null && ar.result != null) {
919 request.result = ar.result;
920 } else {
921 request.result = new IllegalArgumentException(
922 "Failed to retrieve Forbidden Plmns");
923 if (ar.result == null) {
924 loge("getForbiddenPlmns: Empty response");
925 } else {
926 loge("getForbiddenPlmns: Unknown exception");
927 }
928 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700929 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800930 break;
931
932 case CMD_GET_FORBIDDEN_PLMNS:
933 request = (MainThreadRequest) msg.obj;
934 uiccCard = getUiccCardFromRequest(request);
935 if (uiccCard == null) {
936 loge("getForbiddenPlmns() UiccCard is null");
937 request.result = new IllegalArgumentException(
938 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700939 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800940 break;
941 }
942 Integer appType = (Integer) request.argument;
943 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
944 if (uiccApp == null) {
945 loge("getForbiddenPlmns() no app with specified type -- "
946 + appType);
947 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700948 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800949 break;
950 } else {
951 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
952 + " specified type -- " + appType);
953 }
954 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
955 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
956 onCompleted);
957 break;
958
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000959 case CMD_SWITCH_SLOTS:
960 request = (MainThreadRequest) msg.obj;
961 int[] physicalSlots = (int[]) request.argument;
962 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
963 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
964 break;
965
966 case EVENT_SWITCH_SLOTS_DONE:
967 ar = (AsyncResult) msg.obj;
968 request = (MainThreadRequest) ar.userObj;
969 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700970 notifyRequester(request);
971 break;
972 case CMD_GET_NETWORK_SELECTION_MODE:
973 request = (MainThreadRequest) msg.obj;
974 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
975 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
976 break;
977
978 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
979 ar = (AsyncResult) msg.obj;
980 request = (MainThreadRequest) ar.userObj;
981 if (ar.exception != null) {
982 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
983 } else {
984 int mode = ((int[]) ar.result)[0];
985 if (mode == 0) {
986 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
987 } else {
988 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000990 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700991 notifyRequester(request);
992 break;
993 case CMD_GET_CDMA_ROAMING_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
996 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
997 break;
998 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
999 ar = (AsyncResult) msg.obj;
1000 request = (MainThreadRequest) ar.userObj;
1001 if (ar.exception != null) {
1002 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1003 } else {
1004 request.result = ((int[]) ar.result)[0];
1005 }
1006 notifyRequester(request);
1007 break;
1008 case CMD_SET_CDMA_ROAMING_MODE:
1009 request = (MainThreadRequest) msg.obj;
1010 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1011 int mode = (int) request.argument;
1012 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1013 break;
1014 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1015 ar = (AsyncResult) msg.obj;
1016 request = (MainThreadRequest) ar.userObj;
1017 request.result = ar.exception == null;
1018 notifyRequester(request);
1019 break;
1020 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1021 request = (MainThreadRequest) msg.obj;
1022 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1023 int subscriptionMode = (int) request.argument;
1024 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1025 break;
1026 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1027 ar = (AsyncResult) msg.obj;
1028 request = (MainThreadRequest) ar.userObj;
1029 request.result = ar.exception == null;
1030 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001031 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001032 case CMD_GET_ALL_CELL_INFO:
1033 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001035 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001036 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 case EVENT_GET_ALL_CELL_INFO_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001040 // If a timeout occurs, the response will be null
1041 request.result = (ar.exception == null && ar.result != null)
1042 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001043 synchronized (request) {
1044 request.notifyAll();
1045 }
1046 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001047 case CMD_REQUEST_CELL_INFO_UPDATE:
1048 request = (MainThreadRequest) msg.obj;
1049 request.phone.requestCellInfoUpdate(request.workSource,
1050 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1051 break;
1052 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1056 try {
1057 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001058 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001059 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1060 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001063 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 } else {
1065 // use the result as returned
1066 cb.onCellInfo((List<CellInfo>) ar.result);
1067 }
1068 } catch (RemoteException re) {
1069 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1070 }
1071 break;
1072 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001073 request = (MainThreadRequest) msg.obj;
1074 WorkSource ws = (WorkSource) request.argument;
1075 Phone phone = getPhoneFromRequest(request);
1076 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1077 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001078 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 if (ar.exception == null) {
1082 request.result = ar.result;
1083 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001085 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1086 ? new CdmaCellLocation() : new GsmCellLocation();
1087 }
1088
1089 synchronized (request) {
1090 request.notifyAll();
1091 }
1092 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001093 case CMD_MODEM_REBOOT:
1094 request = (MainThreadRequest) msg.obj;
1095 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001096 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001097 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001098 case EVENT_CMD_MODEM_REBOOT_DONE:
1099 handleNullReturnEvent(msg, "rebootModem");
1100 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001101 case CMD_REQUEST_ENABLE_MODEM:
1102 request = (MainThreadRequest) msg.obj;
1103 boolean enable = (boolean) request.argument;
1104 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1105 PhoneConfigurationManager.getInstance()
1106 .enablePhone(request.phone, enable, onCompleted);
1107 break;
1108 case EVENT_ENABLE_MODEM_DONE:
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 request.result = (ar.exception == null);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001112 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001113 notifyRequester(request);
1114 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001115 default:
1116 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1117 break;
1118 }
1119 }
Jake Hambye994d462014-02-03 13:10:13 -08001120
Pengquan Meng0c05b502018-09-06 09:59:22 -07001121 private void notifyRequester(MainThreadRequest request) {
1122 synchronized (request) {
1123 request.notifyAll();
1124 }
1125 }
1126
Jake Hambye994d462014-02-03 13:10:13 -08001127 private void handleNullReturnEvent(Message msg, String command) {
1128 AsyncResult ar = (AsyncResult) msg.obj;
1129 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1130 if (ar.exception == null) {
1131 request.result = true;
1132 } else {
1133 request.result = false;
1134 if (ar.exception instanceof CommandException) {
1135 loge(command + ": CommandException: " + ar.exception);
1136 } else {
1137 loge(command + ": Unknown exception");
1138 }
1139 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001140 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001142 }
1143
1144 /**
1145 * Posts the specified command to be executed on the main thread,
1146 * waits for the request to complete, and returns the result.
1147 * @see #sendRequestAsync
1148 */
1149 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001150 return sendRequest(
1151 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001152 }
1153
1154 /**
1155 * Posts the specified command to be executed on the main thread,
1156 * waits for the request to complete, and returns the result.
1157 * @see #sendRequestAsync
1158 */
1159 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1160 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001161 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001162 }
1163
1164 /**
1165 * Posts the specified command to be executed on the main thread,
1166 * waits for the request to complete, and returns the result.
1167 * @see #sendRequestAsync
1168 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001169 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001170 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001171 }
1172
1173 /**
1174 * Posts the specified command to be executed on the main thread,
1175 * waits for the request to complete, and returns the result.
1176 * @see #sendRequestAsync
1177 */
Nathan Harold92bed182018-10-12 18:16:49 -07001178 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1179 return sendRequest(command, argument, subId, null, workSource);
1180 }
1181
1182 /**
1183 * Posts the specified command to be executed on the main thread,
1184 * waits for the request to complete, and returns the result.
1185 * @see #sendRequestAsync
1186 */
1187 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1188 return sendRequest(
1189 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1190 }
1191
1192 /**
1193 * Posts the specified command to be executed on the main thread,
1194 * waits for the request to complete, and returns the result.
1195 * @see #sendRequestAsync
1196 */
1197 private Object sendRequest(
1198 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001199 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1200 throw new RuntimeException("This method will deadlock if called from the main thread.");
1201 }
1202
Nathan Harold92bed182018-10-12 18:16:49 -07001203 MainThreadRequest request = null;
1204 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1205 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1206 } else if (phone != null) {
1207 request = new MainThreadRequest(argument, phone, workSource);
1208 } else {
1209 request = new MainThreadRequest(argument, subId, workSource);
1210 }
1211
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001212 Message msg = mMainThreadHandler.obtainMessage(command, request);
1213 msg.sendToTarget();
1214
1215 // Wait for the request to complete
1216 synchronized (request) {
1217 while (request.result == null) {
1218 try {
1219 request.wait();
1220 } catch (InterruptedException e) {
1221 // Do nothing, go back and wait until the request is complete
1222 }
1223 }
1224 }
1225 return request.result;
1226 }
1227
1228 /**
1229 * Asynchronous ("fire and forget") version of sendRequest():
1230 * Posts the specified command to be executed on the main thread, and
1231 * returns immediately.
1232 * @see #sendRequest
1233 */
1234 private void sendRequestAsync(int command) {
1235 mMainThreadHandler.sendEmptyMessage(command);
1236 }
1237
1238 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001239 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001240 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001241 */
1242 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 sendRequestAsync(command, argument, null, null);
1244 }
1245
1246 /**
1247 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1248 * @see {@link #sendRequest(int,Object)}
1249 */
1250 private void sendRequestAsync(
1251 int command, Object argument, Phone phone, WorkSource workSource) {
1252 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001253 Message msg = mMainThreadHandler.obtainMessage(command, request);
1254 msg.sendToTarget();
1255 }
1256
1257 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 * Initialize the singleton PhoneInterfaceManager instance.
1259 * This is only done once, at startup, from PhoneApp.onCreate().
1260 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001261 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001262 synchronized (PhoneInterfaceManager.class) {
1263 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001264 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 } else {
1266 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1267 }
1268 return sInstance;
1269 }
1270 }
1271
1272 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001273 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001274 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001276 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1278 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001279 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001280 mTelephonySharedPreferences =
1281 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001282 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001283 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001284
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001285 publish();
1286 }
1287
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001288 private Phone getDefaultPhone() {
1289 Phone thePhone = getPhone(getDefaultSubscription());
1290 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1291 }
1292
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001293 private void publish() {
1294 if (DBG) log("publish: " + this);
1295
1296 ServiceManager.addService("phone", this);
1297 }
1298
Stuart Scott584921c2015-01-15 17:10:34 -08001299 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001300 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001301 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001302 }
1303
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001304 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1305 Phone phone = getPhoneFromRequest(request);
1306 return phone == null ? null :
1307 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1308 }
1309
Wink Saville36469e72014-06-11 15:17:00 -07001310 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001311 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001312 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001313 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001314
1315 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001316 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001317 }
1318
Wink Savilleb564aae2014-10-23 10:18:09 -07001319 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001320 if (DBG) log("dial: " + number);
1321 // No permission check needed here: This is just a wrapper around the
1322 // ACTION_DIAL intent, which is available to any app since it puts up
1323 // the UI before it does anything.
1324
Malcolm Chend965c8b2018-02-28 15:00:40 -08001325 final long identity = Binder.clearCallingIdentity();
1326 try {
1327 String url = createTelUrl(number);
1328 if (url == null) {
1329 return;
1330 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001331
Malcolm Chend965c8b2018-02-28 15:00:40 -08001332 // PENDING: should we just silently fail if phone is offhook or ringing?
1333 PhoneConstants.State state = mCM.getState(subId);
1334 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1335 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1336 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1337 mApp.startActivity(intent);
1338 }
1339 } finally {
1340 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001341 }
1342 }
1343
1344 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001345 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001346 }
1347
Wink Savilleb564aae2014-10-23 10:18:09 -07001348 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001349 if (DBG) log("call: " + number);
1350
1351 // This is just a wrapper around the ACTION_CALL intent, but we still
1352 // need to do a permission check since we're calling startActivity()
1353 // from the context of the phone app.
1354 enforceCallPermission();
1355
1356 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1357 != AppOpsManager.MODE_ALLOWED) {
1358 return;
1359 }
1360
Malcolm Chend965c8b2018-02-28 15:00:40 -08001361 final long identity = Binder.clearCallingIdentity();
1362 try {
1363 String url = createTelUrl(number);
1364 if (url == null) {
1365 return;
1366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001367
Malcolm Chend965c8b2018-02-28 15:00:40 -08001368 boolean isValid = false;
1369 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1370 if (slist != null) {
1371 for (SubscriptionInfo subInfoRecord : slist) {
1372 if (subInfoRecord.getSubscriptionId() == subId) {
1373 isValid = true;
1374 break;
1375 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001376 }
Wink Saville08874612014-08-31 19:19:58 -07001377 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001378 if (!isValid) {
1379 return;
1380 }
Wink Saville08874612014-08-31 19:19:58 -07001381
Malcolm Chend965c8b2018-02-28 15:00:40 -08001382 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1383 intent.putExtra(SUBSCRIPTION_KEY, subId);
1384 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1385 mApp.startActivity(intent);
1386 } finally {
1387 Binder.restoreCallingIdentity(identity);
1388 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 }
1390
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001392 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001393 }
1394
Wink Savilleb564aae2014-10-23 10:18:09 -07001395 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001396 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001397 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1398 }
1399
1400 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001401 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001402 }
1403
Wink Savilleb564aae2014-10-23 10:18:09 -07001404 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001406 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1407 }
1408
1409 /** {@hide} */
1410 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001411 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001412 }
1413
Wink Savilleb564aae2014-10-23 10:18:09 -07001414 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001415 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001416
1417 final long identity = Binder.clearCallingIdentity();
1418 try {
1419 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1420 checkSimPin.start();
1421 return checkSimPin.unlockSim(null, pin);
1422 } finally {
1423 Binder.restoreCallingIdentity(identity);
1424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425 }
1426
Wink Saville9de0f752013-10-22 19:04:03 -07001427 /** {@hide} */
1428 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001429 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001430 }
1431
Wink Savilleb564aae2014-10-23 10:18:09 -07001432 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001433 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001434
1435 final long identity = Binder.clearCallingIdentity();
1436 try {
1437 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1438 checkSimPuk.start();
1439 return checkSimPuk.unlockSim(puk, pin);
1440 } finally {
1441 Binder.restoreCallingIdentity(identity);
1442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001443 }
1444
1445 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001446 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001447 * a synchronous one.
1448 */
1449 private static class UnlockSim extends Thread {
1450
1451 private final IccCard mSimCard;
1452
1453 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001454 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1455 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456
1457 // For replies from SimCard interface
1458 private Handler mHandler;
1459
1460 // For async handler to identify request type
1461 private static final int SUPPLY_PIN_COMPLETE = 100;
1462
1463 public UnlockSim(IccCard simCard) {
1464 mSimCard = simCard;
1465 }
1466
1467 @Override
1468 public void run() {
1469 Looper.prepare();
1470 synchronized (UnlockSim.this) {
1471 mHandler = new Handler() {
1472 @Override
1473 public void handleMessage(Message msg) {
1474 AsyncResult ar = (AsyncResult) msg.obj;
1475 switch (msg.what) {
1476 case SUPPLY_PIN_COMPLETE:
1477 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1478 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001479 mRetryCount = msg.arg1;
1480 if (ar.exception != null) {
1481 if (ar.exception instanceof CommandException &&
1482 ((CommandException)(ar.exception)).getCommandError()
1483 == CommandException.Error.PASSWORD_INCORRECT) {
1484 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1485 } else {
1486 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1487 }
1488 } else {
1489 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1490 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001491 mDone = true;
1492 UnlockSim.this.notifyAll();
1493 }
1494 break;
1495 }
1496 }
1497 };
1498 UnlockSim.this.notifyAll();
1499 }
1500 Looper.loop();
1501 }
1502
1503 /*
1504 * Use PIN or PUK to unlock SIM card
1505 *
1506 * If PUK is null, unlock SIM card with PIN
1507 *
1508 * If PUK is not null, unlock SIM card with PUK and set PIN code
1509 */
Wink Saville9de0f752013-10-22 19:04:03 -07001510 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511
1512 while (mHandler == null) {
1513 try {
1514 wait();
1515 } catch (InterruptedException e) {
1516 Thread.currentThread().interrupt();
1517 }
1518 }
1519 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1520
1521 if (puk == null) {
1522 mSimCard.supplyPin(pin, callback);
1523 } else {
1524 mSimCard.supplyPuk(puk, pin, callback);
1525 }
1526
1527 while (!mDone) {
1528 try {
1529 Log.d(LOG_TAG, "wait for done");
1530 wait();
1531 } catch (InterruptedException e) {
1532 // Restore the interrupted status
1533 Thread.currentThread().interrupt();
1534 }
1535 }
1536 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001537 int[] resultArray = new int[2];
1538 resultArray[0] = mResult;
1539 resultArray[1] = mRetryCount;
1540 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001541 }
1542 }
1543
1544 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001545 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001546
1547 }
1548
Wink Savilleb564aae2014-10-23 10:18:09 -07001549 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 // No permission check needed here: this call is harmless, and it's
1551 // needed for the ServiceState.requestStateUpdate() call (which is
1552 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001553 final long identity = Binder.clearCallingIdentity();
1554 try {
1555 final Phone phone = getPhone(subId);
1556 if (phone != null) {
1557 phone.updateServiceLocation();
1558 }
1559 } finally {
1560 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001561 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001562 }
1563
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001564 @Override
1565 public boolean isRadioOn(String callingPackage) {
1566 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001567 }
1568
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001569 @Override
1570 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001572 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001573 return false;
1574 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001575
1576 final long identity = Binder.clearCallingIdentity();
1577 try {
1578 return isRadioOnForSubscriber(subId);
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
1581 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001582 }
1583
1584 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001585 final long identity = Binder.clearCallingIdentity();
1586 try {
1587 final Phone phone = getPhone(subId);
1588 if (phone != null) {
1589 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1590 } else {
1591 return false;
1592 }
1593 } finally {
1594 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001595 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001596 }
1597
1598 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001599 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
Wink Saville36469e72014-06-11 15:17:00 -07001601
Wink Savilleb564aae2014-10-23 10:18:09 -07001602 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001604
1605 final long identity = Binder.clearCallingIdentity();
1606 try {
1607 final Phone phone = getPhone(subId);
1608 if (phone != null) {
1609 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1610 }
1611 } finally {
1612 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001613 }
Wink Saville36469e72014-06-11 15:17:00 -07001614 }
1615
1616 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001617 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001618 }
1619
Wink Savilleb564aae2014-10-23 10:18:09 -07001620 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001621 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001622
1623 final long identity = Binder.clearCallingIdentity();
1624 try {
1625 final Phone phone = getPhone(subId);
1626 if (phone == null) {
1627 return false;
1628 }
1629 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1630 toggleRadioOnOffForSubscriber(subId);
1631 }
1632 return true;
1633 } finally {
1634 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001636 }
Wink Saville36469e72014-06-11 15:17:00 -07001637
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001638 public boolean needMobileRadioShutdown() {
1639 /*
1640 * If any of the Radios are available, it will need to be
1641 * shutdown. So return true if any Radio is available.
1642 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001643 final long identity = Binder.clearCallingIdentity();
1644 try {
1645 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1646 Phone phone = PhoneFactory.getPhone(i);
1647 if (phone != null && phone.isRadioAvailable()) return true;
1648 }
1649 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1650 return false;
1651 } finally {
1652 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001654 }
1655
Malcolm Chend965c8b2018-02-28 15:00:40 -08001656 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001657 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658 enforceModifyPermission();
1659
1660 final long identity = Binder.clearCallingIdentity();
1661 try {
1662 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1663 logv("Shutting down Phone " + i);
1664 shutdownRadioUsingPhoneId(i);
1665 }
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 }
1669 }
1670
1671 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 Phone phone = PhoneFactory.getPhone(phoneId);
1673 if (phone != null && phone.isRadioAvailable()) {
1674 phone.shutdownRadio();
1675 }
1676 }
1677
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001679 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001680
1681 final long identity = Binder.clearCallingIdentity();
1682 try {
1683 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1684 if (defaultPhone != null) {
1685 defaultPhone.setRadioPower(turnOn);
1686 return true;
1687 } else {
1688 loge("There's no default phone.");
1689 return false;
1690 }
1691 } finally {
1692 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001693 }
Wink Saville36469e72014-06-11 15:17:00 -07001694 }
1695
Wink Savilleb564aae2014-10-23 10:18:09 -07001696 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001697 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001698
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 final Phone phone = getPhone(subId);
1702 if (phone != null) {
1703 phone.setRadioPower(turnOn);
1704 return true;
1705 } else {
1706 return false;
1707 }
1708 } finally {
1709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
1712
Wink Saville36469e72014-06-11 15:17:00 -07001713 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001714 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001715 public boolean enableDataConnectivity() {
1716 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001717
1718 final long identity = Binder.clearCallingIdentity();
1719 try {
1720 int subId = mSubscriptionController.getDefaultDataSubId();
1721 final Phone phone = getPhone(subId);
1722 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001723 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001724 return true;
1725 } else {
1726 return false;
1727 }
1728 } finally {
1729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001731 }
1732
Wink Saville36469e72014-06-11 15:17:00 -07001733 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001734 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 public boolean disableDataConnectivity() {
1736 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737
1738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 int subId = mSubscriptionController.getDefaultDataSubId();
1741 final Phone phone = getPhone(subId);
1742 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001743 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001744 return true;
1745 } else {
1746 return false;
1747 }
1748 } finally {
1749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751 }
1752
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001754 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001755 final long identity = Binder.clearCallingIdentity();
1756 try {
1757 final Phone phone = getPhone(subId);
1758 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001759 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001760 } else {
1761 return false;
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
1768 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001769 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001770 }
1771
pkanwarae03a6b2016-11-06 20:37:09 -08001772 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001773 enforceCallPermission();
1774
1775 final long identity = Binder.clearCallingIdentity();
1776 try {
1777 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1778 return;
1779 }
1780 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1781 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1782 } finally {
1783 Binder.restoreCallingIdentity(identity);
1784 }
pkanwar32d516d2016-10-14 19:37:38 -07001785 };
1786
Wink Savilleb564aae2014-10-23 10:18:09 -07001787 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001788 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1793 return false;
1794 }
1795 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1796 } finally {
1797 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001798 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 }
1800
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001802 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001803 }
1804
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001805 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001806 final long identity = Binder.clearCallingIdentity();
1807 try {
1808 Phone phone = PhoneFactory.getPhone(slotIndex);
1809 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1810 PhoneConstantConversions.convertCallState(phone.getState());
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
1813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Sanket Padawe356d7632015-06-22 14:03:32 -07001816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001818 final long identity = Binder.clearCallingIdentity();
1819 try {
1820 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1821 if (phone != null) {
1822 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1823 } else {
1824 return PhoneConstantConversions.convertDataState(
1825 PhoneConstants.DataState.DISCONNECTED);
1826 }
1827 } finally {
1828 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 }
1831
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1837 if (phone != null) {
1838 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1839 } else {
1840 return TelephonyManager.DATA_ACTIVITY_NONE;
1841 }
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
1847 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001848 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001849 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001850 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001851
1852 LocationAccessPolicy.LocationPermissionResult locationResult =
1853 LocationAccessPolicy.checkLocationPermission(mApp,
1854 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1855 .setCallingPackage(callingPackage)
1856 .setCallingPid(Binder.getCallingPid())
1857 .setCallingUid(Binder.getCallingUid())
1858 .setMethod("getCellLocation")
1859 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1860 .build());
1861 switch (locationResult) {
1862 case DENIED_HARD:
1863 throw new SecurityException("Not allowed to access cell location");
1864 case DENIED_SOFT:
1865 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001866 }
1867
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001868 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001869 final long identity = Binder.clearCallingIdentity();
1870 try {
1871 if (DBG_LOC) log("getCellLocation: is active user");
1872 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001873 int subId = mSubscriptionController.getDefaultDataSubId();
1874 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1875 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001876 return data;
1877 } finally {
1878 Binder.restoreCallingIdentity(identity);
1879 }
Svetoslav64fad262015-04-14 14:35:21 -07001880 }
1881
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001883 public String getNetworkCountryIsoForPhone(int phoneId) {
1884 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1885 // registered cell info, so return a NULL country instead.
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001888 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1889 // Get default phone in this case.
1890 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1891 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001892 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001893 // Todo: fix this when we can get the actual cellular network info when the device
1894 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001895 if (TelephonyManager.NETWORK_TYPE_IWLAN
1896 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1897 return "";
1898 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001899 Phone phone = PhoneFactory.getPhone(phoneId);
1900 if (phone != null) {
1901 ServiceStateTracker sst = phone.getServiceStateTracker();
1902 if (sst != null) {
1903 LocaleTracker lt = sst.getLocaleTracker();
1904 if (lt != null) {
1905 return lt.getCurrentCountry();
1906 }
1907 }
1908 }
1909 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 } finally {
1911 Binder.restoreCallingIdentity(identity);
1912 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001913 }
1914
1915 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001916 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001917 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001918 }
1919
Sanket Padawe356d7632015-06-22 14:03:32 -07001920 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001921 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001922 mApp.enforceCallingOrSelfPermission(
1923 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001924
1925 final long identity = Binder.clearCallingIdentity();
1926 try {
1927 final Phone phone = getPhone(subId);
1928 if (phone != null) {
1929 phone.enableLocationUpdates();
1930 }
1931 } finally {
1932 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001934 }
1935
1936 @Override
1937 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001938 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
Sanket Padawe356d7632015-06-22 14:03:32 -07001941 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001942 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 mApp.enforceCallingOrSelfPermission(
1944 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 phone.disableLocationUpdates();
1951 }
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 }
1956
Nathan Harold31d7ff32018-10-15 20:20:30 -07001957 /**
1958 * Returns the target SDK version number for a given package name.
1959 *
1960 * @return target SDK if the package is found or INT_MAX.
1961 */
1962 private int getTargetSdk(String packageName) {
1963 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001964 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1965 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001966 if (ai != null) return ai.targetSdkVersion;
1967 } catch (PackageManager.NameNotFoundException unexpected) {
1968 }
1969 return Integer.MAX_VALUE;
1970 }
1971
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 @Override
1973 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001974 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1975 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001976 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1977 throw new SecurityException(
1978 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1979 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1982 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1983 return null;
1984 }
Svetoslav64fad262015-04-14 14:35:21 -07001985
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001986 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987
Nathan Haroldf180aac2018-06-01 18:43:55 -07001988 List<CellInfo> info = getAllCellInfo(callingPackage);
1989 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990
Nathan Haroldf180aac2018-06-01 18:43:55 -07001991 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1992 for (CellInfo ci : info) {
1993 if (ci instanceof CellInfoGsm) {
1994 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1995 } else if (ci instanceof CellInfoWcdma) {
1996 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001999 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002002 private List<CellInfo> getCachedCellInfo() {
2003 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2004 for (Phone phone : PhoneFactory.getPhones()) {
2005 List<CellInfo> info = phone.getAllCellInfo();
2006 if (info != null) cellInfos.addAll(info);
2007 }
2008 return cellInfos;
2009 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002010
2011 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002012 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
2020 .setCallingPid(Binder.getCallingPid())
2021 .setCallingUid(Binder.getCallingUid())
2022 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002023 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell info");
2029 case DENIED_SOFT:
2030 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002033 final int targetSdk = getTargetSdk(callingPackage);
2034 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2035 return getCachedCellInfo();
2036 }
2037
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002038 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2043 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002044 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002045 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002046 if (info != null) cellInfos.addAll(info);
2047 }
2048 return cellInfos;
2049 } finally {
2050 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
2052 }
2053
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002054 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002055 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2056 requestCellInfoUpdateInternal(
2057 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2058 }
2059
2060 @Override
2061 public void requestCellInfoUpdateWithWorkSource(
2062 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2063 enforceModifyPermission();
2064 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2065 }
2066
2067 private void requestCellInfoUpdateInternal(
2068 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002069 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002071
2072 LocationAccessPolicy.LocationPermissionResult locationResult =
2073 LocationAccessPolicy.checkLocationPermission(mApp,
2074 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2075 .setCallingPackage(callingPackage)
2076 .setCallingPid(Binder.getCallingPid())
2077 .setCallingUid(Binder.getCallingUid())
2078 .setMethod("requestCellInfoUpdate")
2079 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2080 .build());
2081 switch (locationResult) {
2082 case DENIED_HARD:
2083 throw new SecurityException("Not allowed to access cell info");
2084 case DENIED_SOFT:
2085 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002086 }
2087
2088 final Phone phone = getPhone(subId);
2089 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2090
2091 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2092 }
2093
2094 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002096 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002097 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002098
2099 final long identity = Binder.clearCallingIdentity();
2100 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002101 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002102 } finally {
2103 Binder.restoreCallingIdentity(identity);
2104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105 }
2106
Shishir Agrawala9f32182016-04-12 12:00:16 -07002107 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002108 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002109 Phone phone = PhoneFactory.getPhone(slotIndex);
2110 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002111 return null;
2112 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002113 int subId = phone.getSubId();
2114 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2115 mApp, subId, callingPackage, "getImeiForSlot")) {
2116 return null;
2117 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 return phone.getImei();
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
2124 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002125 }
2126
2127 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002128 public String getTypeAllocationCodeForSlot(int slotIndex) {
2129 Phone phone = PhoneFactory.getPhone(slotIndex);
2130 String tac = null;
2131 if (phone != null) {
2132 String imei = phone.getImei();
2133 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2134 }
2135 return tac;
2136 }
2137
2138 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002139 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002140 Phone phone = PhoneFactory.getPhone(slotIndex);
2141 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002142 return null;
2143 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002144
Jeff Davidson913390f2018-02-23 17:11:49 -08002145 int subId = phone.getSubId();
2146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2147 mApp, subId, callingPackage, "getMeidForSlot")) {
2148 return null;
2149 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002150
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 return phone.getMeid();
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
2156 }
Jack Yu2af8d712017-03-15 17:14:14 -07002157 }
2158
2159 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002160 public String getManufacturerCodeForSlot(int slotIndex) {
2161 Phone phone = PhoneFactory.getPhone(slotIndex);
2162 String manufacturerCode = null;
2163 if (phone != null) {
2164 String meid = phone.getMeid();
2165 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2166 }
2167 return manufacturerCode;
2168 }
2169
2170 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002171 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002172 Phone phone = PhoneFactory.getPhone(slotIndex);
2173 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002174 return null;
2175 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002176 int subId = phone.getSubId();
2177 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2178 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2179 return null;
2180 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002181
2182 final long identity = Binder.clearCallingIdentity();
2183 try {
2184 return phone.getDeviceSvn();
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
2187 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002188 }
2189
fionaxu43304da2017-11-27 22:51:16 -08002190 @Override
2191 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 final Phone phone = getPhone(subId);
2195 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2196 } finally {
2197 Binder.restoreCallingIdentity(identity);
2198 }
fionaxu43304da2017-11-27 22:51:16 -08002199 }
2200
2201 @Override
2202 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002203 final long identity = Binder.clearCallingIdentity();
2204 try {
2205 final Phone phone = getPhone(subId);
2206 return phone == null ? null : phone.getCarrierName();
2207 } finally {
2208 Binder.restoreCallingIdentity(identity);
2209 }
fionaxu43304da2017-11-27 22:51:16 -08002210 }
2211
calvinpaneed9ae82018-11-01 19:43:06 +08002212 @Override
chen xuc93cc282018-11-04 17:17:00 -08002213 public int getSubscriptionPreciseCarrierId(int subId) {
2214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 final Phone phone = getPhone(subId);
2217 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2218 : phone.getPreciseCarrierId();
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
2221 }
2222 }
2223
2224 @Override
2225 public String getSubscriptionPreciseCarrierName(int subId) {
2226 final long identity = Binder.clearCallingIdentity();
2227 try {
2228 final Phone phone = getPhone(subId);
2229 return phone == null ? null : phone.getPreciseCarrierName();
2230 } finally {
2231 Binder.restoreCallingIdentity(identity);
2232 }
2233 }
2234
chen xu02581692018-11-11 19:03:44 -08002235 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002236 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2237 if (!isSubscriptionMccMnc) {
2238 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2239 }
chen xu02581692018-11-11 19:03:44 -08002240 final Phone phone = PhoneFactory.getPhone(slotIndex);
2241 if (phone == null) {
2242 return TelephonyManager.UNKNOWN_CARRIER_ID;
2243 }
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2247 } finally {
2248 Binder.restoreCallingIdentity(identity);
2249 }
2250 }
2251
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 //
2253 // Internal helper methods.
2254 //
2255
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002256 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002257 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2258 *
2259 * @throws SecurityException if the caller does not have the required permission
2260 */
2261 private void enforceModifyPermission() {
2262 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2263 }
2264
2265 /**
2266 * Make sure the caller has the CALL_PHONE permission.
2267 *
2268 * @throws SecurityException if the caller does not have the required permission
2269 */
2270 private void enforceCallPermission() {
2271 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2272 }
2273
Stuart Scott8eef64f2015-04-08 15:13:54 -07002274 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002275 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002276 "ConnectivityService");
2277 }
2278
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 private String createTelUrl(String number) {
2280 if (TextUtils.isEmpty(number)) {
2281 return null;
2282 }
2283
Jake Hambye994d462014-02-03 13:10:13 -08002284 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002285 }
2286
Ihab Awadf9e92732013-12-05 18:02:52 -08002287 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2289 }
2290
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002291 private static void logv(String msg) {
2292 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2293 }
2294
Ihab Awadf9e92732013-12-05 18:02:52 -08002295 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2297 }
2298
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002299 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002301 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002302 }
2303
Sanket Padawe356d7632015-06-22 14:03:32 -07002304 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002305 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 final Phone phone = PhoneFactory.getPhone(slotIndex);
2309 if (phone == null) {
2310 return PhoneConstants.PHONE_TYPE_NONE;
2311 } else {
2312 return phone.getPhoneType();
2313 }
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 }
2318
2319 /**
2320 * Returns the CDMA ERI icon index to display
2321 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002322 @Override
2323 public int getCdmaEriIconIndex(String callingPackage) {
2324 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002325 }
2326
Sanket Padawe356d7632015-06-22 14:03:32 -07002327 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002328 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002330 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002331 return -1;
2332 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002333
2334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 final Phone phone = getPhone(subId);
2337 if (phone != null) {
2338 return phone.getCdmaEriIconIndex();
2339 } else {
2340 return -1;
2341 }
2342 } finally {
2343 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002344 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002345 }
2346
2347 /**
2348 * Returns the CDMA ERI icon mode,
2349 * 0 - ON
2350 * 1 - FLASHING
2351 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002352 @Override
2353 public int getCdmaEriIconMode(String callingPackage) {
2354 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002355 }
2356
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002358 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002359 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002360 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002361 return -1;
2362 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002363
2364 final long identity = Binder.clearCallingIdentity();
2365 try {
2366 final Phone phone = getPhone(subId);
2367 if (phone != null) {
2368 return phone.getCdmaEriIconMode();
2369 } else {
2370 return -1;
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376
2377 /**
2378 * Returns the CDMA ERI text,
2379 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002380 @Override
2381 public String getCdmaEriText(String callingPackage) {
2382 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Sanket Padawe356d7632015-06-22 14:03:32 -07002385 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002386 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002388 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 return null;
2390 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002391
2392 final long identity = Binder.clearCallingIdentity();
2393 try {
2394 final Phone phone = getPhone(subId);
2395 if (phone != null) {
2396 return phone.getCdmaEriText();
2397 } else {
2398 return null;
2399 }
2400 } finally {
2401 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002402 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
2405 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002406 * Returns the CDMA MDN.
2407 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002408 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002409 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002410 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2411 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002416 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002417 return phone.getLine1Number();
2418 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002419 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002420 return null;
2421 }
2422 } finally {
2423 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002424 }
2425 }
2426
2427 /**
2428 * Returns the CDMA MIN.
2429 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002430 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002431 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2433 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002434
2435 final long identity = Binder.clearCallingIdentity();
2436 try {
2437 final Phone phone = getPhone(subId);
2438 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2439 return phone.getCdmaMin();
2440 } else {
2441 return null;
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002445 }
2446 }
2447
Hall Liud892bec2018-11-30 14:51:45 -08002448 @Override
2449 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2450 INumberVerificationCallback callback, String callingPackage) {
2451 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2452 != PERMISSION_GRANTED) {
2453 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2454 }
2455 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2456
2457 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2458 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2459 throw new SecurityException("Calling package must be configured in the device config");
2460 }
2461
2462 if (range == null) {
2463 throw new NullPointerException("Range must be non-null");
2464 }
2465
2466 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002467 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002468
2469 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2470 }
2471
Junda Liuca05d5d2014-08-14 22:36:34 -07002472 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002473 * Returns true if CDMA provisioning needs to run.
2474 */
2475 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002476 final long identity = Binder.clearCallingIdentity();
2477 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002478 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479 } finally {
2480 Binder.restoreCallingIdentity(identity);
2481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
2484 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002485 * Sets the voice mail number of a given subId.
2486 */
2487 @Override
2488 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002489 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2494 new Pair<String, String>(alphaTag, number), new Integer(subId));
2495 return success;
2496 } finally {
2497 Binder.restoreCallingIdentity(identity);
2498 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002499 }
2500
Ta-wei Yen87c49842016-05-13 21:19:52 -07002501 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002502 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2503 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002504 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002505 if (!TextUtils.equals(callingPackage, systemDialer)) {
2506 throw new SecurityException("caller must be system dialer");
2507 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002508
2509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2512 if (phoneAccountHandle == null) {
2513 return null;
2514 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002515 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002518 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002519 }
2520
2521 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002522 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002523 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002526 return null;
2527 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002528
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002529 final long identity = Binder.clearCallingIdentity();
2530 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002531 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002532 } finally {
2533 Binder.restoreCallingIdentity(identity);
2534 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002535 }
2536
2537 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002538 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2539 VisualVoicemailSmsFilterSettings settings) {
2540 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
2544 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002545 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002546 } finally {
2547 Binder.restoreCallingIdentity(identity);
2548 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002549 }
2550
2551 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002552 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002558 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-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 VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2566 String callingPackage, int subId) {
2567 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002568
2569 final long identity = Binder.clearCallingIdentity();
2570 try {
2571 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002572 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002573 } finally {
2574 Binder.restoreCallingIdentity(identity);
2575 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002576 }
2577
2578 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002579 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002580 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002585 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002589 }
2590
2591 @Override
2592 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2593 String number, int port, String text, PendingIntent sentIntent) {
2594 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002595 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002596 enforceSendSmsPermission();
2597 // Make the calls as the phone process.
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2601 if (port == 0) {
2602 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2603 sentIntent, null, false);
2604 } else {
2605 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2606 smsManager.sendDataMessageWithSelfPermissions(number, null,
2607 (short) port, data, sentIntent, null);
2608 }
2609 } finally {
2610 Binder.restoreCallingIdentity(identity);
2611 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002612 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002613 /**
fionaxu0152e512016-11-14 13:36:14 -08002614 * Sets the voice activation state of a given subId.
2615 */
2616 @Override
2617 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2619 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 final Phone phone = getPhone(subId);
2624 if (phone != null) {
2625 phone.setVoiceActivationState(activationState);
2626 } else {
2627 loge("setVoiceActivationState fails with invalid subId: " + subId);
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002631 }
2632 }
2633
2634 /**
2635 * Sets the data activation state of a given subId.
2636 */
2637 @Override
2638 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2640 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null) {
2646 phone.setDataActivationState(activationState);
2647 } else {
2648 loge("setVoiceActivationState fails with invalid subId: " + subId);
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002652 }
2653 }
2654
2655 /**
2656 * Returns the voice activation state of a given subId.
2657 */
2658 @Override
2659 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002660 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002661
fionaxu0152e512016-11-14 13:36:14 -08002662 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 if (phone != null) {
2666 return phone.getVoiceActivationState();
2667 } else {
2668 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2669 }
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002672 }
2673 }
2674
2675 /**
2676 * Returns the data activation state of a given subId.
2677 */
2678 @Override
2679 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002680 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002681
fionaxu0152e512016-11-14 13:36:14 -08002682 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 if (phone != null) {
2686 return phone.getDataActivationState();
2687 } else {
2688 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2689 }
2690 } finally {
2691 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002692 }
2693 }
2694
2695 /**
Wink Saville36469e72014-06-11 15:17:00 -07002696 * Returns the unread count of voicemails for a subId
2697 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002698 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002699 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2701 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2702 return 0;
2703 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002704 final long identity = Binder.clearCallingIdentity();
2705 try {
2706 final Phone phone = getPhone(subId);
2707 if (phone != null) {
2708 return phone.getVoiceMessageCount();
2709 } else {
2710 return 0;
2711 }
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 }
2716
2717 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002718 * returns true, if the device is in a state where both voice and data
2719 * are supported simultaneously. This can change based on location or network condition.
2720 */
2721 @Override
2722 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002723 final long identity = Binder.clearCallingIdentity();
2724 try {
2725 final Phone phone = getPhone(subId);
2726 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
2729 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002730 }
2731
2732 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002733 * Send the dialer code if called from the current default dialer or the caller has
2734 * carrier privilege.
2735 * @param inputCode The dialer code to send
2736 */
2737 @Override
2738 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002739 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002740 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002741 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2742 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002743 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002744 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2745 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002746 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002747
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002750 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002751 } finally {
2752 Binder.restoreCallingIdentity(identity);
2753 }
fionaxu235cc5e2017-03-06 22:25:57 -08002754 }
2755
2756 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002757 * Returns the data network type.
2758 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 *
2760 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2761 */
2762 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002763 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002764 final long identity = Binder.clearCallingIdentity();
2765 try {
2766 final Phone phone = getPhone(getDefaultSubscription());
2767 if (phone != null) {
2768 return phone.getServiceState().getDataNetworkType();
2769 } else {
2770 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2771 }
2772 } finally {
2773 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002774 }
Wink Saville36469e72014-06-11 15:17:00 -07002775 }
2776
Pengquan Meng0c05b502018-09-06 09:59:22 -07002777 @Override
2778 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002779 if (!isActiveSubscription(subId)) {
2780 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2781 }
2782
Pengquan Meng0c05b502018-09-06 09:59:22 -07002783 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2784 }
2785
Brad Ebinger4c460712018-10-01 10:40:55 -07002786 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002787 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2788 throws RemoteException {
2789 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002790 final long token = Binder.clearCallingIdentity();
2791 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002794 .addRegistrationCallbackForSubscription(c, subId);
2795 } finally {
2796 Binder.restoreCallingIdentity(token);
2797 }
2798 }
2799
2800 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002801 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2802 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002803 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2804 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2805 }
2806 Binder.withCleanCallingIdentity(() -> {
2807 try {
2808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002809 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002810 .removeRegistrationCallbackForSubscription(c, subId);
2811 } catch (IllegalArgumentException e) {
2812 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2813 + "is inactive, ignoring unregister.");
2814 // If the subscription is no longer active, just return, since the callback
2815 // will already have been removed internally.
2816 }
2817 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002818 }
2819
2820 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002821 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2822 throws RemoteException {
2823 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002824 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2825 final long token = Binder.clearCallingIdentity();
2826 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002827 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002828 .addCapabilitiesCallbackForSubscription(c, subId);
2829 } finally {
2830 Binder.restoreCallingIdentity(token);
2831 }
2832 }
2833
2834 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002835 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2836 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002837
2838 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2839 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2840 }
2841 Binder.withCleanCallingIdentity(() -> {
2842 try {
2843 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002845 .removeCapabilitiesCallbackForSubscription(c, subId);
2846 } catch (IllegalArgumentException e) {
2847 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2848 + "is inactive, ignoring unregister.");
2849 // If the subscription is no longer active, just return, since the callback
2850 // will already have been removed internally.
2851 }
2852 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002853 }
2854
2855 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002856 public boolean isCapable(int subId, int capability, int regTech) {
2857 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002858 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2859 final long token = Binder.clearCallingIdentity();
2860 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002861 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002862 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2863 } catch (ImsException e) {
2864 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2865 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002866 } catch (IllegalArgumentException e) {
2867 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2868 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002869 } finally {
2870 Binder.restoreCallingIdentity(token);
2871 }
2872 }
2873
2874 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002875 public boolean isAvailable(int subId, int capability, int regTech) {
2876 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002877 final long token = Binder.clearCallingIdentity();
2878 try {
2879 Phone phone = getPhone(subId);
2880 if (phone == null) return false;
2881 return phone.isImsCapabilityAvailable(capability, regTech);
2882 } finally {
2883 Binder.restoreCallingIdentity(token);
2884 }
2885 }
2886
2887 @Override
2888 public boolean isAdvancedCallingSettingEnabled(int subId) {
2889 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2891 final long token = Binder.clearCallingIdentity();
2892 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002893 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002894 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2895 } finally {
2896 Binder.restoreCallingIdentity(token);
2897 }
2898 }
2899
2900 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002901 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002903 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002907 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002908 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
2911 }
2912 }
2913
2914 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002915 public boolean isVtSettingEnabled(int subId) {
2916 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002920 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002921 getSlotIndexOrException(subId)).isVtEnabledByUser();
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
2925 }
2926
2927 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002928 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002930 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002931 final long identity = Binder.clearCallingIdentity();
2932 try {
2933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002934 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
2941 public boolean isVoWiFiSettingEnabled(int subId) {
2942 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
2945 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002946 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002947 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002954 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002956 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002957 final long identity = Binder.clearCallingIdentity();
2958 try {
2959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002960 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
2967 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2968 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002972 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002973 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
2977 }
2978
2979 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002980 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002982 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002983 final long identity = Binder.clearCallingIdentity();
2984 try {
2985 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002986 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002987 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2988 } finally {
2989 Binder.restoreCallingIdentity(identity);
2990 }
2991 }
2992
2993 @Override
2994 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2995 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2996 "setVoWiFiNonPersistent");
2997 final long identity = Binder.clearCallingIdentity();
2998 try {
2999 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003000 boolean isRoaming = TelephonyManager.from(
3001 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003002 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003003 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
3007 }
3008
3009 @Override
3010 public int getVoWiFiModeSetting(int subId) {
3011 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3012 final long identity = Binder.clearCallingIdentity();
3013 try {
3014 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003015 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003016 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 @Override
3023 public void setVoWiFiModeSetting(int subId, int mode) {
3024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3025 "setVoWiFiModeSetting");
3026 final long identity = Binder.clearCallingIdentity();
3027 try {
3028 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003029 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003030 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
3034 }
3035
3036 @Override
3037 public int getVoWiFiRoamingModeSetting(int subId) {
3038 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003042 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003043 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
3050 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3052 "setVoWiFiRoamingModeSetting");
3053 final long identity = Binder.clearCallingIdentity();
3054 try {
3055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003056 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003057 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3058 } finally {
3059 Binder.restoreCallingIdentity(identity);
3060 }
3061 }
3062
3063 @Override
3064 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3065 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3066 "setRttCapabilityEnabled");
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003070 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003071 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3072 } finally {
3073 Binder.restoreCallingIdentity(identity);
3074 }
3075 }
3076
3077 @Override
3078 public boolean isTtyOverVolteEnabled(int subId) {
3079 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003083 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003084 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003090 @Override
3091 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3092 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003096 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003097 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 }
3102
3103 @Override
3104 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3105 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3106 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3108 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3109 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003110 try {
3111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003112 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003113 .removeProvisioningCallbackForSubscription(callback, subId);
3114 } catch (IllegalArgumentException e) {
3115 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3116 + "is inactive, ignoring unregister.");
3117 // If the subscription is no longer active, just return, since the callback will already
3118 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003119 } finally {
3120 Binder.restoreCallingIdentity(identity);
3121 }
3122 }
3123
3124 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003125 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3126 boolean isProvisioned) {
3127 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3128 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3129 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3130 }
3131 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3132 "setProvisioningStatusForCapability");
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3136 Phone phone = getPhone(subId);
3137 if (phone == null) {
3138 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3139 + subId);
3140 return;
3141 }
3142 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3143 return;
3144 }
3145
3146 // this capability requires provisioning, route to the correct API.
3147 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3148 switch (capability) {
3149 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3150 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3151 ims.setVolteProvisioned(isProvisioned);
3152 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3153 ims.setWfcProvisioned(isProvisioned);
3154 }
3155 break;
3156 }
3157 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3158 // There is currently no difference in VT provisioning type.
3159 ims.setVtProvisioned(isProvisioned);
3160 break;
3161 }
3162 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3163 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3164 // change the capability of the feature instead if needed.
3165 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3166 == isProvisioned) {
3167 // No change in provisioning.
3168 return;
3169 }
3170 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3171 try {
3172 ims.changeMmTelCapability(capability, tech, isProvisioned);
3173 } catch (ImsException e) {
3174 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3175 + ", Exception" + e.getMessage());
3176 }
3177 break;
3178 }
3179 default: {
3180 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3181 + capability + "', which does not require provisioning.");
3182 }
3183 }
3184
3185 } finally {
3186 Binder.restoreCallingIdentity(identity);
3187 }
3188 }
3189
3190 @Override
3191 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3192 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3193 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3194 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3195 }
3196 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3197 final long identity = Binder.clearCallingIdentity();
3198 try {
3199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3200 Phone phone = getPhone(subId);
3201 if (phone == null) {
3202 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3203 + subId);
3204 // We will fail with "true" as the provisioning status because this is the default
3205 // if we do not require provisioning.
3206 return true;
3207 }
3208
3209 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3210 return true;
3211 }
3212
3213 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3214 switch (capability) {
3215 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3216 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3217 return ims.isVolteProvisionedOnDevice();
3218 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3219 return ims.isWfcProvisionedOnDevice();
3220 }
3221 // This should never happen, since we are checking tech above to make sure it
3222 // is either LTE or IWLAN.
3223 throw new IllegalArgumentException("Invalid radio technology for voice "
3224 + "capability.");
3225 }
3226 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3227 // There is currently no difference in VT provisioning type.
3228 return ims.isVtProvisionedOnDevice();
3229 }
3230 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3231 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3232 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3233 }
3234 default: {
3235 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3236 + capability + "', which does not require provisioning.");
3237 }
3238 }
3239
3240 } finally {
3241 Binder.restoreCallingIdentity(identity);
3242 }
3243 }
3244
3245 @Override
3246 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3247 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3248 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3249 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3250 }
3251 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3252 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3253 return (provisionedBits & capability) > 0;
3254 }
3255
3256 @Override
3257 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3258 boolean isProvisioned) {
3259 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3260 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3261 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3262 }
3263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3264 "setProvisioningStatusForCapability");
3265 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3266 // If the current provisioning status for capability already matches isProvisioned,
3267 // do nothing.
3268 if (((provisionedBits & capability) > 0) == isProvisioned) {
3269 return;
3270 }
3271 if (isProvisioned) {
3272 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3273 } else {
3274 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3275 }
3276 }
3277
3278 /**
3279 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3280 * technology. The bitfield should mirror the bitfield defined by
3281 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3282 */
3283 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3284 String key = getMmTelProvisioningKey(subId, tech);
3285 // Default is no capabilities are provisioned.
3286 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3287 }
3288
3289 /**
3290 * Sets the MmTel capability provisioning bitfield (defined by
3291 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3292 * technology specified.
3293 *
3294 * Note: This is a synchronous command and should not be called on UI thread.
3295 */
3296 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3297 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3298 String key = getMmTelProvisioningKey(subId, tech);
3299 editor.putInt(key, newField);
3300 editor.commit();
3301 }
3302
3303 private static String getMmTelProvisioningKey(int subId, int tech) {
3304 // resulting key is provision_ims_mmtel_{subId}_{tech}
3305 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3306 }
3307
3308 /**
3309 * Query CarrierConfig to see if the specified capability requires provisioning for the
3310 * carrier associated with the subscription id.
3311 */
3312 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3313 int capability) {
3314 CarrierConfigManager configManager = new CarrierConfigManager(context);
3315 PersistableBundle c = configManager.getConfigForSubId(subId);
3316 boolean requireUtProvisioning = c.getBoolean(
3317 // By default, this config is true (even if there is no SIM). We also check to make
3318 // sure the subscription needs provisioning here, so we do not need to check for
3319 // the no-SIM case, where we would normally shortcut this to false.
3320 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3321 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3322 false);
3323 boolean requireVoiceVtProvisioning = c.getBoolean(
3324 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3325
3326 // First check to make sure that the capability requires provisioning.
3327 switch (capability) {
3328 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3329 // intentional fallthrough
3330 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3331 if (requireVoiceVtProvisioning) {
3332 // Voice and Video requires provisioning
3333 return true;
3334 }
3335 break;
3336 }
3337 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3338 if (requireUtProvisioning) {
3339 // UT requires provisioning
3340 return true;
3341 }
3342 break;
3343 }
3344 }
3345 return false;
3346 }
3347
3348 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003349 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003350 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3351 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3352 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003353 enforceReadPrivilegedPermission("getImsProvisioningInt");
3354 final long identity = Binder.clearCallingIdentity();
3355 try {
3356 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003357 int slotId = getSlotIndex(subId);
3358 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3359 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3360 + subId + "' for key:" + key);
3361 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3362 }
3363 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003364 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003365 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3366 + subId + "' for key:" + key);
3367 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003368 } finally {
3369 Binder.restoreCallingIdentity(identity);
3370 }
3371 }
3372
3373 @Override
3374 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003375 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3376 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3377 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003378 enforceReadPrivilegedPermission("getImsProvisioningString");
3379 final long identity = Binder.clearCallingIdentity();
3380 try {
3381 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003382 int slotId = getSlotIndex(subId);
3383 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3384 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3385 + subId + "' for key:" + key);
3386 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3387 }
3388 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003389 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003390 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3391 + subId + "' for key:" + key);
3392 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
3396 }
3397
3398 @Override
3399 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003400 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3401 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3402 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003403 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3404 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003408 int slotId = getSlotIndex(subId);
3409 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3410 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3411 + subId + "' for key:" + key);
3412 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3413 }
3414 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003415 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003416 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3417 + "' for key:" + key);
3418 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003419 } finally {
3420 Binder.restoreCallingIdentity(identity);
3421 }
3422 }
3423
3424 @Override
3425 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003426 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3427 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3428 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003429 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3430 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003434 int slotId = getSlotIndex(subId);
3435 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3436 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3437 + subId + "' for key:" + key);
3438 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3439 }
3440 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3443 + "' for key:" + key);
3444 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 } finally {
3446 Binder.restoreCallingIdentity(identity);
3447 }
3448 }
3449
Brad Ebinger4c460712018-10-01 10:40:55 -07003450 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3451 int slotId = SubscriptionManager.getSlotIndex(subId);
3452 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003453 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003454 }
3455 return slotId;
3456 }
3457
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003458 private int getSlotIndex(int subId) {
3459 int slotId = SubscriptionManager.getSlotIndex(subId);
3460 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3461 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3462 }
3463 return slotId;
3464 }
3465
Wink Saville36469e72014-06-11 15:17:00 -07003466 /**
3467 * Returns the network type for a subId
3468 */
3469 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003470 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003471 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003472 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003473 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3474 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003475
Malcolm Chend965c8b2018-02-28 15:00:40 -08003476 final long identity = Binder.clearCallingIdentity();
3477 try {
3478 final Phone phone = getPhone(subId);
3479 if (phone != null) {
3480 return phone.getServiceState().getDataNetworkType();
3481 } else {
3482 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3483 }
3484 } finally {
3485 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003486 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003487 }
3488
3489 /**
3490 * Returns the data network type
3491 */
3492 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003493 public int getDataNetworkType(String callingPackage) {
3494 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003495 }
3496
3497 /**
3498 * Returns the data network type for a subId
3499 */
3500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003503 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3505 }
3506
Malcolm Chend965c8b2018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 if (phone != null) {
3511 return phone.getServiceState().getDataNetworkType();
3512 } else {
3513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
3520 /**
Wink Saville36469e72014-06-11 15:17:00 -07003521 * Returns the Voice network type for a subId
3522 */
3523 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003524 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003525 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003526 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003527 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3528 }
3529
Malcolm Chend965c8b2018-02-28 15:00:40 -08003530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 return phone.getServiceState().getVoiceNetworkType();
3535 } else {
3536 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003540 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003541 }
3542
3543 /**
3544 * @return true if a ICC card is present
3545 */
3546 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003547 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003548 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3549 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003550 }
3551
3552 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003553 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003554 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003555 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003556 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 final Phone phone = PhoneFactory.getPhone(slotIndex);
3560 if (phone != null) {
3561 return phone.getIccCard().hasIccCard();
3562 } else {
3563 return false;
3564 }
3565 } finally {
3566 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003568 }
3569
3570 /**
3571 * Return if the current radio is LTE on CDMA. This
3572 * is a tri-state return value as for a period of time
3573 * the mode may be unknown.
3574 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003575 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003577 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003578 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003579 @Override
3580 public int getLteOnCdmaMode(String callingPackage) {
3581 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003582 }
3583
Sanket Padawe356d7632015-06-22 14:03:32 -07003584 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003585 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003587 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003588 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3589 }
3590
Malcolm Chend965c8b2018-02-28 15:00:40 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 final Phone phone = getPhone(subId);
3594 if (phone == null) {
3595 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3596 } else {
3597 return phone.getLteOnCdmaMode();
3598 }
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003601 }
Wink Saville36469e72014-06-11 15:17:00 -07003602 }
3603
Wink Saville36469e72014-06-11 15:17:00 -07003604 /**
3605 * {@hide}
3606 * Returns Default subId, 0 in the case of single standby.
3607 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003608 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003609 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003610 }
3611
Shishir Agrawala9f32182016-04-12 12:00:16 -07003612 private int getSlotForDefaultSubscription() {
3613 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3614 }
3615
Wink Savilleb564aae2014-10-23 10:18:09 -07003616 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003617 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003618 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003619
Pengquan Meng466e2482018-09-21 15:54:48 -07003620 private boolean isActiveSubscription(int subId) {
3621 return mSubscriptionController.isActiveSubId(subId);
3622 }
3623
Ihab Awadf2177b72013-11-25 13:33:23 -08003624 /**
3625 * @see android.telephony.TelephonyManager.WifiCallingChoices
3626 */
3627 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003628 final long identity = Binder.clearCallingIdentity();
3629 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003630 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3632 getWhenToMakeWifiCallsDefaultPreference());
3633 } finally {
3634 Binder.restoreCallingIdentity(identity);
3635 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003636 }
3637
3638 /**
3639 * @see android.telephony.TelephonyManager.WifiCallingChoices
3640 */
3641 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003642 final long identity = Binder.clearCallingIdentity();
3643 try {
3644 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003645 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003646 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3647 } finally {
3648 Binder.restoreCallingIdentity(identity);
3649 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003650 }
3651
Sailesh Nepald1e68152013-12-12 19:08:02 -08003652 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003653 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003654 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003655 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003656
Shishir Agrawal566b7612013-10-28 14:41:00 -07003657 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003658 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3659 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3661 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003663
Malcolm Chend965c8b2018-02-28 15:00:40 -08003664 final long identity = Binder.clearCallingIdentity();
3665 try {
3666 if (TextUtils.equals(ISDR_AID, aid)) {
3667 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003668 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3669 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003670 if (bestComponent == null
3671 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3672 loge("The calling package is not allowed to access ISD-R.");
3673 throw new SecurityException(
3674 "The calling package is not allowed to access ISD-R.");
3675 }
Derek Tan740e1672017-06-27 14:56:27 -07003676 }
Derek Tan740e1672017-06-27 14:56:27 -07003677
Malcolm Chend965c8b2018-02-28 15:00:40 -08003678 if (DBG) {
3679 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3680 }
3681 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3682 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3683 if (DBG) log("iccOpenLogicalChannel: " + response);
3684 return response;
3685 } finally {
3686 Binder.restoreCallingIdentity(identity);
3687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003688 }
3689
3690 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003691 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003692 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3693 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003694
Malcolm Chend965c8b2018-02-28 15:00:40 -08003695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3698 if (channel < 0) {
3699 return false;
3700 }
3701 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3702 if (DBG) log("iccCloseLogicalChannel: " + success);
3703 return success;
3704 } finally {
3705 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003706 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003707 }
3708
3709 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003710 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003711 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3713 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003714
Malcolm Chend965c8b2018-02-28 15:00:40 -08003715 final long identity = Binder.clearCallingIdentity();
3716 try {
3717 if (DBG) {
3718 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3719 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3720 + p3 + " data=" + data);
3721 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003722
Malcolm Chend965c8b2018-02-28 15:00:40 -08003723 if (channel < 0) {
3724 return "";
3725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003726
Malcolm Chend965c8b2018-02-28 15:00:40 -08003727 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3728 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3729 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003730
Malcolm Chend965c8b2018-02-28 15:00:40 -08003731 // Append the returned status code to the end of the response payload.
3732 String s = Integer.toHexString(
3733 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3734 if (response.payload != null) {
3735 s = IccUtils.bytesToHexString(response.payload) + s;
3736 }
3737 return s;
3738 } finally {
3739 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003740 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003741 }
Jake Hambye994d462014-02-03 13:10:13 -08003742
Evan Charltonc66da362014-05-16 14:06:40 -07003743 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003744 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3745 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003746 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3747 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003749
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3753 && TextUtils.equals(ISDR_AID, data)) {
3754 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003755 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3756 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003757 if (bestComponent == null
3758 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3759 loge("The calling package is not allowed to select ISD-R.");
3760 throw new SecurityException(
3761 "The calling package is not allowed to select ISD-R.");
3762 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003763 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003764
Malcolm Chend965c8b2018-02-28 15:00:40 -08003765 if (DBG) {
3766 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3767 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3768 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003769
Malcolm Chend965c8b2018-02-28 15:00:40 -08003770 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3771 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3772 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003773
Malcolm Chend965c8b2018-02-28 15:00:40 -08003774 // Append the returned status code to the end of the response payload.
3775 String s = Integer.toHexString(
3776 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3777 if (response.payload != null) {
3778 s = IccUtils.bytesToHexString(response.payload) + s;
3779 }
3780 return s;
3781 } finally {
3782 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003783 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003784 }
3785
3786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003787 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003788 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003789 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3790 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003791
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
3794 if (DBG) {
3795 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3796 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3797 }
3798
3799 IccIoResult response =
3800 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3801 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3802 subId);
3803
3804 if (DBG) {
3805 log("Exchange SIM_IO [R]" + response);
3806 }
3807
3808 byte[] result = null;
3809 int length = 2;
3810 if (response.payload != null) {
3811 length = 2 + response.payload.length;
3812 result = new byte[length];
3813 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3814 } else {
3815 result = new byte[length];
3816 }
3817
3818 result[length - 1] = (byte) response.sw2;
3819 result[length - 2] = (byte) response.sw1;
3820 return result;
3821 } finally {
3822 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003823 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003824 }
3825
Nathan Haroldb3014052017-01-25 15:57:32 -08003826 /**
3827 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3828 * on a particular subscription
3829 */
sqianb6e41952018-03-12 14:54:01 -07003830 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3831 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3832 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3833 return null;
3834 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003835
3836 final long identity = Binder.clearCallingIdentity();
3837 try {
3838 if (appType != TelephonyManager.APPTYPE_USIM
3839 && appType != TelephonyManager.APPTYPE_SIM) {
3840 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3841 return null;
3842 }
3843 Object response = sendRequest(
3844 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3845 if (response instanceof String[]) {
3846 return (String[]) response;
3847 }
3848 // Response is an Exception of some kind,
3849 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003850 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003851 } finally {
3852 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003853 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003854 }
3855
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003857 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3859 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003860
Malcolm Chend965c8b2018-02-28 15:00:40 -08003861 final long identity = Binder.clearCallingIdentity();
3862 try {
3863 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3864 if (response.payload == null) {
3865 return "";
3866 }
Evan Charltonc66da362014-05-16 14:06:40 -07003867
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868 // Append the returned status code to the end of the response payload.
3869 String s = Integer.toHexString(
3870 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3871 s = IccUtils.bytesToHexString(response.payload) + s;
3872 return s;
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
Evan Charltonc66da362014-05-16 14:06:40 -07003876 }
3877
Jake Hambye994d462014-02-03 13:10:13 -08003878 /**
3879 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3880 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3881 *
3882 * @param itemID the ID of the item to read
3883 * @return the NV item as a String, or null on error.
3884 */
3885 @Override
3886 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3889 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003890
3891 final long identity = Binder.clearCallingIdentity();
3892 try {
3893 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003894 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003895 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3896 return value;
3897 } finally {
3898 Binder.restoreCallingIdentity(identity);
3899 }
Jake Hambye994d462014-02-03 13:10:13 -08003900 }
3901
3902 /**
3903 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3904 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3905 *
3906 * @param itemID the ID of the item to read
3907 * @param itemValue the value to write, as a String
3908 * @return true on success; false on any failure
3909 */
3910 @Override
3911 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003912 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3914 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003915
3916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3919 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003920 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003921 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3922 return success;
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
Jake Hambye994d462014-02-03 13:10:13 -08003926 }
3927
3928 /**
3929 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3930 * Used for device configuration by some CDMA operators.
3931 *
3932 * @param preferredRoamingList byte array containing the new PRL
3933 * @return true on success; false on any failure
3934 */
3935 @Override
3936 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3938 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003939
3940 final long identity = Binder.clearCallingIdentity();
3941 try {
3942 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3943 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3944 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3945 return success;
3946 } finally {
3947 Binder.restoreCallingIdentity(identity);
3948 }
Jake Hambye994d462014-02-03 13:10:13 -08003949 }
3950
3951 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003952 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003953 * Used for device configuration by some CDMA operators.
3954 *
chen xu1cc0abe2018-10-26 17:39:23 -07003955 * @param slotIndex - device slot.
3956 *
Jake Hambye994d462014-02-03 13:10:13 -08003957 * @return true on success; false on any failure
3958 */
3959 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003960 public boolean resetModemConfig(int slotIndex) {
3961 Phone phone = PhoneFactory.getPhone(slotIndex);
3962 if (phone != null) {
3963 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3964 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003965
chen xu1cc0abe2018-10-26 17:39:23 -07003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3969 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3970 return success;
3971 } finally {
3972 Binder.restoreCallingIdentity(identity);
3973 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003974 }
chen xu1cc0abe2018-10-26 17:39:23 -07003975 return false;
3976 }
3977
3978 /**
3979 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3980 *
3981 * @param slotIndex - device slot.
3982 *
3983 * @return true on success; false on any failure
3984 */
3985 @Override
3986 public boolean rebootModem(int slotIndex) {
3987 Phone phone = PhoneFactory.getPhone(slotIndex);
3988 if (phone != null) {
3989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3990 mApp, phone.getSubId(), "rebootModem");
3991
3992 final long identity = Binder.clearCallingIdentity();
3993 try {
3994 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3995 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3996 return success;
3997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
4000 }
4001 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004002 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004003
Svet Ganovb320e182015-04-16 12:30:10 -07004004 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004005 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004007 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004008 return new String[0];
4009 }
4010
Malcolm Chend965c8b2018-02-28 15:00:40 -08004011 final long identity = Binder.clearCallingIdentity();
4012 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004013 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
Wink Saville36469e72014-06-11 15:17:00 -07004017 }
4018
Brad Ebinger51f743a2017-01-23 13:50:20 -08004019 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004020 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4021 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004022 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004023 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004024 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004025
4026 final long identity = Binder.clearCallingIdentity();
4027 try {
4028 PhoneFactory.getImsResolver().enableIms(slotId);
4029 } finally {
4030 Binder.restoreCallingIdentity(identity);
4031 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004032 }
4033
4034 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004035 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4036 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004037 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004038 public void disableIms(int slotId) {
4039 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004040
4041 final long identity = Binder.clearCallingIdentity();
4042 try {
4043 PhoneFactory.getImsResolver().disableIms(slotId);
4044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004047 }
4048
4049 /**
4050 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4051 * feature or {@link null} if the service is not available. If the feature is available, the
4052 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4053 */
4054 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004055 IImsServiceFeatureCallback callback) {
4056 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004057
4058 final long identity = Binder.clearCallingIdentity();
4059 try {
4060 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004064 }
4065
4066 /**
4067 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4068 * feature during emergency calling or {@link null} if the service is not available. If the
4069 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4070 * listener for feature updates.
4071 */
4072 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4073 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004074
4075 final long identity = Binder.clearCallingIdentity();
4076 try {
4077 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4078 } finally {
4079 Binder.restoreCallingIdentity(identity);
4080 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004081 }
4082
Brad Ebinger5f64b052017-12-14 14:26:15 -08004083 /**
4084 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4085 * specified.
4086 */
4087 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4088 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004089
4090 final long identity = Binder.clearCallingIdentity();
4091 try {
4092 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4093 } finally {
4094 Binder.restoreCallingIdentity(identity);
4095 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004096 }
4097
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004098 /**
4099 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4100 * specified.
4101 */
4102 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4103 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004104
4105 final long identity = Binder.clearCallingIdentity();
4106 try {
4107 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004111 }
4112
Brad Ebinger884c07b2018-02-15 16:17:40 -08004113 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004114 * Sets the ImsService Package Name that Telephony will bind to.
4115 *
4116 * @param slotId the slot ID that the ImsService should bind for.
4117 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4118 * ImsService is the device default ImsService.
4119 * @param packageName The package name of the application that contains the ImsService to bind
4120 * to.
4121 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4122 * @hide
4123 */
4124 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004125 int[] subIds = SubscriptionManager.getSubId(slotId);
4126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4127 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4128 "setImsService");
4129
Malcolm Chend965c8b2018-02-28 15:00:40 -08004130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4133 isCarrierImsService, packageName);
4134 } finally {
4135 Binder.restoreCallingIdentity(identity);
4136 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004137 }
4138
4139 /**
4140 * Return the ImsService configuration.
4141 *
4142 * @param slotId The slot that the ImsService is associated with.
4143 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4144 * the device default.
4145 * @return the package name of the ImsService configuration.
4146 */
4147 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004148 int[] subIds = SubscriptionManager.getSubId(slotId);
4149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4150 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4151 "getImsService");
4152
Malcolm Chend965c8b2018-02-28 15:00:40 -08004153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4156 isCarrierImsService);
4157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004160 }
4161
Wink Saville36469e72014-06-11 15:17:00 -07004162 public void setImsRegistrationState(boolean registered) {
4163 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004164
4165 final long identity = Binder.clearCallingIdentity();
4166 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004167 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
Wink Saville36469e72014-06-11 15:17:00 -07004171 }
4172
4173 /**
Stuart Scott54788802015-03-30 13:18:01 -07004174 * Set the network selection mode to automatic.
4175 *
4176 */
4177 @Override
4178 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4180 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004181
Pengquan Meng466e2482018-09-21 15:54:48 -07004182 if (!isActiveSubscription(subId)) {
4183 return;
4184 }
4185
Malcolm Chend965c8b2018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4189 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4190 } finally {
4191 Binder.restoreCallingIdentity(identity);
4192 }
Stuart Scott54788802015-03-30 13:18:01 -07004193 }
4194
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004195 /**
4196 * Ask the radio to connect to the input network and change selection mode to manual.
4197 *
4198 * @param subId the id of the subscription.
4199 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4200 * the operator to attach to.
4201 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4202 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4203 * normal network selection next time.
4204 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004205 */
4206 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004207 public boolean setNetworkSelectionModeManual(
4208 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004209 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4210 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004211
4212 if (!isActiveSubscription(subId)) {
4213 return false;
4214 }
4215
Malcolm Chend965c8b2018-02-28 15:00:40 -08004216 final long identity = Binder.clearCallingIdentity();
4217 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004218 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004219 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004220 if (DBG) {
4221 log("setNetworkSelectionModeManual: subId: " + subId
4222 + " operator: " + operatorInfo);
4223 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004224 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4225 } finally {
4226 Binder.restoreCallingIdentity(identity);
4227 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004228 }
4229
4230 /**
4231 * Scans for available networks.
4232 */
4233 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004234 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004235 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4236 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004237 LocationAccessPolicy.LocationPermissionResult locationResult =
4238 LocationAccessPolicy.checkLocationPermission(mApp,
4239 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4240 .setCallingPackage(callingPackage)
4241 .setCallingPid(Binder.getCallingPid())
4242 .setCallingUid(Binder.getCallingUid())
4243 .setMethod("getCellNetworkScanResults")
4244 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4245 .build());
4246 switch (locationResult) {
4247 case DENIED_HARD:
4248 throw new SecurityException("Not allowed to access scan results -- location");
4249 case DENIED_SOFT:
4250 return null;
4251 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004252
Pengquan Meng0c05b502018-09-06 09:59:22 -07004253 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004254 try {
4255 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004256 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004257 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004258 } finally {
4259 Binder.restoreCallingIdentity(identity);
4260 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004261 }
4262
4263 /**
yinxub1bed742017-04-17 11:45:04 -07004264 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004265 *
yinxub1bed742017-04-17 11:45:04 -07004266 * @param subId id of the subscription
4267 * @param request contains the radio access networks with bands/channels to scan
4268 * @param messenger callback messenger for scan results or errors
4269 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004270 * @return the id of the requested scan which can be used to stop the scan.
4271 */
4272 @Override
4273 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004274 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4276 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004277
Hall Liuf19c44f2018-11-27 14:38:17 -08004278 LocationAccessPolicy.LocationPermissionResult locationResult =
4279 LocationAccessPolicy.checkLocationPermission(mApp,
4280 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4281 .setCallingPackage(callingPackage)
4282 .setCallingPid(Binder.getCallingPid())
4283 .setCallingUid(Binder.getCallingUid())
4284 .setMethod("requestNetworkScan")
4285 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4286 .build());
4287 switch (locationResult) {
4288 case DENIED_HARD:
4289 throw new SecurityException("Not allowed to request network scan -- location");
4290 case DENIED_SOFT:
4291 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004292 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004293
4294 return mNetworkScanRequestTracker.startNetworkScan(
4295 request, messenger, binder, getPhone(subId),
4296 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004297 }
4298
4299 /**
4300 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004301 *
4302 * @param subId id of the subscription
4303 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004304 */
4305 @Override
4306 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004307 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4308 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004309
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
4315 }
yinxu504e1392017-04-12 16:03:22 -07004316 }
4317
4318 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004319 * Get the calculated preferred network type.
4320 * Used for debugging incorrect network type.
4321 *
4322 * @return the preferred network type, defined in RILConstants.java.
4323 */
4324 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004325 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004326 final Phone defaultPhone = getDefaultPhone();
4327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4328 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004329 return RILConstants.PREFERRED_NETWORK_MODE;
4330 }
4331
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004335 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004336 } finally {
4337 Binder.restoreCallingIdentity(identity);
4338 }
Junda Liu84d15a22014-07-02 11:21:04 -07004339 }
4340
4341 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004342 * Get the preferred network type.
4343 * Used for device configuration by some CDMA operators.
4344 *
4345 * @return the preferred network type, defined in RILConstants.java.
4346 */
4347 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004348 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004349 TelephonyPermissions
4350 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4351 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004352
4353 final long identity = Binder.clearCallingIdentity();
4354 try {
4355 if (DBG) log("getPreferredNetworkType");
4356 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4357 int networkType = (result != null ? result[0] : -1);
4358 if (DBG) log("getPreferredNetworkType: " + networkType);
4359 return networkType;
4360 } finally {
4361 Binder.restoreCallingIdentity(identity);
4362 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004363 }
4364
4365 /**
4366 * Set the preferred network type.
4367 * Used for device configuration by some CDMA operators.
4368 *
4369 * @param networkType the preferred network type, defined in RILConstants.java.
4370 * @return true on success; false on any failure.
4371 */
4372 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004373 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4375 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004376
4377 final long identity = Binder.clearCallingIdentity();
4378 try {
4379 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4380 Boolean success = (Boolean) sendRequest(
4381 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4382 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4383 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004384 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004385 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4386 }
4387 return success;
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004390 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004391 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004392
4393 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004394 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004395 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004396 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004397 * @hide
4398 */
4399 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004400 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004401 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004403 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004404 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004405 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004406 } finally {
4407 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004408 }
Junda Liu475951f2014-11-07 16:45:03 -08004409 }
4410
4411 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004412 * Set mobile data enabled
4413 * Used by the user through settings etc to turn on/off mobile data
4414 *
4415 * @param enable {@code true} turn turn data on, else {@code false}
4416 */
4417 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004418 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4420 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004421
4422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 int phoneId = mSubscriptionController.getPhoneId(subId);
4425 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4426 Phone phone = PhoneFactory.getPhone(phoneId);
4427 if (phone != null) {
4428 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004429 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004430 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004431 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004432 }
4433 } finally {
4434 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004435 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004436 }
4437
4438 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004439 * Get the user enabled state of Mobile Data.
4440 *
4441 * TODO: remove and use isUserDataEnabled.
4442 * This can't be removed now because some vendor codes
4443 * calls through ITelephony directly while they should
4444 * use TelephonyManager.
4445 *
4446 * @return true on enabled
4447 */
4448 @Override
4449 public boolean getDataEnabled(int subId) {
4450 return isUserDataEnabled(subId);
4451 }
4452
4453 /**
4454 * Get whether mobile data is enabled per user setting.
4455 *
4456 * There are other factors deciding whether mobile data is actually enabled, but they are
4457 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004458 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004459 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004460 *
4461 * @return {@code true} if data is enabled else {@code false}
4462 */
4463 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004464 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004465 try {
4466 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4467 null);
4468 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4470 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004471 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004472
4473 final long identity = Binder.clearCallingIdentity();
4474 try {
4475 int phoneId = mSubscriptionController.getPhoneId(subId);
4476 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4477 Phone phone = PhoneFactory.getPhone(phoneId);
4478 if (phone != null) {
4479 boolean retVal = phone.isUserDataEnabled();
4480 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4481 return retVal;
4482 } else {
4483 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4484 return false;
4485 }
4486 } finally {
4487 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004488 }
4489 }
4490
4491 /**
4492 * Get whether mobile data is enabled.
4493 *
4494 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4495 * whether mobile data is actually enabled.
4496 *
4497 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4498 *
4499 * @return {@code true} if data is enabled else {@code false}
4500 */
4501 @Override
4502 public boolean isDataEnabled(int subId) {
4503 try {
4504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4505 null);
4506 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4508 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004509 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004510
4511 final long identity = Binder.clearCallingIdentity();
4512 try {
4513 int phoneId = mSubscriptionController.getPhoneId(subId);
4514 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4515 Phone phone = PhoneFactory.getPhone(phoneId);
4516 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004517 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004518 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4519 return retVal;
4520 } else {
4521 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4522 return false;
4523 }
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004526 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004527 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004528
4529 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004530 public int getCarrierPrivilegeStatus(int subId) {
4531 final Phone phone = getPhone(subId);
4532 if (phone == null) {
4533 loge("getCarrierPrivilegeStatus: Invalid subId");
4534 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4535 }
4536 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004537 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004538 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004539 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4540 }
4541 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004542 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004543 }
Junda Liu29340342014-07-10 15:23:27 -07004544
4545 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004546 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4547 final Phone phone = getPhone(subId);
4548 if (phone == null) {
4549 loge("getCarrierPrivilegeStatus: Invalid subId");
4550 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4551 }
4552 UiccProfile profile =
4553 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4554 if (profile == null) {
4555 loge("getCarrierPrivilegeStatus: No UICC");
4556 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4557 }
4558 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4559 }
4560
4561 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004562 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004563 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004564 if (TextUtils.isEmpty(pkgName))
4565 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004566 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004567 if (card == null) {
4568 loge("checkCarrierPrivilegesForPackage: No UICC");
4569 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4570 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004571 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4572 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004573 }
4574
4575 @Override
4576 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004577 if (TextUtils.isEmpty(pkgName))
4578 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004579 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4580 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4581 UiccCard card = UiccController.getInstance().getUiccCard(i);
4582 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004583 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004584 continue;
4585 }
4586
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004587 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004588 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4589 break;
4590 }
4591 }
4592
4593 return result;
Junda Liu29340342014-07-10 15:23:27 -07004594 }
Derek Tan89e89d42014-07-08 17:00:10 -07004595
4596 @Override
Junda Liue64de782015-04-16 17:19:16 -07004597 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4598 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4599 loge("phoneId " + phoneId + " is not valid.");
4600 return null;
4601 }
4602 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004603 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004604 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004605 return null ;
4606 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004607 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004608 }
4609
Amith Yamasani6e118872016-02-19 12:53:51 -08004610 @Override
4611 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004612 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004613 List<String> privilegedPackages = new ArrayList<>();
4614 List<PackageInfo> packages = null;
4615 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4616 UiccCard card = UiccController.getInstance().getUiccCard(i);
4617 if (card == null) {
4618 // No UICC in that slot.
4619 continue;
4620 }
4621 if (card.hasCarrierPrivilegeRules()) {
4622 if (packages == null) {
4623 // Only check packages in user 0 for now
4624 packages = pm.getInstalledPackagesAsUser(
4625 PackageManager.MATCH_DISABLED_COMPONENTS
4626 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4627 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4628 }
4629 for (int p = packages.size() - 1; p >= 0; p--) {
4630 PackageInfo pkgInfo = packages.get(p);
4631 if (pkgInfo != null && pkgInfo.packageName != null
4632 && card.getCarrierPrivilegeStatus(pkgInfo)
4633 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4634 privilegedPackages.add(pkgInfo.packageName);
4635 }
4636 }
4637 }
4638 }
4639 return privilegedPackages;
4640 }
4641
Wink Savilleb564aae2014-10-23 10:18:09 -07004642 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004643 final Phone phone = getPhone(subId);
4644 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004645 if (card == null) {
4646 loge("getIccId: No UICC");
4647 return null;
4648 }
4649 String iccId = card.getIccId();
4650 if (TextUtils.isEmpty(iccId)) {
4651 loge("getIccId: ICC ID is null or empty.");
4652 return null;
4653 }
4654 return iccId;
4655 }
4656
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004657 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004658 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4659 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4661 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004662
Malcolm Chend965c8b2018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 final String iccId = getIccId(subId);
4666 final Phone phone = getPhone(subId);
4667 if (phone == null) {
4668 return false;
4669 }
4670 final String subscriberId = phone.getSubscriberId();
4671
4672 if (DBG_MERGE) {
4673 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4674 + subscriberId + " to " + number);
4675 }
4676
4677 if (TextUtils.isEmpty(iccId)) {
4678 return false;
4679 }
4680
4681 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4682
4683 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4684 if (alphaTag == null) {
4685 editor.remove(alphaTagPrefKey);
4686 } else {
4687 editor.putString(alphaTagPrefKey, alphaTag);
4688 }
4689
4690 // Record both the line number and IMSI for this ICCID, since we need to
4691 // track all merged IMSIs based on line number
4692 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4693 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4694 if (number == null) {
4695 editor.remove(numberPrefKey);
4696 editor.remove(subscriberPrefKey);
4697 } else {
4698 editor.putString(numberPrefKey, number);
4699 editor.putString(subscriberPrefKey, subscriberId);
4700 }
4701
4702 editor.commit();
4703 return true;
4704 } finally {
4705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004706 }
Derek Tan7226c842014-07-02 17:42:23 -07004707 }
4708
4709 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004710 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004711 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004712 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004713 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004714 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004715 return null;
4716 }
Derek Tan97ebb422014-09-05 16:55:38 -07004717
Malcolm Chend965c8b2018-02-28 15:00:40 -08004718 final long identity = Binder.clearCallingIdentity();
4719 try {
4720 String iccId = getIccId(subId);
4721 if (iccId != null) {
4722 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4723 if (DBG_MERGE) {
4724 log("getLine1NumberForDisplay returning "
4725 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4726 }
4727 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004728 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004729 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4730 return null;
4731 } finally {
4732 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004733 }
Derek Tan7226c842014-07-02 17:42:23 -07004734 }
4735
4736 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004737 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004739 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004740 return null;
4741 }
Derek Tan97ebb422014-09-05 16:55:38 -07004742
Malcolm Chend965c8b2018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 String iccId = getIccId(subId);
4746 if (iccId != null) {
4747 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4748 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4749 }
4750 return null;
4751 } finally {
4752 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004753 }
Derek Tan7226c842014-07-02 17:42:23 -07004754 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004755
4756 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004757 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004758 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4759 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004760 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004761 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4762 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004763 return null;
4764 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004765
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004766 final long identity = Binder.clearCallingIdentity();
4767 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004768 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004769 final TelephonyManager tele = TelephonyManager.from(context);
4770 final SubscriptionManager sub = SubscriptionManager.from(context);
4771
4772 // Figure out what subscribers are currently active
4773 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4774 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4775 // the process, where TelephonyManager was instantiated.
4776 // Otherwise AppOps check will fail.
4777
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004778 final int[] subIds = sub.getActiveSubscriptionIdList();
4779 for (int subId : subIds) {
4780 activeSubscriberIds.add(tele.getSubscriberId(subId));
4781 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004782
4783 // First pass, find a number override for an active subscriber
4784 String mergeNumber = null;
4785 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4786 for (String key : prefs.keySet()) {
4787 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4788 final String subscriberId = (String) prefs.get(key);
4789 if (activeSubscriberIds.contains(subscriberId)) {
4790 final String iccId = key.substring(
4791 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4792 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4793 mergeNumber = (String) prefs.get(numberKey);
4794 if (DBG_MERGE) {
4795 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4796 + " for active subscriber " + subscriberId);
4797 }
4798 if (!TextUtils.isEmpty(mergeNumber)) {
4799 break;
4800 }
4801 }
4802 }
4803 }
4804
4805 // Shortcut when no active merged subscribers
4806 if (TextUtils.isEmpty(mergeNumber)) {
4807 return null;
4808 }
4809
4810 // Second pass, find all subscribers under that line override
4811 final ArraySet<String> result = new ArraySet<>();
4812 for (String key : prefs.keySet()) {
4813 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4814 final String number = (String) prefs.get(key);
4815 if (mergeNumber.equals(number)) {
4816 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4817 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4818 final String subscriberId = (String) prefs.get(subscriberKey);
4819 if (!TextUtils.isEmpty(subscriberId)) {
4820 result.add(subscriberId);
4821 }
4822 }
4823 }
4824 }
4825
4826 final String[] resultArray = result.toArray(new String[result.size()]);
4827 Arrays.sort(resultArray);
4828 if (DBG_MERGE) {
4829 Slog.d(LOG_TAG,
4830 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4831 }
4832 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004833 } finally {
4834 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004835 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004836 }
4837
4838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004839 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004840 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4841 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004842
4843 final long identity = Binder.clearCallingIdentity();
4844 try {
4845 final Phone phone = getPhone(subId);
4846 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4847 } finally {
4848 Binder.restoreCallingIdentity(identity);
4849 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004850 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004851
4852 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004853 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004854 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4855 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004856 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004857
4858 final long identity = Binder.clearCallingIdentity();
4859 try {
4860 final Phone phone = getPhone(subId);
4861 if (phone == null) {
4862 return false;
4863 }
4864 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4865 cdmaNonRoamingList);
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004868 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004869 }
4870
4871 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004872 @Deprecated
4873 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4874 enforceModifyPermission();
4875
4876 int returnValue = 0;
4877 try {
vagdevie435a3e2018-08-15 16:01:53 -07004878 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004879 if(result.exception == null) {
4880 if (result.result != null) {
4881 byte[] responseData = (byte[])(result.result);
4882 if(responseData.length > oemResp.length) {
4883 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4884 responseData.length + "bytes. Buffer Size is " +
4885 oemResp.length + "bytes.");
4886 }
4887 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4888 returnValue = responseData.length;
4889 }
4890 } else {
4891 CommandException ex = (CommandException) result.exception;
4892 returnValue = ex.getCommandError().ordinal();
4893 if(returnValue > 0) returnValue *= -1;
4894 }
4895 } catch (RuntimeException e) {
4896 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4897 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4898 if(returnValue > 0) returnValue *= -1;
4899 }
4900
4901 return returnValue;
4902 }
4903
4904 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004905 public void setRadioCapability(RadioAccessFamily[] rafs) {
4906 try {
4907 ProxyController.getInstance().setRadioCapability(rafs);
4908 } catch (RuntimeException e) {
4909 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4910 }
4911 }
4912
4913 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004914 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004915 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004916 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004917 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004918 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004919 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004920 final long identity = Binder.clearCallingIdentity();
4921 try {
chen xufeeed752018-10-26 14:17:57 -07004922 TelephonyPermissions
4923 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4924 mApp, phone.getSubId(), "getRadioAccessFamily");
4925 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004926 } finally {
4927 Binder.restoreCallingIdentity(identity);
4928 }
chen xufeeed752018-10-26 14:17:57 -07004929 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004930 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004931
4932 @Override
4933 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004934 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004935 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004936
4937 final long identity = Binder.clearCallingIdentity();
4938 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004939 ImsManager.getInstance(defaultPhone.getContext(),
4940 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004941 } finally {
4942 Binder.restoreCallingIdentity(identity);
4943 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004944 }
4945
4946 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004947 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004948 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004949 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004950 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004951 return false;
4952 }
Svet Ganovb320e182015-04-16 12:30:10 -07004953
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954 final long identity = Binder.clearCallingIdentity();
4955 try {
4956 // Check the user preference and the system-level IMS setting. Even if the user has
4957 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4958 // In the long run, we may instead need to check if there exists a connection service
4959 // which can support video calling.
4960 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004961 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004962 return imsManager.isVtEnabledByPlatform()
4963 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4964 && imsManager.isVtEnabledByUser();
4965 } finally {
4966 Binder.restoreCallingIdentity(identity);
4967 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004968 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004969
Andrew Leea1239f22015-03-02 17:44:07 -08004970 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004971 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4973 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4974 return false;
4975 }
4976
4977 final long identity = Binder.clearCallingIdentity();
4978 try {
4979 CarrierConfigManager configManager =
4980 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004981 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004982 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Andrew Leea1239f22015-03-02 17:44:07 -08004986 }
4987
4988 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 public boolean isWorldPhone(int subId, String callingPackage) {
4990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4991 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4992 return false;
4993 }
4994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
4997 CarrierConfigManager configManager =
4998 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004999 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005000 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
Andrew Leea1239f22015-03-02 17:44:07 -08005004 }
5005
Andrew Lee9431b832015-03-09 18:46:45 -07005006 @Override
5007 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005008 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005009 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005010 }
5011
5012 @Override
5013 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005014 final long identity = Binder.clearCallingIdentity();
5015 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005016 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005017 } finally {
5018 Binder.restoreCallingIdentity(identity);
5019 }
Andrew Lee9431b832015-03-09 18:46:45 -07005020 }
5021
Hall Liuf6668912018-10-31 17:05:23 -07005022 /**
5023 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5024 * support for the feature and device firmware support.
5025 *
5026 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5027 */
5028 @Override
5029 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005030 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005031 final Phone phone = getPhone(subscriptionId);
5032 if (phone == null) {
5033 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5034 return false;
5035 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005036 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005037 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005038 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5039 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005040 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005041 return isCarrierSupported && isDeviceSupported;
5042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
Hall Liu98187582018-01-22 19:15:32 -08005045 }
5046
Hall Liuf6668912018-10-31 17:05:23 -07005047 /**
5048 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5049 * both also support RTT.
5050 */
5051 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005052 final long identity = Binder.clearCallingIdentity();
5053 try {
Hall Liuf6668912018-10-31 17:05:23 -07005054 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005055 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005056 } finally {
5057 Binder.restoreCallingIdentity(identity);
5058 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005059 }
5060
Sanket Padawe7310cc72015-01-14 09:53:20 -08005061 /**
5062 * Returns the unique device ID of phone, for example, the IMEI for
5063 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5064 *
5065 * <p>Requires Permission:
5066 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5067 */
5068 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005069 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005070 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005071 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005072 return null;
5073 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005074 int subId = phone.getSubId();
5075 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5076 mApp, subId, callingPackage, "getDeviceId")) {
5077 return null;
5078 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005079
5080 final long identity = Binder.clearCallingIdentity();
5081 try {
5082 return phone.getDeviceId();
5083 } finally {
5084 Binder.restoreCallingIdentity(identity);
5085 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005086 }
5087
Ping Sunc67b7c22016-03-02 19:16:45 +08005088 /**
5089 * {@hide}
5090 * Returns the IMS Registration Status on a particular subid
5091 *
5092 * @param subId
5093 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005094 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005095 Phone phone = getPhone(subId);
5096 if (phone != null) {
5097 return phone.isImsRegistered();
5098 } else {
5099 return false;
5100 }
5101 }
5102
Santos Cordon7a1885b2015-02-03 11:15:19 -08005103 @Override
5104 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005111 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005112
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005113 /**
5114 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005115 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005116 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005117 final long identity = Binder.clearCallingIdentity();
5118 try {
5119 Phone phone = getPhone(subId);
5120 if (phone != null) {
5121 return phone.isWifiCallingEnabled();
5122 } else {
5123 return false;
5124 }
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005127 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005128 }
5129
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005130 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005131 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005132 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005133 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005134 final long identity = Binder.clearCallingIdentity();
5135 try {
5136 Phone phone = getPhone(subId);
5137 if (phone != null) {
5138 return phone.isVideoEnabled();
5139 } else {
5140 return false;
5141 }
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005144 }
5145 }
5146
5147 /**
5148 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5149 * defined in {@link ImsRegistrationImplBase}.
5150 */
5151 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005152 final long identity = Binder.clearCallingIdentity();
5153 try {
5154 Phone phone = getPhone(subId);
5155 if (phone != null) {
5156 return phone.getImsRegistrationTech();
5157 } else {
5158 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5159 }
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005162 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005163 }
5164
Stuart Scott8eef64f2015-04-08 15:13:54 -07005165 @Override
5166 public void factoryReset(int subId) {
5167 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005168 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5169 return;
5170 }
5171
Svet Ganovcc087f82015-05-12 20:35:54 -07005172 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005173
Svet Ganovcc087f82015-05-12 20:35:54 -07005174 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005175 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5176 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005177 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005178 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005179 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005180 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5181 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005182 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005183 // There has been issues when Sms raw table somehow stores orphan
5184 // fragments. They lead to garbled message when new fragments come
5185 // in and combined with those stale ones. In case this happens again,
5186 // user can reset all network settings which will clean up this table.
5187 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005188 } finally {
5189 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005190 }
5191 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005192
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005193 private void cleanUpSmsRawTable(Context context) {
5194 ContentResolver resolver = context.getContentResolver();
5195 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5196 resolver.delete(uri, null, null);
5197 }
5198
Narayan Kamath1c496c22015-04-16 14:40:19 +01005199 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005200 public String getSimLocaleForSubscriber(int subId) {
5201 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5202 final Phone phone = getPhone(subId);
5203 if (phone == null) {
5204 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005205 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005206 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005209 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5210 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005211 // Try and fetch the locale from the carrier properties or from the SIM language
5212 // preferences (EF-PL and EF-LI)...
5213 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005214 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005215 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5216 if (localeFromDefaultSim != null) {
5217 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5218 if (DBG) log("Using locale from subId: " + subId + " locale: "
5219 + localeFromDefaultSim);
5220 return localeFromDefaultSim.toLanguageTag();
5221 } else {
5222 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005223 }
5224 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005225
Malcolm Chend965c8b2018-02-28 15:00:40 -08005226 // The SIM language preferences only store a language (e.g. fr = French), not an
5227 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5228 // the SIM and carrier preferences does not include a country we add the country
5229 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005230 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005231 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005232 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005233 return mccLocale.toLanguageTag();
5234 }
5235
5236 if (DBG) log("No locale found - returning null");
5237 return null;
5238 } finally {
5239 Binder.restoreCallingIdentity(identity);
5240 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005241 }
5242
5243 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005244 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005245 }
5246
Malcolm Chend965c8b2018-02-28 15:00:40 -08005247 /**
5248 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5249 */
5250 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005251 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005252 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005253
Chenjie Yu1ba97252018-01-11 18:16:20 -08005254 private final ModemActivityInfo mLastModemActivityInfo =
5255 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5256
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005257 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005258 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5259 * representing the state of the modem.
5260 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005261 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5262 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005263 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005264 */
5265 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005266 public void requestModemActivityInfo(ResultReceiver result) {
5267 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 ModemActivityInfo ret = null;
5273 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005274 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5275 CMD_GET_MODEM_ACTIVITY_INFO,
5276 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005277 if (isModemActivityInfoValid(info)) {
5278 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5279 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5280 mergedTxTimeMs[i] =
5281 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5282 }
5283 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5284 mLastModemActivityInfo.setSleepTimeMillis(
5285 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5286 mLastModemActivityInfo.setIdleTimeMillis(
5287 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5288 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5289 mLastModemActivityInfo.setRxTimeMillis(
5290 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5291 mLastModemActivityInfo.setEnergyUsed(
5292 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005294 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5295 mLastModemActivityInfo.getSleepTimeMillis(),
5296 mLastModemActivityInfo.getIdleTimeMillis(),
5297 mLastModemActivityInfo.getTxTimeMillis(),
5298 mLastModemActivityInfo.getRxTimeMillis(),
5299 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005300 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005301 Bundle bundle = new Bundle();
5302 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5303 result.send(0, bundle);
5304 } finally {
5305 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005306 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005307 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005308
Siddharth Rayf5d29552018-06-17 15:02:38 -07005309 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5310 // less than total activity duration.
5311 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5312 if (info == null) {
5313 return false;
5314 }
5315 int activityDurationMs =
5316 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5317 int totalTxTimeMs = 0;
5318 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5319 totalTxTimeMs += info.getTxTimeMillis()[i];
5320 }
5321 return (info.isValid()
5322 && (info.getSleepTimeMillis() <= activityDurationMs)
5323 && (info.getIdleTimeMillis() <= activityDurationMs)
5324 && (info.getRxTimeMillis() <= activityDurationMs)
5325 && (totalTxTimeMs <= activityDurationMs));
5326 }
5327
Jack Yu85bd38a2015-11-09 11:34:32 -08005328 /**
5329 * {@hide}
5330 * Returns the service state information on specified subscription.
5331 */
5332 @Override
5333 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005335 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005336 return null;
5337 }
5338
Hall Liuf19c44f2018-11-27 14:38:17 -08005339 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5340 LocationAccessPolicy.checkLocationPermission(mApp,
5341 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5342 .setCallingPackage(callingPackage)
5343 .setCallingPid(Binder.getCallingPid())
5344 .setCallingUid(Binder.getCallingUid())
5345 .setMethod("getServiceStateForSubscriber")
5346 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5347 .build());
5348
5349 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5350 LocationAccessPolicy.checkLocationPermission(mApp,
5351 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5352 .setCallingPackage(callingPackage)
5353 .setCallingPid(Binder.getCallingPid())
5354 .setCallingUid(Binder.getCallingUid())
5355 .setMethod("getServiceStateForSubscriber")
5356 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5357 .build());
5358 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5359 boolean hasFinePermission =
5360 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5361 boolean hasCoarsePermission =
5362 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5363
Malcolm Chend965c8b2018-02-28 15:00:40 -08005364 final long identity = Binder.clearCallingIdentity();
5365 try {
5366 final Phone phone = getPhone(subId);
5367 if (phone == null) {
5368 return null;
5369 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005370
Hall Liuf19c44f2018-11-27 14:38:17 -08005371 ServiceState ss = phone.getServiceState();
5372
5373 // Scrub out the location info in ServiceState depending on what level of access
5374 // the caller has.
5375 if (hasFinePermission) return ss;
5376 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5377 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005381 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005382
5383 /**
5384 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5385 *
5386 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5387 * voicemail ringtone.
5388 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5389 * PhoneAccount.
5390 */
5391 @Override
5392 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005393 final long identity = Binder.clearCallingIdentity();
5394 try {
5395 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5396 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005397 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005398 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005399
Malcolm Chend965c8b2018-02-28 15:00:40 -08005400 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5401 } finally {
5402 Binder.restoreCallingIdentity(identity);
5403 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005404 }
5405
5406 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005407 * Sets the per-account voicemail ringtone.
5408 *
5409 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5410 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5411 *
5412 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5413 * voicemail ringtone.
5414 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5415 * PhoneAccount.
5416 */
5417 @Override
5418 public void setVoicemailRingtoneUri(String callingPackage,
5419 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005420 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005421 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5422 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005423 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005424 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5425 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5426 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005427 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005428
5429 final long identity = Binder.clearCallingIdentity();
5430 try {
5431 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5432 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005433 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005434 }
5435 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5436 } finally {
5437 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005438 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005439 }
5440
5441 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005442 * Returns whether vibration is set for voicemail notification in Phone settings.
5443 *
5444 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5445 * voicemail vibration setting.
5446 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5447 */
5448 @Override
5449 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005450 final long identity = Binder.clearCallingIdentity();
5451 try {
5452 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5453 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005454 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005456
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5458 } finally {
5459 Binder.restoreCallingIdentity(identity);
5460 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005461 }
5462
Youhan Wange64578a2016-05-02 15:32:42 -07005463 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005464 * Sets the per-account voicemail vibration.
5465 *
5466 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5467 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5468 *
5469 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5470 * voicemail vibration setting.
5471 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5472 * specific PhoneAccount.
5473 */
5474 @Override
5475 public void setVoicemailVibrationEnabled(String callingPackage,
5476 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005477 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005478 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5479 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005480 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005481 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5482 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5483 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005484 }
5485
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486 final long identity = Binder.clearCallingIdentity();
5487 try {
5488 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5489 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005490 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005491 }
5492 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5493 } finally {
5494 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005495 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005496 }
5497
5498 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005499 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5500 *
5501 * @throws SecurityException if the caller does not have the required permission
5502 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005503 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005504 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005505 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005506 }
5507
5508 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005509 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5510 * permission.
5511 *
5512 * @throws SecurityException if the caller does not have the required permission
5513 */
5514 private void enforceSendSmsPermission() {
5515 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5516 }
5517
5518 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005519 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005520 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005521 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005522 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005523 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005524 final long identity = Binder.clearCallingIdentity();
5525 try {
5526 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005527 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005528 if (componentName == null) {
5529 throw new SecurityException(
5530 "Caller not current active visual voicemail package[null]");
5531 }
5532 String vvmPackage = componentName.getPackageName();
5533 if (!callingPackage.equals(vvmPackage)) {
5534 throw new SecurityException("Caller not current active visual voicemail package["
5535 + vvmPackage + "]");
5536 }
5537 } finally {
5538 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005539 }
5540 }
5541
5542 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005543 * Return the application ID for the app type.
5544 *
5545 * @param subId the subscription ID that this request applies to.
5546 * @param appType the uicc app type.
5547 * @return Application ID for specificied app type, or null if no uicc.
5548 */
5549 @Override
5550 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005551 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005552 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005553
5554 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005555 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005556 if (phone == null) {
5557 return null;
5558 }
5559 String aid = null;
5560 try {
5561 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5562 .getApplicationByType(appType).getAid();
5563 } catch (Exception e) {
5564 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5565 }
5566 return aid;
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005569 }
Youhan Wange64578a2016-05-02 15:32:42 -07005570 }
5571
Youhan Wang4001d252016-05-11 10:29:41 -07005572 /**
5573 * Return the Electronic Serial Number.
5574 *
5575 * @param subId the subscription ID that this request applies to.
5576 * @return ESN or null if error.
5577 */
5578 @Override
5579 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005580 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005581 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005582
5583 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005584 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005585 if (phone == null) {
5586 return null;
5587 }
5588 String esn = null;
5589 try {
5590 esn = phone.getEsn();
5591 } catch (Exception e) {
5592 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5593 }
5594 return esn;
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005597 }
Youhan Wang4001d252016-05-11 10:29:41 -07005598 }
5599
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005600 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005601 * Return the Preferred Roaming List Version.
5602 *
5603 * @param subId the subscription ID that this request applies to.
5604 * @return PRLVersion or null if error.
5605 */
5606 @Override
5607 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005608 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005609 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005610
5611 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005612 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005613 if (phone == null) {
5614 return null;
5615 }
5616 String cdmaPrlVersion = null;
5617 try {
5618 cdmaPrlVersion = phone.getCdmaPrlVersion();
5619 } catch (Exception e) {
5620 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5621 }
5622 return cdmaPrlVersion;
5623 } finally {
5624 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005625 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005626 }
5627
5628 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005629 * Get snapshot of Telephony histograms
5630 * @return List of Telephony histograms
5631 * @hide
5632 */
5633 @Override
5634 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5636 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005637
5638 final long identity = Binder.clearCallingIdentity();
5639 try {
5640 return RIL.getTelephonyRILTimingHistograms();
5641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005644 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005645
5646 /**
5647 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005648 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5649 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005650 * Require system privileges. In the future we may add this to carrier APIs.
5651 *
Michele Berionne0963c862018-11-27 18:57:59 -08005652 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005653 */
5654 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005655 @TelephonyManager.SetCarrierRestrictionResult
5656 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005657 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005658 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005659
Michele Berionne0963c862018-11-27 18:57:59 -08005660 if (carrierRestrictionRules == null) {
5661 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005662 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005663
Malcolm Chend965c8b2018-02-28 15:00:40 -08005664 final long identity = Binder.clearCallingIdentity();
5665 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005666 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005667 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005668 } finally {
5669 Binder.restoreCallingIdentity(identity);
5670 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005671 }
5672
5673 /**
5674 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005675 * Get the allowed carrier list and the excluded carrier list, including the priority between
5676 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005677 * Require system privileges. In the future we may add this to carrier APIs.
5678 *
Michele Berionne0963c862018-11-27 18:57:59 -08005679 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005680 */
5681 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005682 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005683 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005684 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005685
5686 final long identity = Binder.clearCallingIdentity();
5687 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005688 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5689 if (response instanceof CarrierRestrictionRules) {
5690 return (CarrierRestrictionRules) response;
5691 }
5692 // Response is an Exception of some kind,
5693 // which is signalled to the user as a NULL retval
5694 return null;
5695 } catch (Exception e) {
5696 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5697 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005698 } finally {
5699 Binder.restoreCallingIdentity(identity);
5700 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005701 }
5702
fionaxu59545b42016-05-25 15:53:37 -07005703 /**
5704 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5705 * @param subId the subscription ID that this action applies to.
5706 * @param enabled control enable or disable metered apns.
5707 * {@hide}
5708 */
5709 @Override
5710 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5711 enforceModifyPermission();
5712 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005713
5714 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005715 if (phone == null) {
5716 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5717 return;
5718 }
5719 try {
5720 phone.carrierActionSetMeteredApnsEnabled(enabled);
5721 } catch (Exception e) {
5722 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005723 } finally {
5724 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005725 }
5726 }
5727
5728 /**
5729 * Action set from carrier signalling broadcast receivers to enable/disable radio
5730 * @param subId the subscription ID that this action applies to.
5731 * @param enabled control enable or disable radio.
5732 * {@hide}
5733 */
5734 @Override
5735 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5736 enforceModifyPermission();
5737 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005740 if (phone == null) {
5741 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5742 return;
5743 }
5744 try {
5745 phone.carrierActionSetRadioEnabled(enabled);
5746 } catch (Exception e) {
5747 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005748 } finally {
5749 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005750 }
5751 }
5752
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005753 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005754 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5755 * network status based on which carrier apps could apply actions accordingly,
5756 * enable/disable default url handler for example.
5757 *
5758 * @param subId the subscription ID that this action applies to.
5759 * @param report control start/stop reporting the default network status.
5760 * {@hide}
5761 */
5762 @Override
5763 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5764 enforceModifyPermission();
5765 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005766
5767 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005768 if (phone == null) {
5769 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5770 return;
5771 }
5772 try {
5773 phone.carrierActionReportDefaultNetworkStatus(report);
5774 } catch (Exception e) {
5775 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005778 }
5779 }
5780
5781 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005782 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5783 * bug report is being generated.
5784 */
5785 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005786 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005787 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5788 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005789 writer.println("Permission Denial: can't dump Phone from pid="
5790 + Binder.getCallingPid()
5791 + ", uid=" + Binder.getCallingUid()
5792 + "without permission "
5793 + android.Manifest.permission.DUMP);
5794 return;
5795 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005796 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005797 }
Jack Yueb89b242016-06-22 13:27:47 -07005798
Brad Ebingerdac2f002018-04-03 15:17:52 -07005799 @Override
5800 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5801 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5802 throws RemoteException {
5803 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5804 }
5805
Jack Yueb89b242016-06-22 13:27:47 -07005806 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005807 * Get aggregated video call data usage since boot.
5808 *
5809 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5810 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005811 * {@hide}
5812 */
5813 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005814 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005815 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5816 null);
5817
Malcolm Chend965c8b2018-02-28 15:00:40 -08005818 final long identity = Binder.clearCallingIdentity();
5819 try {
5820 // NetworkStatsService keeps tracking the active network interface and identity. It
5821 // records the delta with the corresponding network identity.
5822 // We just return the total video call data usage snapshot since boot.
5823 Phone phone = getPhone(subId);
5824 if (phone != null) {
5825 return phone.getVtDataUsage(perUidStats);
5826 }
5827 return null;
5828 } finally {
5829 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005830 }
Jack Yueb89b242016-06-22 13:27:47 -07005831 }
Jack Yu75ab2952016-07-08 14:29:33 -07005832
5833 /**
5834 * Policy control of data connection. Usually used when data limit is passed.
5835 * @param enabled True if enabling the data, otherwise disabling.
5836 * @param subId Subscription index
5837 * {@hide}
5838 */
5839 @Override
5840 public void setPolicyDataEnabled(boolean enabled, int subId) {
5841 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005842
5843 final long identity = Binder.clearCallingIdentity();
5844 try {
5845 Phone phone = getPhone(subId);
5846 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005847 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005848 }
5849 } finally {
5850 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005851 }
5852 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005853
5854 /**
5855 * Get Client request stats
5856 * @return List of Client Request Stats
5857 * @hide
5858 */
5859 @Override
5860 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005862 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005863 return null;
5864 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005865 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005866
Malcolm Chend965c8b2018-02-28 15:00:40 -08005867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 if (phone != null) {
5870 return phone.getClientRequestStats();
5871 }
5872
5873 return null;
5874 } finally {
5875 Binder.restoreCallingIdentity(identity);
5876 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005877 }
5878
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005879 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005880 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005881 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005882 }
Jack Yueb4124c2017-02-16 15:32:43 -08005883
5884 /**
Grace Chen70990072017-03-24 17:21:30 -07005885 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005886 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005887 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005888 * @param state State of SIM (power down, power up, pass through)
5889 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5890 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5891 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005892 *
5893 **/
5894 @Override
Grace Chen70990072017-03-24 17:21:30 -07005895 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005896 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005897 Phone phone = PhoneFactory.getPhone(slotIndex);
5898
vagdevie435a3e2018-08-15 16:01:53 -07005899 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5900
Malcolm Chend965c8b2018-02-28 15:00:40 -08005901 final long identity = Binder.clearCallingIdentity();
5902 try {
5903 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005904 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005905 }
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005908 }
5909 }
Shuo Qiandd210312017-04-12 22:11:33 +00005910
Tyler Gunn65d45c22017-06-05 11:22:26 -07005911 private boolean isUssdApiAllowed(int subId) {
5912 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005913 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005914 if (configManager == null) {
5915 return false;
5916 }
5917 PersistableBundle pb = configManager.getConfigForSubId(subId);
5918 if (pb == null) {
5919 return false;
5920 }
5921 return pb.getBoolean(
5922 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5923 }
5924
Shuo Qiandd210312017-04-12 22:11:33 +00005925 /**
5926 * Check if phone is in emergency callback mode
5927 * @return true if phone is in emergency callback mode
5928 * @param subId sub id
5929 */
goneil9c5f4872017-12-05 14:07:56 -08005930 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005931 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005932 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005933 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005934
5935 final long identity = Binder.clearCallingIdentity();
5936 try {
5937 if (phone != null) {
5938 return phone.isInEcm();
5939 } else {
5940 return false;
5941 }
5942 } finally {
5943 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005944 }
5945 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005946
5947 /**
5948 * Get the current signal strength information for the given subscription.
5949 * Because this information is not updated when the device is in a low power state
5950 * it should not be relied-upon to be current.
5951 * @param subId Subscription index
5952 * @return the most recent cached signal strength info from the modem
5953 */
5954 @Override
5955 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005956 final long identity = Binder.clearCallingIdentity();
5957 try {
5958 Phone p = getPhone(subId);
5959 if (p == null) {
5960 return null;
5961 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005962
Malcolm Chend965c8b2018-02-28 15:00:40 -08005963 return p.getSignalStrength();
5964 } finally {
5965 Binder.restoreCallingIdentity(identity);
5966 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005967 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005968
Pengquan Meng9140aec2018-08-22 14:49:57 -07005969 /**
chen xu907e5a22018-10-11 13:21:04 -07005970 * Get the current modem radio state for the given slot.
5971 * @param slotIndex slot index.
5972 * @param callingPackage the name of the package making the call.
5973 * @return the current radio power state from the modem
5974 */
5975 @Override
5976 public int getRadioPowerState(int slotIndex, String callingPackage) {
5977 Phone phone = PhoneFactory.getPhone(slotIndex);
5978 if (phone != null) {
5979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5980 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5981 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5982 }
5983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
5986 return phone.getRadioPowerState();
5987 } finally {
5988 Binder.restoreCallingIdentity(identity);
5989 }
5990 }
5991 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5992 }
5993
5994 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005995 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5996 *
5997 * <p>Requires one of the following permissions:
5998 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5999 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6000 * privileges.
6001 *
6002 * @param subId subscription id
6003 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6004 * {@code false}.
6005 */
6006 @Override
6007 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006008 boolean isEnabled = false;
6009 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006010 try {
6011 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006012 null /* message */);
6013 Phone phone = getPhone(subId);
6014 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006015 } catch (Exception e) {
6016 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6017 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006018 } finally {
6019 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006020 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006021 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006022 }
6023
6024
6025 /**
6026 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6027 *
6028 * <p> Requires permission:
6029 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6030 * privileges.
6031 *
6032 * @param subId subscription id
6033 * @param isEnabled {@code true} means enable, {@code false} means disable.
6034 */
6035 @Override
6036 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006037 final long identity = Binder.clearCallingIdentity();
6038 try {
6039 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6040 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006041
Pengquan Meng0c05b502018-09-06 09:59:22 -07006042 Phone phone = getPhone(subId);
6043 if (phone != null) {
6044 phone.setDataRoamingEnabled(isEnabled);
6045 }
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006048 }
6049 }
6050
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006051 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006052 public boolean isManualNetworkSelectionAllowed(int subId) {
6053 boolean isAllowed = true;
6054 final long identity = Binder.clearCallingIdentity();
6055 try {
6056 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "isManualNetworkSelectionAllowed");
6058 Phone phone = getPhone(subId);
6059 if (phone != null) {
6060 isAllowed = phone.isCspPlmnEnabled();
6061 }
6062 } finally {
6063 Binder.restoreCallingIdentity(identity);
6064 }
6065 return isAllowed;
6066 }
6067
6068 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006069 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006070 try {
6071 enforceReadPrivilegedPermission("getUiccCardsInfo");
6072 } catch (SecurityException e) {
6073 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6074 // has carrier privileges on an active UICC
6075 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6076 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6077 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6078 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006079 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006080
6081 final long identity = Binder.clearCallingIdentity();
6082 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006083 UiccController uiccController = UiccController.getInstance();
6084 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6085
6086 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6087 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6088 // Remove private info if the caller doesn't have access
6089 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6090 for (UiccCardInfo cardInfo : cardInfos) {
6091 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6092 UiccProfile profile = card.getUiccProfile();
6093 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6094 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6095 filteredInfos.add(cardInfo.getUnprivileged());
6096 } else {
6097 filteredInfos.add(cardInfo);
6098 }
6099 }
6100 return filteredInfos;
6101 }
6102 return cardInfos;
6103 } catch (PackageManager.NameNotFoundException e) {
6104 // This should not happen since we pass the package info in from TelephonyManager
6105 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
6109 }
6110
6111 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006112 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006113 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006114
Malcolm Chend965c8b2018-02-28 15:00:40 -08006115 final long identity = Binder.clearCallingIdentity();
6116 try {
6117 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6118 if (slots == null) {
6119 Rlog.i(LOG_TAG, "slots is null.");
6120 return null;
6121 }
6122
6123 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6124 for (int i = 0; i < slots.length; i++) {
6125 UiccSlot slot = slots[i];
6126 if (slot == null) {
6127 continue;
6128 }
6129
6130 String cardId;
6131 UiccCard card = slot.getUiccCard();
6132 if (card != null) {
6133 cardId = card.getCardId();
6134 } else {
6135 cardId = slot.getIccId();
6136 }
6137
6138 int cardState = 0;
6139 switch (slot.getCardState()) {
6140 case CARDSTATE_ABSENT:
6141 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6142 break;
6143 case CARDSTATE_PRESENT:
6144 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6145 break;
6146 case CARDSTATE_ERROR:
6147 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6148 break;
6149 case CARDSTATE_RESTRICTED:
6150 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6151 break;
6152 default:
6153 break;
6154
6155 }
6156
6157 infos[i] = new UiccSlotInfo(
6158 slot.isActive(),
6159 slot.isEuicc(),
6160 cardId,
6161 cardState,
6162 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006163 slot.isExtendedApduSupported(),
6164 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006165 }
6166 return infos;
6167 } finally {
6168 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006169 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006170 }
6171
6172 @Override
6173 public boolean switchSlots(int[] physicalSlots) {
6174 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006175
6176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006182 }
Jack Yu4c988042018-02-27 15:30:01 -08006183
6184 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006185 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006186 final long identity = Binder.clearCallingIdentity();
6187 try {
6188 return UiccController.getInstance().getCardIdForDefaultEuicc();
6189 } finally {
6190 Binder.restoreCallingIdentity(identity);
6191 }
6192 }
6193
6194 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006195 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6196 enforceModifyPermission();
6197 final Phone phone = getPhone(subId);
6198 if (phone == null) {
6199 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6200 return;
6201 }
6202
Malcolm Chend965c8b2018-02-28 15:00:40 -08006203 final long identity = Binder.clearCallingIdentity();
6204 try {
6205 phone.setRadioIndicationUpdateMode(filters, mode);
6206 } finally {
6207 Binder.restoreCallingIdentity(identity);
6208 }
Jack Yu4c988042018-02-27 15:30:01 -08006209 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006210
6211 /**
goneil47ffb6e2018-04-06 15:40:58 -07006212 * A test API to reload the UICC profile.
6213 *
6214 * <p>Requires that the calling app has permission
6215 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6216 * @hide
6217 */
6218 @Override
6219 public void refreshUiccProfile(int subId) {
6220 enforceModifyPermission();
6221
6222 final long identity = Binder.clearCallingIdentity();
6223 try {
6224 Phone phone = getPhone(subId);
6225 if (phone == null) {
6226 return;
6227 }
6228 UiccCard uiccCard = phone.getUiccCard();
6229 if (uiccCard == null) {
6230 return;
6231 }
6232 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6233 if (uiccProfile == null) {
6234 return;
6235 }
6236 uiccProfile.refresh();
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
6240 }
6241
6242 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006243 * Returns false if the mobile data is disabled by default, otherwise return true.
6244 */
6245 private boolean getDefaultDataEnabled() {
6246 return "true".equalsIgnoreCase(
6247 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6248 }
6249
6250 /**
6251 * Returns true if the data roaming is enabled by default, i.e the system property
6252 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6253 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6254 */
6255 private boolean getDefaultDataRoamingEnabled(int subId) {
6256 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006257 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006258 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6259 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6260 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6261 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6262 return isDataRoamingEnabled;
6263 }
6264
6265 /**
6266 * Returns the default network type for the given {@code subId}, if the default network type is
6267 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6268 */
6269 private int getDefaultNetworkType(int subId) {
6270 return Integer.parseInt(
6271 TelephonyManager.getTelephonyProperty(
6272 mSubscriptionController.getPhoneId(subId),
6273 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6274 String.valueOf(Phone.PREFERRED_NT_MODE)));
6275 }
fionaxua13278b2018-03-21 00:08:13 -07006276
6277 @Override
6278 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6279 gid1, String gid2, String plmn, String spn) {
6280 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006281
6282 final long identity = Binder.clearCallingIdentity();
6283 try {
6284 final Phone phone = getPhone(subId);
6285 if (phone == null) {
6286 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6287 return;
6288 }
6289 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6290 } finally {
6291 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006292 }
fionaxua13278b2018-03-21 00:08:13 -07006293 }
6294
6295 @Override
6296 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006297 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006298
6299 final long identity = Binder.clearCallingIdentity();
6300 try {
6301 final Phone phone = getPhone(subId);
6302 if (phone == null) {
6303 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6304 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6305 }
6306 return phone.getCarrierIdListVersion();
6307 } finally {
6308 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006309 }
fionaxua13278b2018-03-21 00:08:13 -07006310 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006311
6312 @Override
6313 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6315 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6316 return -1;
6317 }
6318
6319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
6325 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006326
6327 @Override
6328 public int getCdmaRoamingMode(int subId) {
6329 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6330 mApp, subId, "getCdmaRoamingMode");
6331
6332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6335 } finally {
6336 Binder.restoreCallingIdentity(identity);
6337 }
6338 }
6339
6340 @Override
6341 public boolean setCdmaRoamingMode(int subId, int mode) {
6342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6343 mApp, subId, "setCdmaRoamingMode");
6344
6345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
6351 }
6352
6353 @Override
6354 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6355 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6356 mApp, subId, "setCdmaSubscriptionMode");
6357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
6363 }
6364 }
chen xu7ee67862018-10-30 22:27:10 -07006365
sqian2fff4a32018-11-05 14:18:37 -08006366 private void ensureUserRunning(int userId) {
6367 if (!mUserManager.isUserRunning(userId)) {
6368 throw new IllegalStateException("User " + userId + " does not exist or not running");
6369 }
6370 }
6371
6372 /**
6373 * Returns a list of SMS apps on a given user.
6374 *
6375 * Only the shell user (UID 2000 or 0) can call it.
6376 * Target user must be running.
6377 */
6378 @Override
6379 public String[] getSmsApps(int userId) {
6380 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6381 ensureUserRunning(userId);
6382
6383 final Collection<SmsApplicationData> apps =
6384 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6385
6386 String[] ret = new String[apps.size()];
6387 int i = 0;
6388 for (SmsApplicationData app : apps) {
6389 ret[i++] = app.mPackageName;
6390 }
6391 return ret;
6392 }
6393
6394 /**
6395 * Returns the default SMS app package name on a given user.
6396 *
6397 * Only the shell user (UID 2000 or 0) can call it.
6398 * Target user must be running.
6399 */
6400 @Override
6401 public String getDefaultSmsApp(int userId) {
6402 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6403 ensureUserRunning(userId);
6404
6405 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6406 /* updateIfNeeded= */ true, userId);
6407 return cn == null ? null : cn.getPackageName();
6408 }
6409
6410 /**
6411 * Set a package as the default SMS app on a given user.
6412 *
6413 * Only the shell user (UID 2000 or 0) can call it.
6414 * Target user must be running.
6415 */
6416 @Override
6417 public void setDefaultSmsApp(int userId, String packageName) {
6418 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6419 ensureUserRunning(userId);
6420
6421 boolean found = false;
6422 for (String pkg : getSmsApps(userId)) {
6423 if (TextUtils.equals(packageName, pkg)) {
6424 found = true;
6425 break;
6426 }
6427 }
6428 if (!found) {
6429 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6430 }
6431
6432 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6433 }
6434
chen xu7ee67862018-10-30 22:27:10 -07006435 @Override
sqian04b86072018-11-07 14:02:21 -08006436 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6437 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6439 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6440 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6441 }
6442 final long identity = Binder.clearCallingIdentity();
6443 try {
sqian991b35e2018-12-12 16:48:18 -08006444 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6445 for (Phone phone: PhoneFactory.getPhones()) {
6446 if (phone.getEmergencyNumberTracker() != null
6447 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6448 emergencyNumberListInternal.put(
6449 phone.getSubId(),
6450 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6451 }
sqian03bca152018-12-05 18:48:28 -08006452 }
sqian991b35e2018-12-12 16:48:18 -08006453 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
sqian04b86072018-11-07 14:02:21 -08006457 }
6458
6459 @Override
sqian03bca152018-12-05 18:48:28 -08006460 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6461 final Phone defaultPhone = getDefaultPhone();
6462 if (!exactMatch) {
6463 TelephonyPermissions
6464 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6465 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6466 }
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
sqian991b35e2018-12-12 16:48:18 -08006469 for (Phone phone: PhoneFactory.getPhones()) {
6470 if (phone.getEmergencyNumberTracker() != null
6471 && phone.getEmergencyNumberTracker() != null) {
6472 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6473 number, exactMatch)) {
6474 return true;
sqian03bca152018-12-05 18:48:28 -08006475 }
6476 }
sqian03bca152018-12-05 18:48:28 -08006477 }
6478 return false;
6479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
6482 }
6483
sqian9d4df8b2019-01-15 18:32:07 -08006484 /**
6485 * Update emergency number list for test mode.
6486 */
6487 @Override
6488 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6489 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6490 "updateEmergencyNumberListTestMode");
6491
6492 final long identity = Binder.clearCallingIdentity();
6493 try {
6494 for (Phone phone: PhoneFactory.getPhones()) {
6495 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6496 if (tracker != null) {
6497 tracker.executeEmergencyNumberTestModeCommand(action, num);
6498 }
6499 }
6500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
6503 }
6504
6505 /**
6506 * Get the full emergency number list for test mode.
6507 */
6508 @Override
6509 public List<String> getEmergencyNumberListTestMode() {
6510 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6511 "getEmergencyNumberListTestMode");
6512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 Set<String> emergencyNumbers = new HashSet<>();
6516 for (Phone phone: PhoneFactory.getPhones()) {
6517 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6518 if (tracker != null) {
6519 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6520 emergencyNumbers.add(num.getNumber());
6521 }
6522 }
6523 }
6524 return new ArrayList<>(emergencyNumbers);
6525 } finally {
6526 Binder.restoreCallingIdentity(identity);
6527 }
6528 }
6529
sqian04b86072018-11-07 14:02:21 -08006530 @Override
chen xu7ee67862018-10-30 22:27:10 -07006531 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6532 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6533 Phone phone = getPhone(subId);
6534 if (phone == null) {
6535 return null;
6536 }
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 UiccProfile profile = UiccController.getInstance()
6540 .getUiccProfileForPhone(phone.getPhoneId());
6541 if (profile != null) {
6542 return profile.getCertsFromCarrierPrivilegeAccessRules();
6543 }
6544 } finally {
6545 Binder.restoreCallingIdentity(identity);
6546 }
6547 return null;
6548 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006549
6550 /**
6551 * Enable or disable a modem stack.
6552 */
6553 @Override
6554 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6555 enforceModifyPermission();
6556
6557 final long identity = Binder.clearCallingIdentity();
6558 try {
6559 Phone phone = PhoneFactory.getPhone(slotIndex);
6560 if (phone == null) {
6561 return false;
6562 } else {
6563 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6564 }
6565 } finally {
6566 Binder.restoreCallingIdentity(identity);
6567 }
6568 }
Micheled3107c52018-12-21 15:00:11 -08006569
6570 @Override
6571 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6572 enforceModifyPermission();
6573
6574 final long identity = Binder.clearCallingIdentity();
6575 try {
6576 mTelephonySharedPreferences.edit()
6577 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6578 .commit();
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
6582 }
6583
6584 @Override
Michelebcb01bc2019-02-04 11:36:23 -08006585 public boolean isMultisimSupported(String callingPackage) {
6586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6587 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6588 return false;
6589 }
Micheled3107c52018-12-21 15:00:11 -08006590
6591 final long identity = Binder.clearCallingIdentity();
6592 try {
Michele30b57b22019-03-01 12:01:14 -08006593 return isMultisimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006594 } finally {
6595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006598
Michele30b57b22019-03-01 12:01:14 -08006599 private boolean isMultisimSupportedInternal() {
6600 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6601 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6602 if (numPhysicalSlots < 2) {
6603 loge("isMultisimSupportedInternal: requires at least 2 cards");
6604 return false;
6605 }
6606 // Check if the hardware supports multisim functionality. If usage of multisim is not
6607 // supported by the modem, indicate that it is restricted.
6608 PhoneCapability staticCapability =
6609 mPhoneConfigurationManager.getStaticPhoneCapability();
6610 if (staticCapability == null) {
6611 loge("isMultisimSupportedInternal: no static configuration available");
6612 return false;
6613 }
6614 if (staticCapability.logicalModemList.size() < 2) {
6615 loge("isMultisimSupportedInternal: maximum number of modem is < 2");
6616 return false;
6617 }
6618 // Check if support of multiple SIMs is restricted by carrier
6619 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6620 return false;
6621 }
6622
6623 return true;
6624 }
6625
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006626 /**
6627 * Switch configs to enable multi-sim or switch back to single-sim
6628 * @param numOfSims number of active sims we want to switch to
6629 */
6630 @Override
6631 public void switchMultiSimConfig(int numOfSims) {
6632 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6633 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6634 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006635
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006636 try {
Michele30b57b22019-03-01 12:01:14 -08006637 //only proceed if multi-sim is not restricted
6638 if (!isMultisimSupportedInternal()) {
6639 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6640 return;
6641 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006642 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
6648 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006649 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006650 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006651 */
6652 @Override
6653 public boolean isRebootRequiredForModemConfigChange() {
6654 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
6661 }
6662
Pengquan Meng92d253b2019-02-06 11:12:53 -08006663 private void updateModemStateMetrics() {
6664 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6665 // TODO: check the state for each modem if the api is ready.
6666 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6667 }
6668
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006669 @Override
6670 public int[] getSlotsMapping() {
6671 enforceReadPrivilegedPermission("getSlotsMapping");
6672
6673 final long identity = Binder.clearCallingIdentity();
6674 try {
6675 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6676 // All logical slots should have a mapping to a physical slot.
6677 int[] logicalSlotsMapping = new int[phoneCount];
6678 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6679 for (int i = 0; i < slotInfos.length; i++) {
6680 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6681 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6682 }
6683 }
6684 return logicalSlotsMapping;
6685 } finally {
6686 Binder.restoreCallingIdentity(identity);
6687 }
6688 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006689
6690 /**
6691 * Get the IRadio HAL Version
6692 */
6693 @Override
6694 public int getRadioHalVersion() {
6695 Phone phone = getDefaultPhone();
6696 if (phone == null) return -1;
6697 HalVersion hv = phone.getHalVersion();
6698 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6699 return hv.major * 100 + hv.minor;
6700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006701}