blob: e4ba73b148b4db7b639b8efde4a61252a64e88df [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080038import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Bundle;
40import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Looper;
43import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070045import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080046import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070047import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070049import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070050import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070052import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080055import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080060import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070062import android.telephony.CellInfoGsm;
63import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070064import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070066import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070067import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080068import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070069import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080070import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070071import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080072import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080073import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070074import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070075import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080077import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070078import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080079import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070081import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070082import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080083import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000084import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070087import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080088import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080089import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070090import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080091import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070092import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070094import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080095import android.telephony.ims.aidl.IImsMmTelFeature;
96import android.telephony.ims.aidl.IImsRcsFeature;
97import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.feature.MmTelFeature;
100import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800101import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800107
Brad Ebinger4c460712018-10-01 10:40:55 -0700108import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700109import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800110import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700112import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700113import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800114import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700115import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800118import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800119import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700122import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100123import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700124import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700125import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700127import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800128import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700129import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700130import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700131import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700132import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700133import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800135import com.android.internal.telephony.SmsApplication;
136import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800137import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800138import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800139import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700140import com.android.internal.telephony.euicc.EuiccConnector;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800141import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.uicc.IccIoResult;
143import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800144import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700145import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800146import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000149import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700150import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700152import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800153import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700154import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700155import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800156
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700157import java.io.FileDescriptor;
158import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800159import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800162import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800163import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800164import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800165import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100166import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800168import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169
170/**
171 * Implementation of the ITelephony interface.
172 */
Santos Cordon117fee72014-05-16 17:56:12 -0700173public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 private static final String LOG_TAG = "PhoneInterfaceManager";
175 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
176 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 // Message codes used with mMainThreadHandler
180 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700181 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
182 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183 private static final int CMD_OPEN_CHANNEL = 9;
184 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
185 private static final int CMD_CLOSE_CHANNEL = 11;
186 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800187 private static final int CMD_NV_READ_ITEM = 13;
188 private static final int EVENT_NV_READ_ITEM_DONE = 14;
189 private static final int CMD_NV_WRITE_ITEM = 15;
190 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
191 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
192 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700193 private static final int CMD_RESET_MODEM_CONFIG = 19;
194 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800195 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
196 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
197 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
198 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800199 private static final int CMD_SEND_ENVELOPE = 25;
200 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000201 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
202 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700203 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
204 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
205 private static final int CMD_EXCHANGE_SIM_IO = 31;
206 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800207 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
208 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700209 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
210 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700211 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
212 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700213 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
214 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
215 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
216 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700217 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
218 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
219 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
220 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700221 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
223 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000224 private static final int CMD_SWITCH_SLOTS = 50;
225 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700226 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
227 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
228 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
229 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
230 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
231 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
232 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
233 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700234 private static final int CMD_GET_ALL_CELL_INFO = 60;
235 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
236 private static final int CMD_GET_CELL_LOCATION = 62;
237 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700238 private static final int CMD_MODEM_REBOOT = 64;
239 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700240 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
241 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800242 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
243 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800245 // Parameters of select command.
246 private static final int SELECT_COMMAND = 0xA4;
247 private static final int SELECT_P1 = 0x04;
248 private static final int SELECT_P2 = 0;
249 private static final int SELECT_P3 = 0x10;
250
Pengquan Meng85728fb2018-03-12 16:31:21 -0700251 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
252 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
253 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
254
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 /** The singleton instance. */
256 private static PhoneInterfaceManager sInstance;
257
Wink Saville3ab207e2014-11-20 13:07:20 -0800258 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800259 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700260 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private AppOpsManager mAppOps;
262 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800263 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700265 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
Derek Tan97ebb422014-09-05 16:55:38 -0700267 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
268 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800269 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800270 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700271
Micheled3107c52018-12-21 15:00:11 -0800272 // String to store multi SIM allowed
273 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
274
Derek Tan740e1672017-06-27 14:56:27 -0700275 // The AID of ISD-R.
276 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
277
yinxub1bed742017-04-17 11:45:04 -0700278 private NetworkScanRequestTracker mNetworkScanRequestTracker;
279
David Kelly5e06a7f2018-03-12 14:10:59 +0000280 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
281 private static final int MANUFACTURER_CODE_LENGTH = 8;
282
Derek Tan89e89d42014-07-08 17:00:10 -0700283 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700284 * A request object to use for transmitting data to an ICC.
285 */
286 private static final class IccAPDUArgument {
287 public int channel, cla, command, p1, p2, p3;
288 public String data;
289
290 public IccAPDUArgument(int channel, int cla, int command,
291 int p1, int p2, int p3, String data) {
292 this.channel = channel;
293 this.cla = cla;
294 this.command = command;
295 this.p1 = p1;
296 this.p2 = p2;
297 this.p3 = p3;
298 this.data = data;
299 }
300 }
301
302 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700303 * A request object to use for transmitting data to an ICC.
304 */
305 private static final class ManualNetworkSelectionArgument {
306 public OperatorInfo operatorInfo;
307 public boolean persistSelection;
308
309 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
310 this.operatorInfo = operatorInfo;
311 this.persistSelection = persistSelection;
312 }
313 }
314
315 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
317 * request after sending. The main thread will notify the request when it is complete.
318 */
319 private static final class MainThreadRequest {
320 /** The argument to use for the request */
321 public Object argument;
322 /** The result of the request that is run on the main thread */
323 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800324 // The subscriber id that this request applies to. Defaults to
325 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
326 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
Nathan Harold92bed182018-10-12 18:16:49 -0700328 // In cases where subId is unavailable, the caller needs to specify the phone.
329 public Phone phone;
330
vagdevie435a3e2018-08-15 16:01:53 -0700331 public WorkSource workSource;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 public MainThreadRequest(Object argument) {
334 this.argument = argument;
335 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800336
Nathan Harold92bed182018-10-12 18:16:49 -0700337 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
338 this.argument = argument;
339 if (phone != null) {
340 this.phone = phone;
341 }
342 this.workSource = workSource;
343 }
344
vagdevie435a3e2018-08-15 16:01:53 -0700345 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800346 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800347 if (subId != null) {
348 this.subId = subId;
349 }
vagdevie435a3e2018-08-15 16:01:53 -0700350 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 }
353
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800354 private static final class IncomingThirdPartyCallArgs {
355 public final ComponentName component;
356 public final String callId;
357 public final String callerDisplayName;
358
359 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
360 String callerDisplayName) {
361 this.component = component;
362 this.callId = callId;
363 this.callerDisplayName = callerDisplayName;
364 }
365 }
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /**
368 * A handler that processes messages on the main thread in the phone process. Since many
369 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
370 * inbound binder threads to the main thread in the phone process. The Binder thread
371 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
372 * on, which will be notified when the operation completes and will contain the result of the
373 * request.
374 *
375 * <p>If a MainThreadRequest object is provided in the msg.obj field,
376 * note that request.result must be set to something non-null for the calling thread to
377 * unblock.
378 */
379 private final class MainThreadHandler extends Handler {
380 @Override
381 public void handleMessage(Message msg) {
382 MainThreadRequest request;
383 Message onCompleted;
384 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800385 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800387 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
389 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700390 case CMD_HANDLE_USSD_REQUEST: {
391 request = (MainThreadRequest) msg.obj;
392 final Phone phone = getPhoneFromRequest(request);
393 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
394 String ussdRequest = ussdObject.first;
395 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700396
Pengquan Meng0c05b502018-09-06 09:59:22 -0700397 if (!isUssdApiAllowed(request.subId)) {
398 // Carrier does not support use of this API, return failure.
399 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
400 UssdResponse response = new UssdResponse(ussdRequest, null);
401 Bundle returnData = new Bundle();
402 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
403 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700404
Pengquan Meng0c05b502018-09-06 09:59:22 -0700405 request.result = true;
406 notifyRequester(request);
407 return;
408 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 try {
411 request.result = phone != null
412 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
413 } catch (CallStateException cse) {
414 request.result = false;
415 }
416 // Wake up the requesting thread
417 notifyRequester(request);
418 break;
pkanwar32d516d2016-10-14 19:37:38 -0700419 }
420
Yorke Lee716f67e2015-06-17 15:39:16 -0700421 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700423 final Phone phone = getPhoneFromRequest(request);
424 request.result = phone != null ?
425 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
426 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700428 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800435 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 if (uiccCard == null) {
437 loge("iccTransmitApduLogicalChannel: No UICC");
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700439 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
442 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 iccArgument.channel, iccArgument.cla, iccArgument.command,
445 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 break;
449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 ar = (AsyncResult) msg.obj;
452 request = (MainThreadRequest) ar.userObj;
453 if (ar.exception == null && ar.result != null) {
454 request.result = ar.result;
455 } else {
456 request.result = new IccIoResult(0x6F, 0, (byte[])null);
457 if (ar.result == null) {
458 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800459 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800461 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 } else {
463 loge("iccTransmitApduLogicalChannel: Unknown exception");
464 }
465 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 break;
468
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
470 request = (MainThreadRequest) msg.obj;
471 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800472 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 if (uiccCard == null) {
474 loge("iccTransmitApduBasicChannel: No UICC");
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700476 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 } else {
478 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
479 request);
480 uiccCard.iccTransmitApduBasicChannel(
481 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
482 iccArgument.p3, iccArgument.data, onCompleted);
483 }
484 break;
485
486 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
487 ar = (AsyncResult) msg.obj;
488 request = (MainThreadRequest) ar.userObj;
489 if (ar.exception == null && ar.result != null) {
490 request.result = ar.result;
491 } else {
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 if (ar.result == null) {
494 loge("iccTransmitApduBasicChannel: Empty response");
495 } else if (ar.exception instanceof CommandException) {
496 loge("iccTransmitApduBasicChannel: CommandException: " +
497 ar.exception);
498 } else {
499 loge("iccTransmitApduBasicChannel: Unknown exception");
500 }
501 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 break;
504
505 case CMD_EXCHANGE_SIM_IO:
506 request = (MainThreadRequest) msg.obj;
507 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 if (uiccCard == null) {
510 loge("iccExchangeSimIO: No UICC");
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 } else {
514 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
515 request);
516 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
517 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
518 iccArgument.data, onCompleted);
519 }
520 break;
521
522 case EVENT_EXCHANGE_SIM_IO_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
527 } else {
528 request.result = new IccIoResult(0x6f, 0, (byte[])null);
529 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 case CMD_SEND_ENVELOPE:
534 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 if (uiccCard == null) {
537 loge("sendEnvelopeWithStatus: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
542 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
543 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 break;
545
546 case EVENT_SEND_ENVELOPE_DONE:
547 ar = (AsyncResult) msg.obj;
548 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700549 if (ar.exception == null && ar.result != null) {
550 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 if (ar.result == null) {
554 loge("sendEnvelopeWithStatus: Empty response");
555 } else if (ar.exception instanceof CommandException) {
556 loge("sendEnvelopeWithStatus: CommandException: " +
557 ar.exception);
558 } else {
559 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700562 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 break;
564
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 case CMD_OPEN_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800568 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 if (uiccCard == null) {
570 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800571 request.result = new IccOpenLogicalChannelResponse(-1,
572 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
577 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 break;
580
581 case EVENT_OPEN_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 int[] result = (int[]) ar.result;
587 int channelId = result[0];
588 byte[] selectResponse = null;
589 if (result.length > 1) {
590 selectResponse = new byte[result.length - 1];
591 for (int i = 1; i < result.length; ++i) {
592 selectResponse[i - 1] = (byte) result[i];
593 }
594 }
595 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.result == null) {
599 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 if (ar.exception != null) {
602 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
603 }
604
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700606 if (ar.exception instanceof CommandException) {
607 CommandException.Error error =
608 ((CommandException) (ar.exception)).getCommandError();
609 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700611 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(
616 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700618 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case CMD_CLOSE_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900627 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
631 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800636 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
637 break;
638
639 case CMD_NV_READ_ITEM:
640 request = (MainThreadRequest) msg.obj;
641 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800642 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
643 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800644 break;
645
646 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 request.result = "";
653 if (ar.result == null) {
654 loge("nvReadItem: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("nvReadItem: CommandException: " +
657 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800659 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
661 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
Jake Hambye994d462014-02-03 13:10:13 -0800665 case CMD_NV_WRITE_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
668 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800669 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_WRITE_ITEM_DONE:
674 handleNullReturnEvent(msg, "nvWriteItem");
675 break;
676
677 case CMD_NV_WRITE_CDMA_PRL:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800680 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
683 case EVENT_NV_WRITE_CDMA_PRL_DONE:
684 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
685 break;
686
chen xu1cc0abe2018-10-26 17:39:23 -0700687 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800688 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700689 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800690 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
chen xu1cc0abe2018-10-26 17:39:23 -0700693 case EVENT_RESET_MODEM_CONFIG_DONE:
694 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 case CMD_GET_PREFERRED_NETWORK_TYPE:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700700 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // Integer
708 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800709 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 if (ar.result == null) {
711 loge("getPreferredNetworkType: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("getPreferredNetworkType: CommandException: " +
714 ar.exception);
715 } else {
716 loge("getPreferredNetworkType: Unknown exception");
717 }
718 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700719 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case CMD_SET_PREFERRED_NETWORK_TYPE:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
725 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
730 handleNullReturnEvent(msg, "setPreferredNetworkType");
731 break;
732
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
734 request = (MainThreadRequest)msg.obj;
735 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800736 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000737 break;
738
739 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
740 ar = (AsyncResult)msg.obj;
741 request = (MainThreadRequest)ar.userObj;
742 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700743 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000744 break;
745
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800746 case CMD_SET_VOICEMAIL_NUMBER:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
749 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800750 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
751 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800752 break;
753
754 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
755 handleNullReturnEvent(msg, "setVoicemailNumber");
756 break;
757
Stuart Scott54788802015-03-30 13:18:01 -0700758 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
761 request);
762 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
763 break;
764
765 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
766 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
767 break;
768
Shishir Agrawal302c8692015-06-19 13:49:39 -0700769 case CMD_PERFORM_NETWORK_SCAN:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
772 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
773 break;
774
775 case EVENT_PERFORM_NETWORK_SCAN_DONE:
776 ar = (AsyncResult) msg.obj;
777 request = (MainThreadRequest) ar.userObj;
778 CellNetworkScanResult cellScanResult;
779 if (ar.exception == null && ar.result != null) {
780 cellScanResult = new CellNetworkScanResult(
781 CellNetworkScanResult.STATUS_SUCCESS,
782 (List<OperatorInfo>) ar.result);
783 } else {
784 if (ar.result == null) {
785 loge("getCellNetworkScanResults: Empty response");
786 }
787 if (ar.exception != null) {
788 loge("getCellNetworkScanResults: Exception: " + ar.exception);
789 }
790 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
791 if (ar.exception instanceof CommandException) {
792 CommandException.Error error =
793 ((CommandException) (ar.exception)).getCommandError();
794 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
795 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
796 } else if (error == CommandException.Error.GENERIC_FAILURE) {
797 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
798 }
799 }
800 cellScanResult = new CellNetworkScanResult(errorCode, null);
801 }
802 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700803 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 break;
805
806 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
807 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 ManualNetworkSelectionArgument selArg =
809 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
811 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700812 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
813 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
816 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null) {
820 request.result = true;
821 } else {
822 request.result = false;
823 loge("setNetworkSelectionModeManual " + ar.exception);
824 }
825 notifyRequester(request);
826 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 case CMD_GET_MODEM_ACTIVITY_INFO:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800832 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700833 break;
834
835 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 if (ar.result == null) {
842 loge("queryModemActivityInfo: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("queryModemActivityInfo: CommandException: " +
845 ar.exception);
846 } else {
847 loge("queryModemActivityInfo: Unknown exception");
848 }
849 }
Amit Mahajand4766222016-01-28 15:28:28 -0800850 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
851 if (request.result == null) {
852 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
853 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700854 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 break;
856
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 case CMD_SET_ALLOWED_CARRIERS:
858 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800859 CarrierRestrictionRules argument =
860 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800862 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 break;
864
865 case EVENT_SET_ALLOWED_CARRIERS_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800871 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
872 if (ar.exception instanceof CommandException) {
873 loge("setAllowedCarriers: CommandException: " + ar.exception);
874 CommandException.Error error =
875 ((CommandException) (ar.exception)).getCommandError();
876 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
877 request.result =
878 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
879 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 } else {
881 loge("setAllowedCarriers: Unknown exception");
882 }
883 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700884 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
887 case CMD_GET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800890 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_GET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800899 request.result = new IllegalStateException(
900 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 if (ar.result == null) {
902 loge("getAllowedCarriers: Empty response");
903 } else if (ar.exception instanceof CommandException) {
904 loge("getAllowedCarriers: CommandException: " +
905 ar.exception);
906 } else {
907 loge("getAllowedCarriers: Unknown exception");
908 }
909 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700910 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
Nathan Haroldb3014052017-01-25 15:57:32 -0800913 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
919 request.result = new IllegalArgumentException(
920 "Failed to retrieve Forbidden Plmns");
921 if (ar.result == null) {
922 loge("getForbiddenPlmns: Empty response");
923 } else {
924 loge("getForbiddenPlmns: Unknown exception");
925 }
926 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700927 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 break;
929
930 case CMD_GET_FORBIDDEN_PLMNS:
931 request = (MainThreadRequest) msg.obj;
932 uiccCard = getUiccCardFromRequest(request);
933 if (uiccCard == null) {
934 loge("getForbiddenPlmns() UiccCard is null");
935 request.result = new IllegalArgumentException(
936 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700937 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800938 break;
939 }
940 Integer appType = (Integer) request.argument;
941 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
942 if (uiccApp == null) {
943 loge("getForbiddenPlmns() no app with specified type -- "
944 + appType);
945 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948 } else {
949 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
950 + " specified type -- " + appType);
951 }
952 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
953 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
954 onCompleted);
955 break;
956
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000957 case CMD_SWITCH_SLOTS:
958 request = (MainThreadRequest) msg.obj;
959 int[] physicalSlots = (int[]) request.argument;
960 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
961 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
962 break;
963
964 case EVENT_SWITCH_SLOTS_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700968 notifyRequester(request);
969 break;
970 case CMD_GET_NETWORK_SELECTION_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
973 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
974 break;
975
976 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 if (ar.exception != null) {
980 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
981 } else {
982 int mode = ((int[]) ar.result)[0];
983 if (mode == 0) {
984 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
985 } else {
986 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
987 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700989 notifyRequester(request);
990 break;
991 case CMD_GET_CDMA_ROAMING_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
994 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
995 break;
996 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception != null) {
1000 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1001 } else {
1002 request.result = ((int[]) ar.result)[0];
1003 }
1004 notifyRequester(request);
1005 break;
1006 case CMD_SET_CDMA_ROAMING_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1009 int mode = (int) request.argument;
1010 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1011 break;
1012 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = ar.exception == null;
1016 notifyRequester(request);
1017 break;
1018 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1021 int subscriptionMode = (int) request.argument;
1022 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1023 break;
1024 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 request.result = ar.exception == null;
1028 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001029 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 case CMD_GET_ALL_CELL_INFO:
1031 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001032 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001033 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 case EVENT_GET_ALL_CELL_INFO_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001038 // If a timeout occurs, the response will be null
1039 request.result = (ar.exception == null && ar.result != null)
1040 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001041 synchronized (request) {
1042 request.notifyAll();
1043 }
1044 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001045 case CMD_REQUEST_CELL_INFO_UPDATE:
1046 request = (MainThreadRequest) msg.obj;
1047 request.phone.requestCellInfoUpdate(request.workSource,
1048 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1049 break;
1050 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
1053 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1054 try {
1055 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001057 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1058 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001061 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 } else {
1063 // use the result as returned
1064 cb.onCellInfo((List<CellInfo>) ar.result);
1065 }
1066 } catch (RemoteException re) {
1067 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1068 }
1069 break;
1070 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 request = (MainThreadRequest) msg.obj;
1072 WorkSource ws = (WorkSource) request.argument;
1073 Phone phone = getPhoneFromRequest(request);
1074 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
1079 if (ar.exception == null) {
1080 request.result = ar.result;
1081 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1084 ? new CdmaCellLocation() : new GsmCellLocation();
1085 }
1086
1087 synchronized (request) {
1088 request.notifyAll();
1089 }
1090 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001091 case CMD_MODEM_REBOOT:
1092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001094 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001095 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001096 case EVENT_CMD_MODEM_REBOOT_DONE:
1097 handleNullReturnEvent(msg, "rebootModem");
1098 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001099 case CMD_REQUEST_ENABLE_MODEM:
1100 request = (MainThreadRequest) msg.obj;
1101 boolean enable = (boolean) request.argument;
1102 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001103 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001104 PhoneConfigurationManager.getInstance()
1105 .enablePhone(request.phone, enable, onCompleted);
1106 break;
1107 case EVENT_ENABLE_MODEM_DONE:
1108 ar = (AsyncResult) msg.obj;
1109 request = (MainThreadRequest) ar.userObj;
1110 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001111 //update the cache as modem status has changed
1112 mPhoneConfigurationManager.addToPhoneStatusCache(
1113 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001114 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001115 notifyRequester(request);
1116 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001117 default:
1118 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1119 break;
1120 }
1121 }
Jake Hambye994d462014-02-03 13:10:13 -08001122
Pengquan Meng0c05b502018-09-06 09:59:22 -07001123 private void notifyRequester(MainThreadRequest request) {
1124 synchronized (request) {
1125 request.notifyAll();
1126 }
1127 }
1128
Jake Hambye994d462014-02-03 13:10:13 -08001129 private void handleNullReturnEvent(Message msg, String command) {
1130 AsyncResult ar = (AsyncResult) msg.obj;
1131 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1132 if (ar.exception == null) {
1133 request.result = true;
1134 } else {
1135 request.result = false;
1136 if (ar.exception instanceof CommandException) {
1137 loge(command + ": CommandException: " + ar.exception);
1138 } else {
1139 loge(command + ": Unknown exception");
1140 }
1141 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001142 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001144 }
1145
1146 /**
1147 * Posts the specified command to be executed on the main thread,
1148 * waits for the request to complete, and returns the result.
1149 * @see #sendRequestAsync
1150 */
1151 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001152 return sendRequest(
1153 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001154 }
1155
1156 /**
1157 * Posts the specified command to be executed on the main thread,
1158 * waits for the request to complete, and returns the result.
1159 * @see #sendRequestAsync
1160 */
1161 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1162 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001163 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001164 }
1165
1166 /**
1167 * Posts the specified command to be executed on the main thread,
1168 * waits for the request to complete, and returns the result.
1169 * @see #sendRequestAsync
1170 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001171 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001172 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001173 }
1174
1175 /**
1176 * Posts the specified command to be executed on the main thread,
1177 * waits for the request to complete, and returns the result.
1178 * @see #sendRequestAsync
1179 */
Nathan Harold92bed182018-10-12 18:16:49 -07001180 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1181 return sendRequest(command, argument, subId, null, workSource);
1182 }
1183
1184 /**
1185 * Posts the specified command to be executed on the main thread,
1186 * waits for the request to complete, and returns the result.
1187 * @see #sendRequestAsync
1188 */
1189 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1190 return sendRequest(
1191 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1192 }
1193
1194 /**
1195 * Posts the specified command to be executed on the main thread,
1196 * waits for the request to complete, and returns the result.
1197 * @see #sendRequestAsync
1198 */
1199 private Object sendRequest(
1200 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001201 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1202 throw new RuntimeException("This method will deadlock if called from the main thread.");
1203 }
1204
Nathan Harold92bed182018-10-12 18:16:49 -07001205 MainThreadRequest request = null;
1206 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1207 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1208 } else if (phone != null) {
1209 request = new MainThreadRequest(argument, phone, workSource);
1210 } else {
1211 request = new MainThreadRequest(argument, subId, workSource);
1212 }
1213
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001214 Message msg = mMainThreadHandler.obtainMessage(command, request);
1215 msg.sendToTarget();
1216
1217 // Wait for the request to complete
1218 synchronized (request) {
1219 while (request.result == null) {
1220 try {
1221 request.wait();
1222 } catch (InterruptedException e) {
1223 // Do nothing, go back and wait until the request is complete
1224 }
1225 }
1226 }
1227 return request.result;
1228 }
1229
1230 /**
1231 * Asynchronous ("fire and forget") version of sendRequest():
1232 * Posts the specified command to be executed on the main thread, and
1233 * returns immediately.
1234 * @see #sendRequest
1235 */
1236 private void sendRequestAsync(int command) {
1237 mMainThreadHandler.sendEmptyMessage(command);
1238 }
1239
1240 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001241 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001242 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001243 */
1244 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 sendRequestAsync(command, argument, null, null);
1246 }
1247
1248 /**
1249 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1250 * @see {@link #sendRequest(int,Object)}
1251 */
1252 private void sendRequestAsync(
1253 int command, Object argument, Phone phone, WorkSource workSource) {
1254 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001255 Message msg = mMainThreadHandler.obtainMessage(command, request);
1256 msg.sendToTarget();
1257 }
1258
1259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 * Initialize the singleton PhoneInterfaceManager instance.
1261 * This is only done once, at startup, from PhoneApp.onCreate().
1262 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001263 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001264 synchronized (PhoneInterfaceManager.class) {
1265 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001266 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 } else {
1268 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1269 }
1270 return sInstance;
1271 }
1272 }
1273
1274 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001275 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001276 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001278 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1280 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001282 mTelephonySharedPreferences =
1283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001285 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001286
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001287 publish();
1288 }
1289
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001290 private Phone getDefaultPhone() {
1291 Phone thePhone = getPhone(getDefaultSubscription());
1292 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1293 }
1294
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001295 private void publish() {
1296 if (DBG) log("publish: " + this);
1297
1298 ServiceManager.addService("phone", this);
1299 }
1300
Stuart Scott584921c2015-01-15 17:10:34 -08001301 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001302 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001303 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001304 }
1305
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001306 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1307 Phone phone = getPhoneFromRequest(request);
1308 return phone == null ? null :
1309 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1310 }
1311
Wink Saville36469e72014-06-11 15:17:00 -07001312 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001313 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001314 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316
1317 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001318 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001319 }
1320
Wink Savilleb564aae2014-10-23 10:18:09 -07001321 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001322 if (DBG) log("dial: " + number);
1323 // No permission check needed here: This is just a wrapper around the
1324 // ACTION_DIAL intent, which is available to any app since it puts up
1325 // the UI before it does anything.
1326
Malcolm Chend965c8b2018-02-28 15:00:40 -08001327 final long identity = Binder.clearCallingIdentity();
1328 try {
1329 String url = createTelUrl(number);
1330 if (url == null) {
1331 return;
1332 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333
Malcolm Chend965c8b2018-02-28 15:00:40 -08001334 // PENDING: should we just silently fail if phone is offhook or ringing?
1335 PhoneConstants.State state = mCM.getState(subId);
1336 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1337 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1338 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1339 mApp.startActivity(intent);
1340 }
1341 } finally {
1342 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001343 }
1344 }
1345
1346 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001347 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001348 }
1349
Wink Savilleb564aae2014-10-23 10:18:09 -07001350 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001351 if (DBG) log("call: " + number);
1352
1353 // This is just a wrapper around the ACTION_CALL intent, but we still
1354 // need to do a permission check since we're calling startActivity()
1355 // from the context of the phone app.
1356 enforceCallPermission();
1357
1358 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1359 != AppOpsManager.MODE_ALLOWED) {
1360 return;
1361 }
1362
Malcolm Chend965c8b2018-02-28 15:00:40 -08001363 final long identity = Binder.clearCallingIdentity();
1364 try {
1365 String url = createTelUrl(number);
1366 if (url == null) {
1367 return;
1368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001369
Malcolm Chend965c8b2018-02-28 15:00:40 -08001370 boolean isValid = false;
1371 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1372 if (slist != null) {
1373 for (SubscriptionInfo subInfoRecord : slist) {
1374 if (subInfoRecord.getSubscriptionId() == subId) {
1375 isValid = true;
1376 break;
1377 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001378 }
Wink Saville08874612014-08-31 19:19:58 -07001379 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001380 if (!isValid) {
1381 return;
1382 }
Wink Saville08874612014-08-31 19:19:58 -07001383
Malcolm Chend965c8b2018-02-28 15:00:40 -08001384 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1385 intent.putExtra(SUBSCRIPTION_KEY, subId);
1386 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1387 mApp.startActivity(intent);
1388 } finally {
1389 Binder.restoreCallingIdentity(identity);
1390 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 }
1392
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001393 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001395 }
1396
Wink Savilleb564aae2014-10-23 10:18:09 -07001397 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001398 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001399 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1400 }
1401
1402 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001404 }
1405
Wink Savilleb564aae2014-10-23 10:18:09 -07001406 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001408 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1409 }
1410
1411 /** {@hide} */
1412 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001413 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001414 }
1415
Wink Savilleb564aae2014-10-23 10:18:09 -07001416 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001417 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001418
1419 final long identity = Binder.clearCallingIdentity();
1420 try {
1421 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1422 checkSimPin.start();
1423 return checkSimPin.unlockSim(null, pin);
1424 } finally {
1425 Binder.restoreCallingIdentity(identity);
1426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 }
1428
Wink Saville9de0f752013-10-22 19:04:03 -07001429 /** {@hide} */
1430 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001431 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001432 }
1433
Wink Savilleb564aae2014-10-23 10:18:09 -07001434 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001435 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001436
1437 final long identity = Binder.clearCallingIdentity();
1438 try {
1439 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1440 checkSimPuk.start();
1441 return checkSimPuk.unlockSim(puk, pin);
1442 } finally {
1443 Binder.restoreCallingIdentity(identity);
1444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 }
1446
1447 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001448 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001449 * a synchronous one.
1450 */
1451 private static class UnlockSim extends Thread {
1452
1453 private final IccCard mSimCard;
1454
1455 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001456 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1457 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458
1459 // For replies from SimCard interface
1460 private Handler mHandler;
1461
1462 // For async handler to identify request type
1463 private static final int SUPPLY_PIN_COMPLETE = 100;
1464
1465 public UnlockSim(IccCard simCard) {
1466 mSimCard = simCard;
1467 }
1468
1469 @Override
1470 public void run() {
1471 Looper.prepare();
1472 synchronized (UnlockSim.this) {
1473 mHandler = new Handler() {
1474 @Override
1475 public void handleMessage(Message msg) {
1476 AsyncResult ar = (AsyncResult) msg.obj;
1477 switch (msg.what) {
1478 case SUPPLY_PIN_COMPLETE:
1479 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1480 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001481 mRetryCount = msg.arg1;
1482 if (ar.exception != null) {
1483 if (ar.exception instanceof CommandException &&
1484 ((CommandException)(ar.exception)).getCommandError()
1485 == CommandException.Error.PASSWORD_INCORRECT) {
1486 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1487 } else {
1488 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1489 }
1490 } else {
1491 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1492 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001493 mDone = true;
1494 UnlockSim.this.notifyAll();
1495 }
1496 break;
1497 }
1498 }
1499 };
1500 UnlockSim.this.notifyAll();
1501 }
1502 Looper.loop();
1503 }
1504
1505 /*
1506 * Use PIN or PUK to unlock SIM card
1507 *
1508 * If PUK is null, unlock SIM card with PIN
1509 *
1510 * If PUK is not null, unlock SIM card with PUK and set PIN code
1511 */
Wink Saville9de0f752013-10-22 19:04:03 -07001512 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001513
1514 while (mHandler == null) {
1515 try {
1516 wait();
1517 } catch (InterruptedException e) {
1518 Thread.currentThread().interrupt();
1519 }
1520 }
1521 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1522
1523 if (puk == null) {
1524 mSimCard.supplyPin(pin, callback);
1525 } else {
1526 mSimCard.supplyPuk(puk, pin, callback);
1527 }
1528
1529 while (!mDone) {
1530 try {
1531 Log.d(LOG_TAG, "wait for done");
1532 wait();
1533 } catch (InterruptedException e) {
1534 // Restore the interrupted status
1535 Thread.currentThread().interrupt();
1536 }
1537 }
1538 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001539 int[] resultArray = new int[2];
1540 resultArray[0] = mResult;
1541 resultArray[1] = mRetryCount;
1542 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001543 }
1544 }
1545
1546 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001547 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001548
1549 }
1550
Wink Savilleb564aae2014-10-23 10:18:09 -07001551 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001552 // No permission check needed here: this call is harmless, and it's
1553 // needed for the ServiceState.requestStateUpdate() call (which is
1554 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001555 final long identity = Binder.clearCallingIdentity();
1556 try {
1557 final Phone phone = getPhone(subId);
1558 if (phone != null) {
1559 phone.updateServiceLocation();
1560 }
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001566 @Override
1567 public boolean isRadioOn(String callingPackage) {
1568 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001571 @Override
1572 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001573 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001574 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001575 return false;
1576 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001577
1578 final long identity = Binder.clearCallingIdentity();
1579 try {
1580 return isRadioOnForSubscriber(subId);
1581 } finally {
1582 Binder.restoreCallingIdentity(identity);
1583 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001584 }
1585
1586 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001587 final long identity = Binder.clearCallingIdentity();
1588 try {
1589 final Phone phone = getPhone(subId);
1590 if (phone != null) {
1591 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1592 } else {
1593 return false;
1594 }
1595 } finally {
1596 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001597 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
1599
1600 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001601 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 }
Wink Saville36469e72014-06-11 15:17:00 -07001603
Wink Savilleb564aae2014-10-23 10:18:09 -07001604 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001605 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001606
1607 final long identity = Binder.clearCallingIdentity();
1608 try {
1609 final Phone phone = getPhone(subId);
1610 if (phone != null) {
1611 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1612 }
1613 } finally {
1614 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001615 }
Wink Saville36469e72014-06-11 15:17:00 -07001616 }
1617
1618 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001619 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001620 }
1621
Wink Savilleb564aae2014-10-23 10:18:09 -07001622 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001623 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001624
1625 final long identity = Binder.clearCallingIdentity();
1626 try {
1627 final Phone phone = getPhone(subId);
1628 if (phone == null) {
1629 return false;
1630 }
1631 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1632 toggleRadioOnOffForSubscriber(subId);
1633 }
1634 return true;
1635 } finally {
1636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 }
Wink Saville36469e72014-06-11 15:17:00 -07001639
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001640 public boolean needMobileRadioShutdown() {
1641 /*
1642 * If any of the Radios are available, it will need to be
1643 * shutdown. So return true if any Radio is available.
1644 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001645 final long identity = Binder.clearCallingIdentity();
1646 try {
1647 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1648 Phone phone = PhoneFactory.getPhone(i);
1649 if (phone != null && phone.isRadioAvailable()) return true;
1650 }
1651 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1652 return false;
1653 } finally {
1654 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001655 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001656 }
1657
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001659 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001660 enforceModifyPermission();
1661
1662 final long identity = Binder.clearCallingIdentity();
1663 try {
1664 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1665 logv("Shutting down Phone " + i);
1666 shutdownRadioUsingPhoneId(i);
1667 }
1668 } finally {
1669 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 }
1671 }
1672
1673 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001674 Phone phone = PhoneFactory.getPhone(phoneId);
1675 if (phone != null && phone.isRadioAvailable()) {
1676 phone.shutdownRadio();
1677 }
1678 }
1679
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001681 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001682
1683 final long identity = Binder.clearCallingIdentity();
1684 try {
1685 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1686 if (defaultPhone != null) {
1687 defaultPhone.setRadioPower(turnOn);
1688 return true;
1689 } else {
1690 loge("There's no default phone.");
1691 return false;
1692 }
1693 } finally {
1694 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001695 }
Wink Saville36469e72014-06-11 15:17:00 -07001696 }
1697
Wink Savilleb564aae2014-10-23 10:18:09 -07001698 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001699 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001700
1701 final long identity = Binder.clearCallingIdentity();
1702 try {
1703 final Phone phone = getPhone(subId);
1704 if (phone != null) {
1705 phone.setRadioPower(turnOn);
1706 return true;
1707 } else {
1708 return false;
1709 }
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 }
1714
Wink Saville36469e72014-06-11 15:17:00 -07001715 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001716 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001717 public boolean enableDataConnectivity() {
1718 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001719
1720 final long identity = Binder.clearCallingIdentity();
1721 try {
1722 int subId = mSubscriptionController.getDefaultDataSubId();
1723 final Phone phone = getPhone(subId);
1724 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001725 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001726 return true;
1727 } else {
1728 return false;
1729 }
1730 } finally {
1731 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 }
1734
Wink Saville36469e72014-06-11 15:17:00 -07001735 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001736 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public boolean disableDataConnectivity() {
1738 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 int subId = mSubscriptionController.getDefaultDataSubId();
1743 final Phone phone = getPhone(subId);
1744 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001745 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001746 return true;
1747 } else {
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
1754
Sanket Padawe356d7632015-06-22 14:03:32 -07001755 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001756 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001761 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001762 } else {
1763 return false;
1764 }
1765 } finally {
1766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 }
1769
1770 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001771 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001772 }
1773
pkanwarae03a6b2016-11-06 20:37:09 -08001774 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775 enforceCallPermission();
1776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1780 return;
1781 }
1782 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1783 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1784 } finally {
1785 Binder.restoreCallingIdentity(identity);
1786 }
pkanwar32d516d2016-10-14 19:37:38 -07001787 };
1788
Wink Savilleb564aae2014-10-23 10:18:09 -07001789 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1795 return false;
1796 }
1797 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1798 } finally {
1799 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 }
1802
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001804 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001807 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 Phone phone = PhoneFactory.getPhone(slotIndex);
1811 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1812 PhoneConstantConversions.convertCallState(phone.getState());
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
1815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Sanket Padawe356d7632015-06-22 14:03:32 -07001818 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1823 if (phone != null) {
1824 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1825 } else {
1826 return PhoneConstantConversions.convertDataState(
1827 PhoneConstants.DataState.DISCONNECTED);
1828 }
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Sanket Padawe356d7632015-06-22 14:03:32 -07001834 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1839 if (phone != null) {
1840 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1841 } else {
1842 return TelephonyManager.DATA_ACTIVITY_NONE;
1843 }
1844 } finally {
1845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 }
1848
1849 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001850 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001851 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001852 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001853
1854 LocationAccessPolicy.LocationPermissionResult locationResult =
1855 LocationAccessPolicy.checkLocationPermission(mApp,
1856 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1857 .setCallingPackage(callingPackage)
1858 .setCallingPid(Binder.getCallingPid())
1859 .setCallingUid(Binder.getCallingUid())
1860 .setMethod("getCellLocation")
1861 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1862 .build());
1863 switch (locationResult) {
1864 case DENIED_HARD:
1865 throw new SecurityException("Not allowed to access cell location");
1866 case DENIED_SOFT:
1867 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001870 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001871 final long identity = Binder.clearCallingIdentity();
1872 try {
1873 if (DBG_LOC) log("getCellLocation: is active user");
1874 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001875 int subId = mSubscriptionController.getDefaultDataSubId();
1876 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1877 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001878 return data;
1879 } finally {
1880 Binder.restoreCallingIdentity(identity);
1881 }
Svetoslav64fad262015-04-14 14:35:21 -07001882 }
1883
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001884 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001885 public String getNetworkCountryIsoForPhone(int phoneId) {
1886 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1887 // registered cell info, so return a NULL country instead.
1888 final long identity = Binder.clearCallingIdentity();
1889 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001890 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1891 // Get default phone in this case.
1892 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1893 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001894 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001895 // Todo: fix this when we can get the actual cellular network info when the device
1896 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001897 if (TelephonyManager.NETWORK_TYPE_IWLAN
1898 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1899 return "";
1900 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001901 Phone phone = PhoneFactory.getPhone(phoneId);
1902 if (phone != null) {
1903 ServiceStateTracker sst = phone.getServiceStateTracker();
1904 if (sst != null) {
1905 LocaleTracker lt = sst.getLocaleTracker();
1906 if (lt != null) {
1907 return lt.getCurrentCountry();
1908 }
1909 }
1910 }
1911 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001912 } finally {
1913 Binder.restoreCallingIdentity(identity);
1914 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001915 }
1916
1917 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001919 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001920 }
1921
Sanket Padawe356d7632015-06-22 14:03:32 -07001922 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001923 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001924 mApp.enforceCallingOrSelfPermission(
1925 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001926
1927 final long identity = Binder.clearCallingIdentity();
1928 try {
1929 final Phone phone = getPhone(subId);
1930 if (phone != null) {
1931 phone.enableLocationUpdates();
1932 }
1933 } finally {
1934 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001936 }
1937
1938 @Override
1939 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001940 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Sanket Padawe356d7632015-06-22 14:03:32 -07001943 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001944 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 mApp.enforceCallingOrSelfPermission(
1946 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001947
1948 final long identity = Binder.clearCallingIdentity();
1949 try {
1950 final Phone phone = getPhone(subId);
1951 if (phone != null) {
1952 phone.disableLocationUpdates();
1953 }
1954 } finally {
1955 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 }
1958
Nathan Harold31d7ff32018-10-15 20:20:30 -07001959 /**
1960 * Returns the target SDK version number for a given package name.
1961 *
1962 * @return target SDK if the package is found or INT_MAX.
1963 */
1964 private int getTargetSdk(String packageName) {
1965 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001966 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1967 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001968 if (ai != null) return ai.targetSdkVersion;
1969 } catch (PackageManager.NameNotFoundException unexpected) {
1970 }
1971 return Integer.MAX_VALUE;
1972 }
1973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 @Override
1975 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001976 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1977 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001978 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1979 throw new SecurityException(
1980 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1981 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001982
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1984 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1985 return null;
1986 }
Svetoslav64fad262015-04-14 14:35:21 -07001987
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001988 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989
Nathan Haroldf180aac2018-06-01 18:43:55 -07001990 List<CellInfo> info = getAllCellInfo(callingPackage);
1991 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992
Nathan Haroldf180aac2018-06-01 18:43:55 -07001993 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1994 for (CellInfo ci : info) {
1995 if (ci instanceof CellInfoGsm) {
1996 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1997 } else if (ci instanceof CellInfoWcdma) {
1998 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002001 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002 }
2003
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002004 private List<CellInfo> getCachedCellInfo() {
2005 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2006 for (Phone phone : PhoneFactory.getPhones()) {
2007 List<CellInfo> info = phone.getAllCellInfo();
2008 if (info != null) cellInfos.addAll(info);
2009 }
2010 return cellInfos;
2011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012
2013 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002014 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002015 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002016 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002017
2018 LocationAccessPolicy.LocationPermissionResult locationResult =
2019 LocationAccessPolicy.checkLocationPermission(mApp,
2020 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2021 .setCallingPackage(callingPackage)
2022 .setCallingPid(Binder.getCallingPid())
2023 .setCallingUid(Binder.getCallingUid())
2024 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002025 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002026 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2027 .build());
2028 switch (locationResult) {
2029 case DENIED_HARD:
2030 throw new SecurityException("Not allowed to access cell info");
2031 case DENIED_SOFT:
2032 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002035 final int targetSdk = getTargetSdk(callingPackage);
2036 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2037 return getCachedCellInfo();
2038 }
2039
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002040 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002041 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2045 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002046 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002047 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002048 if (info != null) cellInfos.addAll(info);
2049 }
2050 return cellInfos;
2051 } finally {
2052 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054 }
2055
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002056 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002057 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2058 requestCellInfoUpdateInternal(
2059 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2060 }
2061
2062 @Override
2063 public void requestCellInfoUpdateWithWorkSource(
2064 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2065 enforceModifyPermission();
2066 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2067 }
2068
2069 private void requestCellInfoUpdateInternal(
2070 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002071 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002072 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002073
2074 LocationAccessPolicy.LocationPermissionResult locationResult =
2075 LocationAccessPolicy.checkLocationPermission(mApp,
2076 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2077 .setCallingPackage(callingPackage)
2078 .setCallingPid(Binder.getCallingPid())
2079 .setCallingUid(Binder.getCallingUid())
2080 .setMethod("requestCellInfoUpdate")
2081 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2082 .build());
2083 switch (locationResult) {
2084 case DENIED_HARD:
2085 throw new SecurityException("Not allowed to access cell info");
2086 case DENIED_SOFT:
2087 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002088 }
2089
2090 final Phone phone = getPhone(subId);
2091 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2092
2093 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2094 }
2095
2096 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002097 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002098 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002099 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002100
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002103 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002104 } finally {
2105 Binder.restoreCallingIdentity(identity);
2106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
Shishir Agrawala9f32182016-04-12 12:00:16 -07002109 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002110 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002111 Phone phone = PhoneFactory.getPhone(slotIndex);
2112 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002113 return null;
2114 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002115 int subId = phone.getSubId();
2116 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2117 mApp, subId, callingPackage, "getImeiForSlot")) {
2118 return null;
2119 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 return phone.getImei();
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
2126 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002127 }
2128
2129 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002130 public String getTypeAllocationCodeForSlot(int slotIndex) {
2131 Phone phone = PhoneFactory.getPhone(slotIndex);
2132 String tac = null;
2133 if (phone != null) {
2134 String imei = phone.getImei();
2135 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2136 }
2137 return tac;
2138 }
2139
2140 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002141 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002142 Phone phone = PhoneFactory.getPhone(slotIndex);
2143 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002144 return null;
2145 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002146
Jeff Davidson913390f2018-02-23 17:11:49 -08002147 int subId = phone.getSubId();
2148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2149 mApp, subId, callingPackage, "getMeidForSlot")) {
2150 return null;
2151 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 return phone.getMeid();
2156 } finally {
2157 Binder.restoreCallingIdentity(identity);
2158 }
Jack Yu2af8d712017-03-15 17:14:14 -07002159 }
2160
2161 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002162 public String getManufacturerCodeForSlot(int slotIndex) {
2163 Phone phone = PhoneFactory.getPhone(slotIndex);
2164 String manufacturerCode = null;
2165 if (phone != null) {
2166 String meid = phone.getMeid();
2167 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2168 }
2169 return manufacturerCode;
2170 }
2171
2172 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002173 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 Phone phone = PhoneFactory.getPhone(slotIndex);
2175 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002176 return null;
2177 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002178 int subId = phone.getSubId();
2179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2180 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2181 return null;
2182 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002183
2184 final long identity = Binder.clearCallingIdentity();
2185 try {
2186 return phone.getDeviceSvn();
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
2189 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002190 }
2191
fionaxu43304da2017-11-27 22:51:16 -08002192 @Override
2193 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002194 final long identity = Binder.clearCallingIdentity();
2195 try {
2196 final Phone phone = getPhone(subId);
2197 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
fionaxu43304da2017-11-27 22:51:16 -08002201 }
2202
2203 @Override
2204 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 return phone == null ? null : phone.getCarrierName();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
fionaxu43304da2017-11-27 22:51:16 -08002212 }
2213
calvinpaneed9ae82018-11-01 19:43:06 +08002214 @Override
chen xuc93cc282018-11-04 17:17:00 -08002215 public int getSubscriptionPreciseCarrierId(int subId) {
2216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 final Phone phone = getPhone(subId);
2219 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2220 : phone.getPreciseCarrierId();
2221 } finally {
2222 Binder.restoreCallingIdentity(identity);
2223 }
2224 }
2225
2226 @Override
2227 public String getSubscriptionPreciseCarrierName(int subId) {
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
2231 return phone == null ? null : phone.getPreciseCarrierName();
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
2235 }
2236
chen xu02581692018-11-11 19:03:44 -08002237 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002238 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2239 if (!isSubscriptionMccMnc) {
2240 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2241 }
chen xu02581692018-11-11 19:03:44 -08002242 final Phone phone = PhoneFactory.getPhone(slotIndex);
2243 if (phone == null) {
2244 return TelephonyManager.UNKNOWN_CARRIER_ID;
2245 }
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
2248 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
2252 }
2253
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002254 //
2255 // Internal helper methods.
2256 //
2257
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002258 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2260 *
2261 * @throws SecurityException if the caller does not have the required permission
2262 */
2263 private void enforceModifyPermission() {
2264 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2265 }
2266
2267 /**
2268 * Make sure the caller has the CALL_PHONE permission.
2269 *
2270 * @throws SecurityException if the caller does not have the required permission
2271 */
2272 private void enforceCallPermission() {
2273 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2274 }
2275
Stuart Scott8eef64f2015-04-08 15:13:54 -07002276 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002278 "ConnectivityService");
2279 }
2280
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 private String createTelUrl(String number) {
2282 if (TextUtils.isEmpty(number)) {
2283 return null;
2284 }
2285
Jake Hambye994d462014-02-03 13:10:13 -08002286 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
Ihab Awadf9e92732013-12-05 18:02:52 -08002289 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002290 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2291 }
2292
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002293 private static void logv(String msg) {
2294 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2295 }
2296
Ihab Awadf9e92732013-12-05 18:02:52 -08002297 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2299 }
2300
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002302 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002303 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002307 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002308 final long identity = Binder.clearCallingIdentity();
2309 try {
2310 final Phone phone = PhoneFactory.getPhone(slotIndex);
2311 if (phone == null) {
2312 return PhoneConstants.PHONE_TYPE_NONE;
2313 } else {
2314 return phone.getPhoneType();
2315 }
2316 } finally {
2317 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002318 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002319 }
2320
2321 /**
2322 * Returns the CDMA ERI icon index to display
2323 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 @Override
2325 public int getCdmaEriIconIndex(String callingPackage) {
2326 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002327 }
2328
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002330 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 return -1;
2334 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002335
2336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 if (phone != null) {
2340 return phone.getCdmaEriIconIndex();
2341 } else {
2342 return -1;
2343 }
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
2349 /**
2350 * Returns the CDMA ERI icon mode,
2351 * 0 - ON
2352 * 1 - FLASHING
2353 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002354 @Override
2355 public int getCdmaEriIconMode(String callingPackage) {
2356 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002357 }
2358
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002360 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002361 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002362 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002363 return -1;
2364 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 if (phone != null) {
2370 return phone.getCdmaEriIconMode();
2371 } else {
2372 return -1;
2373 }
2374 } finally {
2375 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002376 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 }
2378
2379 /**
2380 * Returns the CDMA ERI text,
2381 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002382 @Override
2383 public String getCdmaEriText(String callingPackage) {
2384 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002385 }
2386
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002388 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002389 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002390 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002391 return null;
2392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002393
2394 final long identity = Binder.clearCallingIdentity();
2395 try {
2396 final Phone phone = getPhone(subId);
2397 if (phone != null) {
2398 return phone.getCdmaEriText();
2399 } else {
2400 return null;
2401 }
2402 } finally {
2403 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002405 }
2406
2407 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002408 * Returns the CDMA MDN.
2409 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002410 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002411 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002412 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2413 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002418 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002419 return phone.getLine1Number();
2420 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002421 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002422 return null;
2423 }
2424 } finally {
2425 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002426 }
2427 }
2428
2429 /**
2430 * Returns the CDMA MIN.
2431 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002432 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002433 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2435 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002436
2437 final long identity = Binder.clearCallingIdentity();
2438 try {
2439 final Phone phone = getPhone(subId);
2440 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2441 return phone.getCdmaMin();
2442 } else {
2443 return null;
2444 }
2445 } finally {
2446 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002447 }
2448 }
2449
Hall Liud892bec2018-11-30 14:51:45 -08002450 @Override
2451 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2452 INumberVerificationCallback callback, String callingPackage) {
2453 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2454 != PERMISSION_GRANTED) {
2455 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2456 }
2457 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2458
2459 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2460 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2461 throw new SecurityException("Calling package must be configured in the device config");
2462 }
2463
2464 if (range == null) {
2465 throw new NullPointerException("Range must be non-null");
2466 }
2467
2468 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002469 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002470
2471 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2472 }
2473
Junda Liuca05d5d2014-08-14 22:36:34 -07002474 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 * Returns true if CDMA provisioning needs to run.
2476 */
2477 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002480 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002481 } finally {
2482 Binder.restoreCallingIdentity(identity);
2483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
2486 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002487 * Sets the voice mail number of a given subId.
2488 */
2489 @Override
2490 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002491 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492
2493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2496 new Pair<String, String>(alphaTag, number), new Integer(subId));
2497 return success;
2498 } finally {
2499 Binder.restoreCallingIdentity(identity);
2500 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002501 }
2502
Ta-wei Yen87c49842016-05-13 21:19:52 -07002503 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002504 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2505 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002506 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002507 if (!TextUtils.equals(callingPackage, systemDialer)) {
2508 throw new SecurityException("caller must be system dialer");
2509 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2514 if (phoneAccountHandle == null) {
2515 return null;
2516 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002517 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002518 } finally {
2519 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002520 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002521 }
2522
2523 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002524 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002527 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002528 return null;
2529 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002530
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002531 final long identity = Binder.clearCallingIdentity();
2532 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002533 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002537 }
2538
2539 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002540 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2541 VisualVoicemailSmsFilterSettings settings) {
2542 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002547 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002548 } finally {
2549 Binder.restoreCallingIdentity(identity);
2550 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002551 }
2552
2553 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002554 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002560 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002564 }
2565
2566 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002567 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2568 String callingPackage, int subId) {
2569 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002574 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002578 }
2579
2580 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002581 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002582 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002587 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002591 }
2592
2593 @Override
2594 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2595 String number, int port, String text, PendingIntent sentIntent) {
2596 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002597 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002598 enforceSendSmsPermission();
2599 // Make the calls as the phone process.
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2603 if (port == 0) {
2604 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2605 sentIntent, null, false);
2606 } else {
2607 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2608 smsManager.sendDataMessageWithSelfPermissions(number, null,
2609 (short) port, data, sentIntent, null);
2610 }
2611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002614 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002615 /**
fionaxu0152e512016-11-14 13:36:14 -08002616 * Sets the voice activation state of a given subId.
2617 */
2618 @Override
2619 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2621 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002622
2623 final long identity = Binder.clearCallingIdentity();
2624 try {
2625 final Phone phone = getPhone(subId);
2626 if (phone != null) {
2627 phone.setVoiceActivationState(activationState);
2628 } else {
2629 loge("setVoiceActivationState fails with invalid subId: " + subId);
2630 }
2631 } finally {
2632 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002633 }
2634 }
2635
2636 /**
2637 * Sets the data activation state of a given subId.
2638 */
2639 @Override
2640 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2642 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002643
2644 final long identity = Binder.clearCallingIdentity();
2645 try {
2646 final Phone phone = getPhone(subId);
2647 if (phone != null) {
2648 phone.setDataActivationState(activationState);
2649 } else {
2650 loge("setVoiceActivationState fails with invalid subId: " + subId);
2651 }
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002654 }
2655 }
2656
2657 /**
2658 * Returns the voice activation state of a given subId.
2659 */
2660 @Override
2661 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002662 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002663
fionaxu0152e512016-11-14 13:36:14 -08002664 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 if (phone != null) {
2668 return phone.getVoiceActivationState();
2669 } else {
2670 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2671 }
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002674 }
2675 }
2676
2677 /**
2678 * Returns the data activation state of a given subId.
2679 */
2680 @Override
2681 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002682 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002683
fionaxu0152e512016-11-14 13:36:14 -08002684 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002685 final long identity = Binder.clearCallingIdentity();
2686 try {
2687 if (phone != null) {
2688 return phone.getDataActivationState();
2689 } else {
2690 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2691 }
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002694 }
2695 }
2696
2697 /**
Wink Saville36469e72014-06-11 15:17:00 -07002698 * Returns the unread count of voicemails for a subId
2699 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002700 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002701 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2703 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2704 return 0;
2705 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002706 final long identity = Binder.clearCallingIdentity();
2707 try {
2708 final Phone phone = getPhone(subId);
2709 if (phone != null) {
2710 return phone.getVoiceMessageCount();
2711 } else {
2712 return 0;
2713 }
2714 } finally {
2715 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002716 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 }
2718
2719 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002720 * returns true, if the device is in a state where both voice and data
2721 * are supported simultaneously. This can change based on location or network condition.
2722 */
2723 @Override
2724 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002725 final long identity = Binder.clearCallingIdentity();
2726 try {
2727 final Phone phone = getPhone(subId);
2728 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2729 } finally {
2730 Binder.restoreCallingIdentity(identity);
2731 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002732 }
2733
2734 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002735 * Send the dialer code if called from the current default dialer or the caller has
2736 * carrier privilege.
2737 * @param inputCode The dialer code to send
2738 */
2739 @Override
2740 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002741 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002743 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2744 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002745 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002746 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2747 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002748 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002752 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002753 } finally {
2754 Binder.restoreCallingIdentity(identity);
2755 }
fionaxu235cc5e2017-03-06 22:25:57 -08002756 }
2757
2758 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002759 * Returns the data network type.
2760 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002761 *
2762 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2763 */
2764 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002765 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = getPhone(getDefaultSubscription());
2769 if (phone != null) {
2770 return phone.getServiceState().getDataNetworkType();
2771 } else {
2772 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002776 }
Wink Saville36469e72014-06-11 15:17:00 -07002777 }
2778
Pengquan Meng0c05b502018-09-06 09:59:22 -07002779 @Override
2780 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002781 if (!isActiveSubscription(subId)) {
2782 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2783 }
2784
Pengquan Meng0c05b502018-09-06 09:59:22 -07002785 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2786 }
2787
Brad Ebinger4c460712018-10-01 10:40:55 -07002788 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002789 public boolean isInEmergencySmsMode() {
2790 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 for (Phone phone : PhoneFactory.getPhones()) {
2794 if (phone.isInEmergencySmsMode()) {
2795 return true;
2796 }
2797 }
2798 } finally {
2799 Binder.restoreCallingIdentity(identity);
2800 }
2801 return false;
2802 }
2803
2804 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002805 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2806 throws RemoteException {
2807 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002808 final long token = Binder.clearCallingIdentity();
2809 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002812 .addRegistrationCallbackForSubscription(c, subId);
2813 } finally {
2814 Binder.restoreCallingIdentity(token);
2815 }
2816 }
2817
2818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002819 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2820 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002821 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2822 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2823 }
2824 Binder.withCleanCallingIdentity(() -> {
2825 try {
2826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002827 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002828 .removeRegistrationCallbackForSubscription(c, subId);
2829 } catch (IllegalArgumentException e) {
2830 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2831 + "is inactive, ignoring unregister.");
2832 // If the subscription is no longer active, just return, since the callback
2833 // will already have been removed internally.
2834 }
2835 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002836 }
2837
2838 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002839 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2840 throws RemoteException {
2841 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002842 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2843 final long token = Binder.clearCallingIdentity();
2844 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002845 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002846 .addCapabilitiesCallbackForSubscription(c, subId);
2847 } finally {
2848 Binder.restoreCallingIdentity(token);
2849 }
2850 }
2851
2852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002853 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2854 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002855
2856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2858 }
2859 Binder.withCleanCallingIdentity(() -> {
2860 try {
2861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002862 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002863 .removeCapabilitiesCallbackForSubscription(c, subId);
2864 } catch (IllegalArgumentException e) {
2865 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2866 + "is inactive, ignoring unregister.");
2867 // If the subscription is no longer active, just return, since the callback
2868 // will already have been removed internally.
2869 }
2870 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002871 }
2872
2873 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002874 public boolean isCapable(int subId, int capability, int regTech) {
2875 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002876 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2877 final long token = Binder.clearCallingIdentity();
2878 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002879 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002880 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2881 } catch (ImsException e) {
2882 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2883 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002884 } catch (IllegalArgumentException e) {
2885 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2886 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002887 } finally {
2888 Binder.restoreCallingIdentity(token);
2889 }
2890 }
2891
2892 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002893 public boolean isAvailable(int subId, int capability, int regTech) {
2894 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002895 final long token = Binder.clearCallingIdentity();
2896 try {
2897 Phone phone = getPhone(subId);
2898 if (phone == null) return false;
2899 return phone.isImsCapabilityAvailable(capability, regTech);
2900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
2906 public boolean isAdvancedCallingSettingEnabled(int subId) {
2907 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2909 final long token = Binder.clearCallingIdentity();
2910 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002911 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002912 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2913 } finally {
2914 Binder.restoreCallingIdentity(token);
2915 }
2916 }
2917
2918 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002919 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002921 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002925 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002926 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2927 } finally {
2928 Binder.restoreCallingIdentity(identity);
2929 }
2930 }
2931
2932 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002933 public boolean isVtSettingEnabled(int subId) {
2934 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002938 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).isVtEnabledByUser();
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002946 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002948 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002949 final long identity = Binder.clearCallingIdentity();
2950 try {
2951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002952 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
2959 public boolean isVoWiFiSettingEnabled(int subId) {
2960 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002964 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002965 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002972 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002974 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002975 final long identity = Binder.clearCallingIdentity();
2976 try {
2977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002978 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
2985 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2986 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
2989 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002990 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002991 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002998 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003000 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003005 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3014 "setVoWiFiNonPersistent");
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003018 boolean isRoaming = TelephonyManager.from(
3019 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003020 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003021 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003022 } finally {
3023 Binder.restoreCallingIdentity(identity);
3024 }
3025 }
3026
3027 @Override
3028 public int getVoWiFiModeSetting(int subId) {
3029 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3030 final long identity = Binder.clearCallingIdentity();
3031 try {
3032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003033 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003034 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public void setVoWiFiModeSetting(int subId, int mode) {
3042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3043 "setVoWiFiModeSetting");
3044 final long identity = Binder.clearCallingIdentity();
3045 try {
3046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003047 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003048 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
3051 }
3052 }
3053
3054 @Override
3055 public int getVoWiFiRoamingModeSetting(int subId) {
3056 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003060 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3069 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3070 "setVoWiFiRoamingModeSetting");
3071 final long identity = Binder.clearCallingIdentity();
3072 try {
3073 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003074 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003075 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
3081 @Override
3082 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3084 "setRttCapabilityEnabled");
3085 final long identity = Binder.clearCallingIdentity();
3086 try {
3087 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003088 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003089 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3090 } finally {
3091 Binder.restoreCallingIdentity(identity);
3092 }
3093 }
3094
3095 @Override
3096 public boolean isTtyOverVolteEnabled(int subId) {
3097 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003101 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003102 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003108 @Override
3109 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3110 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003114 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003115 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
3121 @Override
3122 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3123 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3124 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003125 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3126 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3127 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003128 try {
3129 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003130 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003131 .removeProvisioningCallbackForSubscription(callback, subId);
3132 } catch (IllegalArgumentException e) {
3133 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3134 + "is inactive, ignoring unregister.");
3135 // If the subscription is no longer active, just return, since the callback will already
3136 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
3142 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003143 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3144 boolean isProvisioned) {
3145 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3146 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3147 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3148 }
3149 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3150 "setProvisioningStatusForCapability");
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3154 Phone phone = getPhone(subId);
3155 if (phone == null) {
3156 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3157 + subId);
3158 return;
3159 }
3160 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3161 return;
3162 }
3163
3164 // this capability requires provisioning, route to the correct API.
3165 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3166 switch (capability) {
3167 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3168 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3169 ims.setVolteProvisioned(isProvisioned);
3170 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3171 ims.setWfcProvisioned(isProvisioned);
3172 }
3173 break;
3174 }
3175 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3176 // There is currently no difference in VT provisioning type.
3177 ims.setVtProvisioned(isProvisioned);
3178 break;
3179 }
3180 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3181 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3182 // change the capability of the feature instead if needed.
3183 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3184 == isProvisioned) {
3185 // No change in provisioning.
3186 return;
3187 }
3188 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3189 try {
3190 ims.changeMmTelCapability(capability, tech, isProvisioned);
3191 } catch (ImsException e) {
3192 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3193 + ", Exception" + e.getMessage());
3194 }
3195 break;
3196 }
3197 default: {
3198 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3199 + capability + "', which does not require provisioning.");
3200 }
3201 }
3202
3203 } finally {
3204 Binder.restoreCallingIdentity(identity);
3205 }
3206 }
3207
3208 @Override
3209 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3210 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3211 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3212 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3213 }
3214 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3218 Phone phone = getPhone(subId);
3219 if (phone == null) {
3220 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3221 + subId);
3222 // We will fail with "true" as the provisioning status because this is the default
3223 // if we do not require provisioning.
3224 return true;
3225 }
3226
3227 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3228 return true;
3229 }
3230
3231 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3232 switch (capability) {
3233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3234 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3235 return ims.isVolteProvisionedOnDevice();
3236 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3237 return ims.isWfcProvisionedOnDevice();
3238 }
3239 // This should never happen, since we are checking tech above to make sure it
3240 // is either LTE or IWLAN.
3241 throw new IllegalArgumentException("Invalid radio technology for voice "
3242 + "capability.");
3243 }
3244 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3245 // There is currently no difference in VT provisioning type.
3246 return ims.isVtProvisionedOnDevice();
3247 }
3248 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3249 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3250 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3251 }
3252 default: {
3253 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3254 + capability + "', which does not require provisioning.");
3255 }
3256 }
3257
3258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
3264 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3265 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3266 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3267 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3268 }
3269 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3270 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3271 return (provisionedBits & capability) > 0;
3272 }
3273
3274 @Override
3275 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3276 boolean isProvisioned) {
3277 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3278 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3279 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3280 }
3281 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3282 "setProvisioningStatusForCapability");
3283 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3284 // If the current provisioning status for capability already matches isProvisioned,
3285 // do nothing.
3286 if (((provisionedBits & capability) > 0) == isProvisioned) {
3287 return;
3288 }
3289 if (isProvisioned) {
3290 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3291 } else {
3292 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3293 }
3294 }
3295
3296 /**
3297 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3298 * technology. The bitfield should mirror the bitfield defined by
3299 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3300 */
3301 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3302 String key = getMmTelProvisioningKey(subId, tech);
3303 // Default is no capabilities are provisioned.
3304 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3305 }
3306
3307 /**
3308 * Sets the MmTel capability provisioning bitfield (defined by
3309 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3310 * technology specified.
3311 *
3312 * Note: This is a synchronous command and should not be called on UI thread.
3313 */
3314 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3315 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3316 String key = getMmTelProvisioningKey(subId, tech);
3317 editor.putInt(key, newField);
3318 editor.commit();
3319 }
3320
3321 private static String getMmTelProvisioningKey(int subId, int tech) {
3322 // resulting key is provision_ims_mmtel_{subId}_{tech}
3323 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3324 }
3325
3326 /**
3327 * Query CarrierConfig to see if the specified capability requires provisioning for the
3328 * carrier associated with the subscription id.
3329 */
3330 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3331 int capability) {
3332 CarrierConfigManager configManager = new CarrierConfigManager(context);
3333 PersistableBundle c = configManager.getConfigForSubId(subId);
3334 boolean requireUtProvisioning = c.getBoolean(
3335 // By default, this config is true (even if there is no SIM). We also check to make
3336 // sure the subscription needs provisioning here, so we do not need to check for
3337 // the no-SIM case, where we would normally shortcut this to false.
3338 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3339 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3340 false);
3341 boolean requireVoiceVtProvisioning = c.getBoolean(
3342 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3343
3344 // First check to make sure that the capability requires provisioning.
3345 switch (capability) {
3346 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3347 // intentional fallthrough
3348 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3349 if (requireVoiceVtProvisioning) {
3350 // Voice and Video requires provisioning
3351 return true;
3352 }
3353 break;
3354 }
3355 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3356 if (requireUtProvisioning) {
3357 // UT requires provisioning
3358 return true;
3359 }
3360 break;
3361 }
3362 }
3363 return false;
3364 }
3365
3366 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003367 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003368 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3369 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3370 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003371 enforceReadPrivilegedPermission("getImsProvisioningInt");
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003375 int slotId = getSlotIndex(subId);
3376 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3377 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3378 + subId + "' for key:" + key);
3379 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3380 }
3381 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003382 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003383 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3384 + subId + "' for key:" + key);
3385 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003386 } finally {
3387 Binder.restoreCallingIdentity(identity);
3388 }
3389 }
3390
3391 @Override
3392 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003393 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3394 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3395 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 enforceReadPrivilegedPermission("getImsProvisioningString");
3397 final long identity = Binder.clearCallingIdentity();
3398 try {
3399 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003400 int slotId = getSlotIndex(subId);
3401 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3402 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3403 + subId + "' for key:" + key);
3404 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3405 }
3406 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003407 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003408 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3409 + subId + "' for key:" + key);
3410 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
3414 }
3415
3416 @Override
3417 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003418 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3419 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3420 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3422 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003423 final long identity = Binder.clearCallingIdentity();
3424 try {
3425 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003426 int slotId = getSlotIndex(subId);
3427 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3428 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3429 + subId + "' for key:" + key);
3430 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3431 }
3432 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003433 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003434 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3435 + "' for key:" + key);
3436 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003437 } finally {
3438 Binder.restoreCallingIdentity(identity);
3439 }
3440 }
3441
3442 @Override
3443 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003444 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3445 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3446 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3448 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003452 int slotId = getSlotIndex(subId);
3453 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3454 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3455 + subId + "' for key:" + key);
3456 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3457 }
3458 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003459 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3461 + "' for key:" + key);
3462 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
Brad Ebinger4c460712018-10-01 10:40:55 -07003468 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3469 int slotId = SubscriptionManager.getSlotIndex(subId);
3470 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003471 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003472 }
3473 return slotId;
3474 }
3475
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003476 private int getSlotIndex(int subId) {
3477 int slotId = SubscriptionManager.getSlotIndex(subId);
3478 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3479 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3480 }
3481 return slotId;
3482 }
3483
Wink Saville36469e72014-06-11 15:17:00 -07003484 /**
3485 * Returns the network type for a subId
3486 */
3487 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003488 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003489 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003490 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003491 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3492 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003493
Malcolm Chend965c8b2018-02-28 15:00:40 -08003494 final long identity = Binder.clearCallingIdentity();
3495 try {
3496 final Phone phone = getPhone(subId);
3497 if (phone != null) {
3498 return phone.getServiceState().getDataNetworkType();
3499 } else {
3500 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3501 }
3502 } finally {
3503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003505 }
3506
3507 /**
3508 * Returns the data network type
3509 */
3510 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003511 public int getDataNetworkType(String callingPackage) {
3512 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003513 }
3514
3515 /**
3516 * Returns the data network type for a subId
3517 */
3518 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003519 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003521 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003522 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3523 }
3524
Malcolm Chend965c8b2018-02-28 15:00:40 -08003525 final long identity = Binder.clearCallingIdentity();
3526 try {
3527 final Phone phone = getPhone(subId);
3528 if (phone != null) {
3529 return phone.getServiceState().getDataNetworkType();
3530 } else {
3531 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3532 }
3533 } finally {
3534 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003536 }
3537
3538 /**
Wink Saville36469e72014-06-11 15:17:00 -07003539 * Returns the Voice network type for a subId
3540 */
3541 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003542 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003543 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003544 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003545 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3546 }
3547
Malcolm Chend965c8b2018-02-28 15:00:40 -08003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 final Phone phone = getPhone(subId);
3551 if (phone != null) {
3552 return phone.getServiceState().getVoiceNetworkType();
3553 } else {
3554 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003559 }
3560
3561 /**
3562 * @return true if a ICC card is present
3563 */
3564 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003565 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003566 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3567 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003568 }
3569
3570 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003571 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003572 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003573 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003574 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003575 final long identity = Binder.clearCallingIdentity();
3576 try {
3577 final Phone phone = PhoneFactory.getPhone(slotIndex);
3578 if (phone != null) {
3579 return phone.getIccCard().hasIccCard();
3580 } else {
3581 return false;
3582 }
3583 } finally {
3584 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003585 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003586 }
3587
3588 /**
3589 * Return if the current radio is LTE on CDMA. This
3590 * is a tri-state return value as for a period of time
3591 * the mode may be unknown.
3592 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003593 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003594 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003595 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003596 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003597 @Override
3598 public int getLteOnCdmaMode(String callingPackage) {
3599 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
Sanket Padawe356d7632015-06-22 14:03:32 -07003602 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003603 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003604 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003605 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3607 }
3608
Malcolm Chend965c8b2018-02-28 15:00:40 -08003609 final long identity = Binder.clearCallingIdentity();
3610 try {
3611 final Phone phone = getPhone(subId);
3612 if (phone == null) {
3613 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3614 } else {
3615 return phone.getLteOnCdmaMode();
3616 }
3617 } finally {
3618 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003619 }
Wink Saville36469e72014-06-11 15:17:00 -07003620 }
3621
Wink Saville36469e72014-06-11 15:17:00 -07003622 /**
3623 * {@hide}
3624 * Returns Default subId, 0 in the case of single standby.
3625 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003626 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003627 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003628 }
3629
Shishir Agrawala9f32182016-04-12 12:00:16 -07003630 private int getSlotForDefaultSubscription() {
3631 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3632 }
3633
Wink Savilleb564aae2014-10-23 10:18:09 -07003634 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003635 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003636 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003637
Pengquan Meng466e2482018-09-21 15:54:48 -07003638 private boolean isActiveSubscription(int subId) {
3639 return mSubscriptionController.isActiveSubId(subId);
3640 }
3641
Ihab Awadf2177b72013-11-25 13:33:23 -08003642 /**
3643 * @see android.telephony.TelephonyManager.WifiCallingChoices
3644 */
3645 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003646 final long identity = Binder.clearCallingIdentity();
3647 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003648 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003649 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3650 getWhenToMakeWifiCallsDefaultPreference());
3651 } finally {
3652 Binder.restoreCallingIdentity(identity);
3653 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003654 }
3655
3656 /**
3657 * @see android.telephony.TelephonyManager.WifiCallingChoices
3658 */
3659 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003660 final long identity = Binder.clearCallingIdentity();
3661 try {
3662 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003663 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003664 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3665 } finally {
3666 Binder.restoreCallingIdentity(identity);
3667 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003668 }
3669
Sailesh Nepald1e68152013-12-12 19:08:02 -08003670 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003671 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003672 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003673 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003674
Shishir Agrawal566b7612013-10-28 14:41:00 -07003675 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003676 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3677 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003678 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3679 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003680 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003681
Malcolm Chend965c8b2018-02-28 15:00:40 -08003682 final long identity = Binder.clearCallingIdentity();
3683 try {
3684 if (TextUtils.equals(ISDR_AID, aid)) {
3685 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003686 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3687 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003688 if (bestComponent == null
3689 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3690 loge("The calling package is not allowed to access ISD-R.");
3691 throw new SecurityException(
3692 "The calling package is not allowed to access ISD-R.");
3693 }
Derek Tan740e1672017-06-27 14:56:27 -07003694 }
Derek Tan740e1672017-06-27 14:56:27 -07003695
Malcolm Chend965c8b2018-02-28 15:00:40 -08003696 if (DBG) {
3697 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3698 }
3699 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3700 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3701 if (DBG) log("iccOpenLogicalChannel: " + response);
3702 return response;
3703 } finally {
3704 Binder.restoreCallingIdentity(identity);
3705 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003706 }
3707
3708 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003709 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3711 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003712
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3716 if (channel < 0) {
3717 return false;
3718 }
3719 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3720 if (DBG) log("iccCloseLogicalChannel: " + success);
3721 return success;
3722 } finally {
3723 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003724 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003725 }
3726
3727 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003728 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003729 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3731 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003732
Malcolm Chend965c8b2018-02-28 15:00:40 -08003733 final long identity = Binder.clearCallingIdentity();
3734 try {
3735 if (DBG) {
3736 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3737 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3738 + p3 + " data=" + data);
3739 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003740
Malcolm Chend965c8b2018-02-28 15:00:40 -08003741 if (channel < 0) {
3742 return "";
3743 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003744
Malcolm Chend965c8b2018-02-28 15:00:40 -08003745 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3746 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3747 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003748
Malcolm Chend965c8b2018-02-28 15:00:40 -08003749 // Append the returned status code to the end of the response payload.
3750 String s = Integer.toHexString(
3751 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3752 if (response.payload != null) {
3753 s = IccUtils.bytesToHexString(response.payload) + s;
3754 }
3755 return s;
3756 } finally {
3757 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003758 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003759 }
Jake Hambye994d462014-02-03 13:10:13 -08003760
Evan Charltonc66da362014-05-16 14:06:40 -07003761 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003762 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3763 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003764 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3765 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003767
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 final long identity = Binder.clearCallingIdentity();
3769 try {
3770 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3771 && TextUtils.equals(ISDR_AID, data)) {
3772 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003773 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3774 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003775 if (bestComponent == null
3776 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3777 loge("The calling package is not allowed to select ISD-R.");
3778 throw new SecurityException(
3779 "The calling package is not allowed to select ISD-R.");
3780 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003781 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003782
Malcolm Chend965c8b2018-02-28 15:00:40 -08003783 if (DBG) {
3784 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3785 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003787
Malcolm Chend965c8b2018-02-28 15:00:40 -08003788 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3789 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3790 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003791
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792 // Append the returned status code to the end of the response payload.
3793 String s = Integer.toHexString(
3794 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3795 if (response.payload != null) {
3796 s = IccUtils.bytesToHexString(response.payload) + s;
3797 }
3798 return s;
3799 } finally {
3800 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003801 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003802 }
3803
3804 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003805 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003806 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003807 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3808 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003809
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
3812 if (DBG) {
3813 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3814 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3815 }
3816
3817 IccIoResult response =
3818 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3819 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3820 subId);
3821
3822 if (DBG) {
3823 log("Exchange SIM_IO [R]" + response);
3824 }
3825
3826 byte[] result = null;
3827 int length = 2;
3828 if (response.payload != null) {
3829 length = 2 + response.payload.length;
3830 result = new byte[length];
3831 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3832 } else {
3833 result = new byte[length];
3834 }
3835
3836 result[length - 1] = (byte) response.sw2;
3837 result[length - 2] = (byte) response.sw1;
3838 return result;
3839 } finally {
3840 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003841 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003842 }
3843
Nathan Haroldb3014052017-01-25 15:57:32 -08003844 /**
3845 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3846 * on a particular subscription
3847 */
sqianb6e41952018-03-12 14:54:01 -07003848 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3850 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3851 return null;
3852 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003853
3854 final long identity = Binder.clearCallingIdentity();
3855 try {
3856 if (appType != TelephonyManager.APPTYPE_USIM
3857 && appType != TelephonyManager.APPTYPE_SIM) {
3858 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3859 return null;
3860 }
3861 Object response = sendRequest(
3862 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3863 if (response instanceof String[]) {
3864 return (String[]) response;
3865 }
3866 // Response is an Exception of some kind,
3867 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003868 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003869 } finally {
3870 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003871 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003872 }
3873
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003875 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003876 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3877 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003878
Malcolm Chend965c8b2018-02-28 15:00:40 -08003879 final long identity = Binder.clearCallingIdentity();
3880 try {
3881 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3882 if (response.payload == null) {
3883 return "";
3884 }
Evan Charltonc66da362014-05-16 14:06:40 -07003885
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886 // Append the returned status code to the end of the response payload.
3887 String s = Integer.toHexString(
3888 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3889 s = IccUtils.bytesToHexString(response.payload) + s;
3890 return s;
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
3893 }
Evan Charltonc66da362014-05-16 14:06:40 -07003894 }
3895
Jake Hambye994d462014-02-03 13:10:13 -08003896 /**
3897 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3898 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3899 *
3900 * @param itemID the ID of the item to read
3901 * @return the NV item as a String, or null on error.
3902 */
3903 @Override
3904 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3907 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003908
3909 final long identity = Binder.clearCallingIdentity();
3910 try {
3911 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003912 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003913 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3914 return value;
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
3917 }
Jake Hambye994d462014-02-03 13:10:13 -08003918 }
3919
3920 /**
3921 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3922 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3923 *
3924 * @param itemID the ID of the item to read
3925 * @param itemValue the value to write, as a String
3926 * @return true on success; false on any failure
3927 */
3928 @Override
3929 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3932 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003933
3934 final long identity = Binder.clearCallingIdentity();
3935 try {
3936 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3937 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003938 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003939 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3940 return success;
3941 } finally {
3942 Binder.restoreCallingIdentity(identity);
3943 }
Jake Hambye994d462014-02-03 13:10:13 -08003944 }
3945
3946 /**
3947 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3948 * Used for device configuration by some CDMA operators.
3949 *
3950 * @param preferredRoamingList byte array containing the new PRL
3951 * @return true on success; false on any failure
3952 */
3953 @Override
3954 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3956 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003957
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3961 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3962 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3963 return success;
3964 } finally {
3965 Binder.restoreCallingIdentity(identity);
3966 }
Jake Hambye994d462014-02-03 13:10:13 -08003967 }
3968
3969 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003970 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003971 * Used for device configuration by some CDMA operators.
3972 *
chen xu1cc0abe2018-10-26 17:39:23 -07003973 * @param slotIndex - device slot.
3974 *
Jake Hambye994d462014-02-03 13:10:13 -08003975 * @return true on success; false on any failure
3976 */
3977 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003978 public boolean resetModemConfig(int slotIndex) {
3979 Phone phone = PhoneFactory.getPhone(slotIndex);
3980 if (phone != null) {
3981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3982 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003983
chen xu1cc0abe2018-10-26 17:39:23 -07003984 final long identity = Binder.clearCallingIdentity();
3985 try {
3986 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3987 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3988 return success;
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003992 }
chen xu1cc0abe2018-10-26 17:39:23 -07003993 return false;
3994 }
3995
3996 /**
3997 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3998 *
3999 * @param slotIndex - device slot.
4000 *
4001 * @return true on success; false on any failure
4002 */
4003 @Override
4004 public boolean rebootModem(int slotIndex) {
4005 Phone phone = PhoneFactory.getPhone(slotIndex);
4006 if (phone != null) {
4007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4008 mApp, phone.getSubId(), "rebootModem");
4009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4013 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4014 return success;
4015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 }
4019 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004020 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004021
Svet Ganovb320e182015-04-16 12:30:10 -07004022 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004023 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004025 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004026 return new String[0];
4027 }
4028
Malcolm Chend965c8b2018-02-28 15:00:40 -08004029 final long identity = Binder.clearCallingIdentity();
4030 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004031 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004032 } finally {
4033 Binder.restoreCallingIdentity(identity);
4034 }
Wink Saville36469e72014-06-11 15:17:00 -07004035 }
4036
Brad Ebinger51f743a2017-01-23 13:50:20 -08004037 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004038 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4039 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004040 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004041 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004042 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004043
4044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 PhoneFactory.getImsResolver().enableIms(slotId);
4047 } finally {
4048 Binder.restoreCallingIdentity(identity);
4049 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004050 }
4051
4052 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004053 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4054 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004055 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004056 public void disableIms(int slotId) {
4057 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004058
4059 final long identity = Binder.clearCallingIdentity();
4060 try {
4061 PhoneFactory.getImsResolver().disableIms(slotId);
4062 } finally {
4063 Binder.restoreCallingIdentity(identity);
4064 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004065 }
4066
4067 /**
4068 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4069 * feature or {@link null} if the service is not available. If the feature is available, the
4070 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4071 */
4072 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004073 IImsServiceFeatureCallback callback) {
4074 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004075
4076 final long identity = Binder.clearCallingIdentity();
4077 try {
4078 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004082 }
4083
4084 /**
4085 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4086 * feature during emergency calling or {@link null} if the service is not available. If the
4087 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4088 * listener for feature updates.
4089 */
4090 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4091 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004092
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004099 }
4100
Brad Ebinger5f64b052017-12-14 14:26:15 -08004101 /**
4102 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4103 * specified.
4104 */
4105 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4106 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004107
4108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4111 } finally {
4112 Binder.restoreCallingIdentity(identity);
4113 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004114 }
4115
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004116 /**
4117 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4118 * specified.
4119 */
4120 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4121 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004122
4123 final long identity = Binder.clearCallingIdentity();
4124 try {
4125 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004129 }
4130
Brad Ebinger884c07b2018-02-15 16:17:40 -08004131 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004132 * Sets the ImsService Package Name that Telephony will bind to.
4133 *
4134 * @param slotId the slot ID that the ImsService should bind for.
4135 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4136 * ImsService is the device default ImsService.
4137 * @param packageName The package name of the application that contains the ImsService to bind
4138 * to.
4139 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4140 * @hide
4141 */
4142 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004143 int[] subIds = SubscriptionManager.getSubId(slotId);
4144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4145 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4146 "setImsService");
4147
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 final long identity = Binder.clearCallingIdentity();
4149 try {
4150 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4151 isCarrierImsService, packageName);
4152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004155 }
4156
4157 /**
4158 * Return the ImsService configuration.
4159 *
4160 * @param slotId The slot that the ImsService is associated with.
4161 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4162 * the device default.
4163 * @return the package name of the ImsService configuration.
4164 */
4165 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004166 int[] subIds = SubscriptionManager.getSubId(slotId);
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4168 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4169 "getImsService");
4170
Malcolm Chend965c8b2018-02-28 15:00:40 -08004171 final long identity = Binder.clearCallingIdentity();
4172 try {
4173 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4174 isCarrierImsService);
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004178 }
4179
Wink Saville36469e72014-06-11 15:17:00 -07004180 public void setImsRegistrationState(boolean registered) {
4181 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004182
4183 final long identity = Binder.clearCallingIdentity();
4184 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004185 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
Wink Saville36469e72014-06-11 15:17:00 -07004189 }
4190
4191 /**
Stuart Scott54788802015-03-30 13:18:01 -07004192 * Set the network selection mode to automatic.
4193 *
4194 */
4195 @Override
4196 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4198 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004199
Pengquan Meng466e2482018-09-21 15:54:48 -07004200 if (!isActiveSubscription(subId)) {
4201 return;
4202 }
4203
Malcolm Chend965c8b2018-02-28 15:00:40 -08004204 final long identity = Binder.clearCallingIdentity();
4205 try {
4206 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4207 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4208 } finally {
4209 Binder.restoreCallingIdentity(identity);
4210 }
Stuart Scott54788802015-03-30 13:18:01 -07004211 }
4212
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004213 /**
4214 * Ask the radio to connect to the input network and change selection mode to manual.
4215 *
4216 * @param subId the id of the subscription.
4217 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4218 * the operator to attach to.
4219 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4220 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4221 * normal network selection next time.
4222 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004223 */
4224 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004225 public boolean setNetworkSelectionModeManual(
4226 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004227 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4228 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004229
4230 if (!isActiveSubscription(subId)) {
4231 return false;
4232 }
4233
Malcolm Chend965c8b2018-02-28 15:00:40 -08004234 final long identity = Binder.clearCallingIdentity();
4235 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004236 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004237 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004238 if (DBG) {
4239 log("setNetworkSelectionModeManual: subId: " + subId
4240 + " operator: " + operatorInfo);
4241 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004242 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004246 }
4247
4248 /**
4249 * Scans for available networks.
4250 */
4251 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004252 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4254 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004255 LocationAccessPolicy.LocationPermissionResult locationResult =
4256 LocationAccessPolicy.checkLocationPermission(mApp,
4257 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4258 .setCallingPackage(callingPackage)
4259 .setCallingPid(Binder.getCallingPid())
4260 .setCallingUid(Binder.getCallingUid())
4261 .setMethod("getCellNetworkScanResults")
4262 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4263 .build());
4264 switch (locationResult) {
4265 case DENIED_HARD:
4266 throw new SecurityException("Not allowed to access scan results -- location");
4267 case DENIED_SOFT:
4268 return null;
4269 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004270
Pengquan Meng0c05b502018-09-06 09:59:22 -07004271 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004272 try {
4273 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004274 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004279 }
4280
4281 /**
yinxub1bed742017-04-17 11:45:04 -07004282 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004283 *
yinxub1bed742017-04-17 11:45:04 -07004284 * @param subId id of the subscription
4285 * @param request contains the radio access networks with bands/channels to scan
4286 * @param messenger callback messenger for scan results or errors
4287 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004288 * @return the id of the requested scan which can be used to stop the scan.
4289 */
4290 @Override
4291 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004292 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4294 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004295
Hall Liuf19c44f2018-11-27 14:38:17 -08004296 LocationAccessPolicy.LocationPermissionResult locationResult =
4297 LocationAccessPolicy.checkLocationPermission(mApp,
4298 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4299 .setCallingPackage(callingPackage)
4300 .setCallingPid(Binder.getCallingPid())
4301 .setCallingUid(Binder.getCallingUid())
4302 .setMethod("requestNetworkScan")
4303 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4304 .build());
4305 switch (locationResult) {
4306 case DENIED_HARD:
4307 throw new SecurityException("Not allowed to request network scan -- location");
4308 case DENIED_SOFT:
4309 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004310 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004311
4312 return mNetworkScanRequestTracker.startNetworkScan(
4313 request, messenger, binder, getPhone(subId),
4314 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004315 }
4316
4317 /**
4318 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004319 *
4320 * @param subId id of the subscription
4321 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004322 */
4323 @Override
4324 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004325 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4326 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004327
4328 final long identity = Binder.clearCallingIdentity();
4329 try {
4330 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
yinxu504e1392017-04-12 16:03:22 -07004334 }
4335
4336 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004337 * Get the calculated preferred network type.
4338 * Used for debugging incorrect network type.
4339 *
4340 * @return the preferred network type, defined in RILConstants.java.
4341 */
4342 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004343 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004344 final Phone defaultPhone = getDefaultPhone();
4345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4346 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004347 return RILConstants.PREFERRED_NETWORK_MODE;
4348 }
4349
Malcolm Chend965c8b2018-02-28 15:00:40 -08004350 final long identity = Binder.clearCallingIdentity();
4351 try {
4352 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004353 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004354 } finally {
4355 Binder.restoreCallingIdentity(identity);
4356 }
Junda Liu84d15a22014-07-02 11:21:04 -07004357 }
4358
4359 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004360 * Get the preferred network type.
4361 * Used for device configuration by some CDMA operators.
4362 *
4363 * @return the preferred network type, defined in RILConstants.java.
4364 */
4365 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004366 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004367 TelephonyPermissions
4368 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4369 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370
4371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 if (DBG) log("getPreferredNetworkType");
4374 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4375 int networkType = (result != null ? result[0] : -1);
4376 if (DBG) log("getPreferredNetworkType: " + networkType);
4377 return networkType;
4378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004381 }
4382
4383 /**
4384 * Set the preferred network type.
4385 * Used for device configuration by some CDMA operators.
4386 *
4387 * @param networkType the preferred network type, defined in RILConstants.java.
4388 * @return true on success; false on any failure.
4389 */
4390 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004391 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004392 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4393 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004394
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4398 Boolean success = (Boolean) sendRequest(
4399 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4400 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4401 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004402 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004403 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4404 }
4405 return success;
4406 } finally {
4407 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004408 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004409 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004410
4411 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004412 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004413 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004414 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004415 * @hide
4416 */
4417 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004418 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004419 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004420 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004421 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004422 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004423 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004424 } finally {
4425 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004426 }
Junda Liu475951f2014-11-07 16:45:03 -08004427 }
4428
4429 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004430 * Set mobile data enabled
4431 * Used by the user through settings etc to turn on/off mobile data
4432 *
4433 * @param enable {@code true} turn turn data on, else {@code false}
4434 */
4435 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004436 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4438 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004439
4440 final long identity = Binder.clearCallingIdentity();
4441 try {
4442 int phoneId = mSubscriptionController.getPhoneId(subId);
4443 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4444 Phone phone = PhoneFactory.getPhone(phoneId);
4445 if (phone != null) {
4446 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004447 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004449 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004450 }
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004453 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004454 }
4455
4456 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004457 * Get the user enabled state of Mobile Data.
4458 *
4459 * TODO: remove and use isUserDataEnabled.
4460 * This can't be removed now because some vendor codes
4461 * calls through ITelephony directly while they should
4462 * use TelephonyManager.
4463 *
4464 * @return true on enabled
4465 */
4466 @Override
4467 public boolean getDataEnabled(int subId) {
4468 return isUserDataEnabled(subId);
4469 }
4470
4471 /**
4472 * Get whether mobile data is enabled per user setting.
4473 *
4474 * There are other factors deciding whether mobile data is actually enabled, but they are
4475 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004476 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004477 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004478 *
4479 * @return {@code true} if data is enabled else {@code false}
4480 */
4481 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004482 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004483 try {
4484 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4485 null);
4486 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4488 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004489 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004490
4491 final long identity = Binder.clearCallingIdentity();
4492 try {
4493 int phoneId = mSubscriptionController.getPhoneId(subId);
4494 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4495 Phone phone = PhoneFactory.getPhone(phoneId);
4496 if (phone != null) {
4497 boolean retVal = phone.isUserDataEnabled();
4498 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4499 return retVal;
4500 } else {
4501 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4502 return false;
4503 }
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004506 }
4507 }
4508
4509 /**
4510 * Get whether mobile data is enabled.
4511 *
4512 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4513 * whether mobile data is actually enabled.
4514 *
4515 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4516 *
4517 * @return {@code true} if data is enabled else {@code false}
4518 */
4519 @Override
4520 public boolean isDataEnabled(int subId) {
4521 try {
4522 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4523 null);
4524 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4526 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004527 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004528
4529 final long identity = Binder.clearCallingIdentity();
4530 try {
4531 int phoneId = mSubscriptionController.getPhoneId(subId);
4532 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4533 Phone phone = PhoneFactory.getPhone(phoneId);
4534 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004535 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004536 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4537 return retVal;
4538 } else {
4539 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4540 return false;
4541 }
4542 } finally {
4543 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004544 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004545 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004546
4547 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004548 public int getCarrierPrivilegeStatus(int subId) {
4549 final Phone phone = getPhone(subId);
4550 if (phone == null) {
4551 loge("getCarrierPrivilegeStatus: Invalid subId");
4552 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4553 }
4554 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004555 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004556 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4558 }
4559 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004560 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004561 }
Junda Liu29340342014-07-10 15:23:27 -07004562
4563 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004564 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4565 final Phone phone = getPhone(subId);
4566 if (phone == null) {
4567 loge("getCarrierPrivilegeStatus: Invalid subId");
4568 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4569 }
4570 UiccProfile profile =
4571 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4572 if (profile == null) {
4573 loge("getCarrierPrivilegeStatus: No UICC");
4574 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4575 }
4576 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4577 }
4578
4579 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004580 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004581 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004582 if (TextUtils.isEmpty(pkgName))
4583 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004584 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004585 if (card == null) {
4586 loge("checkCarrierPrivilegesForPackage: No UICC");
4587 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4588 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004589 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4590 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004591 }
4592
4593 @Override
4594 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004595 if (TextUtils.isEmpty(pkgName))
4596 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004597 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4598 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4599 UiccCard card = UiccController.getInstance().getUiccCard(i);
4600 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004601 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004602 continue;
4603 }
4604
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004605 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004606 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4607 break;
4608 }
4609 }
4610
4611 return result;
Junda Liu29340342014-07-10 15:23:27 -07004612 }
Derek Tan89e89d42014-07-08 17:00:10 -07004613
4614 @Override
Junda Liue64de782015-04-16 17:19:16 -07004615 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4616 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4617 loge("phoneId " + phoneId + " is not valid.");
4618 return null;
4619 }
4620 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004621 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004622 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004623 return null ;
4624 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004625 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004626 }
4627
Amith Yamasani6e118872016-02-19 12:53:51 -08004628 @Override
4629 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004630 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004631 List<String> privilegedPackages = new ArrayList<>();
4632 List<PackageInfo> packages = null;
4633 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4634 UiccCard card = UiccController.getInstance().getUiccCard(i);
4635 if (card == null) {
4636 // No UICC in that slot.
4637 continue;
4638 }
4639 if (card.hasCarrierPrivilegeRules()) {
4640 if (packages == null) {
4641 // Only check packages in user 0 for now
4642 packages = pm.getInstalledPackagesAsUser(
4643 PackageManager.MATCH_DISABLED_COMPONENTS
4644 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4645 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4646 }
4647 for (int p = packages.size() - 1; p >= 0; p--) {
4648 PackageInfo pkgInfo = packages.get(p);
4649 if (pkgInfo != null && pkgInfo.packageName != null
4650 && card.getCarrierPrivilegeStatus(pkgInfo)
4651 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4652 privilegedPackages.add(pkgInfo.packageName);
4653 }
4654 }
4655 }
4656 }
4657 return privilegedPackages;
4658 }
4659
Wink Savilleb564aae2014-10-23 10:18:09 -07004660 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004661 final Phone phone = getPhone(subId);
4662 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004663 if (card == null) {
4664 loge("getIccId: No UICC");
4665 return null;
4666 }
4667 String iccId = card.getIccId();
4668 if (TextUtils.isEmpty(iccId)) {
4669 loge("getIccId: ICC ID is null or empty.");
4670 return null;
4671 }
4672 return iccId;
4673 }
4674
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004675 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004676 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4677 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004678 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4679 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004680
Malcolm Chend965c8b2018-02-28 15:00:40 -08004681 final long identity = Binder.clearCallingIdentity();
4682 try {
4683 final String iccId = getIccId(subId);
4684 final Phone phone = getPhone(subId);
4685 if (phone == null) {
4686 return false;
4687 }
4688 final String subscriberId = phone.getSubscriberId();
4689
4690 if (DBG_MERGE) {
4691 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4692 + subscriberId + " to " + number);
4693 }
4694
4695 if (TextUtils.isEmpty(iccId)) {
4696 return false;
4697 }
4698
4699 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4700
4701 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4702 if (alphaTag == null) {
4703 editor.remove(alphaTagPrefKey);
4704 } else {
4705 editor.putString(alphaTagPrefKey, alphaTag);
4706 }
4707
4708 // Record both the line number and IMSI for this ICCID, since we need to
4709 // track all merged IMSIs based on line number
4710 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4711 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4712 if (number == null) {
4713 editor.remove(numberPrefKey);
4714 editor.remove(subscriberPrefKey);
4715 } else {
4716 editor.putString(numberPrefKey, number);
4717 editor.putString(subscriberPrefKey, subscriberId);
4718 }
4719
4720 editor.commit();
4721 return true;
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004724 }
Derek Tan7226c842014-07-02 17:42:23 -07004725 }
4726
4727 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004728 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004729 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004731 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004732 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004733 return null;
4734 }
Derek Tan97ebb422014-09-05 16:55:38 -07004735
Malcolm Chend965c8b2018-02-28 15:00:40 -08004736 final long identity = Binder.clearCallingIdentity();
4737 try {
4738 String iccId = getIccId(subId);
4739 if (iccId != null) {
4740 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4741 if (DBG_MERGE) {
4742 log("getLine1NumberForDisplay returning "
4743 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4744 }
4745 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004746 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004747 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4748 return null;
4749 } finally {
4750 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004751 }
Derek Tan7226c842014-07-02 17:42:23 -07004752 }
4753
4754 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004755 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004756 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004757 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004758 return null;
4759 }
Derek Tan97ebb422014-09-05 16:55:38 -07004760
Malcolm Chend965c8b2018-02-28 15:00:40 -08004761 final long identity = Binder.clearCallingIdentity();
4762 try {
4763 String iccId = getIccId(subId);
4764 if (iccId != null) {
4765 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4766 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4767 }
4768 return null;
4769 } finally {
4770 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004771 }
Derek Tan7226c842014-07-02 17:42:23 -07004772 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004773
4774 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004775 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004776 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4777 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004778 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004779 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4780 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004781 return null;
4782 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004783
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004784 final long identity = Binder.clearCallingIdentity();
4785 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004786 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004787 final TelephonyManager tele = TelephonyManager.from(context);
4788 final SubscriptionManager sub = SubscriptionManager.from(context);
4789
4790 // Figure out what subscribers are currently active
4791 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4792 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4793 // the process, where TelephonyManager was instantiated.
4794 // Otherwise AppOps check will fail.
4795
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004796 final int[] subIds = sub.getActiveSubscriptionIdList();
4797 for (int subId : subIds) {
4798 activeSubscriberIds.add(tele.getSubscriberId(subId));
4799 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004800
4801 // First pass, find a number override for an active subscriber
4802 String mergeNumber = null;
4803 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4804 for (String key : prefs.keySet()) {
4805 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4806 final String subscriberId = (String) prefs.get(key);
4807 if (activeSubscriberIds.contains(subscriberId)) {
4808 final String iccId = key.substring(
4809 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4810 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4811 mergeNumber = (String) prefs.get(numberKey);
4812 if (DBG_MERGE) {
4813 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4814 + " for active subscriber " + subscriberId);
4815 }
4816 if (!TextUtils.isEmpty(mergeNumber)) {
4817 break;
4818 }
4819 }
4820 }
4821 }
4822
4823 // Shortcut when no active merged subscribers
4824 if (TextUtils.isEmpty(mergeNumber)) {
4825 return null;
4826 }
4827
4828 // Second pass, find all subscribers under that line override
4829 final ArraySet<String> result = new ArraySet<>();
4830 for (String key : prefs.keySet()) {
4831 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4832 final String number = (String) prefs.get(key);
4833 if (mergeNumber.equals(number)) {
4834 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4835 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4836 final String subscriberId = (String) prefs.get(subscriberKey);
4837 if (!TextUtils.isEmpty(subscriberId)) {
4838 result.add(subscriberId);
4839 }
4840 }
4841 }
4842 }
4843
4844 final String[] resultArray = result.toArray(new String[result.size()]);
4845 Arrays.sort(resultArray);
4846 if (DBG_MERGE) {
4847 Slog.d(LOG_TAG,
4848 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4849 }
4850 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004851 } finally {
4852 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004853 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004854 }
4855
4856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004857 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4859 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004860
4861 final long identity = Binder.clearCallingIdentity();
4862 try {
4863 final Phone phone = getPhone(subId);
4864 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004868 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004869
4870 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004871 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004872 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4873 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004874 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004875
4876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 final Phone phone = getPhone(subId);
4879 if (phone == null) {
4880 return false;
4881 }
4882 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4883 cdmaNonRoamingList);
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004886 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004887 }
4888
4889 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004890 @Deprecated
4891 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4892 enforceModifyPermission();
4893
4894 int returnValue = 0;
4895 try {
vagdevie435a3e2018-08-15 16:01:53 -07004896 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004897 if(result.exception == null) {
4898 if (result.result != null) {
4899 byte[] responseData = (byte[])(result.result);
4900 if(responseData.length > oemResp.length) {
4901 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4902 responseData.length + "bytes. Buffer Size is " +
4903 oemResp.length + "bytes.");
4904 }
4905 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4906 returnValue = responseData.length;
4907 }
4908 } else {
4909 CommandException ex = (CommandException) result.exception;
4910 returnValue = ex.getCommandError().ordinal();
4911 if(returnValue > 0) returnValue *= -1;
4912 }
4913 } catch (RuntimeException e) {
4914 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4915 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4916 if(returnValue > 0) returnValue *= -1;
4917 }
4918
4919 return returnValue;
4920 }
4921
4922 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004923 public void setRadioCapability(RadioAccessFamily[] rafs) {
4924 try {
4925 ProxyController.getInstance().setRadioCapability(rafs);
4926 } catch (RuntimeException e) {
4927 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4928 }
4929 }
4930
4931 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004932 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004933 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004934 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004935 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004936 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004937 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004938 final long identity = Binder.clearCallingIdentity();
4939 try {
chen xufeeed752018-10-26 14:17:57 -07004940 TelephonyPermissions
4941 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4942 mApp, phone.getSubId(), "getRadioAccessFamily");
4943 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
chen xufeeed752018-10-26 14:17:57 -07004947 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004948 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004949
4950 @Override
4951 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004952 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004953 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004954
4955 final long identity = Binder.clearCallingIdentity();
4956 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004957 ImsManager.getInstance(defaultPhone.getContext(),
4958 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004962 }
4963
4964 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004965 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004966 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004968 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004969 return false;
4970 }
Svet Ganovb320e182015-04-16 12:30:10 -07004971
Malcolm Chend965c8b2018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
4974 // Check the user preference and the system-level IMS setting. Even if the user has
4975 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4976 // In the long run, we may instead need to check if there exists a connection service
4977 // which can support video calling.
4978 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004979 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004980 return imsManager.isVtEnabledByPlatform()
4981 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4982 && imsManager.isVtEnabledByUser();
4983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004986 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004987
Andrew Leea1239f22015-03-02 17:44:07 -08004988 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 public boolean canChangeDtmfToneLength(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_DTMF_TYPE_ENABLED_BOOL);
5001 } finally {
5002 Binder.restoreCallingIdentity(identity);
5003 }
Andrew Leea1239f22015-03-02 17:44:07 -08005004 }
5005
5006 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005007 public boolean isWorldPhone(int subId, String callingPackage) {
5008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5009 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5010 return false;
5011 }
5012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
5015 CarrierConfigManager configManager =
5016 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005017 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005018 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
Andrew Leea1239f22015-03-02 17:44:07 -08005022 }
5023
Andrew Lee9431b832015-03-09 18:46:45 -07005024 @Override
5025 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005026 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005027 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005028 }
5029
5030 @Override
5031 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
5033 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005034 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005035 } finally {
5036 Binder.restoreCallingIdentity(identity);
5037 }
Andrew Lee9431b832015-03-09 18:46:45 -07005038 }
5039
Hall Liuf6668912018-10-31 17:05:23 -07005040 /**
5041 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5042 * support for the feature and device firmware support.
5043 *
5044 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5045 */
5046 @Override
5047 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005049 final Phone phone = getPhone(subscriptionId);
5050 if (phone == null) {
5051 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5052 return false;
5053 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005054 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005055 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005056 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5057 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005058 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005059 return isCarrierSupported && isDeviceSupported;
5060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
Hall Liu98187582018-01-22 19:15:32 -08005063 }
5064
Hall Liuf6668912018-10-31 17:05:23 -07005065 /**
5066 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5067 * both also support RTT.
5068 */
5069 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005070 final long identity = Binder.clearCallingIdentity();
5071 try {
Hall Liuf6668912018-10-31 17:05:23 -07005072 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005073 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005077 }
5078
Sanket Padawe7310cc72015-01-14 09:53:20 -08005079 /**
5080 * Returns the unique device ID of phone, for example, the IMEI for
5081 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5082 *
5083 * <p>Requires Permission:
5084 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5085 */
5086 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005087 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005088 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005089 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005090 return null;
5091 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005092 int subId = phone.getSubId();
5093 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5094 mApp, subId, callingPackage, "getDeviceId")) {
5095 return null;
5096 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005097
5098 final long identity = Binder.clearCallingIdentity();
5099 try {
5100 return phone.getDeviceId();
5101 } finally {
5102 Binder.restoreCallingIdentity(identity);
5103 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005104 }
5105
Ping Sunc67b7c22016-03-02 19:16:45 +08005106 /**
5107 * {@hide}
5108 * Returns the IMS Registration Status on a particular subid
5109 *
5110 * @param subId
5111 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005112 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005113 Phone phone = getPhone(subId);
5114 if (phone != null) {
5115 return phone.isImsRegistered();
5116 } else {
5117 return false;
5118 }
5119 }
5120
Santos Cordon7a1885b2015-02-03 11:15:19 -08005121 @Override
5122 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005123 final long identity = Binder.clearCallingIdentity();
5124 try {
5125 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5126 } finally {
5127 Binder.restoreCallingIdentity(identity);
5128 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005129 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005130
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005131 /**
5132 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005133 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005134 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
5137 Phone phone = getPhone(subId);
5138 if (phone != null) {
5139 return phone.isWifiCallingEnabled();
5140 } else {
5141 return false;
5142 }
5143 } finally {
5144 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005145 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005146 }
5147
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005148 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005149 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005150 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005151 public boolean isVideoTelephonyAvailable(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.isVideoEnabled();
5157 } else {
5158 return false;
5159 }
5160 } finally {
5161 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005162 }
5163 }
5164
5165 /**
5166 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5167 * defined in {@link ImsRegistrationImplBase}.
5168 */
5169 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005170 final long identity = Binder.clearCallingIdentity();
5171 try {
5172 Phone phone = getPhone(subId);
5173 if (phone != null) {
5174 return phone.getImsRegistrationTech();
5175 } else {
5176 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5177 }
5178 } finally {
5179 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005180 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005181 }
5182
Stuart Scott8eef64f2015-04-08 15:13:54 -07005183 @Override
5184 public void factoryReset(int subId) {
5185 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005186 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5187 return;
5188 }
5189
Svet Ganovcc087f82015-05-12 20:35:54 -07005190 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005191
Svet Ganovcc087f82015-05-12 20:35:54 -07005192 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005193 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5194 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005195 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005196 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005197 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005198 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5199 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005200 }
5201 } finally {
5202 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005203 }
5204 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005205
5206 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005207 public String getSimLocaleForSubscriber(int subId) {
5208 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5209 final Phone phone = getPhone(subId);
5210 if (phone == null) {
5211 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005212 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005213 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005214 final long identity = Binder.clearCallingIdentity();
5215 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005216 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5217 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005218 // Try and fetch the locale from the carrier properties or from the SIM language
5219 // preferences (EF-PL and EF-LI)...
5220 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005221 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005222 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5223 if (localeFromDefaultSim != null) {
5224 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5225 if (DBG) log("Using locale from subId: " + subId + " locale: "
5226 + localeFromDefaultSim);
5227 return localeFromDefaultSim.toLanguageTag();
5228 } else {
5229 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005230 }
5231 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005232
Malcolm Chend965c8b2018-02-28 15:00:40 -08005233 // The SIM language preferences only store a language (e.g. fr = French), not an
5234 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5235 // the SIM and carrier preferences does not include a country we add the country
5236 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005237 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005238 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005239 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005240 return mccLocale.toLanguageTag();
5241 }
5242
5243 if (DBG) log("No locale found - returning null");
5244 return null;
5245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005248 }
5249
5250 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005251 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005252 }
5253
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254 /**
5255 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5256 */
5257 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005258 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005259 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005260
Chenjie Yu1ba97252018-01-11 18:16:20 -08005261 private final ModemActivityInfo mLastModemActivityInfo =
5262 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5263
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005264 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005265 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5266 * representing the state of the modem.
5267 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005268 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5269 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005270 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005271 */
5272 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005273 public void requestModemActivityInfo(ResultReceiver result) {
5274 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005275 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 ModemActivityInfo ret = null;
5280 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005281 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5282 CMD_GET_MODEM_ACTIVITY_INFO,
5283 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005284 if (isModemActivityInfoValid(info)) {
5285 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5286 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5287 mergedTxTimeMs[i] =
5288 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5289 }
5290 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5291 mLastModemActivityInfo.setSleepTimeMillis(
5292 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5293 mLastModemActivityInfo.setIdleTimeMillis(
5294 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5295 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5296 mLastModemActivityInfo.setRxTimeMillis(
5297 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5298 mLastModemActivityInfo.setEnergyUsed(
5299 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005300 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005301 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5302 mLastModemActivityInfo.getSleepTimeMillis(),
5303 mLastModemActivityInfo.getIdleTimeMillis(),
5304 mLastModemActivityInfo.getTxTimeMillis(),
5305 mLastModemActivityInfo.getRxTimeMillis(),
5306 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005307 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005308 Bundle bundle = new Bundle();
5309 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5310 result.send(0, bundle);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005313 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005314 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005315
Siddharth Rayf5d29552018-06-17 15:02:38 -07005316 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5317 // less than total activity duration.
5318 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5319 if (info == null) {
5320 return false;
5321 }
5322 int activityDurationMs =
5323 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5324 int totalTxTimeMs = 0;
5325 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5326 totalTxTimeMs += info.getTxTimeMillis()[i];
5327 }
5328 return (info.isValid()
5329 && (info.getSleepTimeMillis() <= activityDurationMs)
5330 && (info.getIdleTimeMillis() <= activityDurationMs)
5331 && (info.getRxTimeMillis() <= activityDurationMs)
5332 && (totalTxTimeMs <= activityDurationMs));
5333 }
5334
Jack Yu85bd38a2015-11-09 11:34:32 -08005335 /**
5336 * {@hide}
5337 * Returns the service state information on specified subscription.
5338 */
5339 @Override
5340 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005342 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005343 return null;
5344 }
5345
Hall Liuf19c44f2018-11-27 14:38:17 -08005346 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5347 LocationAccessPolicy.checkLocationPermission(mApp,
5348 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5349 .setCallingPackage(callingPackage)
5350 .setCallingPid(Binder.getCallingPid())
5351 .setCallingUid(Binder.getCallingUid())
5352 .setMethod("getServiceStateForSubscriber")
5353 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5354 .build());
5355
5356 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5357 LocationAccessPolicy.checkLocationPermission(mApp,
5358 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5359 .setCallingPackage(callingPackage)
5360 .setCallingPid(Binder.getCallingPid())
5361 .setCallingUid(Binder.getCallingUid())
5362 .setMethod("getServiceStateForSubscriber")
5363 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5364 .build());
5365 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5366 boolean hasFinePermission =
5367 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5368 boolean hasCoarsePermission =
5369 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5370
Malcolm Chend965c8b2018-02-28 15:00:40 -08005371 final long identity = Binder.clearCallingIdentity();
5372 try {
5373 final Phone phone = getPhone(subId);
5374 if (phone == null) {
5375 return null;
5376 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005377
Hall Liuf19c44f2018-11-27 14:38:17 -08005378 ServiceState ss = phone.getServiceState();
5379
5380 // Scrub out the location info in ServiceState depending on what level of access
5381 // the caller has.
5382 if (hasFinePermission) return ss;
5383 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5384 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005385 } finally {
5386 Binder.restoreCallingIdentity(identity);
5387 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005388 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005389
5390 /**
5391 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5392 *
5393 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5394 * voicemail ringtone.
5395 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5396 * PhoneAccount.
5397 */
5398 @Override
5399 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5403 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005404 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005405 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005406
Malcolm Chend965c8b2018-02-28 15:00:40 -08005407 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5408 } finally {
5409 Binder.restoreCallingIdentity(identity);
5410 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005411 }
5412
5413 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005414 * Sets the per-account voicemail ringtone.
5415 *
5416 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5417 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5418 *
5419 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5420 * voicemail ringtone.
5421 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5422 * PhoneAccount.
5423 */
5424 @Override
5425 public void setVoicemailRingtoneUri(String callingPackage,
5426 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005427 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005428 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5429 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005430 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5432 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5433 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005434 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005435
5436 final long identity = Binder.clearCallingIdentity();
5437 try {
5438 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5439 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005440 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005441 }
5442 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5443 } finally {
5444 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005445 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005446 }
5447
5448 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005449 * Returns whether vibration is set for voicemail notification in Phone settings.
5450 *
5451 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5452 * voicemail vibration setting.
5453 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5454 */
5455 @Override
5456 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5460 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005461 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005462 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005463
Malcolm Chend965c8b2018-02-28 15:00:40 -08005464 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005468 }
5469
Youhan Wange64578a2016-05-02 15:32:42 -07005470 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005471 * Sets the per-account voicemail vibration.
5472 *
5473 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5474 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5475 *
5476 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5477 * voicemail vibration setting.
5478 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5479 * specific PhoneAccount.
5480 */
5481 @Override
5482 public void setVoicemailVibrationEnabled(String callingPackage,
5483 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005484 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5486 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005487 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5489 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5490 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005491 }
5492
Malcolm Chend965c8b2018-02-28 15:00:40 -08005493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5496 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005497 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005498 }
5499 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5500 } finally {
5501 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005502 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005503 }
5504
5505 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005506 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5507 *
5508 * @throws SecurityException if the caller does not have the required permission
5509 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005510 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005512 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005513 }
5514
5515 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005516 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5517 * permission.
5518 *
5519 * @throws SecurityException if the caller does not have the required permission
5520 */
5521 private void enforceSendSmsPermission() {
5522 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5523 }
5524
5525 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005526 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005527 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005528 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005529 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005530 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005531 final long identity = Binder.clearCallingIdentity();
5532 try {
5533 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005534 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005535 if (componentName == null) {
5536 throw new SecurityException(
5537 "Caller not current active visual voicemail package[null]");
5538 }
5539 String vvmPackage = componentName.getPackageName();
5540 if (!callingPackage.equals(vvmPackage)) {
5541 throw new SecurityException("Caller not current active visual voicemail package["
5542 + vvmPackage + "]");
5543 }
5544 } finally {
5545 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005546 }
5547 }
5548
5549 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005550 * Return the application ID for the app type.
5551 *
5552 * @param subId the subscription ID that this request applies to.
5553 * @param appType the uicc app type.
5554 * @return Application ID for specificied app type, or null if no uicc.
5555 */
5556 @Override
5557 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005558 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005559 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005560
5561 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005562 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005563 if (phone == null) {
5564 return null;
5565 }
5566 String aid = null;
5567 try {
5568 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5569 .getApplicationByType(appType).getAid();
5570 } catch (Exception e) {
5571 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5572 }
5573 return aid;
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005576 }
Youhan Wange64578a2016-05-02 15:32:42 -07005577 }
5578
Youhan Wang4001d252016-05-11 10:29:41 -07005579 /**
5580 * Return the Electronic Serial Number.
5581 *
5582 * @param subId the subscription ID that this request applies to.
5583 * @return ESN or null if error.
5584 */
5585 @Override
5586 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005587 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005588 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005589
5590 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005591 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005592 if (phone == null) {
5593 return null;
5594 }
5595 String esn = null;
5596 try {
5597 esn = phone.getEsn();
5598 } catch (Exception e) {
5599 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5600 }
5601 return esn;
5602 } finally {
5603 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005604 }
Youhan Wang4001d252016-05-11 10:29:41 -07005605 }
5606
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005607 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005608 * Return the Preferred Roaming List Version.
5609 *
5610 * @param subId the subscription ID that this request applies to.
5611 * @return PRLVersion or null if error.
5612 */
5613 @Override
5614 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005615 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005616 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005617
5618 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005619 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005620 if (phone == null) {
5621 return null;
5622 }
5623 String cdmaPrlVersion = null;
5624 try {
5625 cdmaPrlVersion = phone.getCdmaPrlVersion();
5626 } catch (Exception e) {
5627 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5628 }
5629 return cdmaPrlVersion;
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005632 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005633 }
5634
5635 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005636 * Get snapshot of Telephony histograms
5637 * @return List of Telephony histograms
5638 * @hide
5639 */
5640 @Override
5641 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5643 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005644
5645 final long identity = Binder.clearCallingIdentity();
5646 try {
5647 return RIL.getTelephonyRILTimingHistograms();
5648 } finally {
5649 Binder.restoreCallingIdentity(identity);
5650 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005651 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005652
5653 /**
5654 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005655 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5656 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005657 * Require system privileges. In the future we may add this to carrier APIs.
5658 *
Michele Berionne0963c862018-11-27 18:57:59 -08005659 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005660 */
5661 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005662 @TelephonyManager.SetCarrierRestrictionResult
5663 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005664 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005665 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005666
Michele Berionne0963c862018-11-27 18:57:59 -08005667 if (carrierRestrictionRules == null) {
5668 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005669 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005670
Malcolm Chend965c8b2018-02-28 15:00:40 -08005671 final long identity = Binder.clearCallingIdentity();
5672 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005673 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005674 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005678 }
5679
5680 /**
5681 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005682 * Get the allowed carrier list and the excluded carrier list, including the priority between
5683 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005684 * Require system privileges. In the future we may add this to carrier APIs.
5685 *
Michele Berionne0963c862018-11-27 18:57:59 -08005686 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005687 */
5688 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005689 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005690 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005691 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005695 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5696 if (response instanceof CarrierRestrictionRules) {
5697 return (CarrierRestrictionRules) response;
5698 }
5699 // Response is an Exception of some kind,
5700 // which is signalled to the user as a NULL retval
5701 return null;
5702 } catch (Exception e) {
5703 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5704 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005705 } finally {
5706 Binder.restoreCallingIdentity(identity);
5707 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005708 }
5709
fionaxu59545b42016-05-25 15:53:37 -07005710 /**
5711 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5712 * @param subId the subscription ID that this action applies to.
5713 * @param enabled control enable or disable metered apns.
5714 * {@hide}
5715 */
5716 @Override
5717 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5718 enforceModifyPermission();
5719 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005720
5721 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005722 if (phone == null) {
5723 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5724 return;
5725 }
5726 try {
5727 phone.carrierActionSetMeteredApnsEnabled(enabled);
5728 } catch (Exception e) {
5729 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005730 } finally {
5731 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005732 }
5733 }
5734
5735 /**
5736 * Action set from carrier signalling broadcast receivers to enable/disable radio
5737 * @param subId the subscription ID that this action applies to.
5738 * @param enabled control enable or disable radio.
5739 * {@hide}
5740 */
5741 @Override
5742 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5743 enforceModifyPermission();
5744 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005747 if (phone == null) {
5748 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5749 return;
5750 }
5751 try {
5752 phone.carrierActionSetRadioEnabled(enabled);
5753 } catch (Exception e) {
5754 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005757 }
5758 }
5759
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005760 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005761 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5762 * network status based on which carrier apps could apply actions accordingly,
5763 * enable/disable default url handler for example.
5764 *
5765 * @param subId the subscription ID that this action applies to.
5766 * @param report control start/stop reporting the default network status.
5767 * {@hide}
5768 */
5769 @Override
5770 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5771 enforceModifyPermission();
5772 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005773
5774 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005775 if (phone == null) {
5776 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5777 return;
5778 }
5779 try {
5780 phone.carrierActionReportDefaultNetworkStatus(report);
5781 } catch (Exception e) {
5782 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005783 } finally {
5784 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005785 }
5786 }
5787
5788 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005789 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5790 * bug report is being generated.
5791 */
5792 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005793 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005794 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5795 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005796 writer.println("Permission Denial: can't dump Phone from pid="
5797 + Binder.getCallingPid()
5798 + ", uid=" + Binder.getCallingUid()
5799 + "without permission "
5800 + android.Manifest.permission.DUMP);
5801 return;
5802 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005803 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005804 }
Jack Yueb89b242016-06-22 13:27:47 -07005805
Brad Ebingerdac2f002018-04-03 15:17:52 -07005806 @Override
5807 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5808 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5809 throws RemoteException {
5810 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5811 }
5812
Jack Yueb89b242016-06-22 13:27:47 -07005813 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005814 * Get aggregated video call data usage since boot.
5815 *
5816 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5817 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005818 * {@hide}
5819 */
5820 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005821 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005822 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5823 null);
5824
Malcolm Chend965c8b2018-02-28 15:00:40 -08005825 final long identity = Binder.clearCallingIdentity();
5826 try {
5827 // NetworkStatsService keeps tracking the active network interface and identity. It
5828 // records the delta with the corresponding network identity.
5829 // We just return the total video call data usage snapshot since boot.
5830 Phone phone = getPhone(subId);
5831 if (phone != null) {
5832 return phone.getVtDataUsage(perUidStats);
5833 }
5834 return null;
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005837 }
Jack Yueb89b242016-06-22 13:27:47 -07005838 }
Jack Yu75ab2952016-07-08 14:29:33 -07005839
5840 /**
5841 * Policy control of data connection. Usually used when data limit is passed.
5842 * @param enabled True if enabling the data, otherwise disabling.
5843 * @param subId Subscription index
5844 * {@hide}
5845 */
5846 @Override
5847 public void setPolicyDataEnabled(boolean enabled, int subId) {
5848 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005849
5850 final long identity = Binder.clearCallingIdentity();
5851 try {
5852 Phone phone = getPhone(subId);
5853 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005854 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005855 }
5856 } finally {
5857 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005858 }
5859 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005860
5861 /**
5862 * Get Client request stats
5863 * @return List of Client Request Stats
5864 * @hide
5865 */
5866 @Override
5867 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005869 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005870 return null;
5871 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005872 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005873
Malcolm Chend965c8b2018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 if (phone != null) {
5877 return phone.getClientRequestStats();
5878 }
5879
5880 return null;
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
5883 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005884 }
5885
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005886 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005887 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005888 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005889 }
Jack Yueb4124c2017-02-16 15:32:43 -08005890
5891 /**
Grace Chen70990072017-03-24 17:21:30 -07005892 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005893 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005894 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005895 * @param state State of SIM (power down, power up, pass through)
5896 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5897 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5898 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005899 *
5900 **/
5901 @Override
Grace Chen70990072017-03-24 17:21:30 -07005902 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005903 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005904 Phone phone = PhoneFactory.getPhone(slotIndex);
5905
vagdevie435a3e2018-08-15 16:01:53 -07005906 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5907
Malcolm Chend965c8b2018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005911 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005912 }
5913 } finally {
5914 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005915 }
5916 }
Shuo Qiandd210312017-04-12 22:11:33 +00005917
Tyler Gunn65d45c22017-06-05 11:22:26 -07005918 private boolean isUssdApiAllowed(int subId) {
5919 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005920 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005921 if (configManager == null) {
5922 return false;
5923 }
5924 PersistableBundle pb = configManager.getConfigForSubId(subId);
5925 if (pb == null) {
5926 return false;
5927 }
5928 return pb.getBoolean(
5929 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5930 }
5931
Shuo Qiandd210312017-04-12 22:11:33 +00005932 /**
5933 * Check if phone is in emergency callback mode
5934 * @return true if phone is in emergency callback mode
5935 * @param subId sub id
5936 */
goneil9c5f4872017-12-05 14:07:56 -08005937 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005938 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005939 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005940 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005941
5942 final long identity = Binder.clearCallingIdentity();
5943 try {
5944 if (phone != null) {
5945 return phone.isInEcm();
5946 } else {
5947 return false;
5948 }
5949 } finally {
5950 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005951 }
5952 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005953
5954 /**
5955 * Get the current signal strength information for the given subscription.
5956 * Because this information is not updated when the device is in a low power state
5957 * it should not be relied-upon to be current.
5958 * @param subId Subscription index
5959 * @return the most recent cached signal strength info from the modem
5960 */
5961 @Override
5962 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005963 final long identity = Binder.clearCallingIdentity();
5964 try {
5965 Phone p = getPhone(subId);
5966 if (p == null) {
5967 return null;
5968 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005969
Malcolm Chend965c8b2018-02-28 15:00:40 -08005970 return p.getSignalStrength();
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005975
Pengquan Meng9140aec2018-08-22 14:49:57 -07005976 /**
chen xu907e5a22018-10-11 13:21:04 -07005977 * Get the current modem radio state for the given slot.
5978 * @param slotIndex slot index.
5979 * @param callingPackage the name of the package making the call.
5980 * @return the current radio power state from the modem
5981 */
5982 @Override
5983 public int getRadioPowerState(int slotIndex, String callingPackage) {
5984 Phone phone = PhoneFactory.getPhone(slotIndex);
5985 if (phone != null) {
5986 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5987 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5988 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5989 }
5990
5991 final long identity = Binder.clearCallingIdentity();
5992 try {
5993 return phone.getRadioPowerState();
5994 } finally {
5995 Binder.restoreCallingIdentity(identity);
5996 }
5997 }
5998 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5999 }
6000
6001 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006002 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6003 *
6004 * <p>Requires one of the following permissions:
6005 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6006 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6007 * privileges.
6008 *
6009 * @param subId subscription id
6010 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6011 * {@code false}.
6012 */
6013 @Override
6014 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006015 boolean isEnabled = false;
6016 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006017 try {
6018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006019 null /* message */);
6020 Phone phone = getPhone(subId);
6021 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006022 } catch (Exception e) {
6023 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6024 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006025 } finally {
6026 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006027 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006028 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006029 }
6030
6031
6032 /**
6033 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6034 *
6035 * <p> Requires permission:
6036 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6037 * privileges.
6038 *
6039 * @param subId subscription id
6040 * @param isEnabled {@code true} means enable, {@code false} means disable.
6041 */
6042 @Override
6043 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6047 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006048
Pengquan Meng0c05b502018-09-06 09:59:22 -07006049 Phone phone = getPhone(subId);
6050 if (phone != null) {
6051 phone.setDataRoamingEnabled(isEnabled);
6052 }
6053 } finally {
6054 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006055 }
6056 }
6057
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006058 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006059 public boolean isManualNetworkSelectionAllowed(int subId) {
6060 boolean isAllowed = true;
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6064 mApp, subId, "isManualNetworkSelectionAllowed");
6065 Phone phone = getPhone(subId);
6066 if (phone != null) {
6067 isAllowed = phone.isCspPlmnEnabled();
6068 }
6069 } finally {
6070 Binder.restoreCallingIdentity(identity);
6071 }
6072 return isAllowed;
6073 }
6074
6075 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006076 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006077 try {
6078 enforceReadPrivilegedPermission("getUiccCardsInfo");
6079 } catch (SecurityException e) {
6080 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6081 // has carrier privileges on an active UICC
6082 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6083 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6084 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6085 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006086 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006087
6088 final long identity = Binder.clearCallingIdentity();
6089 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006090 UiccController uiccController = UiccController.getInstance();
6091 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6092
6093 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6094 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6095 // Remove private info if the caller doesn't have access
6096 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6097 for (UiccCardInfo cardInfo : cardInfos) {
6098 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6099 UiccProfile profile = card.getUiccProfile();
6100 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6101 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6102 filteredInfos.add(cardInfo.getUnprivileged());
6103 } else {
6104 filteredInfos.add(cardInfo);
6105 }
6106 }
6107 return filteredInfos;
6108 }
6109 return cardInfos;
6110 } catch (PackageManager.NameNotFoundException e) {
6111 // This should not happen since we pass the package info in from TelephonyManager
6112 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006113 } finally {
6114 Binder.restoreCallingIdentity(identity);
6115 }
6116 }
6117
6118 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006119 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006120 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006121
Malcolm Chend965c8b2018-02-28 15:00:40 -08006122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6125 if (slots == null) {
6126 Rlog.i(LOG_TAG, "slots is null.");
6127 return null;
6128 }
6129
6130 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6131 for (int i = 0; i < slots.length; i++) {
6132 UiccSlot slot = slots[i];
6133 if (slot == null) {
6134 continue;
6135 }
6136
6137 String cardId;
6138 UiccCard card = slot.getUiccCard();
6139 if (card != null) {
6140 cardId = card.getCardId();
6141 } else {
6142 cardId = slot.getIccId();
6143 }
6144
6145 int cardState = 0;
6146 switch (slot.getCardState()) {
6147 case CARDSTATE_ABSENT:
6148 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6149 break;
6150 case CARDSTATE_PRESENT:
6151 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6152 break;
6153 case CARDSTATE_ERROR:
6154 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6155 break;
6156 case CARDSTATE_RESTRICTED:
6157 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6158 break;
6159 default:
6160 break;
6161
6162 }
6163
6164 infos[i] = new UiccSlotInfo(
6165 slot.isActive(),
6166 slot.isEuicc(),
6167 cardId,
6168 cardState,
6169 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006170 slot.isExtendedApduSupported(),
6171 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006172 }
6173 return infos;
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006176 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006177 }
6178
6179 @Override
6180 public boolean switchSlots(int[] physicalSlots) {
6181 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006182
6183 final long identity = Binder.clearCallingIdentity();
6184 try {
6185 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6186 } finally {
6187 Binder.restoreCallingIdentity(identity);
6188 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006189 }
Jack Yu4c988042018-02-27 15:30:01 -08006190
6191 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006192 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 return UiccController.getInstance().getCardIdForDefaultEuicc();
6196 } finally {
6197 Binder.restoreCallingIdentity(identity);
6198 }
6199 }
6200
6201 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006202 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6203 enforceModifyPermission();
6204 final Phone phone = getPhone(subId);
6205 if (phone == null) {
6206 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6207 return;
6208 }
6209
Malcolm Chend965c8b2018-02-28 15:00:40 -08006210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 phone.setRadioIndicationUpdateMode(filters, mode);
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
Jack Yu4c988042018-02-27 15:30:01 -08006216 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006217
6218 /**
goneil47ffb6e2018-04-06 15:40:58 -07006219 * A test API to reload the UICC profile.
6220 *
6221 * <p>Requires that the calling app has permission
6222 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6223 * @hide
6224 */
6225 @Override
6226 public void refreshUiccProfile(int subId) {
6227 enforceModifyPermission();
6228
6229 final long identity = Binder.clearCallingIdentity();
6230 try {
6231 Phone phone = getPhone(subId);
6232 if (phone == null) {
6233 return;
6234 }
6235 UiccCard uiccCard = phone.getUiccCard();
6236 if (uiccCard == null) {
6237 return;
6238 }
6239 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6240 if (uiccProfile == null) {
6241 return;
6242 }
6243 uiccProfile.refresh();
6244 } finally {
6245 Binder.restoreCallingIdentity(identity);
6246 }
6247 }
6248
6249 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006250 * Returns false if the mobile data is disabled by default, otherwise return true.
6251 */
6252 private boolean getDefaultDataEnabled() {
6253 return "true".equalsIgnoreCase(
6254 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6255 }
6256
6257 /**
6258 * Returns true if the data roaming is enabled by default, i.e the system property
6259 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6260 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6261 */
6262 private boolean getDefaultDataRoamingEnabled(int subId) {
6263 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006264 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006265 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6266 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6267 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6268 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6269 return isDataRoamingEnabled;
6270 }
6271
6272 /**
6273 * Returns the default network type for the given {@code subId}, if the default network type is
6274 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6275 */
6276 private int getDefaultNetworkType(int subId) {
6277 return Integer.parseInt(
6278 TelephonyManager.getTelephonyProperty(
6279 mSubscriptionController.getPhoneId(subId),
6280 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6281 String.valueOf(Phone.PREFERRED_NT_MODE)));
6282 }
fionaxua13278b2018-03-21 00:08:13 -07006283
6284 @Override
6285 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6286 gid1, String gid2, String plmn, String spn) {
6287 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 final Phone phone = getPhone(subId);
6292 if (phone == null) {
6293 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6294 return;
6295 }
6296 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006299 }
fionaxua13278b2018-03-21 00:08:13 -07006300 }
6301
6302 @Override
6303 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006304 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006305
6306 final long identity = Binder.clearCallingIdentity();
6307 try {
6308 final Phone phone = getPhone(subId);
6309 if (phone == null) {
6310 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6311 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6312 }
6313 return phone.getCarrierIdListVersion();
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006316 }
fionaxua13278b2018-03-21 00:08:13 -07006317 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006318
6319 @Override
6320 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6322 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6323 return -1;
6324 }
6325
6326 final long identity = Binder.clearCallingIdentity();
6327 try {
6328 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6329 } finally {
6330 Binder.restoreCallingIdentity(identity);
6331 }
6332 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006333
6334 @Override
6335 public int getCdmaRoamingMode(int subId) {
6336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6337 mApp, subId, "getCdmaRoamingMode");
6338
6339 final long identity = Binder.clearCallingIdentity();
6340 try {
6341 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6342 } finally {
6343 Binder.restoreCallingIdentity(identity);
6344 }
6345 }
6346
6347 @Override
6348 public boolean setCdmaRoamingMode(int subId, int mode) {
6349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6350 mApp, subId, "setCdmaRoamingMode");
6351
6352 final long identity = Binder.clearCallingIdentity();
6353 try {
6354 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6355 } finally {
6356 Binder.restoreCallingIdentity(identity);
6357 }
6358 }
6359
6360 @Override
6361 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6363 mApp, subId, "setCdmaSubscriptionMode");
6364
6365 final long identity = Binder.clearCallingIdentity();
6366 try {
6367 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
6371 }
chen xu7ee67862018-10-30 22:27:10 -07006372
sqian2fff4a32018-11-05 14:18:37 -08006373 private void ensureUserRunning(int userId) {
6374 if (!mUserManager.isUserRunning(userId)) {
6375 throw new IllegalStateException("User " + userId + " does not exist or not running");
6376 }
6377 }
6378
6379 /**
6380 * Returns a list of SMS apps on a given user.
6381 *
6382 * Only the shell user (UID 2000 or 0) can call it.
6383 * Target user must be running.
6384 */
6385 @Override
6386 public String[] getSmsApps(int userId) {
6387 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6388 ensureUserRunning(userId);
6389
6390 final Collection<SmsApplicationData> apps =
6391 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6392
6393 String[] ret = new String[apps.size()];
6394 int i = 0;
6395 for (SmsApplicationData app : apps) {
6396 ret[i++] = app.mPackageName;
6397 }
6398 return ret;
6399 }
6400
6401 /**
6402 * Returns the default SMS app package name on a given user.
6403 *
6404 * Only the shell user (UID 2000 or 0) can call it.
6405 * Target user must be running.
6406 */
6407 @Override
6408 public String getDefaultSmsApp(int userId) {
6409 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6410 ensureUserRunning(userId);
6411
6412 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6413 /* updateIfNeeded= */ true, userId);
6414 return cn == null ? null : cn.getPackageName();
6415 }
6416
6417 /**
6418 * Set a package as the default SMS app on a given user.
6419 *
6420 * Only the shell user (UID 2000 or 0) can call it.
6421 * Target user must be running.
6422 */
6423 @Override
6424 public void setDefaultSmsApp(int userId, String packageName) {
6425 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6426 ensureUserRunning(userId);
6427
6428 boolean found = false;
6429 for (String pkg : getSmsApps(userId)) {
6430 if (TextUtils.equals(packageName, pkg)) {
6431 found = true;
6432 break;
6433 }
6434 }
6435 if (!found) {
6436 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6437 }
6438
6439 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6440 }
6441
chen xu7ee67862018-10-30 22:27:10 -07006442 @Override
sqian04b86072018-11-07 14:02:21 -08006443 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6444 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6446 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6447 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6448 }
6449 final long identity = Binder.clearCallingIdentity();
6450 try {
sqian991b35e2018-12-12 16:48:18 -08006451 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6452 for (Phone phone: PhoneFactory.getPhones()) {
6453 if (phone.getEmergencyNumberTracker() != null
6454 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6455 emergencyNumberListInternal.put(
6456 phone.getSubId(),
6457 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6458 }
sqian03bca152018-12-05 18:48:28 -08006459 }
sqian991b35e2018-12-12 16:48:18 -08006460 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
sqian04b86072018-11-07 14:02:21 -08006464 }
6465
6466 @Override
sqian03bca152018-12-05 18:48:28 -08006467 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6468 final Phone defaultPhone = getDefaultPhone();
6469 if (!exactMatch) {
6470 TelephonyPermissions
6471 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6472 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6473 }
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
sqian991b35e2018-12-12 16:48:18 -08006476 for (Phone phone: PhoneFactory.getPhones()) {
6477 if (phone.getEmergencyNumberTracker() != null
6478 && phone.getEmergencyNumberTracker() != null) {
6479 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6480 number, exactMatch)) {
6481 return true;
sqian03bca152018-12-05 18:48:28 -08006482 }
6483 }
sqian03bca152018-12-05 18:48:28 -08006484 }
6485 return false;
6486 } finally {
6487 Binder.restoreCallingIdentity(identity);
6488 }
6489 }
6490
sqian9d4df8b2019-01-15 18:32:07 -08006491 /**
6492 * Update emergency number list for test mode.
6493 */
6494 @Override
6495 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6496 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6497 "updateEmergencyNumberListTestMode");
6498
6499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 for (Phone phone: PhoneFactory.getPhones()) {
6502 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6503 if (tracker != null) {
6504 tracker.executeEmergencyNumberTestModeCommand(action, num);
6505 }
6506 }
6507 } finally {
6508 Binder.restoreCallingIdentity(identity);
6509 }
6510 }
6511
6512 /**
6513 * Get the full emergency number list for test mode.
6514 */
6515 @Override
6516 public List<String> getEmergencyNumberListTestMode() {
6517 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6518 "getEmergencyNumberListTestMode");
6519
6520 final long identity = Binder.clearCallingIdentity();
6521 try {
6522 Set<String> emergencyNumbers = new HashSet<>();
6523 for (Phone phone: PhoneFactory.getPhones()) {
6524 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6525 if (tracker != null) {
6526 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6527 emergencyNumbers.add(num.getNumber());
6528 }
6529 }
6530 }
6531 return new ArrayList<>(emergencyNumbers);
6532 } finally {
6533 Binder.restoreCallingIdentity(identity);
6534 }
6535 }
6536
sqian04b86072018-11-07 14:02:21 -08006537 @Override
chen xu7ee67862018-10-30 22:27:10 -07006538 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6539 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6540 Phone phone = getPhone(subId);
6541 if (phone == null) {
6542 return null;
6543 }
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 UiccProfile profile = UiccController.getInstance()
6547 .getUiccProfileForPhone(phone.getPhoneId());
6548 if (profile != null) {
6549 return profile.getCertsFromCarrierPrivilegeAccessRules();
6550 }
6551 } finally {
6552 Binder.restoreCallingIdentity(identity);
6553 }
6554 return null;
6555 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006556
6557 /**
6558 * Enable or disable a modem stack.
6559 */
6560 @Override
6561 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6562 enforceModifyPermission();
6563
6564 final long identity = Binder.clearCallingIdentity();
6565 try {
6566 Phone phone = PhoneFactory.getPhone(slotIndex);
6567 if (phone == null) {
6568 return false;
6569 } else {
6570 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6571 }
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
6574 }
6575 }
Micheled3107c52018-12-21 15:00:11 -08006576
6577 @Override
6578 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6579 enforceModifyPermission();
6580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 mTelephonySharedPreferences.edit()
6584 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6585 .commit();
6586 } finally {
6587 Binder.restoreCallingIdentity(identity);
6588 }
6589 }
6590
6591 @Override
Michelebcb01bc2019-02-04 11:36:23 -08006592 public boolean isMultisimSupported(String callingPackage) {
6593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6594 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6595 return false;
6596 }
Micheled3107c52018-12-21 15:00:11 -08006597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
Michele30b57b22019-03-01 12:01:14 -08006600 return isMultisimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006605
Michele30b57b22019-03-01 12:01:14 -08006606 private boolean isMultisimSupportedInternal() {
6607 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6608 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6609 if (numPhysicalSlots < 2) {
6610 loge("isMultisimSupportedInternal: requires at least 2 cards");
6611 return false;
6612 }
6613 // Check if the hardware supports multisim functionality. If usage of multisim is not
6614 // supported by the modem, indicate that it is restricted.
6615 PhoneCapability staticCapability =
6616 mPhoneConfigurationManager.getStaticPhoneCapability();
6617 if (staticCapability == null) {
6618 loge("isMultisimSupportedInternal: no static configuration available");
6619 return false;
6620 }
6621 if (staticCapability.logicalModemList.size() < 2) {
6622 loge("isMultisimSupportedInternal: maximum number of modem is < 2");
6623 return false;
6624 }
6625 // Check if support of multiple SIMs is restricted by carrier
6626 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6627 return false;
6628 }
6629
6630 return true;
6631 }
6632
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006633 /**
6634 * Switch configs to enable multi-sim or switch back to single-sim
6635 * @param numOfSims number of active sims we want to switch to
6636 */
6637 @Override
6638 public void switchMultiSimConfig(int numOfSims) {
6639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6640 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6641 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006642
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006643 try {
Michele30b57b22019-03-01 12:01:14 -08006644 //only proceed if multi-sim is not restricted
6645 if (!isMultisimSupportedInternal()) {
6646 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6647 return;
6648 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006649 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
6652 }
6653 }
6654
6655 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006656 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006657 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006658 */
6659 @Override
6660 public boolean isRebootRequiredForModemConfigChange() {
6661 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6662 final long identity = Binder.clearCallingIdentity();
6663 try {
6664 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
6667 }
6668 }
6669
Pengquan Meng92d253b2019-02-06 11:12:53 -08006670 private void updateModemStateMetrics() {
6671 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6672 // TODO: check the state for each modem if the api is ready.
6673 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6674 }
6675
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006676 @Override
6677 public int[] getSlotsMapping() {
6678 enforceReadPrivilegedPermission("getSlotsMapping");
6679
6680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6683 // All logical slots should have a mapping to a physical slot.
6684 int[] logicalSlotsMapping = new int[phoneCount];
6685 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6686 for (int i = 0; i < slotInfos.length; i++) {
6687 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6688 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6689 }
6690 }
6691 return logicalSlotsMapping;
6692 } finally {
6693 Binder.restoreCallingIdentity(identity);
6694 }
6695 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006696
6697 /**
6698 * Get the IRadio HAL Version
6699 */
6700 @Override
6701 public int getRadioHalVersion() {
6702 Phone phone = getDefaultPhone();
6703 if (phone == null) return -1;
6704 HalVersion hv = phone.getHalVersion();
6705 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6706 return hv.major * 100 + hv.minor;
6707 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006708}