blob: ee653b19aff93570781d833fbf87f2a9369cdd0a [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 Berionne482f8202018-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;
Michele4245e952019-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 Yub5d8f642018-11-26 11:20:48 -080088import android.telephony.data.ApnSetting;
89import 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 Ebinger35c841c2018-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 Ebinger35c841c2018-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 Ebinger35c841c2018-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 xu651eec72018-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 Chen2c63d402018-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700135import 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;
sqianf4ca7ed2019-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 Meng6c2dc9f2019-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;
Makoto Onukida3bf792018-09-18 16:06:29 -0700162import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800163import java.util.HashMap;
sqianf4ca7ed2019-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;
sqianf4ca7ed2019-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 xu6dac5ab2018-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 Menga1bb6272018-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 xu6dac5ab2018-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 Chen8e4ed912019-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 Chen2c63d402018-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
Michelecea4cf22018-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
vagdeviaf9a5b92018-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
vagdeviaf9a5b92018-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 }
vagdeviaf9a5b92018-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 Bakhshif782e562018-12-11 15:15:39 -0800387 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
389 switch (msg.what) {
Pengquan Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-09-06 09:59:22 -0700405 request.result = true;
406 notifyRequester(request);
407 return;
408 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Menga1bb6272018-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 Bakhshif782e562018-12-11 15:15:39 -0800669 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-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 Bakhshif782e562018-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 xu6dac5ab2018-10-26 17:39:23 -0700687 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800688 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700689 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
chen xu6dac5ab2018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menge3d01e22018-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 Bakhshif782e562018-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 Menga1bb6272018-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 Berionne482f8202018-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 Berionne482f8202018-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 Berionne482f8202018-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 Menga1bb6272018-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 Bakhshif782e562018-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 Berionne482f8202018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 Menga1bb6272018-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 xu6dac5ab2018-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 Bakhshif782e562018-12-11 15:15:39 -08001094 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001095 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001096 case EVENT_CMD_MODEM_REBOOT_DONE:
1097 handleNullReturnEvent(msg, "rebootModem");
1098 break;
Malcolm Chen8e4ed912019-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 Bakhshi33d584b2019-02-27 10:44:32 -08001103 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-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 Bakhshi33d584b2019-02-27 10:44:32 -08001111 //update the cache as modem status has changed
1112 mPhoneConfigurationManager.addToPhoneStatusCache(
1113 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -08001114 updateModemStateMetrics();
Malcolm Chen8e4ed912019-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 Menga1bb6272018-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 Menga1bb6272018-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);
vagdeviaf9a5b92018-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);
vagdeviaf9a5b92018-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 Bakhshif782e562018-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 Bakhshif782e562018-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 Bakhshif782e562018-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();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001281 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001282 mTelephonySharedPreferences =
1283 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001284 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-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 Bakhshif782e562018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001380 if (!isValid) {
1381 return;
1382 }
Wink Saville08874612014-08-31 19:19:58 -07001383
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001658 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001659 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Yud79fba22018-12-13 11:51:28 -08001725 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Yud79fba22018-12-13 11:51:28 -08001745 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08001757 final long identity = Binder.clearCallingIdentity();
1758 try {
1759 final Phone phone = getPhone(subId);
1760 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001761 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Bakhshif782e562018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Bakhshif782e562018-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 Chenaa4a8532018-02-28 15:00:40 -08002100
2101 final long identity = Binder.clearCallingIdentity();
2102 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002103 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-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();
Michael Groover70af6dc2018-10-01 16:23:15 -07002116 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2117 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002118 return null;
2119 }
Malcolm Chenaa4a8532018-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 Bakhshif782e562018-12-11 15:15:39 -08002146
Jeff Davidson913390f2018-02-23 17:11:49 -08002147 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002148 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2149 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002150 return null;
2151 }
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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
calvinpanffe225e2018-11-01 19:43:06 +08002214 @Override
chen xu25637222018-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 xu651eec72018-11-11 19:03:44 -08002237 @Override
chen xu864e11c2018-12-06 22:10:03 -08002238 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2239 if (!isSubscriptionMccMnc) {
2240 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2241 }
chen xu651eec72018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08002414
2415 final long identity = Binder.clearCallingIdentity();
2416 try {
2417 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002418 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002419 return phone.getLine1Number();
2420 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002421 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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,
2469 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2470
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 Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002480 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Bakhshif782e562018-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 Chenaa4a8532018-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 Bakhshif782e562018-12-11 15:15:39 -08002517 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08002530
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002531 final long identity = Binder.clearCallingIdentity();
2532 try {
Nazanin Bakhshif782e562018-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 Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002547 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002574 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-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 Ebinger35c841c2018-10-01 10:40:55 -07002582 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002587 mApp, subId);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Ebinger35c841c2018-10-01 10:40:55 -07002662 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002663
fionaxu0152e512016-11-14 13:36:14 -08002664 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-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 Ebinger35c841c2018-10-01 10:40:55 -07002682 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683
fionaxu0152e512016-11-14 13:36:14 -08002684 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Chenaa4a8532018-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 Bakhshif782e562018-12-11 15:15:39 -08002741 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002742 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-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 Chenaa4a8532018-02-28 15:00:40 -08002749
2750 final long identity = Binder.clearCallingIdentity();
2751 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002752 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-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 Chenaa4a8532018-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 Menga1bb6272018-09-06 09:59:22 -07002779 @Override
2780 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002781 if (!isActiveSubscription(subId)) {
2782 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2783 }
2784
Pengquan Menga1bb6272018-09-06 09:59:22 -07002785 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2786 }
2787
Brad Ebinger35c841c2018-10-01 10:40:55 -07002788 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002789 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2790 throws RemoteException {
2791 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002792 final long token = Binder.clearCallingIdentity();
2793 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002796 .addRegistrationCallbackForSubscription(c, subId);
2797 } finally {
2798 Binder.restoreCallingIdentity(token);
2799 }
2800 }
2801
2802 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002803 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2804 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2806 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2807 }
2808 Binder.withCleanCallingIdentity(() -> {
2809 try {
2810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002812 .removeRegistrationCallbackForSubscription(c, subId);
2813 } catch (IllegalArgumentException e) {
2814 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2815 + "is inactive, ignoring unregister.");
2816 // If the subscription is no longer active, just return, since the callback
2817 // will already have been removed internally.
2818 }
2819 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002820 }
2821
2822 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002823 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2824 throws RemoteException {
2825 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002826 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2827 final long token = Binder.clearCallingIdentity();
2828 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002829 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002830 .addCapabilitiesCallbackForSubscription(c, subId);
2831 } finally {
2832 Binder.restoreCallingIdentity(token);
2833 }
2834 }
2835
2836 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002837 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2838 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002839
2840 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2841 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2842 }
2843 Binder.withCleanCallingIdentity(() -> {
2844 try {
2845 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002846 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002847 .removeCapabilitiesCallbackForSubscription(c, subId);
2848 } catch (IllegalArgumentException e) {
2849 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2850 + "is inactive, ignoring unregister.");
2851 // If the subscription is no longer active, just return, since the callback
2852 // will already have been removed internally.
2853 }
2854 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002855 }
2856
2857 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002858 public boolean isCapable(int subId, int capability, int regTech) {
2859 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2861 final long token = Binder.clearCallingIdentity();
2862 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002863 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002864 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2865 } catch (ImsException e) {
2866 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2867 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002868 } catch (IllegalArgumentException e) {
2869 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2870 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002871 } finally {
2872 Binder.restoreCallingIdentity(token);
2873 }
2874 }
2875
2876 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002877 public boolean isAvailable(int subId, int capability, int regTech) {
2878 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 final long token = Binder.clearCallingIdentity();
2880 try {
2881 Phone phone = getPhone(subId);
2882 if (phone == null) return false;
2883 return phone.isImsCapabilityAvailable(capability, regTech);
2884 } finally {
2885 Binder.restoreCallingIdentity(token);
2886 }
2887 }
2888
2889 @Override
2890 public boolean isAdvancedCallingSettingEnabled(int subId) {
2891 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2893 final long token = Binder.clearCallingIdentity();
2894 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002895 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2897 } finally {
2898 Binder.restoreCallingIdentity(token);
2899 }
2900 }
2901
2902 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002903 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002905 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002906 final long identity = Binder.clearCallingIdentity();
2907 try {
2908 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002909 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002910 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
2913 }
2914 }
2915
2916 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002917 public boolean isVtSettingEnabled(int subId) {
2918 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002919 final long identity = Binder.clearCallingIdentity();
2920 try {
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002922 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002923 getSlotIndexOrException(subId)).isVtEnabledByUser();
2924 } finally {
2925 Binder.restoreCallingIdentity(identity);
2926 }
2927 }
2928
2929 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002930 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002932 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002933 final long identity = Binder.clearCallingIdentity();
2934 try {
2935 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002936 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002937 } finally {
2938 Binder.restoreCallingIdentity(identity);
2939 }
2940 }
2941
2942 @Override
2943 public boolean isVoWiFiSettingEnabled(int subId) {
2944 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2945 final long identity = Binder.clearCallingIdentity();
2946 try {
2947 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002948 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002949 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2950 } finally {
2951 Binder.restoreCallingIdentity(identity);
2952 }
2953 }
2954
2955 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002956 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002958 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002959 final long identity = Binder.clearCallingIdentity();
2960 try {
2961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002962 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger35c841c2018-10-01 10:40:55 -07002963 } finally {
2964 Binder.restoreCallingIdentity(identity);
2965 }
2966 }
2967
2968 @Override
2969 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2970 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2971 final long identity = Binder.clearCallingIdentity();
2972 try {
2973 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002974 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002975 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 }
2980
2981 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002982 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002984 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002985 final long identity = Binder.clearCallingIdentity();
2986 try {
2987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002989 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
2993 }
2994
2995 @Override
2996 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2997 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2998 "setVoWiFiNonPersistent");
2999 final long identity = Binder.clearCallingIdentity();
3000 try {
3001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003002 boolean isRoaming = TelephonyManager.from(
3003 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003005 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
3009 }
3010
3011 @Override
3012 public int getVoWiFiModeSetting(int subId) {
3013 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003017 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public void setVoWiFiModeSetting(int subId, int mode) {
3026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3027 "setVoWiFiModeSetting");
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003032 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3033 } finally {
3034 Binder.restoreCallingIdentity(identity);
3035 }
3036 }
3037
3038 @Override
3039 public int getVoWiFiRoamingModeSetting(int subId) {
3040 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003044 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003045 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
3049 }
3050
3051 @Override
3052 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3054 "setVoWiFiRoamingModeSetting");
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3060 } finally {
3061 Binder.restoreCallingIdentity(identity);
3062 }
3063 }
3064
3065 @Override
3066 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3067 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3068 "setRttCapabilityEnabled");
3069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003072 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3074 } finally {
3075 Binder.restoreCallingIdentity(identity);
3076 }
3077 }
3078
3079 @Override
3080 public boolean isTtyOverVolteEnabled(int subId) {
3081 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003085 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3087 } finally {
3088 Binder.restoreCallingIdentity(identity);
3089 }
3090 }
3091
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003092 @Override
3093 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3094 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3095 final long identity = Binder.clearCallingIdentity();
3096 try {
3097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003098 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003099 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003100 } finally {
3101 Binder.restoreCallingIdentity(identity);
3102 }
3103 }
3104
3105 @Override
3106 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3107 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3108 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003109 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3110 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3111 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003112 try {
3113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003114 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003115 .removeProvisioningCallbackForSubscription(callback, subId);
3116 } catch (IllegalArgumentException e) {
3117 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3118 + "is inactive, ignoring unregister.");
3119 // If the subscription is no longer active, just return, since the callback will already
3120 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003121 } finally {
3122 Binder.restoreCallingIdentity(identity);
3123 }
3124 }
3125
3126 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003127 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3128 boolean isProvisioned) {
3129 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3130 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3131 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3132 }
3133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3134 "setProvisioningStatusForCapability");
3135 final long identity = Binder.clearCallingIdentity();
3136 try {
3137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3138 Phone phone = getPhone(subId);
3139 if (phone == null) {
3140 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3141 + subId);
3142 return;
3143 }
3144 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3145 return;
3146 }
3147
3148 // this capability requires provisioning, route to the correct API.
3149 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3150 switch (capability) {
3151 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3152 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3153 ims.setVolteProvisioned(isProvisioned);
3154 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3155 ims.setWfcProvisioned(isProvisioned);
3156 }
3157 break;
3158 }
3159 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3160 // There is currently no difference in VT provisioning type.
3161 ims.setVtProvisioned(isProvisioned);
3162 break;
3163 }
3164 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3165 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3166 // change the capability of the feature instead if needed.
3167 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3168 == isProvisioned) {
3169 // No change in provisioning.
3170 return;
3171 }
3172 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3173 try {
3174 ims.changeMmTelCapability(capability, tech, isProvisioned);
3175 } catch (ImsException e) {
3176 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3177 + ", Exception" + e.getMessage());
3178 }
3179 break;
3180 }
3181 default: {
3182 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3183 + capability + "', which does not require provisioning.");
3184 }
3185 }
3186
3187 } finally {
3188 Binder.restoreCallingIdentity(identity);
3189 }
3190 }
3191
3192 @Override
3193 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3194 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3195 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3196 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3197 }
3198 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3202 Phone phone = getPhone(subId);
3203 if (phone == null) {
3204 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3205 + subId);
3206 // We will fail with "true" as the provisioning status because this is the default
3207 // if we do not require provisioning.
3208 return true;
3209 }
3210
3211 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3212 return true;
3213 }
3214
3215 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3216 switch (capability) {
3217 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3218 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3219 return ims.isVolteProvisionedOnDevice();
3220 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3221 return ims.isWfcProvisionedOnDevice();
3222 }
3223 // This should never happen, since we are checking tech above to make sure it
3224 // is either LTE or IWLAN.
3225 throw new IllegalArgumentException("Invalid radio technology for voice "
3226 + "capability.");
3227 }
3228 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3229 // There is currently no difference in VT provisioning type.
3230 return ims.isVtProvisionedOnDevice();
3231 }
3232 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3233 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3234 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3235 }
3236 default: {
3237 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3238 + capability + "', which does not require provisioning.");
3239 }
3240 }
3241
3242 } finally {
3243 Binder.restoreCallingIdentity(identity);
3244 }
3245 }
3246
3247 @Override
3248 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3249 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3250 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3251 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3252 }
3253 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3254 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3255 return (provisionedBits & capability) > 0;
3256 }
3257
3258 @Override
3259 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3260 boolean isProvisioned) {
3261 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3262 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3263 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3264 }
3265 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3266 "setProvisioningStatusForCapability");
3267 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3268 // If the current provisioning status for capability already matches isProvisioned,
3269 // do nothing.
3270 if (((provisionedBits & capability) > 0) == isProvisioned) {
3271 return;
3272 }
3273 if (isProvisioned) {
3274 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3275 } else {
3276 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3277 }
3278 }
3279
3280 /**
3281 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3282 * technology. The bitfield should mirror the bitfield defined by
3283 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3284 */
3285 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3286 String key = getMmTelProvisioningKey(subId, tech);
3287 // Default is no capabilities are provisioned.
3288 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3289 }
3290
3291 /**
3292 * Sets the MmTel capability provisioning bitfield (defined by
3293 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3294 * technology specified.
3295 *
3296 * Note: This is a synchronous command and should not be called on UI thread.
3297 */
3298 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3299 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3300 String key = getMmTelProvisioningKey(subId, tech);
3301 editor.putInt(key, newField);
3302 editor.commit();
3303 }
3304
3305 private static String getMmTelProvisioningKey(int subId, int tech) {
3306 // resulting key is provision_ims_mmtel_{subId}_{tech}
3307 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3308 }
3309
3310 /**
3311 * Query CarrierConfig to see if the specified capability requires provisioning for the
3312 * carrier associated with the subscription id.
3313 */
3314 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3315 int capability) {
3316 CarrierConfigManager configManager = new CarrierConfigManager(context);
3317 PersistableBundle c = configManager.getConfigForSubId(subId);
3318 boolean requireUtProvisioning = c.getBoolean(
3319 // By default, this config is true (even if there is no SIM). We also check to make
3320 // sure the subscription needs provisioning here, so we do not need to check for
3321 // the no-SIM case, where we would normally shortcut this to false.
3322 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3323 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3324 false);
3325 boolean requireVoiceVtProvisioning = c.getBoolean(
3326 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3327
3328 // First check to make sure that the capability requires provisioning.
3329 switch (capability) {
3330 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3331 // intentional fallthrough
3332 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3333 if (requireVoiceVtProvisioning) {
3334 // Voice and Video requires provisioning
3335 return true;
3336 }
3337 break;
3338 }
3339 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3340 if (requireUtProvisioning) {
3341 // UT requires provisioning
3342 return true;
3343 }
3344 break;
3345 }
3346 }
3347 return false;
3348 }
3349
3350 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003351 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003352 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3353 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3354 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003355 enforceReadPrivilegedPermission("getImsProvisioningInt");
3356 final long identity = Binder.clearCallingIdentity();
3357 try {
3358 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003359 int slotId = getSlotIndex(subId);
3360 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3361 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3362 + subId + "' for key:" + key);
3363 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3364 }
3365 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003367 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3368 + subId + "' for key:" + key);
3369 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003370 } finally {
3371 Binder.restoreCallingIdentity(identity);
3372 }
3373 }
3374
3375 @Override
3376 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003377 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3378 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3379 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003380 enforceReadPrivilegedPermission("getImsProvisioningString");
3381 final long identity = Binder.clearCallingIdentity();
3382 try {
3383 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003384 int slotId = getSlotIndex(subId);
3385 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3386 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3387 + subId + "' for key:" + key);
3388 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3389 }
3390 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003392 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3393 + subId + "' for key:" + key);
3394 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
3398 }
3399
3400 @Override
3401 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003402 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3403 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3404 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3406 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003410 int slotId = getSlotIndex(subId);
3411 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3412 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3413 + subId + "' for key:" + key);
3414 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3415 }
3416 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003418 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3419 + "' for key:" + key);
3420 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003421 } finally {
3422 Binder.restoreCallingIdentity(identity);
3423 }
3424 }
3425
3426 @Override
3427 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003428 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3429 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3430 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3432 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003433 final long identity = Binder.clearCallingIdentity();
3434 try {
3435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003436 int slotId = getSlotIndex(subId);
3437 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3438 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3439 + subId + "' for key:" + key);
3440 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3441 }
3442 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003444 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3445 + "' for key:" + key);
3446 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003447 } finally {
3448 Binder.restoreCallingIdentity(identity);
3449 }
3450 }
3451
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3453 int slotId = SubscriptionManager.getSlotIndex(subId);
3454 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003455 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 }
3457 return slotId;
3458 }
3459
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003460 private int getSlotIndex(int subId) {
3461 int slotId = SubscriptionManager.getSlotIndex(subId);
3462 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3463 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3464 }
3465 return slotId;
3466 }
3467
Wink Saville36469e72014-06-11 15:17:00 -07003468 /**
3469 * Returns the network type for a subId
3470 */
3471 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003472 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003474 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003475 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3476 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003477
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 final long identity = Binder.clearCallingIdentity();
3479 try {
3480 final Phone phone = getPhone(subId);
3481 if (phone != null) {
3482 return phone.getServiceState().getDataNetworkType();
3483 } else {
3484 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3485 }
3486 } finally {
3487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003489 }
3490
3491 /**
3492 * Returns the data network type
3493 */
3494 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003495 public int getDataNetworkType(String callingPackage) {
3496 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003497 }
3498
3499 /**
3500 * Returns the data network type for a subId
3501 */
3502 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003503 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003504 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003505 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003506 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3507 }
3508
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 final Phone phone = getPhone(subId);
3512 if (phone != null) {
3513 return phone.getServiceState().getDataNetworkType();
3514 } else {
3515 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3516 }
3517 } finally {
3518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003520 }
3521
3522 /**
Wink Saville36469e72014-06-11 15:17:00 -07003523 * Returns the Voice network type for a subId
3524 */
3525 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003526 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003528 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003529 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3530 }
3531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 final Phone phone = getPhone(subId);
3535 if (phone != null) {
3536 return phone.getServiceState().getVoiceNetworkType();
3537 } else {
3538 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3539 }
3540 } finally {
3541 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003543 }
3544
3545 /**
3546 * @return true if a ICC card is present
3547 */
3548 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003549 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003550 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3551 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003552 }
3553
3554 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003555 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003556 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003557 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003558 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 final long identity = Binder.clearCallingIdentity();
3560 try {
3561 final Phone phone = PhoneFactory.getPhone(slotIndex);
3562 if (phone != null) {
3563 return phone.getIccCard().hasIccCard();
3564 } else {
3565 return false;
3566 }
3567 } finally {
3568 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003569 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003570 }
3571
3572 /**
3573 * Return if the current radio is LTE on CDMA. This
3574 * is a tri-state return value as for a period of time
3575 * the mode may be unknown.
3576 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003578 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003579 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003580 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003581 @Override
3582 public int getLteOnCdmaMode(String callingPackage) {
3583 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003584 }
3585
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003587 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003588 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003589 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003590 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3591 }
3592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 final Phone phone = getPhone(subId);
3596 if (phone == null) {
3597 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3598 } else {
3599 return phone.getLteOnCdmaMode();
3600 }
3601 } finally {
3602 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003603 }
Wink Saville36469e72014-06-11 15:17:00 -07003604 }
3605
Wink Saville36469e72014-06-11 15:17:00 -07003606 /**
3607 * {@hide}
3608 * Returns Default subId, 0 in the case of single standby.
3609 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003610 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003611 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003612 }
3613
Shishir Agrawala9f32182016-04-12 12:00:16 -07003614 private int getSlotForDefaultSubscription() {
3615 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3616 }
3617
Wink Savilleb564aae2014-10-23 10:18:09 -07003618 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003619 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003620 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003621
Pengquan Menge92a50d2018-09-21 15:54:48 -07003622 private boolean isActiveSubscription(int subId) {
3623 return mSubscriptionController.isActiveSubId(subId);
3624 }
3625
Ihab Awadf2177b72013-11-25 13:33:23 -08003626 /**
3627 * @see android.telephony.TelephonyManager.WifiCallingChoices
3628 */
3629 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003630 final long identity = Binder.clearCallingIdentity();
3631 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003632 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3634 getWhenToMakeWifiCallsDefaultPreference());
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
3637 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003638 }
3639
3640 /**
3641 * @see android.telephony.TelephonyManager.WifiCallingChoices
3642 */
3643 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003644 final long identity = Binder.clearCallingIdentity();
3645 try {
3646 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003647 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003648 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3649 } finally {
3650 Binder.restoreCallingIdentity(identity);
3651 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003652 }
3653
Sailesh Nepald1e68152013-12-12 19:08:02 -08003654 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003655 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003656 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003657 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003658
Shishir Agrawal566b7612013-10-28 14:41:00 -07003659 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003660 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3661 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003662 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3663 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003664 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003665
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003666 final long identity = Binder.clearCallingIdentity();
3667 try {
3668 if (TextUtils.equals(ISDR_AID, aid)) {
3669 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003670 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3671 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003672 if (bestComponent == null
3673 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3674 loge("The calling package is not allowed to access ISD-R.");
3675 throw new SecurityException(
3676 "The calling package is not allowed to access ISD-R.");
3677 }
Derek Tan740e1672017-06-27 14:56:27 -07003678 }
Derek Tan740e1672017-06-27 14:56:27 -07003679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003680 if (DBG) {
3681 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3682 }
3683 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3684 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3685 if (DBG) log("iccOpenLogicalChannel: " + response);
3686 return response;
3687 } finally {
3688 Binder.restoreCallingIdentity(identity);
3689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003690 }
3691
3692 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003693 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3695 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003697 final long identity = Binder.clearCallingIdentity();
3698 try {
3699 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3700 if (channel < 0) {
3701 return false;
3702 }
3703 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3704 if (DBG) log("iccCloseLogicalChannel: " + success);
3705 return success;
3706 } finally {
3707 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003708 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709 }
3710
3711 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003712 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003713 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3715 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003717 final long identity = Binder.clearCallingIdentity();
3718 try {
3719 if (DBG) {
3720 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3721 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3722 + p3 + " data=" + data);
3723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 if (channel < 0) {
3726 return "";
3727 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003729 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3730 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3731 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003733 // Append the returned status code to the end of the response payload.
3734 String s = Integer.toHexString(
3735 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3736 if (response.payload != null) {
3737 s = IccUtils.bytesToHexString(response.payload) + s;
3738 }
3739 return s;
3740 } finally {
3741 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003742 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003743 }
Jake Hambye994d462014-02-03 13:10:13 -08003744
Evan Charltonc66da362014-05-16 14:06:40 -07003745 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003746 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3747 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3749 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3755 && TextUtils.equals(ISDR_AID, data)) {
3756 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3758 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003759 if (bestComponent == null
3760 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3761 loge("The calling package is not allowed to select ISD-R.");
3762 throw new SecurityException(
3763 "The calling package is not allowed to select ISD-R.");
3764 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003765 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003767 if (DBG) {
3768 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3769 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3770 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003772 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3773 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3774 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003776 // Append the returned status code to the end of the response payload.
3777 String s = Integer.toHexString(
3778 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3779 if (response.payload != null) {
3780 s = IccUtils.bytesToHexString(response.payload) + s;
3781 }
3782 return s;
3783 } finally {
3784 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003785 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003786 }
3787
3788 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003789 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003790 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3792 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003793
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003794 final long identity = Binder.clearCallingIdentity();
3795 try {
3796 if (DBG) {
3797 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3798 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3799 }
3800
3801 IccIoResult response =
3802 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3803 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3804 subId);
3805
3806 if (DBG) {
3807 log("Exchange SIM_IO [R]" + response);
3808 }
3809
3810 byte[] result = null;
3811 int length = 2;
3812 if (response.payload != null) {
3813 length = 2 + response.payload.length;
3814 result = new byte[length];
3815 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3816 } else {
3817 result = new byte[length];
3818 }
3819
3820 result[length - 1] = (byte) response.sw2;
3821 result[length - 2] = (byte) response.sw1;
3822 return result;
3823 } finally {
3824 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003825 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003826 }
3827
Nathan Haroldb3014052017-01-25 15:57:32 -08003828 /**
3829 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3830 * on a particular subscription
3831 */
sqianb6e41952018-03-12 14:54:01 -07003832 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3834 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3835 return null;
3836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003837
3838 final long identity = Binder.clearCallingIdentity();
3839 try {
3840 if (appType != TelephonyManager.APPTYPE_USIM
3841 && appType != TelephonyManager.APPTYPE_SIM) {
3842 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3843 return null;
3844 }
3845 Object response = sendRequest(
3846 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3847 if (response instanceof String[]) {
3848 return (String[]) response;
3849 }
3850 // Response is an Exception of some kind,
3851 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003852 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003853 } finally {
3854 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003855 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003856 }
3857
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003858 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003859 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003860 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3861 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3866 if (response.payload == null) {
3867 return "";
3868 }
Evan Charltonc66da362014-05-16 14:06:40 -07003869
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003870 // Append the returned status code to the end of the response payload.
3871 String s = Integer.toHexString(
3872 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3873 s = IccUtils.bytesToHexString(response.payload) + s;
3874 return s;
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
Evan Charltonc66da362014-05-16 14:06:40 -07003878 }
3879
Jake Hambye994d462014-02-03 13:10:13 -08003880 /**
3881 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3882 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3883 *
3884 * @param itemID the ID of the item to read
3885 * @return the NV item as a String, or null on error.
3886 */
3887 @Override
3888 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003889 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003890 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3891 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003892
3893 final long identity = Binder.clearCallingIdentity();
3894 try {
3895 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07003896 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003897 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3898 return value;
3899 } finally {
3900 Binder.restoreCallingIdentity(identity);
3901 }
Jake Hambye994d462014-02-03 13:10:13 -08003902 }
3903
3904 /**
3905 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3906 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3907 *
3908 * @param itemID the ID of the item to read
3909 * @param itemValue the value to write, as a String
3910 * @return true on success; false on any failure
3911 */
3912 @Override
3913 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07003914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3916 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003917
3918 final long identity = Binder.clearCallingIdentity();
3919 try {
3920 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3921 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07003922 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003923 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3924 return success;
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
Jake Hambye994d462014-02-03 13:10:13 -08003928 }
3929
3930 /**
3931 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3932 * Used for device configuration by some CDMA operators.
3933 *
3934 * @param preferredRoamingList byte array containing the new PRL
3935 * @return true on success; false on any failure
3936 */
3937 @Override
3938 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003939 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3940 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003941
3942 final long identity = Binder.clearCallingIdentity();
3943 try {
3944 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3945 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3946 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3947 return success;
3948 } finally {
3949 Binder.restoreCallingIdentity(identity);
3950 }
Jake Hambye994d462014-02-03 13:10:13 -08003951 }
3952
3953 /**
chen xu6dac5ab2018-10-26 17:39:23 -07003954 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003955 * Used for device configuration by some CDMA operators.
3956 *
chen xu6dac5ab2018-10-26 17:39:23 -07003957 * @param slotIndex - device slot.
3958 *
Jake Hambye994d462014-02-03 13:10:13 -08003959 * @return true on success; false on any failure
3960 */
3961 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07003962 public boolean resetModemConfig(int slotIndex) {
3963 Phone phone = PhoneFactory.getPhone(slotIndex);
3964 if (phone != null) {
3965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3966 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003967
chen xu6dac5ab2018-10-26 17:39:23 -07003968 final long identity = Binder.clearCallingIdentity();
3969 try {
3970 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3971 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3972 return success;
3973 } finally {
3974 Binder.restoreCallingIdentity(identity);
3975 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003976 }
chen xu6dac5ab2018-10-26 17:39:23 -07003977 return false;
3978 }
3979
3980 /**
3981 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3982 *
3983 * @param slotIndex - device slot.
3984 *
3985 * @return true on success; false on any failure
3986 */
3987 @Override
3988 public boolean rebootModem(int slotIndex) {
3989 Phone phone = PhoneFactory.getPhone(slotIndex);
3990 if (phone != null) {
3991 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3992 mApp, phone.getSubId(), "rebootModem");
3993
3994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3997 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3998 return success;
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
4002 }
4003 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004004 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004005
Svet Ganovb320e182015-04-16 12:30:10 -07004006 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004007 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004010 return new String[0];
4011 }
4012
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004015 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
Wink Saville36469e72014-06-11 15:17:00 -07004019 }
4020
Brad Ebinger51f743a2017-01-23 13:50:20 -08004021 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004022 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4023 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004024 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004025 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004026 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 PhoneFactory.getImsResolver().enableIms(slotId);
4031 } finally {
4032 Binder.restoreCallingIdentity(identity);
4033 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004034 }
4035
4036 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004037 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4038 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004039 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004040 public void disableIms(int slotId) {
4041 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004042
4043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 PhoneFactory.getImsResolver().disableIms(slotId);
4046 } finally {
4047 Binder.restoreCallingIdentity(identity);
4048 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004049 }
4050
4051 /**
4052 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4053 * feature or {@link null} if the service is not available. If the feature is available, the
4054 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4055 */
4056 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004057 IImsServiceFeatureCallback callback) {
4058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004059
4060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4063 } finally {
4064 Binder.restoreCallingIdentity(identity);
4065 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004066 }
4067
4068 /**
4069 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4070 * feature during emergency calling or {@link null} if the service is not available. If the
4071 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4072 * listener for feature updates.
4073 */
4074 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004076
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004083 }
4084
Brad Ebinger5f64b052017-12-14 14:26:15 -08004085 /**
4086 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4087 * specified.
4088 */
4089 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4090 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091
4092 final long identity = Binder.clearCallingIdentity();
4093 try {
4094 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4095 } finally {
4096 Binder.restoreCallingIdentity(identity);
4097 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004098 }
4099
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004100 /**
4101 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4102 * specified.
4103 */
4104 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4105 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004106
4107 final long identity = Binder.clearCallingIdentity();
4108 try {
4109 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004113 }
4114
Brad Ebinger884c07b2018-02-15 16:17:40 -08004115 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004116 * Sets the ImsService Package Name that Telephony will bind to.
4117 *
4118 * @param slotId the slot ID that the ImsService should bind for.
4119 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4120 * ImsService is the device default ImsService.
4121 * @param packageName The package name of the application that contains the ImsService to bind
4122 * to.
4123 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4124 * @hide
4125 */
4126 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004127 int[] subIds = SubscriptionManager.getSubId(slotId);
4128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4129 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4130 "setImsService");
4131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4135 isCarrierImsService, packageName);
4136 } finally {
4137 Binder.restoreCallingIdentity(identity);
4138 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004139 }
4140
4141 /**
4142 * Return the ImsService configuration.
4143 *
4144 * @param slotId The slot that the ImsService is associated with.
4145 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4146 * the device default.
4147 * @return the package name of the ImsService configuration.
4148 */
4149 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004150 int[] subIds = SubscriptionManager.getSubId(slotId);
4151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4152 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4153 "getImsService");
4154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4158 isCarrierImsService);
4159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004162 }
4163
Wink Saville36469e72014-06-11 15:17:00 -07004164 public void setImsRegistrationState(boolean registered) {
4165 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004166
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004169 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
Wink Saville36469e72014-06-11 15:17:00 -07004173 }
4174
4175 /**
Stuart Scott54788802015-03-30 13:18:01 -07004176 * Set the network selection mode to automatic.
4177 *
4178 */
4179 @Override
4180 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4182 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004183
Pengquan Menge92a50d2018-09-21 15:54:48 -07004184 if (!isActiveSubscription(subId)) {
4185 return;
4186 }
4187
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004188 final long identity = Binder.clearCallingIdentity();
4189 try {
4190 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4191 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Stuart Scott54788802015-03-30 13:18:01 -07004195 }
4196
Pengquan Mengea84e042018-09-20 14:57:26 -07004197 /**
4198 * Ask the radio to connect to the input network and change selection mode to manual.
4199 *
4200 * @param subId the id of the subscription.
4201 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4202 * the operator to attach to.
4203 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4204 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4205 * normal network selection next time.
4206 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004207 */
4208 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004209 public boolean setNetworkSelectionModeManual(
4210 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004211 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4212 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004213
4214 if (!isActiveSubscription(subId)) {
4215 return false;
4216 }
4217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004218 final long identity = Binder.clearCallingIdentity();
4219 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004220 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004221 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004222 if (DBG) {
4223 log("setNetworkSelectionModeManual: subId: " + subId
4224 + " operator: " + operatorInfo);
4225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004226 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4227 } finally {
4228 Binder.restoreCallingIdentity(identity);
4229 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004230 }
4231
4232 /**
4233 * Scans for available networks.
4234 */
4235 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004236 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4238 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004239 LocationAccessPolicy.LocationPermissionResult locationResult =
4240 LocationAccessPolicy.checkLocationPermission(mApp,
4241 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4242 .setCallingPackage(callingPackage)
4243 .setCallingPid(Binder.getCallingPid())
4244 .setCallingUid(Binder.getCallingUid())
4245 .setMethod("getCellNetworkScanResults")
4246 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4247 .build());
4248 switch (locationResult) {
4249 case DENIED_HARD:
4250 throw new SecurityException("Not allowed to access scan results -- location");
4251 case DENIED_SOFT:
4252 return null;
4253 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254
Pengquan Menga1bb6272018-09-06 09:59:22 -07004255 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004256 try {
4257 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004258 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004260 } finally {
4261 Binder.restoreCallingIdentity(identity);
4262 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004263 }
4264
4265 /**
yinxub1bed742017-04-17 11:45:04 -07004266 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004267 *
yinxub1bed742017-04-17 11:45:04 -07004268 * @param subId id of the subscription
4269 * @param request contains the radio access networks with bands/channels to scan
4270 * @param messenger callback messenger for scan results or errors
4271 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004272 * @return the id of the requested scan which can be used to stop the scan.
4273 */
4274 @Override
4275 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004276 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4278 mApp, subId, "requestNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004279
Hall Liuf19c44f2018-11-27 14:38:17 -08004280 LocationAccessPolicy.LocationPermissionResult locationResult =
4281 LocationAccessPolicy.checkLocationPermission(mApp,
4282 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4283 .setCallingPackage(callingPackage)
4284 .setCallingPid(Binder.getCallingPid())
4285 .setCallingUid(Binder.getCallingUid())
4286 .setMethod("requestNetworkScan")
4287 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4288 .build());
4289 switch (locationResult) {
4290 case DENIED_HARD:
4291 throw new SecurityException("Not allowed to request network scan -- location");
4292 case DENIED_SOFT:
4293 return -1;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004294 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004295
4296 return mNetworkScanRequestTracker.startNetworkScan(
4297 request, messenger, binder, getPhone(subId),
4298 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004299 }
4300
4301 /**
4302 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004303 *
4304 * @param subId id of the subscription
4305 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004306 */
4307 @Override
4308 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4310 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004311
4312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
4317 }
yinxu504e1392017-04-12 16:03:22 -07004318 }
4319
4320 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004321 * Get the calculated preferred network type.
4322 * Used for debugging incorrect network type.
4323 *
4324 * @return the preferred network type, defined in RILConstants.java.
4325 */
4326 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004327 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004328 final Phone defaultPhone = getDefaultPhone();
4329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4330 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004331 return RILConstants.PREFERRED_NETWORK_MODE;
4332 }
4333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004334 final long identity = Binder.clearCallingIdentity();
4335 try {
4336 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004337 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 } finally {
4339 Binder.restoreCallingIdentity(identity);
4340 }
Junda Liu84d15a22014-07-02 11:21:04 -07004341 }
4342
4343 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004344 * Get the preferred network type.
4345 * Used for device configuration by some CDMA operators.
4346 *
4347 * @return the preferred network type, defined in RILConstants.java.
4348 */
4349 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004350 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004351 TelephonyPermissions
4352 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4353 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004354
4355 final long identity = Binder.clearCallingIdentity();
4356 try {
4357 if (DBG) log("getPreferredNetworkType");
4358 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4359 int networkType = (result != null ? result[0] : -1);
4360 if (DBG) log("getPreferredNetworkType: " + networkType);
4361 return networkType;
4362 } finally {
4363 Binder.restoreCallingIdentity(identity);
4364 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004365 }
4366
4367 /**
4368 * Set the preferred network type.
4369 * Used for device configuration by some CDMA operators.
4370 *
4371 * @param networkType the preferred network type, defined in RILConstants.java.
4372 * @return true on success; false on any failure.
4373 */
4374 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004375 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004376 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4377 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378
4379 final long identity = Binder.clearCallingIdentity();
4380 try {
4381 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4382 Boolean success = (Boolean) sendRequest(
4383 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4384 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4385 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004386 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004387 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4388 }
4389 return success;
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004392 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004393 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004394
4395 /**
Junda Liu475951f2014-11-07 16:45:03 -08004396 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu3cda1cd2018-10-30 17:41:31 -07004397 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004398 * tethering.
4399 *
4400 * @return 0: Not required. 1: required. 2: Not set.
4401 * @hide
4402 */
4403 @Override
4404 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004405 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406
4407 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004408 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004409 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004410 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu3cda1cd2018-10-30 17:41:31 -07004412 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004413 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 dunRequired = 1;
4415 }
4416 return dunRequired;
4417 } finally {
4418 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004419 }
Junda Liu475951f2014-11-07 16:45:03 -08004420 }
4421
4422 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004423 * Set mobile data enabled
4424 * Used by the user through settings etc to turn on/off mobile data
4425 *
4426 * @param enable {@code true} turn turn data on, else {@code false}
4427 */
4428 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004429 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4431 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432
4433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 int phoneId = mSubscriptionController.getPhoneId(subId);
4436 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4437 Phone phone = PhoneFactory.getPhone(phoneId);
4438 if (phone != null) {
4439 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004440 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004442 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004443 }
4444 } finally {
4445 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004446 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004447 }
4448
4449 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004450 * Get the user enabled state of Mobile Data.
4451 *
4452 * TODO: remove and use isUserDataEnabled.
4453 * This can't be removed now because some vendor codes
4454 * calls through ITelephony directly while they should
4455 * use TelephonyManager.
4456 *
4457 * @return true on enabled
4458 */
4459 @Override
4460 public boolean getDataEnabled(int subId) {
4461 return isUserDataEnabled(subId);
4462 }
4463
4464 /**
4465 * Get whether mobile data is enabled per user setting.
4466 *
4467 * There are other factors deciding whether mobile data is actually enabled, but they are
4468 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004469 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004470 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004471 *
4472 * @return {@code true} if data is enabled else {@code false}
4473 */
4474 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004475 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004476 try {
4477 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4478 null);
4479 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4481 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004483
4484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 int phoneId = mSubscriptionController.getPhoneId(subId);
4487 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4488 Phone phone = PhoneFactory.getPhone(phoneId);
4489 if (phone != null) {
4490 boolean retVal = phone.isUserDataEnabled();
4491 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4492 return retVal;
4493 } else {
4494 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4495 return false;
4496 }
4497 } finally {
4498 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004499 }
4500 }
4501
4502 /**
4503 * Get whether mobile data is enabled.
4504 *
4505 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4506 * whether mobile data is actually enabled.
4507 *
4508 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4509 *
4510 * @return {@code true} if data is enabled else {@code false}
4511 */
4512 @Override
4513 public boolean isDataEnabled(int subId) {
4514 try {
4515 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4516 null);
4517 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004518 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4519 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004521
4522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 int phoneId = mSubscriptionController.getPhoneId(subId);
4525 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4526 Phone phone = PhoneFactory.getPhone(phoneId);
4527 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004528 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4530 return retVal;
4531 } else {
4532 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4533 return false;
4534 }
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004537 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004538 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004539
4540 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004541 public int getCarrierPrivilegeStatus(int subId) {
4542 final Phone phone = getPhone(subId);
4543 if (phone == null) {
4544 loge("getCarrierPrivilegeStatus: Invalid subId");
4545 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4546 }
4547 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004548 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004549 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004550 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4551 }
4552 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004553 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004554 }
Junda Liu29340342014-07-10 15:23:27 -07004555
4556 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004557 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4558 final Phone phone = getPhone(subId);
4559 if (phone == null) {
4560 loge("getCarrierPrivilegeStatus: Invalid subId");
4561 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4562 }
4563 UiccProfile profile =
4564 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4565 if (profile == null) {
4566 loge("getCarrierPrivilegeStatus: No UICC");
4567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4568 }
4569 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4570 }
4571
4572 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004573 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004574 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004575 if (TextUtils.isEmpty(pkgName))
4576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004577 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004578 if (card == null) {
4579 loge("checkCarrierPrivilegesForPackage: No UICC");
4580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4581 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004582 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4583 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004584 }
4585
4586 @Override
4587 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004588 if (TextUtils.isEmpty(pkgName))
4589 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004590 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4591 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4592 UiccCard card = UiccController.getInstance().getUiccCard(i);
4593 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004594 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004595 continue;
4596 }
4597
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004598 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004599 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4600 break;
4601 }
4602 }
4603
4604 return result;
Junda Liu29340342014-07-10 15:23:27 -07004605 }
Derek Tan89e89d42014-07-08 17:00:10 -07004606
4607 @Override
Junda Liue64de782015-04-16 17:19:16 -07004608 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4609 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4610 loge("phoneId " + phoneId + " is not valid.");
4611 return null;
4612 }
4613 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004614 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004615 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004616 return null ;
4617 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004618 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004619 }
4620
Amith Yamasani6e118872016-02-19 12:53:51 -08004621 @Override
4622 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004623 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004624 List<String> privilegedPackages = new ArrayList<>();
4625 List<PackageInfo> packages = null;
4626 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4627 UiccCard card = UiccController.getInstance().getUiccCard(i);
4628 if (card == null) {
4629 // No UICC in that slot.
4630 continue;
4631 }
4632 if (card.hasCarrierPrivilegeRules()) {
4633 if (packages == null) {
4634 // Only check packages in user 0 for now
4635 packages = pm.getInstalledPackagesAsUser(
4636 PackageManager.MATCH_DISABLED_COMPONENTS
4637 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4638 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4639 }
4640 for (int p = packages.size() - 1; p >= 0; p--) {
4641 PackageInfo pkgInfo = packages.get(p);
4642 if (pkgInfo != null && pkgInfo.packageName != null
4643 && card.getCarrierPrivilegeStatus(pkgInfo)
4644 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4645 privilegedPackages.add(pkgInfo.packageName);
4646 }
4647 }
4648 }
4649 }
4650 return privilegedPackages;
4651 }
4652
Wink Savilleb564aae2014-10-23 10:18:09 -07004653 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004654 final Phone phone = getPhone(subId);
4655 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004656 if (card == null) {
4657 loge("getIccId: No UICC");
4658 return null;
4659 }
4660 String iccId = card.getIccId();
4661 if (TextUtils.isEmpty(iccId)) {
4662 loge("getIccId: ICC ID is null or empty.");
4663 return null;
4664 }
4665 return iccId;
4666 }
4667
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004668 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004669 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4670 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004671 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4672 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004673
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004674 final long identity = Binder.clearCallingIdentity();
4675 try {
4676 final String iccId = getIccId(subId);
4677 final Phone phone = getPhone(subId);
4678 if (phone == null) {
4679 return false;
4680 }
4681 final String subscriberId = phone.getSubscriberId();
4682
4683 if (DBG_MERGE) {
4684 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4685 + subscriberId + " to " + number);
4686 }
4687
4688 if (TextUtils.isEmpty(iccId)) {
4689 return false;
4690 }
4691
4692 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4693
4694 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4695 if (alphaTag == null) {
4696 editor.remove(alphaTagPrefKey);
4697 } else {
4698 editor.putString(alphaTagPrefKey, alphaTag);
4699 }
4700
4701 // Record both the line number and IMSI for this ICCID, since we need to
4702 // track all merged IMSIs based on line number
4703 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4704 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4705 if (number == null) {
4706 editor.remove(numberPrefKey);
4707 editor.remove(subscriberPrefKey);
4708 } else {
4709 editor.putString(numberPrefKey, number);
4710 editor.putString(subscriberPrefKey, subscriberId);
4711 }
4712
4713 editor.commit();
4714 return true;
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004717 }
Derek Tan7226c842014-07-02 17:42:23 -07004718 }
4719
4720 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004721 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004722 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004724 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004725 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004726 return null;
4727 }
Derek Tan97ebb422014-09-05 16:55:38 -07004728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004729 final long identity = Binder.clearCallingIdentity();
4730 try {
4731 String iccId = getIccId(subId);
4732 if (iccId != null) {
4733 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4734 if (DBG_MERGE) {
4735 log("getLine1NumberForDisplay returning "
4736 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4737 }
4738 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004739 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004740 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4741 return null;
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004744 }
Derek Tan7226c842014-07-02 17:42:23 -07004745 }
4746
4747 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004748 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004750 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004751 return null;
4752 }
Derek Tan97ebb422014-09-05 16:55:38 -07004753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004754 final long identity = Binder.clearCallingIdentity();
4755 try {
4756 String iccId = getIccId(subId);
4757 if (iccId != null) {
4758 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4759 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4760 }
4761 return null;
4762 } finally {
4763 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004764 }
Derek Tan7226c842014-07-02 17:42:23 -07004765 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004766
4767 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004768 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004769 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4770 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004771 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004772 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4773 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004774 return null;
4775 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004776
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004777 final long identity = Binder.clearCallingIdentity();
4778 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004779 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004780 final TelephonyManager tele = TelephonyManager.from(context);
4781 final SubscriptionManager sub = SubscriptionManager.from(context);
4782
4783 // Figure out what subscribers are currently active
4784 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4785 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4786 // the process, where TelephonyManager was instantiated.
4787 // Otherwise AppOps check will fail.
4788
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004789 final int[] subIds = sub.getActiveSubscriptionIdList();
4790 for (int subId : subIds) {
4791 activeSubscriberIds.add(tele.getSubscriberId(subId));
4792 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793
4794 // First pass, find a number override for an active subscriber
4795 String mergeNumber = null;
4796 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4797 for (String key : prefs.keySet()) {
4798 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4799 final String subscriberId = (String) prefs.get(key);
4800 if (activeSubscriberIds.contains(subscriberId)) {
4801 final String iccId = key.substring(
4802 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4803 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4804 mergeNumber = (String) prefs.get(numberKey);
4805 if (DBG_MERGE) {
4806 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4807 + " for active subscriber " + subscriberId);
4808 }
4809 if (!TextUtils.isEmpty(mergeNumber)) {
4810 break;
4811 }
4812 }
4813 }
4814 }
4815
4816 // Shortcut when no active merged subscribers
4817 if (TextUtils.isEmpty(mergeNumber)) {
4818 return null;
4819 }
4820
4821 // Second pass, find all subscribers under that line override
4822 final ArraySet<String> result = new ArraySet<>();
4823 for (String key : prefs.keySet()) {
4824 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4825 final String number = (String) prefs.get(key);
4826 if (mergeNumber.equals(number)) {
4827 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4828 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4829 final String subscriberId = (String) prefs.get(subscriberKey);
4830 if (!TextUtils.isEmpty(subscriberId)) {
4831 result.add(subscriberId);
4832 }
4833 }
4834 }
4835 }
4836
4837 final String[] resultArray = result.toArray(new String[result.size()]);
4838 Arrays.sort(resultArray);
4839 if (DBG_MERGE) {
4840 Slog.d(LOG_TAG,
4841 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4842 }
4843 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004844 } finally {
4845 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004846 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004847 }
4848
4849 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004850 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4852 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 final Phone phone = getPhone(subId);
4857 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4858 } finally {
4859 Binder.restoreCallingIdentity(identity);
4860 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004861 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004862
4863 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004864 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004865 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4866 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004867 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868
4869 final long identity = Binder.clearCallingIdentity();
4870 try {
4871 final Phone phone = getPhone(subId);
4872 if (phone == null) {
4873 return false;
4874 }
4875 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4876 cdmaNonRoamingList);
4877 } finally {
4878 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004879 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004880 }
4881
4882 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004883 @Deprecated
4884 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4885 enforceModifyPermission();
4886
4887 int returnValue = 0;
4888 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004889 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004890 if(result.exception == null) {
4891 if (result.result != null) {
4892 byte[] responseData = (byte[])(result.result);
4893 if(responseData.length > oemResp.length) {
4894 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4895 responseData.length + "bytes. Buffer Size is " +
4896 oemResp.length + "bytes.");
4897 }
4898 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4899 returnValue = responseData.length;
4900 }
4901 } else {
4902 CommandException ex = (CommandException) result.exception;
4903 returnValue = ex.getCommandError().ordinal();
4904 if(returnValue > 0) returnValue *= -1;
4905 }
4906 } catch (RuntimeException e) {
4907 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4908 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4909 if(returnValue > 0) returnValue *= -1;
4910 }
4911
4912 return returnValue;
4913 }
4914
4915 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004916 public void setRadioCapability(RadioAccessFamily[] rafs) {
4917 try {
4918 ProxyController.getInstance().setRadioCapability(rafs);
4919 } catch (RuntimeException e) {
4920 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4921 }
4922 }
4923
4924 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004925 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004926 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004927 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004928 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004929 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004930 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
chen xub97461a2018-10-26 14:17:57 -07004933 TelephonyPermissions
4934 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4935 mApp, phone.getSubId(), "getRadioAccessFamily");
4936 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
chen xub97461a2018-10-26 14:17:57 -07004940 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004941 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004942
4943 @Override
4944 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004945 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004946 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004947
4948 final long identity = Binder.clearCallingIdentity();
4949 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004950 ImsManager.getInstance(defaultPhone.getContext(),
4951 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004952 } finally {
4953 Binder.restoreCallingIdentity(identity);
4954 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004955 }
4956
4957 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004958 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004959 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004960 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004961 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004962 return false;
4963 }
Svet Ganovb320e182015-04-16 12:30:10 -07004964
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004965 final long identity = Binder.clearCallingIdentity();
4966 try {
4967 // Check the user preference and the system-level IMS setting. Even if the user has
4968 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4969 // In the long run, we may instead need to check if there exists a connection service
4970 // which can support video calling.
4971 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004972 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 return imsManager.isVtEnabledByPlatform()
4974 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4975 && imsManager.isVtEnabledByUser();
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
4978 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004979 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004980
Andrew Leea1239f22015-03-02 17:44:07 -08004981 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4984 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4985 return false;
4986 }
4987
4988 final long identity = Binder.clearCallingIdentity();
4989 try {
4990 CarrierConfigManager configManager =
4991 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004992 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004993 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4994 } finally {
4995 Binder.restoreCallingIdentity(identity);
4996 }
Andrew Leea1239f22015-03-02 17:44:07 -08004997 }
4998
4999 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005000 public boolean isWorldPhone(int subId, String callingPackage) {
5001 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5002 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5003 return false;
5004 }
5005
5006 final long identity = Binder.clearCallingIdentity();
5007 try {
5008 CarrierConfigManager configManager =
5009 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005010 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5012 } finally {
5013 Binder.restoreCallingIdentity(identity);
5014 }
Andrew Leea1239f22015-03-02 17:44:07 -08005015 }
5016
Andrew Lee9431b832015-03-09 18:46:45 -07005017 @Override
5018 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005019 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005020 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005021 }
5022
5023 @Override
5024 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 final long identity = Binder.clearCallingIdentity();
5026 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005027 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005028 } finally {
5029 Binder.restoreCallingIdentity(identity);
5030 }
Andrew Lee9431b832015-03-09 18:46:45 -07005031 }
5032
Hall Liuf6668912018-10-31 17:05:23 -07005033 /**
5034 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5035 * support for the feature and device firmware support.
5036 *
5037 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5038 */
5039 @Override
5040 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005041 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005042 final Phone phone = getPhone(subscriptionId);
5043 if (phone == null) {
5044 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5045 return false;
5046 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005048 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5050 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005051 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052 return isCarrierSupported && isDeviceSupported;
5053 } finally {
5054 Binder.restoreCallingIdentity(identity);
5055 }
Hall Liu98187582018-01-22 19:15:32 -08005056 }
5057
Hall Liuf6668912018-10-31 17:05:23 -07005058 /**
5059 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5060 * both also support RTT.
5061 */
5062 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 final long identity = Binder.clearCallingIdentity();
5064 try {
Hall Liuf6668912018-10-31 17:05:23 -07005065 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005066 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 } finally {
5068 Binder.restoreCallingIdentity(identity);
5069 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005070 }
5071
Sanket Padawe7310cc72015-01-14 09:53:20 -08005072 /**
5073 * Returns the unique device ID of phone, for example, the IMEI for
5074 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5075 *
5076 * <p>Requires Permission:
5077 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5078 */
5079 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005080 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005081 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005082 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005083 return null;
5084 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005085 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005086 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5087 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005088 return null;
5089 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005090
5091 final long identity = Binder.clearCallingIdentity();
5092 try {
5093 return phone.getDeviceId();
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
5096 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005097 }
5098
Ping Sunc67b7c22016-03-02 19:16:45 +08005099 /**
5100 * {@hide}
5101 * Returns the IMS Registration Status on a particular subid
5102 *
5103 * @param subId
5104 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005105 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005106 Phone phone = getPhone(subId);
5107 if (phone != null) {
5108 return phone.isImsRegistered();
5109 } else {
5110 return false;
5111 }
5112 }
5113
Santos Cordon7a1885b2015-02-03 11:15:19 -08005114 @Override
5115 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 final long identity = Binder.clearCallingIdentity();
5117 try {
5118 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5119 } finally {
5120 Binder.restoreCallingIdentity(identity);
5121 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005122 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005123
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005124 /**
5125 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005126 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005127 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 Phone phone = getPhone(subId);
5131 if (phone != null) {
5132 return phone.isWifiCallingEnabled();
5133 } else {
5134 return false;
5135 }
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005138 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005139 }
5140
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005141 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005142 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005143 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005144 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005145 final long identity = Binder.clearCallingIdentity();
5146 try {
5147 Phone phone = getPhone(subId);
5148 if (phone != null) {
5149 return phone.isVideoEnabled();
5150 } else {
5151 return false;
5152 }
5153 } finally {
5154 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005155 }
5156 }
5157
5158 /**
5159 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5160 * defined in {@link ImsRegistrationImplBase}.
5161 */
5162 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
5164 try {
5165 Phone phone = getPhone(subId);
5166 if (phone != null) {
5167 return phone.getImsRegistrationTech();
5168 } else {
5169 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5170 }
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005173 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005174 }
5175
Stuart Scott8eef64f2015-04-08 15:13:54 -07005176 @Override
5177 public void factoryReset(int subId) {
5178 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005179 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5180 return;
5181 }
5182
Svet Ganovcc087f82015-05-12 20:35:54 -07005183 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005184
Svet Ganovcc087f82015-05-12 20:35:54 -07005185 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005186 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5187 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005188 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005189 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005190 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5192 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005193 }
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005196 }
5197 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005198
5199 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005200 public String getSimLocaleForSubscriber(int subId) {
5201 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5202 final Phone phone = getPhone(subId);
5203 if (phone == null) {
5204 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005205 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005206 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005207 final long identity = Binder.clearCallingIdentity();
5208 try {
chen xu5d3637b2019-01-21 23:31:38 -08005209 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5210 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005211 if (info == null) {
5212 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5213 return null;
5214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 // Try and fetch the locale from the carrier properties or from the SIM language
5216 // preferences (EF-PL and EF-LI)...
5217 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005219 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5220 if (localeFromDefaultSim != null) {
5221 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5222 if (DBG) log("Using locale from subId: " + subId + " locale: "
5223 + localeFromDefaultSim);
5224 return localeFromDefaultSim.toLanguageTag();
5225 } else {
5226 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005227 }
5228 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005229
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 // The SIM language preferences only store a language (e.g. fr = French), not an
5231 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5232 // the SIM and carrier preferences does not include a country we add the country
5233 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005234 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005235 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005236 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005237 return mccLocale.toLanguageTag();
5238 }
5239
5240 if (DBG) log("No locale found - returning null");
5241 return null;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005245 }
5246
5247 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005248 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005249 }
5250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 /**
5252 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5253 */
5254 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005255 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005256 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005257
Chenjie Yu1ba97252018-01-11 18:16:20 -08005258 private final ModemActivityInfo mLastModemActivityInfo =
5259 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5260
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005261 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005262 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5263 * representing the state of the modem.
5264 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005265 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5266 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005267 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005268 */
5269 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005270 public void requestModemActivityInfo(ResultReceiver result) {
5271 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005272 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273
5274 final long identity = Binder.clearCallingIdentity();
5275 try {
5276 ModemActivityInfo ret = null;
5277 synchronized (mLastModemActivityInfo) {
5278 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5279 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005280 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005281 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5283 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005284 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5285 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 }
5287 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005288 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5289 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005290 mLastModemActivityInfo.setIdleTimeMillis(
5291 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5292 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5293 mLastModemActivityInfo.setRxTimeMillis(
5294 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5295 mLastModemActivityInfo.setEnergyUsed(
5296 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005298 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5299 mLastModemActivityInfo.getSleepTimeMillis(),
5300 mLastModemActivityInfo.getIdleTimeMillis(),
5301 mLastModemActivityInfo.getTxTimeMillis(),
5302 mLastModemActivityInfo.getRxTimeMillis(),
5303 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 Bundle bundle = new Bundle();
5306 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5307 result.send(0, bundle);
5308 } finally {
5309 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005310 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005311 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005312
Siddharth Rayb8114062018-06-17 15:02:38 -07005313 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5314 // less than total activity duration.
5315 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5316 if (info == null) {
5317 return false;
5318 }
5319 int activityDurationMs =
5320 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5321 int totalTxTimeMs = 0;
5322 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5323 totalTxTimeMs += info.getTxTimeMillis()[i];
5324 }
5325 return (info.isValid()
5326 && (info.getSleepTimeMillis() <= activityDurationMs)
5327 && (info.getIdleTimeMillis() <= activityDurationMs)
5328 && (info.getRxTimeMillis() <= activityDurationMs)
5329 && (totalTxTimeMs <= activityDurationMs));
5330 }
5331
Jack Yu85bd38a2015-11-09 11:34:32 -08005332 /**
5333 * {@hide}
5334 * Returns the service state information on specified subscription.
5335 */
5336 @Override
5337 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005339 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005340 return null;
5341 }
5342
Hall Liuf19c44f2018-11-27 14:38:17 -08005343 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5344 LocationAccessPolicy.checkLocationPermission(mApp,
5345 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5346 .setCallingPackage(callingPackage)
5347 .setCallingPid(Binder.getCallingPid())
5348 .setCallingUid(Binder.getCallingUid())
5349 .setMethod("getServiceStateForSubscriber")
5350 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5351 .build());
5352
5353 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5354 LocationAccessPolicy.checkLocationPermission(mApp,
5355 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5356 .setCallingPackage(callingPackage)
5357 .setCallingPid(Binder.getCallingPid())
5358 .setCallingUid(Binder.getCallingUid())
5359 .setMethod("getServiceStateForSubscriber")
5360 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5361 .build());
5362 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5363 boolean hasFinePermission =
5364 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5365 boolean hasCoarsePermission =
5366 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
5370 final Phone phone = getPhone(subId);
5371 if (phone == null) {
5372 return null;
5373 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005374
Hall Liuf19c44f2018-11-27 14:38:17 -08005375 ServiceState ss = phone.getServiceState();
5376
5377 // Scrub out the location info in ServiceState depending on what level of access
5378 // the caller has.
5379 if (hasFinePermission) return ss;
5380 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5381 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005385 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005386
5387 /**
5388 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5389 *
5390 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5391 * voicemail ringtone.
5392 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5393 * PhoneAccount.
5394 */
5395 @Override
5396 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005397 final long identity = Binder.clearCallingIdentity();
5398 try {
5399 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5400 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005401 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005403
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5405 } finally {
5406 Binder.restoreCallingIdentity(identity);
5407 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005408 }
5409
5410 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005411 * Sets the per-account voicemail ringtone.
5412 *
5413 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5414 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5415 *
5416 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5417 * voicemail ringtone.
5418 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5419 * PhoneAccount.
5420 */
5421 @Override
5422 public void setVoicemailRingtoneUri(String callingPackage,
5423 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005424 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005425 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5426 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005427 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5429 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5430 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005431 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005432
5433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5436 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005437 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 }
5439 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5440 } finally {
5441 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005442 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005443 }
5444
5445 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005446 * Returns whether vibration is set for voicemail notification in Phone settings.
5447 *
5448 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5449 * voicemail vibration setting.
5450 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5451 */
5452 @Override
5453 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 final long identity = Binder.clearCallingIdentity();
5455 try {
5456 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5457 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005458 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005459 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5462 } finally {
5463 Binder.restoreCallingIdentity(identity);
5464 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005465 }
5466
Youhan Wange64578a2016-05-02 15:32:42 -07005467 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005468 * Sets the per-account voicemail vibration.
5469 *
5470 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5471 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5472 *
5473 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5474 * voicemail vibration setting.
5475 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5476 * specific PhoneAccount.
5477 */
5478 @Override
5479 public void setVoicemailVibrationEnabled(String callingPackage,
5480 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005481 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005482 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5483 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5486 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5487 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005488 }
5489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5493 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 }
5496 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5497 } finally {
5498 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005499 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005500 }
5501
5502 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005503 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5504 *
5505 * @throws SecurityException if the caller does not have the required permission
5506 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005507 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005509 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005510 }
5511
5512 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005513 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5514 * permission.
5515 *
5516 * @throws SecurityException if the caller does not have the required permission
5517 */
5518 private void enforceSendSmsPermission() {
5519 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5520 }
5521
5522 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005523 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005524 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005525 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005526 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005527 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 final long identity = Binder.clearCallingIdentity();
5529 try {
5530 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005531 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 if (componentName == null) {
5533 throw new SecurityException(
5534 "Caller not current active visual voicemail package[null]");
5535 }
5536 String vvmPackage = componentName.getPackageName();
5537 if (!callingPackage.equals(vvmPackage)) {
5538 throw new SecurityException("Caller not current active visual voicemail package["
5539 + vvmPackage + "]");
5540 }
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005543 }
5544 }
5545
5546 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005547 * Return the application ID for the app type.
5548 *
5549 * @param subId the subscription ID that this request applies to.
5550 * @param appType the uicc app type.
5551 * @return Application ID for specificied app type, or null if no uicc.
5552 */
5553 @Override
5554 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005555 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005556 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557
5558 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005559 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 if (phone == null) {
5561 return null;
5562 }
5563 String aid = null;
5564 try {
5565 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5566 .getApplicationByType(appType).getAid();
5567 } catch (Exception e) {
5568 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5569 }
5570 return aid;
5571 } finally {
5572 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005573 }
Youhan Wange64578a2016-05-02 15:32:42 -07005574 }
5575
Youhan Wang4001d252016-05-11 10:29:41 -07005576 /**
5577 * Return the Electronic Serial Number.
5578 *
5579 * @param subId the subscription ID that this request applies to.
5580 * @return ESN or null if error.
5581 */
5582 @Override
5583 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005584 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005585 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005586
5587 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005588 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005589 if (phone == null) {
5590 return null;
5591 }
5592 String esn = null;
5593 try {
5594 esn = phone.getEsn();
5595 } catch (Exception e) {
5596 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5597 }
5598 return esn;
5599 } finally {
5600 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005601 }
Youhan Wang4001d252016-05-11 10:29:41 -07005602 }
5603
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005604 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005605 * Return the Preferred Roaming List Version.
5606 *
5607 * @param subId the subscription ID that this request applies to.
5608 * @return PRLVersion or null if error.
5609 */
5610 @Override
5611 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005612 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005613 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614
5615 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005616 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617 if (phone == null) {
5618 return null;
5619 }
5620 String cdmaPrlVersion = null;
5621 try {
5622 cdmaPrlVersion = phone.getCdmaPrlVersion();
5623 } catch (Exception e) {
5624 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5625 }
5626 return cdmaPrlVersion;
5627 } finally {
5628 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005629 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005630 }
5631
5632 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005633 * Get snapshot of Telephony histograms
5634 * @return List of Telephony histograms
5635 * @hide
5636 */
5637 @Override
5638 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5640 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641
5642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 return RIL.getTelephonyRILTimingHistograms();
5645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005648 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005649
5650 /**
5651 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005652 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5653 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005654 * Require system privileges. In the future we may add this to carrier APIs.
5655 *
Michele Berionne482f8202018-11-27 18:57:59 -08005656 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005657 */
5658 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005659 @TelephonyManager.SetCarrierRestrictionResult
5660 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005661 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005662 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005663
Michele Berionne482f8202018-11-27 18:57:59 -08005664 if (carrierRestrictionRules == null) {
5665 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005666 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 final long identity = Binder.clearCallingIdentity();
5669 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005670 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005671 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005675 }
5676
5677 /**
5678 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005679 * Get the allowed carrier list and the excluded carrier list, including the priority between
5680 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005681 * Require system privileges. In the future we may add this to carrier APIs.
5682 *
Michele Berionne482f8202018-11-27 18:57:59 -08005683 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005684 */
5685 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005686 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005687 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005688 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689
5690 final long identity = Binder.clearCallingIdentity();
5691 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005692 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5693 if (response instanceof CarrierRestrictionRules) {
5694 return (CarrierRestrictionRules) response;
5695 }
5696 // Response is an Exception of some kind,
5697 // which is signalled to the user as a NULL retval
5698 return null;
5699 } catch (Exception e) {
5700 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5701 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } finally {
5703 Binder.restoreCallingIdentity(identity);
5704 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005705 }
5706
fionaxu59545b42016-05-25 15:53:37 -07005707 /**
5708 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5709 * @param subId the subscription ID that this action applies to.
5710 * @param enabled control enable or disable metered apns.
5711 * {@hide}
5712 */
5713 @Override
5714 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5715 enforceModifyPermission();
5716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005717
5718 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005719 if (phone == null) {
5720 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5721 return;
5722 }
5723 try {
5724 phone.carrierActionSetMeteredApnsEnabled(enabled);
5725 } catch (Exception e) {
5726 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005729 }
5730 }
5731
5732 /**
5733 * Action set from carrier signalling broadcast receivers to enable/disable radio
5734 * @param subId the subscription ID that this action applies to.
5735 * @param enabled control enable or disable radio.
5736 * {@hide}
5737 */
5738 @Override
5739 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5740 enforceModifyPermission();
5741 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005742
5743 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005744 if (phone == null) {
5745 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5746 return;
5747 }
5748 try {
5749 phone.carrierActionSetRadioEnabled(enabled);
5750 } catch (Exception e) {
5751 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005752 } finally {
5753 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005754 }
5755 }
5756
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005757 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005758 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5759 * network status based on which carrier apps could apply actions accordingly,
5760 * enable/disable default url handler for example.
5761 *
5762 * @param subId the subscription ID that this action applies to.
5763 * @param report control start/stop reporting the default network status.
5764 * {@hide}
5765 */
5766 @Override
5767 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5768 enforceModifyPermission();
5769 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770
5771 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005772 if (phone == null) {
5773 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5774 return;
5775 }
5776 try {
5777 phone.carrierActionReportDefaultNetworkStatus(report);
5778 } catch (Exception e) {
5779 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005782 }
5783 }
5784
5785 /**
fionaxud9622282017-07-17 17:51:30 -07005786 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5787 * @param subId the subscription ID that this action applies to.
5788 * {@hide}
5789 */
5790 @Override
5791 public void carrierActionResetAll(int subId) {
5792 enforceModifyPermission();
5793 final Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5796 return;
5797 }
5798 try {
5799 phone.carrierActionResetAll();
5800 } catch (Exception e) {
5801 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5802 }
5803 }
5804
5805 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005806 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5807 * bug report is being generated.
5808 */
5809 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005810 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005811 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5812 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005813 writer.println("Permission Denial: can't dump Phone from pid="
5814 + Binder.getCallingPid()
5815 + ", uid=" + Binder.getCallingUid()
5816 + "without permission "
5817 + android.Manifest.permission.DUMP);
5818 return;
5819 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005820 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005821 }
Jack Yueb89b242016-06-22 13:27:47 -07005822
Brad Ebingerdac2f002018-04-03 15:17:52 -07005823 @Override
5824 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5825 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5826 throws RemoteException {
5827 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5828 }
5829
Jack Yueb89b242016-06-22 13:27:47 -07005830 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005831 * Get aggregated video call data usage since boot.
5832 *
5833 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5834 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005835 * {@hide}
5836 */
5837 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005838 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005839 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5840 null);
5841
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005842 final long identity = Binder.clearCallingIdentity();
5843 try {
5844 // NetworkStatsService keeps tracking the active network interface and identity. It
5845 // records the delta with the corresponding network identity.
5846 // We just return the total video call data usage snapshot since boot.
5847 Phone phone = getPhone(subId);
5848 if (phone != null) {
5849 return phone.getVtDataUsage(perUidStats);
5850 }
5851 return null;
5852 } finally {
5853 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005854 }
Jack Yueb89b242016-06-22 13:27:47 -07005855 }
Jack Yu75ab2952016-07-08 14:29:33 -07005856
5857 /**
5858 * Policy control of data connection. Usually used when data limit is passed.
5859 * @param enabled True if enabling the data, otherwise disabling.
5860 * @param subId Subscription index
5861 * {@hide}
5862 */
5863 @Override
5864 public void setPolicyDataEnabled(boolean enabled, int subId) {
5865 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005866
5867 final long identity = Binder.clearCallingIdentity();
5868 try {
5869 Phone phone = getPhone(subId);
5870 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005871 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872 }
5873 } finally {
5874 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005875 }
5876 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005877
5878 /**
5879 * Get Client request stats
5880 * @return List of Client Request Stats
5881 * @hide
5882 */
5883 @Override
5884 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005885 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005886 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005887 return null;
5888 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005889 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005891 final long identity = Binder.clearCallingIdentity();
5892 try {
5893 if (phone != null) {
5894 return phone.getClientRequestStats();
5895 }
5896
5897 return null;
5898 } finally {
5899 Binder.restoreCallingIdentity(identity);
5900 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005901 }
5902
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005903 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005904 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005905 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005906 }
Jack Yueb4124c2017-02-16 15:32:43 -08005907
5908 /**
Grace Chen70990072017-03-24 17:21:30 -07005909 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005910 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005911 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005912 * @param state State of SIM (power down, power up, pass through)
5913 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5914 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5915 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005916 *
5917 **/
5918 @Override
Grace Chen70990072017-03-24 17:21:30 -07005919 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005920 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005921 Phone phone = PhoneFactory.getPhone(slotIndex);
5922
vagdeviaf9a5b92018-08-15 16:01:53 -07005923 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005925 final long identity = Binder.clearCallingIdentity();
5926 try {
5927 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005928 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 }
5930 } finally {
5931 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005932 }
5933 }
Shuo Qiandd210312017-04-12 22:11:33 +00005934
Tyler Gunn65d45c22017-06-05 11:22:26 -07005935 private boolean isUssdApiAllowed(int subId) {
5936 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005937 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005938 if (configManager == null) {
5939 return false;
5940 }
5941 PersistableBundle pb = configManager.getConfigForSubId(subId);
5942 if (pb == null) {
5943 return false;
5944 }
5945 return pb.getBoolean(
5946 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5947 }
5948
Shuo Qiandd210312017-04-12 22:11:33 +00005949 /**
5950 * Check if phone is in emergency callback mode
5951 * @return true if phone is in emergency callback mode
5952 * @param subId sub id
5953 */
goneil9c5f4872017-12-05 14:07:56 -08005954 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005955 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005956 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
5960 try {
5961 if (phone != null) {
5962 return phone.isInEcm();
5963 } else {
5964 return false;
5965 }
5966 } finally {
5967 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005968 }
5969 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005970
5971 /**
5972 * Get the current signal strength information for the given subscription.
5973 * Because this information is not updated when the device is in a low power state
5974 * it should not be relied-upon to be current.
5975 * @param subId Subscription index
5976 * @return the most recent cached signal strength info from the modem
5977 */
5978 @Override
5979 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 Phone p = getPhone(subId);
5983 if (p == null) {
5984 return null;
5985 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 return p.getSignalStrength();
5988 } finally {
5989 Binder.restoreCallingIdentity(identity);
5990 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005991 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005992
Pengquan Meng77b7f132018-08-22 14:49:57 -07005993 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005994 * Get the current modem radio state for the given slot.
5995 * @param slotIndex slot index.
5996 * @param callingPackage the name of the package making the call.
5997 * @return the current radio power state from the modem
5998 */
5999 @Override
6000 public int getRadioPowerState(int slotIndex, String callingPackage) {
6001 Phone phone = PhoneFactory.getPhone(slotIndex);
6002 if (phone != null) {
6003 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6004 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6005 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6006 }
6007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 return phone.getRadioPowerState();
6011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
6014 }
6015 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6016 }
6017
6018 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006019 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6020 *
6021 * <p>Requires one of the following permissions:
6022 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6023 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6024 * privileges.
6025 *
6026 * @param subId subscription id
6027 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6028 * {@code false}.
6029 */
6030 @Override
6031 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006032 boolean isEnabled = false;
6033 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006034 try {
6035 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07006036 null /* message */);
6037 Phone phone = getPhone(subId);
6038 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006039 } catch (Exception e) {
6040 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6041 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006044 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006045 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006046 }
6047
6048
6049 /**
6050 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6051 *
6052 * <p> Requires permission:
6053 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6054 * privileges.
6055 *
6056 * @param subId subscription id
6057 * @param isEnabled {@code true} means enable, {@code false} means disable.
6058 */
6059 @Override
6060 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6064 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07006065
Pengquan Menga1bb6272018-09-06 09:59:22 -07006066 Phone phone = getPhone(subId);
6067 if (phone != null) {
6068 phone.setDataRoamingEnabled(isEnabled);
6069 }
6070 } finally {
6071 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006072 }
6073 }
6074
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006075 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006076 public boolean isManualNetworkSelectionAllowed(int subId) {
6077 boolean isAllowed = true;
6078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6081 mApp, subId, "isManualNetworkSelectionAllowed");
6082 Phone phone = getPhone(subId);
6083 if (phone != null) {
6084 isAllowed = phone.isCspPlmnEnabled();
6085 }
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
6089 return isAllowed;
6090 }
6091
6092 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006093 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liuc65bc952019-02-12 17:54:02 -08006094 try {
6095 enforceReadPrivilegedPermission("getUiccCardsInfo");
6096 } catch (SecurityException e) {
6097 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6098 // has carrier privileges on an active UICC
6099 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6100 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6101 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6102 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006103 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006104
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006107 UiccController uiccController = UiccController.getInstance();
6108 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6109
6110 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6111 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6112 // Remove private info if the caller doesn't have access
6113 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6114 for (UiccCardInfo cardInfo : cardInfos) {
6115 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6116 UiccProfile profile = card.getUiccProfile();
6117 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6118 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6119 filteredInfos.add(cardInfo.getUnprivileged());
6120 } else {
6121 filteredInfos.add(cardInfo);
6122 }
6123 }
6124 return filteredInfos;
6125 }
6126 return cardInfos;
6127 } catch (PackageManager.NameNotFoundException e) {
6128 // This should not happen since we pass the package info in from TelephonyManager
6129 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
6133 }
6134
6135 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006136 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006137 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006139 final long identity = Binder.clearCallingIdentity();
6140 try {
6141 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6142 if (slots == null) {
6143 Rlog.i(LOG_TAG, "slots is null.");
6144 return null;
6145 }
6146
6147 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6148 for (int i = 0; i < slots.length; i++) {
6149 UiccSlot slot = slots[i];
6150 if (slot == null) {
6151 continue;
6152 }
6153
6154 String cardId;
6155 UiccCard card = slot.getUiccCard();
6156 if (card != null) {
6157 cardId = card.getCardId();
6158 } else {
6159 cardId = slot.getIccId();
6160 }
6161
6162 int cardState = 0;
6163 switch (slot.getCardState()) {
6164 case CARDSTATE_ABSENT:
6165 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6166 break;
6167 case CARDSTATE_PRESENT:
6168 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6169 break;
6170 case CARDSTATE_ERROR:
6171 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6172 break;
6173 case CARDSTATE_RESTRICTED:
6174 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6175 break;
6176 default:
6177 break;
6178
6179 }
6180
6181 infos[i] = new UiccSlotInfo(
6182 slot.isActive(),
6183 slot.isEuicc(),
6184 cardId,
6185 cardState,
6186 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006187 slot.isExtendedApduSupported(),
6188 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 }
6190 return infos;
6191 } finally {
6192 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006193 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006194 }
6195
6196 @Override
6197 public boolean switchSlots(int[] physicalSlots) {
6198 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199
6200 final long identity = Binder.clearCallingIdentity();
6201 try {
6202 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6203 } finally {
6204 Binder.restoreCallingIdentity(identity);
6205 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006206 }
Jack Yu4c988042018-02-27 15:30:01 -08006207
6208 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006209 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006210 final long identity = Binder.clearCallingIdentity();
6211 try {
6212 return UiccController.getInstance().getCardIdForDefaultEuicc();
6213 } finally {
6214 Binder.restoreCallingIdentity(identity);
6215 }
6216 }
6217
6218 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006219 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6220 enforceModifyPermission();
6221 final Phone phone = getPhone(subId);
6222 if (phone == null) {
6223 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6224 return;
6225 }
6226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 phone.setRadioIndicationUpdateMode(filters, mode);
6230 } finally {
6231 Binder.restoreCallingIdentity(identity);
6232 }
Jack Yu4c988042018-02-27 15:30:01 -08006233 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006234
6235 /**
goneil47ffb6e2018-04-06 15:40:58 -07006236 * A test API to reload the UICC profile.
6237 *
6238 * <p>Requires that the calling app has permission
6239 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6240 * @hide
6241 */
6242 @Override
6243 public void refreshUiccProfile(int subId) {
6244 enforceModifyPermission();
6245
6246 final long identity = Binder.clearCallingIdentity();
6247 try {
6248 Phone phone = getPhone(subId);
6249 if (phone == null) {
6250 return;
6251 }
6252 UiccCard uiccCard = phone.getUiccCard();
6253 if (uiccCard == null) {
6254 return;
6255 }
6256 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6257 if (uiccProfile == null) {
6258 return;
6259 }
6260 uiccProfile.refresh();
6261 } finally {
6262 Binder.restoreCallingIdentity(identity);
6263 }
6264 }
6265
6266 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006267 * Returns false if the mobile data is disabled by default, otherwise return true.
6268 */
6269 private boolean getDefaultDataEnabled() {
6270 return "true".equalsIgnoreCase(
6271 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6272 }
6273
6274 /**
6275 * Returns true if the data roaming is enabled by default, i.e the system property
6276 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6277 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6278 */
6279 private boolean getDefaultDataRoamingEnabled(int subId) {
6280 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006281 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006282 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6283 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6284 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6285 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6286 return isDataRoamingEnabled;
6287 }
6288
6289 /**
6290 * Returns the default network type for the given {@code subId}, if the default network type is
6291 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6292 */
6293 private int getDefaultNetworkType(int subId) {
6294 return Integer.parseInt(
6295 TelephonyManager.getTelephonyProperty(
6296 mSubscriptionController.getPhoneId(subId),
6297 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6298 String.valueOf(Phone.PREFERRED_NT_MODE)));
6299 }
fionaxua13278b2018-03-21 00:08:13 -07006300
6301 @Override
6302 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6303 gid1, String gid2, String plmn, String spn) {
6304 enforceModifyPermission();
Malcolm Chenaa4a8532018-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("setCarrierTestOverride fails with invalid subId: " + subId);
6311 return;
6312 }
6313 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006316 }
fionaxua13278b2018-03-21 00:08:13 -07006317 }
6318
6319 @Override
6320 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006321 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322
6323 final long identity = Binder.clearCallingIdentity();
6324 try {
6325 final Phone phone = getPhone(subId);
6326 if (phone == null) {
6327 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6328 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6329 }
6330 return phone.getCarrierIdListVersion();
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006333 }
fionaxua13278b2018-03-21 00:08:13 -07006334 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006335
6336 @Override
6337 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6338 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6339 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6340 return -1;
6341 }
6342
6343 final long identity = Binder.clearCallingIdentity();
6344 try {
6345 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
6349 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006350
6351 @Override
6352 public int getCdmaRoamingMode(int subId) {
6353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6354 mApp, subId, "getCdmaRoamingMode");
6355
6356 final long identity = Binder.clearCallingIdentity();
6357 try {
6358 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6359 } finally {
6360 Binder.restoreCallingIdentity(identity);
6361 }
6362 }
6363
6364 @Override
6365 public boolean setCdmaRoamingMode(int subId, int mode) {
6366 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6367 mApp, subId, "setCdmaRoamingMode");
6368
6369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
6375 }
6376
6377 @Override
6378 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6379 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6380 mApp, subId, "setCdmaSubscriptionMode");
6381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
6384 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6385 } finally {
6386 Binder.restoreCallingIdentity(identity);
6387 }
6388 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006389
6390 private void ensureUserRunning(int userId) {
6391 if (!mUserManager.isUserRunning(userId)) {
6392 throw new IllegalStateException("User " + userId + " does not exist or not running");
6393 }
6394 }
6395
6396 /**
6397 * Returns a list of SMS apps on a given user.
6398 *
6399 * Only the shell user (UID 2000 or 0) can call it.
6400 * Target user must be running.
6401 */
6402 @Override
6403 public String[] getSmsApps(int userId) {
6404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6405 ensureUserRunning(userId);
6406
6407 final Collection<SmsApplicationData> apps =
6408 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6409
6410 String[] ret = new String[apps.size()];
6411 int i = 0;
6412 for (SmsApplicationData app : apps) {
6413 ret[i++] = app.mPackageName;
6414 }
6415 return ret;
6416 }
6417
6418 /**
6419 * Returns the default SMS app package name on a given user.
6420 *
6421 * Only the shell user (UID 2000 or 0) can call it.
6422 * Target user must be running.
6423 */
6424 @Override
6425 public String getDefaultSmsApp(int userId) {
6426 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6427 ensureUserRunning(userId);
6428
6429 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6430 /* updateIfNeeded= */ true, userId);
6431 return cn == null ? null : cn.getPackageName();
6432 }
6433
6434 /**
6435 * Set a package as the default SMS app on a given user.
6436 *
6437 * Only the shell user (UID 2000 or 0) can call it.
6438 * Target user must be running.
6439 */
6440 @Override
6441 public void setDefaultSmsApp(int userId, String packageName) {
6442 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6443 ensureUserRunning(userId);
6444
6445 boolean found = false;
6446 for (String pkg : getSmsApps(userId)) {
6447 if (TextUtils.equals(packageName, pkg)) {
6448 found = true;
6449 break;
6450 }
6451 }
6452 if (!found) {
6453 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6454 }
6455
6456 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6457 }
sqianc5eccab2018-10-19 18:46:41 -07006458
6459 @Override
6460 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6461 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6463 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6464 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6465 }
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
sqian854d44b2018-12-12 16:48:18 -08006468 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6469 for (Phone phone: PhoneFactory.getPhones()) {
6470 if (phone.getEmergencyNumberTracker() != null
6471 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6472 emergencyNumberListInternal.put(
6473 phone.getSubId(),
6474 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6475 }
sqian11b7a0e2018-12-05 18:48:28 -08006476 }
sqian854d44b2018-12-12 16:48:18 -08006477 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
sqianc5eccab2018-10-19 18:46:41 -07006481 }
6482
6483 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006484 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006485 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006486 if (!exactMatch) {
6487 TelephonyPermissions
6488 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006489 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006490 }
6491 final long identity = Binder.clearCallingIdentity();
6492 try {
sqian854d44b2018-12-12 16:48:18 -08006493 for (Phone phone: PhoneFactory.getPhones()) {
6494 if (phone.getEmergencyNumberTracker() != null
6495 && phone.getEmergencyNumberTracker() != null) {
6496 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6497 number, exactMatch)) {
6498 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006499 }
6500 }
sqian11b7a0e2018-12-05 18:48:28 -08006501 }
6502 return false;
6503 } finally {
6504 Binder.restoreCallingIdentity(identity);
6505 }
6506 }
6507
sqianf4ca7ed2019-01-15 18:32:07 -08006508 /**
6509 * Update emergency number list for test mode.
6510 */
6511 @Override
6512 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6514 "updateEmergencyNumberListTestMode");
6515
6516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 for (Phone phone: PhoneFactory.getPhones()) {
6519 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6520 if (tracker != null) {
6521 tracker.executeEmergencyNumberTestModeCommand(action, num);
6522 }
6523 }
6524 } finally {
6525 Binder.restoreCallingIdentity(identity);
6526 }
6527 }
6528
6529 /**
6530 * Get the full emergency number list for test mode.
6531 */
6532 @Override
6533 public List<String> getEmergencyNumberListTestMode() {
6534 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6535 "getEmergencyNumberListTestMode");
6536
6537 final long identity = Binder.clearCallingIdentity();
6538 try {
6539 Set<String> emergencyNumbers = new HashSet<>();
6540 for (Phone phone: PhoneFactory.getPhones()) {
6541 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6542 if (tracker != null) {
6543 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6544 emergencyNumbers.add(num.getNumber());
6545 }
6546 }
6547 }
6548 return new ArrayList<>(emergencyNumbers);
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
6552 }
6553
chen xud6b45bd2018-10-30 22:27:10 -07006554 @Override
6555 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6556 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6557 Phone phone = getPhone(subId);
6558 if (phone == null) {
6559 return null;
6560 }
6561 final long identity = Binder.clearCallingIdentity();
6562 try {
6563 UiccProfile profile = UiccController.getInstance()
6564 .getUiccProfileForPhone(phone.getPhoneId());
6565 if (profile != null) {
6566 return profile.getCertsFromCarrierPrivilegeAccessRules();
6567 }
6568 } finally {
6569 Binder.restoreCallingIdentity(identity);
6570 }
6571 return null;
6572 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006573
6574 /**
6575 * Enable or disable a modem stack.
6576 */
6577 @Override
6578 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6579 enforceModifyPermission();
6580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 Phone phone = PhoneFactory.getPhone(slotIndex);
6584 if (phone == null) {
6585 return false;
6586 } else {
6587 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6588 }
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 }
Michelecea4cf22018-12-21 15:00:11 -08006593
6594 @Override
6595 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6596 enforceModifyPermission();
6597
6598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 mTelephonySharedPreferences.edit()
6601 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6602 .commit();
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
6605 }
6606 }
6607
6608 @Override
Michele4245e952019-02-04 11:36:23 -08006609 public boolean isMultisimSupported(String callingPackage) {
6610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6611 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6612 return false;
6613 }
Michelecea4cf22018-12-21 15:00:11 -08006614
6615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6618 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6619 if (numPhysicalSlots < 2) {
Michele4245e952019-02-04 11:36:23 -08006620 loge("isMultisimSupported: requires at least 2 cards");
6621 return false;
6622 }
6623 // Check if the hardware supports multisim functionality. If usage of multisim is not
6624 // supported by the modem, indicate that it is restricted.
6625 PhoneCapability staticCapability =
6626 mPhoneConfigurationManager.getStaticPhoneCapability();
6627 if (staticCapability == null) {
6628 loge("isMultisimSupported: no static configuration available");
6629 return false;
6630 }
6631 if (staticCapability.logicalModemList.size() < 2) {
6632 loge("isMultisimSupported: maximum number of modem is < 2");
6633 return false;
6634 }
6635 // Check if support of multiple SIMs is restricted by carrier
6636 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6637 return false;
Michelecea4cf22018-12-21 15:00:11 -08006638 }
6639
Michele4245e952019-02-04 11:36:23 -08006640 return true;
Michelecea4cf22018-12-21 15:00:11 -08006641 } finally {
6642 Binder.restoreCallingIdentity(identity);
6643 }
6644 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006645
6646 /**
6647 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006648 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6649 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6650 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006651 * @param numOfSims number of active sims we want to switch to
6652 */
6653 @Override
6654 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006655 if (numOfSims == 1) {
6656 enforceModifyPermission();
6657 } else {
6658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6659 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6660 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006661 final long identity = Binder.clearCallingIdentity();
6662 try {
6663 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6664 } finally {
6665 Binder.restoreCallingIdentity(identity);
6666 }
6667 }
6668
6669 /**
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006670 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006671 * Return value defaults to true
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006672 */
6673 @Override
6674 public boolean isRebootRequiredForModemConfigChange() {
6675 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6676 final long identity = Binder.clearCallingIdentity();
6677 try {
6678 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
6682 }
6683
Nathan Harold29f5f052019-02-15 13:41:57 -08006684 private void updateModemStateMetrics() {
6685 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6686 // TODO: check the state for each modem if the api is ready.
6687 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6688 }
6689
Pengquan Meng3889a572019-01-23 11:16:29 -08006690 @Override
6691 public int[] getSlotsMapping() {
6692 enforceReadPrivilegedPermission("getSlotsMapping");
6693
6694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6697 // All logical slots should have a mapping to a physical slot.
6698 int[] logicalSlotsMapping = new int[phoneCount];
6699 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6700 for (int i = 0; i < slotInfos.length; i++) {
6701 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6702 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6703 }
6704 }
6705 return logicalSlotsMapping;
6706 } finally {
6707 Binder.restoreCallingIdentity(identity);
6708 }
6709 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006710
6711 /**
6712 * Get the IRadio HAL Version
6713 */
6714 @Override
6715 public int getRadioHalVersion() {
6716 Phone phone = getDefaultPhone();
6717 if (phone == null) return -1;
6718 HalVersion hv = phone.getHalVersion();
6719 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6720 return hv.major * 100 + hv.minor;
6721 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006722}