blob: 797a5bd584aa23cba34bb07e49af201ecd0abdeb [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 xu0026ca62019-03-06 15:28:50 -08002215 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 final Phone phone = getPhone(subId);
2219 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002220 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002221 } finally {
2222 Binder.restoreCallingIdentity(identity);
2223 }
2224 }
2225
2226 @Override
chen xu0026ca62019-03-06 15:28:50 -08002227 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002231 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002232 } 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,
Hall Liubd069e32019-02-28 18:56:30 -08002469 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002470
2471 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2472 }
2473
Junda Liuca05d5d2014-08-14 22:36:34 -07002474 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 * Returns true if CDMA provisioning needs to run.
2476 */
2477 public boolean needsOtaServiceProvisioning() {
Malcolm 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 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004396 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004397 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004398 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004399 * @hide
4400 */
4401 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004402 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004403 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004405 final Phone defaultPhone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004406 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004407 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 } finally {
4409 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004410 }
Junda Liu475951f2014-11-07 16:45:03 -08004411 }
4412
4413 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004414 * Set mobile data enabled
4415 * Used by the user through settings etc to turn on/off mobile data
4416 *
4417 * @param enable {@code true} turn turn data on, else {@code false}
4418 */
4419 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004420 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4422 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004423
4424 final long identity = Binder.clearCallingIdentity();
4425 try {
4426 int phoneId = mSubscriptionController.getPhoneId(subId);
4427 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4428 Phone phone = PhoneFactory.getPhone(phoneId);
4429 if (phone != null) {
4430 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004431 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004433 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 }
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004437 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004438 }
4439
4440 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004441 * Get the user enabled state of Mobile Data.
4442 *
4443 * TODO: remove and use isUserDataEnabled.
4444 * This can't be removed now because some vendor codes
4445 * calls through ITelephony directly while they should
4446 * use TelephonyManager.
4447 *
4448 * @return true on enabled
4449 */
4450 @Override
4451 public boolean getDataEnabled(int subId) {
4452 return isUserDataEnabled(subId);
4453 }
4454
4455 /**
4456 * Get whether mobile data is enabled per user setting.
4457 *
4458 * There are other factors deciding whether mobile data is actually enabled, but they are
4459 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004460 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004461 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004462 *
4463 * @return {@code true} if data is enabled else {@code false}
4464 */
4465 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004466 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004467 try {
4468 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4469 null);
4470 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4472 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004473 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474
4475 final long identity = Binder.clearCallingIdentity();
4476 try {
4477 int phoneId = mSubscriptionController.getPhoneId(subId);
4478 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4479 Phone phone = PhoneFactory.getPhone(phoneId);
4480 if (phone != null) {
4481 boolean retVal = phone.isUserDataEnabled();
4482 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4483 return retVal;
4484 } else {
4485 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4486 return false;
4487 }
4488 } finally {
4489 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004490 }
4491 }
4492
4493 /**
4494 * Get whether mobile data is enabled.
4495 *
4496 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4497 * whether mobile data is actually enabled.
4498 *
4499 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4500 *
4501 * @return {@code true} if data is enabled else {@code false}
4502 */
4503 @Override
4504 public boolean isDataEnabled(int subId) {
4505 try {
4506 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4507 null);
4508 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004509 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4510 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512
4513 final long identity = Binder.clearCallingIdentity();
4514 try {
4515 int phoneId = mSubscriptionController.getPhoneId(subId);
4516 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4517 Phone phone = PhoneFactory.getPhone(phoneId);
4518 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004519 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4521 return retVal;
4522 } else {
4523 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4524 return false;
4525 }
4526 } finally {
4527 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004528 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004529 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004530
4531 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004532 public int getCarrierPrivilegeStatus(int subId) {
4533 final Phone phone = getPhone(subId);
4534 if (phone == null) {
4535 loge("getCarrierPrivilegeStatus: Invalid subId");
4536 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4537 }
4538 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004539 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004540 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4542 }
4543 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004544 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004545 }
Junda Liu29340342014-07-10 15:23:27 -07004546
4547 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004548 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4549 final Phone phone = getPhone(subId);
4550 if (phone == null) {
4551 loge("getCarrierPrivilegeStatus: Invalid subId");
4552 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4553 }
4554 UiccProfile profile =
4555 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4556 if (profile == null) {
4557 loge("getCarrierPrivilegeStatus: No UICC");
4558 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4559 }
4560 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4561 }
4562
4563 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004564 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004565 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004566 if (TextUtils.isEmpty(pkgName))
4567 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004568 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004569 if (card == null) {
4570 loge("checkCarrierPrivilegesForPackage: No UICC");
4571 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4572 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004573 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4574 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004575 }
4576
4577 @Override
4578 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004579 if (TextUtils.isEmpty(pkgName))
4580 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004581 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4582 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4583 UiccCard card = UiccController.getInstance().getUiccCard(i);
4584 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004585 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004586 continue;
4587 }
4588
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004589 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004590 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4591 break;
4592 }
4593 }
4594
4595 return result;
Junda Liu29340342014-07-10 15:23:27 -07004596 }
Derek Tan89e89d42014-07-08 17:00:10 -07004597
4598 @Override
Junda Liue64de782015-04-16 17:19:16 -07004599 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4600 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4601 loge("phoneId " + phoneId + " is not valid.");
4602 return null;
4603 }
4604 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004605 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004606 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004607 return null ;
4608 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004609 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004610 }
4611
Amith Yamasani6e118872016-02-19 12:53:51 -08004612 @Override
4613 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004614 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004615 List<String> privilegedPackages = new ArrayList<>();
4616 List<PackageInfo> packages = null;
4617 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4618 UiccCard card = UiccController.getInstance().getUiccCard(i);
4619 if (card == null) {
4620 // No UICC in that slot.
4621 continue;
4622 }
4623 if (card.hasCarrierPrivilegeRules()) {
4624 if (packages == null) {
4625 // Only check packages in user 0 for now
4626 packages = pm.getInstalledPackagesAsUser(
4627 PackageManager.MATCH_DISABLED_COMPONENTS
4628 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4629 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4630 }
4631 for (int p = packages.size() - 1; p >= 0; p--) {
4632 PackageInfo pkgInfo = packages.get(p);
4633 if (pkgInfo != null && pkgInfo.packageName != null
4634 && card.getCarrierPrivilegeStatus(pkgInfo)
4635 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4636 privilegedPackages.add(pkgInfo.packageName);
4637 }
4638 }
4639 }
4640 }
4641 return privilegedPackages;
4642 }
4643
Wink Savilleb564aae2014-10-23 10:18:09 -07004644 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004645 final Phone phone = getPhone(subId);
4646 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004647 if (card == null) {
4648 loge("getIccId: No UICC");
4649 return null;
4650 }
4651 String iccId = card.getIccId();
4652 if (TextUtils.isEmpty(iccId)) {
4653 loge("getIccId: ICC ID is null or empty.");
4654 return null;
4655 }
4656 return iccId;
4657 }
4658
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004659 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004660 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4661 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004662 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4663 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004664
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 final String iccId = getIccId(subId);
4668 final Phone phone = getPhone(subId);
4669 if (phone == null) {
4670 return false;
4671 }
4672 final String subscriberId = phone.getSubscriberId();
4673
4674 if (DBG_MERGE) {
4675 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4676 + subscriberId + " to " + number);
4677 }
4678
4679 if (TextUtils.isEmpty(iccId)) {
4680 return false;
4681 }
4682
4683 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4684
4685 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4686 if (alphaTag == null) {
4687 editor.remove(alphaTagPrefKey);
4688 } else {
4689 editor.putString(alphaTagPrefKey, alphaTag);
4690 }
4691
4692 // Record both the line number and IMSI for this ICCID, since we need to
4693 // track all merged IMSIs based on line number
4694 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4695 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4696 if (number == null) {
4697 editor.remove(numberPrefKey);
4698 editor.remove(subscriberPrefKey);
4699 } else {
4700 editor.putString(numberPrefKey, number);
4701 editor.putString(subscriberPrefKey, subscriberId);
4702 }
4703
4704 editor.commit();
4705 return true;
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004708 }
Derek Tan7226c842014-07-02 17:42:23 -07004709 }
4710
4711 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004712 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004713 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004714 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004715 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004716 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004717 return null;
4718 }
Derek Tan97ebb422014-09-05 16:55:38 -07004719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 final long identity = Binder.clearCallingIdentity();
4721 try {
4722 String iccId = getIccId(subId);
4723 if (iccId != null) {
4724 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4725 if (DBG_MERGE) {
4726 log("getLine1NumberForDisplay returning "
4727 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4728 }
4729 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004730 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4732 return null;
4733 } finally {
4734 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004735 }
Derek Tan7226c842014-07-02 17:42:23 -07004736 }
4737
4738 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004739 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004740 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004741 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004742 return null;
4743 }
Derek Tan97ebb422014-09-05 16:55:38 -07004744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 final long identity = Binder.clearCallingIdentity();
4746 try {
4747 String iccId = getIccId(subId);
4748 if (iccId != null) {
4749 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4750 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4751 }
4752 return null;
4753 } finally {
4754 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004755 }
Derek Tan7226c842014-07-02 17:42:23 -07004756 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004757
4758 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004759 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004760 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4761 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004763 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4764 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004765 return null;
4766 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004767
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004768 final long identity = Binder.clearCallingIdentity();
4769 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004770 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004771 final TelephonyManager tele = TelephonyManager.from(context);
4772 final SubscriptionManager sub = SubscriptionManager.from(context);
4773
4774 // Figure out what subscribers are currently active
4775 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4776 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4777 // the process, where TelephonyManager was instantiated.
4778 // Otherwise AppOps check will fail.
4779
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004780 final int[] subIds = sub.getActiveSubscriptionIdList();
4781 for (int subId : subIds) {
4782 activeSubscriberIds.add(tele.getSubscriberId(subId));
4783 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784
4785 // First pass, find a number override for an active subscriber
4786 String mergeNumber = null;
4787 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4788 for (String key : prefs.keySet()) {
4789 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4790 final String subscriberId = (String) prefs.get(key);
4791 if (activeSubscriberIds.contains(subscriberId)) {
4792 final String iccId = key.substring(
4793 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4794 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4795 mergeNumber = (String) prefs.get(numberKey);
4796 if (DBG_MERGE) {
4797 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4798 + " for active subscriber " + subscriberId);
4799 }
4800 if (!TextUtils.isEmpty(mergeNumber)) {
4801 break;
4802 }
4803 }
4804 }
4805 }
4806
4807 // Shortcut when no active merged subscribers
4808 if (TextUtils.isEmpty(mergeNumber)) {
4809 return null;
4810 }
4811
4812 // Second pass, find all subscribers under that line override
4813 final ArraySet<String> result = new ArraySet<>();
4814 for (String key : prefs.keySet()) {
4815 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4816 final String number = (String) prefs.get(key);
4817 if (mergeNumber.equals(number)) {
4818 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4819 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4820 final String subscriberId = (String) prefs.get(subscriberKey);
4821 if (!TextUtils.isEmpty(subscriberId)) {
4822 result.add(subscriberId);
4823 }
4824 }
4825 }
4826 }
4827
4828 final String[] resultArray = result.toArray(new String[result.size()]);
4829 Arrays.sort(resultArray);
4830 if (DBG_MERGE) {
4831 Slog.d(LOG_TAG,
4832 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4833 }
4834 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004835 } finally {
4836 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004837 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004838 }
4839
4840 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004841 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004842 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4843 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844
4845 final long identity = Binder.clearCallingIdentity();
4846 try {
4847 final Phone phone = getPhone(subId);
4848 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4849 } finally {
4850 Binder.restoreCallingIdentity(identity);
4851 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004852 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004853
4854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004855 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004856 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4857 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859
4860 final long identity = Binder.clearCallingIdentity();
4861 try {
4862 final Phone phone = getPhone(subId);
4863 if (phone == null) {
4864 return false;
4865 }
4866 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4867 cdmaNonRoamingList);
4868 } finally {
4869 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004870 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004871 }
4872
4873 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004874 @Deprecated
4875 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4876 enforceModifyPermission();
4877
4878 int returnValue = 0;
4879 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07004880 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004881 if(result.exception == null) {
4882 if (result.result != null) {
4883 byte[] responseData = (byte[])(result.result);
4884 if(responseData.length > oemResp.length) {
4885 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4886 responseData.length + "bytes. Buffer Size is " +
4887 oemResp.length + "bytes.");
4888 }
4889 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4890 returnValue = responseData.length;
4891 }
4892 } else {
4893 CommandException ex = (CommandException) result.exception;
4894 returnValue = ex.getCommandError().ordinal();
4895 if(returnValue > 0) returnValue *= -1;
4896 }
4897 } catch (RuntimeException e) {
4898 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4899 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4900 if(returnValue > 0) returnValue *= -1;
4901 }
4902
4903 return returnValue;
4904 }
4905
4906 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004907 public void setRadioCapability(RadioAccessFamily[] rafs) {
4908 try {
4909 ProxyController.getInstance().setRadioCapability(rafs);
4910 } catch (RuntimeException e) {
4911 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4912 }
4913 }
4914
4915 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004916 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004917 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07004918 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004919 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07004920 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004921 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004922 final long identity = Binder.clearCallingIdentity();
4923 try {
chen xub97461a2018-10-26 14:17:57 -07004924 TelephonyPermissions
4925 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4926 mApp, phone.getSubId(), "getRadioAccessFamily");
4927 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 } finally {
4929 Binder.restoreCallingIdentity(identity);
4930 }
chen xub97461a2018-10-26 14:17:57 -07004931 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004932 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004933
4934 @Override
4935 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004937 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004938
4939 final long identity = Binder.clearCallingIdentity();
4940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004941 ImsManager.getInstance(defaultPhone.getContext(),
4942 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004946 }
4947
4948 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004949 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004950 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004951 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004952 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004953 return false;
4954 }
Svet Ganovb320e182015-04-16 12:30:10 -07004955
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 // Check the user preference and the system-level IMS setting. Even if the user has
4959 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4960 // In the long run, we may instead need to check if there exists a connection service
4961 // which can support video calling.
4962 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004963 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 return imsManager.isVtEnabledByPlatform()
4965 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4966 && imsManager.isVtEnabledByUser();
4967 } finally {
4968 Binder.restoreCallingIdentity(identity);
4969 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004970 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004971
Andrew Leea1239f22015-03-02 17:44:07 -08004972 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004973 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4974 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4975 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4976 return false;
4977 }
4978
4979 final long identity = Binder.clearCallingIdentity();
4980 try {
4981 CarrierConfigManager configManager =
4982 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004983 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Andrew Leea1239f22015-03-02 17:44:07 -08004988 }
4989
4990 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991 public boolean isWorldPhone(int subId, String callingPackage) {
4992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4993 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4994 return false;
4995 }
4996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
4999 CarrierConfigManager configManager =
5000 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005001 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5003 } finally {
5004 Binder.restoreCallingIdentity(identity);
5005 }
Andrew Leea1239f22015-03-02 17:44:07 -08005006 }
5007
Andrew Lee9431b832015-03-09 18:46:45 -07005008 @Override
5009 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005010 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005011 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005012 }
5013
5014 @Override
5015 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
5017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005018 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 } finally {
5020 Binder.restoreCallingIdentity(identity);
5021 }
Andrew Lee9431b832015-03-09 18:46:45 -07005022 }
5023
Hall Liuf6668912018-10-31 17:05:23 -07005024 /**
5025 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5026 * support for the feature and device firmware support.
5027 *
5028 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5029 */
5030 @Override
5031 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005033 final Phone phone = getPhone(subscriptionId);
5034 if (phone == null) {
5035 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5036 return false;
5037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005039 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5041 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005042 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043 return isCarrierSupported && isDeviceSupported;
5044 } finally {
5045 Binder.restoreCallingIdentity(identity);
5046 }
Hall Liu98187582018-01-22 19:15:32 -08005047 }
5048
Hall Liuf6668912018-10-31 17:05:23 -07005049 /**
5050 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5051 * both also support RTT.
5052 */
5053 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Hall Liuf6668912018-10-31 17:05:23 -07005056 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005057 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005061 }
5062
Sanket Padawe7310cc72015-01-14 09:53:20 -08005063 /**
5064 * Returns the unique device ID of phone, for example, the IMEI for
5065 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5066 *
5067 * <p>Requires Permission:
5068 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5069 */
5070 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005071 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005072 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005073 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005074 return null;
5075 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005076 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005077 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5078 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005079 return null;
5080 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081
5082 final long identity = Binder.clearCallingIdentity();
5083 try {
5084 return phone.getDeviceId();
5085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005088 }
5089
Ping Sunc67b7c22016-03-02 19:16:45 +08005090 /**
5091 * {@hide}
5092 * Returns the IMS Registration Status on a particular subid
5093 *
5094 * @param subId
5095 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005096 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005097 Phone phone = getPhone(subId);
5098 if (phone != null) {
5099 return phone.isImsRegistered();
5100 } else {
5101 return false;
5102 }
5103 }
5104
Santos Cordon7a1885b2015-02-03 11:15:19 -08005105 @Override
5106 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005113 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005114
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005115 /**
5116 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005117 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005118 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 final long identity = Binder.clearCallingIdentity();
5120 try {
5121 Phone phone = getPhone(subId);
5122 if (phone != null) {
5123 return phone.isWifiCallingEnabled();
5124 } else {
5125 return false;
5126 }
5127 } finally {
5128 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005129 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005130 }
5131
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005132 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005133 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005134 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005135 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 final long identity = Binder.clearCallingIdentity();
5137 try {
5138 Phone phone = getPhone(subId);
5139 if (phone != null) {
5140 return phone.isVideoEnabled();
5141 } else {
5142 return false;
5143 }
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005146 }
5147 }
5148
5149 /**
5150 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5151 * defined in {@link ImsRegistrationImplBase}.
5152 */
5153 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154 final long identity = Binder.clearCallingIdentity();
5155 try {
5156 Phone phone = getPhone(subId);
5157 if (phone != null) {
5158 return phone.getImsRegistrationTech();
5159 } else {
5160 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5161 }
5162 } finally {
5163 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005164 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005165 }
5166
Stuart Scott8eef64f2015-04-08 15:13:54 -07005167 @Override
5168 public void factoryReset(int subId) {
5169 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005170 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5171 return;
5172 }
5173
Svet Ganovcc087f82015-05-12 20:35:54 -07005174 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005175
Svet Ganovcc087f82015-05-12 20:35:54 -07005176 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005177 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5178 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005179 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005180 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005181 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005182 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5183 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005184 }
5185 } finally {
5186 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005187 }
5188 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005189
5190 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005191 public String getSimLocaleForSubscriber(int subId) {
5192 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5193 final Phone phone = getPhone(subId);
5194 if (phone == null) {
5195 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005196 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005197 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 final long identity = Binder.clearCallingIdentity();
5199 try {
chen xu5d3637b2019-01-21 23:31:38 -08005200 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5201 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005202 if (info == null) {
5203 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5204 return null;
5205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005206 // Try and fetch the locale from the carrier properties or from the SIM language
5207 // preferences (EF-PL and EF-LI)...
5208 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005210 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5211 if (localeFromDefaultSim != null) {
5212 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5213 if (DBG) log("Using locale from subId: " + subId + " locale: "
5214 + localeFromDefaultSim);
5215 return localeFromDefaultSim.toLanguageTag();
5216 } else {
5217 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 }
5219 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005220
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005221 // The SIM language preferences only store a language (e.g. fr = French), not an
5222 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5223 // the SIM and carrier preferences does not include a country we add the country
5224 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005225 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005226 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005227 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 return mccLocale.toLanguageTag();
5229 }
5230
5231 if (DBG) log("No locale found - returning null");
5232 return null;
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005236 }
5237
5238 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005239 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005240 }
5241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 /**
5243 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5244 */
5245 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005246 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005247 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005248
Chenjie Yu1ba97252018-01-11 18:16:20 -08005249 private final ModemActivityInfo mLastModemActivityInfo =
5250 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5251
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005252 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005253 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5254 * representing the state of the modem.
5255 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005256 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5257 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005258 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005259 */
5260 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005261 public void requestModemActivityInfo(ResultReceiver result) {
5262 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005263 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 ModemActivityInfo ret = null;
5268 synchronized (mLastModemActivityInfo) {
5269 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5270 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005271 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005272 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5274 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005275 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5276 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 }
5278 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005279 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5280 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 mLastModemActivityInfo.setIdleTimeMillis(
5282 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5283 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5284 mLastModemActivityInfo.setRxTimeMillis(
5285 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5286 mLastModemActivityInfo.setEnergyUsed(
5287 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005289 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5290 mLastModemActivityInfo.getSleepTimeMillis(),
5291 mLastModemActivityInfo.getIdleTimeMillis(),
5292 mLastModemActivityInfo.getTxTimeMillis(),
5293 mLastModemActivityInfo.getRxTimeMillis(),
5294 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296 Bundle bundle = new Bundle();
5297 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5298 result.send(0, bundle);
5299 } finally {
5300 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005301 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005302 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005303
Siddharth Rayb8114062018-06-17 15:02:38 -07005304 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5305 // less than total activity duration.
5306 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5307 if (info == null) {
5308 return false;
5309 }
5310 int activityDurationMs =
5311 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5312 int totalTxTimeMs = 0;
5313 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5314 totalTxTimeMs += info.getTxTimeMillis()[i];
5315 }
5316 return (info.isValid()
5317 && (info.getSleepTimeMillis() <= activityDurationMs)
5318 && (info.getIdleTimeMillis() <= activityDurationMs)
5319 && (info.getRxTimeMillis() <= activityDurationMs)
5320 && (totalTxTimeMs <= activityDurationMs));
5321 }
5322
Jack Yu85bd38a2015-11-09 11:34:32 -08005323 /**
5324 * {@hide}
5325 * Returns the service state information on specified subscription.
5326 */
5327 @Override
5328 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005330 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005331 return null;
5332 }
5333
Hall Liuf19c44f2018-11-27 14:38:17 -08005334 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5335 LocationAccessPolicy.checkLocationPermission(mApp,
5336 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5337 .setCallingPackage(callingPackage)
5338 .setCallingPid(Binder.getCallingPid())
5339 .setCallingUid(Binder.getCallingUid())
5340 .setMethod("getServiceStateForSubscriber")
5341 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5342 .build());
5343
5344 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5345 LocationAccessPolicy.checkLocationPermission(mApp,
5346 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5347 .setCallingPackage(callingPackage)
5348 .setCallingPid(Binder.getCallingPid())
5349 .setCallingUid(Binder.getCallingUid())
5350 .setMethod("getServiceStateForSubscriber")
5351 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5352 .build());
5353 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5354 boolean hasFinePermission =
5355 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5356 boolean hasCoarsePermission =
5357 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5358
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 final long identity = Binder.clearCallingIdentity();
5360 try {
5361 final Phone phone = getPhone(subId);
5362 if (phone == null) {
5363 return null;
5364 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005365
Hall Liuf19c44f2018-11-27 14:38:17 -08005366 ServiceState ss = phone.getServiceState();
5367
5368 // Scrub out the location info in ServiceState depending on what level of access
5369 // the caller has.
5370 if (hasFinePermission) return ss;
5371 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5372 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005376 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005377
5378 /**
5379 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5380 *
5381 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5382 * voicemail ringtone.
5383 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5384 * PhoneAccount.
5385 */
5386 @Override
5387 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5391 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005392 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005393 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005394
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005399 }
5400
5401 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005402 * Sets the per-account voicemail ringtone.
5403 *
5404 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5405 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5406 *
5407 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5408 * voicemail ringtone.
5409 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5410 * PhoneAccount.
5411 */
5412 @Override
5413 public void setVoicemailRingtoneUri(String callingPackage,
5414 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005415 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005416 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5417 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005418 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5420 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5421 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005422 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5427 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005428 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 }
5430 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5431 } finally {
5432 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005433 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005434 }
5435
5436 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005437 * Returns whether vibration is set for voicemail notification in Phone settings.
5438 *
5439 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5440 * voicemail vibration setting.
5441 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5442 */
5443 @Override
5444 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
5447 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5448 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005449 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005451
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5453 } finally {
5454 Binder.restoreCallingIdentity(identity);
5455 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005456 }
5457
Youhan Wange64578a2016-05-02 15:32:42 -07005458 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005459 * Sets the per-account voicemail vibration.
5460 *
5461 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5462 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5463 *
5464 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5465 * voicemail vibration setting.
5466 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5467 * specific PhoneAccount.
5468 */
5469 @Override
5470 public void setVoicemailVibrationEnabled(String callingPackage,
5471 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005472 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5474 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005475 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5477 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5478 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005479 }
5480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5484 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005485 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005486 }
5487 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5488 } finally {
5489 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005490 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005491 }
5492
5493 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005494 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5495 *
5496 * @throws SecurityException if the caller does not have the required permission
5497 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005498 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005499 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005500 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005501 }
5502
5503 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005504 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5505 * permission.
5506 *
5507 * @throws SecurityException if the caller does not have the required permission
5508 */
5509 private void enforceSendSmsPermission() {
5510 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5511 }
5512
5513 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005514 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005515 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005516 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005517 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005518 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005522 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005523 if (componentName == null) {
5524 throw new SecurityException(
5525 "Caller not current active visual voicemail package[null]");
5526 }
5527 String vvmPackage = componentName.getPackageName();
5528 if (!callingPackage.equals(vvmPackage)) {
5529 throw new SecurityException("Caller not current active visual voicemail package["
5530 + vvmPackage + "]");
5531 }
5532 } finally {
5533 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005534 }
5535 }
5536
5537 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005538 * Return the application ID for the app type.
5539 *
5540 * @param subId the subscription ID that this request applies to.
5541 * @param appType the uicc app type.
5542 * @return Application ID for specificied app type, or null if no uicc.
5543 */
5544 @Override
5545 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005546 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005547 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548
5549 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005550 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 if (phone == null) {
5552 return null;
5553 }
5554 String aid = null;
5555 try {
5556 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5557 .getApplicationByType(appType).getAid();
5558 } catch (Exception e) {
5559 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5560 }
5561 return aid;
5562 } finally {
5563 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005564 }
Youhan Wange64578a2016-05-02 15:32:42 -07005565 }
5566
Youhan Wang4001d252016-05-11 10:29:41 -07005567 /**
5568 * Return the Electronic Serial Number.
5569 *
5570 * @param subId the subscription ID that this request applies to.
5571 * @return ESN or null if error.
5572 */
5573 @Override
5574 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005575 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005576 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005577
5578 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005579 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005580 if (phone == null) {
5581 return null;
5582 }
5583 String esn = null;
5584 try {
5585 esn = phone.getEsn();
5586 } catch (Exception e) {
5587 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5588 }
5589 return esn;
5590 } finally {
5591 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005592 }
Youhan Wang4001d252016-05-11 10:29:41 -07005593 }
5594
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005595 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005596 * Return the Preferred Roaming List Version.
5597 *
5598 * @param subId the subscription ID that this request applies to.
5599 * @return PRLVersion or null if error.
5600 */
5601 @Override
5602 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005603 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005604 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605
5606 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005607 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005608 if (phone == null) {
5609 return null;
5610 }
5611 String cdmaPrlVersion = null;
5612 try {
5613 cdmaPrlVersion = phone.getCdmaPrlVersion();
5614 } catch (Exception e) {
5615 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5616 }
5617 return cdmaPrlVersion;
5618 } finally {
5619 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005620 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005621 }
5622
5623 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005624 * Get snapshot of Telephony histograms
5625 * @return List of Telephony histograms
5626 * @hide
5627 */
5628 @Override
5629 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005630 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5631 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 return RIL.getTelephonyRILTimingHistograms();
5636 } finally {
5637 Binder.restoreCallingIdentity(identity);
5638 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005639 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005640
5641 /**
5642 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005643 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5644 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005645 * Require system privileges. In the future we may add this to carrier APIs.
5646 *
Michele Berionne482f8202018-11-27 18:57:59 -08005647 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005648 */
5649 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005650 @TelephonyManager.SetCarrierRestrictionResult
5651 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005652 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005653 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005654
Michele Berionne482f8202018-11-27 18:57:59 -08005655 if (carrierRestrictionRules == null) {
5656 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005657 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659 final long identity = Binder.clearCallingIdentity();
5660 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005661 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005662 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005663 } finally {
5664 Binder.restoreCallingIdentity(identity);
5665 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005666 }
5667
5668 /**
5669 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005670 * Get the allowed carrier list and the excluded carrier list, including the priority between
5671 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005672 * Require system privileges. In the future we may add this to carrier APIs.
5673 *
Michele Berionne482f8202018-11-27 18:57:59 -08005674 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005675 */
5676 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005677 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005678 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07005679 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680
5681 final long identity = Binder.clearCallingIdentity();
5682 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005683 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5684 if (response instanceof CarrierRestrictionRules) {
5685 return (CarrierRestrictionRules) response;
5686 }
5687 // Response is an Exception of some kind,
5688 // which is signalled to the user as a NULL retval
5689 return null;
5690 } catch (Exception e) {
5691 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5692 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693 } finally {
5694 Binder.restoreCallingIdentity(identity);
5695 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005696 }
5697
fionaxu59545b42016-05-25 15:53:37 -07005698 /**
5699 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5700 * @param subId the subscription ID that this action applies to.
5701 * @param enabled control enable or disable metered apns.
5702 * {@hide}
5703 */
5704 @Override
5705 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5706 enforceModifyPermission();
5707 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708
5709 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005710 if (phone == null) {
5711 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5712 return;
5713 }
5714 try {
5715 phone.carrierActionSetMeteredApnsEnabled(enabled);
5716 } catch (Exception e) {
5717 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005718 } finally {
5719 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005720 }
5721 }
5722
5723 /**
5724 * Action set from carrier signalling broadcast receivers to enable/disable radio
5725 * @param subId the subscription ID that this action applies to.
5726 * @param enabled control enable or disable radio.
5727 * {@hide}
5728 */
5729 @Override
5730 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5731 enforceModifyPermission();
5732 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005733
5734 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005735 if (phone == null) {
5736 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5737 return;
5738 }
5739 try {
5740 phone.carrierActionSetRadioEnabled(enabled);
5741 } catch (Exception e) {
5742 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005743 } finally {
5744 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005745 }
5746 }
5747
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005748 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005749 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5750 * network status based on which carrier apps could apply actions accordingly,
5751 * enable/disable default url handler for example.
5752 *
5753 * @param subId the subscription ID that this action applies to.
5754 * @param report control start/stop reporting the default network status.
5755 * {@hide}
5756 */
5757 @Override
5758 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5759 enforceModifyPermission();
5760 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005761
5762 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005763 if (phone == null) {
5764 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5765 return;
5766 }
5767 try {
5768 phone.carrierActionReportDefaultNetworkStatus(report);
5769 } catch (Exception e) {
5770 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 } finally {
5772 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005773 }
5774 }
5775
5776 /**
fionaxud9622282017-07-17 17:51:30 -07005777 * Action set from carrier signalling broadcast receivers to reset all carrier actions
5778 * @param subId the subscription ID that this action applies to.
5779 * {@hide}
5780 */
5781 @Override
5782 public void carrierActionResetAll(int subId) {
5783 enforceModifyPermission();
5784 final Phone phone = getPhone(subId);
5785 if (phone == null) {
5786 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
5787 return;
5788 }
5789 try {
5790 phone.carrierActionResetAll();
5791 } catch (Exception e) {
5792 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
5793 }
5794 }
5795
5796 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005797 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5798 * bug report is being generated.
5799 */
5800 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005801 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005802 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5803 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005804 writer.println("Permission Denial: can't dump Phone from pid="
5805 + Binder.getCallingPid()
5806 + ", uid=" + Binder.getCallingUid()
5807 + "without permission "
5808 + android.Manifest.permission.DUMP);
5809 return;
5810 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005811 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005812 }
Jack Yueb89b242016-06-22 13:27:47 -07005813
Brad Ebingerdac2f002018-04-03 15:17:52 -07005814 @Override
5815 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5816 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5817 throws RemoteException {
5818 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5819 }
5820
Jack Yueb89b242016-06-22 13:27:47 -07005821 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005822 * Get aggregated video call data usage since boot.
5823 *
5824 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5825 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005826 * {@hide}
5827 */
5828 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005829 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005830 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5831 null);
5832
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005833 final long identity = Binder.clearCallingIdentity();
5834 try {
5835 // NetworkStatsService keeps tracking the active network interface and identity. It
5836 // records the delta with the corresponding network identity.
5837 // We just return the total video call data usage snapshot since boot.
5838 Phone phone = getPhone(subId);
5839 if (phone != null) {
5840 return phone.getVtDataUsage(perUidStats);
5841 }
5842 return null;
5843 } finally {
5844 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005845 }
Jack Yueb89b242016-06-22 13:27:47 -07005846 }
Jack Yu75ab2952016-07-08 14:29:33 -07005847
5848 /**
5849 * Policy control of data connection. Usually used when data limit is passed.
5850 * @param enabled True if enabling the data, otherwise disabling.
5851 * @param subId Subscription index
5852 * {@hide}
5853 */
5854 @Override
5855 public void setPolicyDataEnabled(boolean enabled, int subId) {
5856 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005857
5858 final long identity = Binder.clearCallingIdentity();
5859 try {
5860 Phone phone = getPhone(subId);
5861 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005862 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005863 }
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005866 }
5867 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005868
5869 /**
5870 * Get Client request stats
5871 * @return List of Client Request Stats
5872 * @hide
5873 */
5874 @Override
5875 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005877 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005878 return null;
5879 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005880 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 final long identity = Binder.clearCallingIdentity();
5883 try {
5884 if (phone != null) {
5885 return phone.getClientRequestStats();
5886 }
5887
5888 return null;
5889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005892 }
5893
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005894 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005895 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005896 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005897 }
Jack Yueb4124c2017-02-16 15:32:43 -08005898
5899 /**
Grace Chen70990072017-03-24 17:21:30 -07005900 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005901 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005902 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005903 * @param state State of SIM (power down, power up, pass through)
5904 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5905 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5906 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005907 *
5908 **/
5909 @Override
Grace Chen70990072017-03-24 17:21:30 -07005910 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005911 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005912 Phone phone = PhoneFactory.getPhone(slotIndex);
5913
vagdeviaf9a5b92018-08-15 16:01:53 -07005914 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916 final long identity = Binder.clearCallingIdentity();
5917 try {
5918 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005919 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005920 }
5921 } finally {
5922 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005923 }
5924 }
Shuo Qiandd210312017-04-12 22:11:33 +00005925
Tyler Gunn65d45c22017-06-05 11:22:26 -07005926 private boolean isUssdApiAllowed(int subId) {
5927 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005928 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005929 if (configManager == null) {
5930 return false;
5931 }
5932 PersistableBundle pb = configManager.getConfigForSubId(subId);
5933 if (pb == null) {
5934 return false;
5935 }
5936 return pb.getBoolean(
5937 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5938 }
5939
Shuo Qiandd210312017-04-12 22:11:33 +00005940 /**
5941 * Check if phone is in emergency callback mode
5942 * @return true if phone is in emergency callback mode
5943 * @param subId sub id
5944 */
goneil9c5f4872017-12-05 14:07:56 -08005945 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005946 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005947 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005948 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 if (phone != null) {
5953 return phone.isInEcm();
5954 } else {
5955 return false;
5956 }
5957 } finally {
5958 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005959 }
5960 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005961
5962 /**
5963 * Get the current signal strength information for the given subscription.
5964 * Because this information is not updated when the device is in a low power state
5965 * it should not be relied-upon to be current.
5966 * @param subId Subscription index
5967 * @return the most recent cached signal strength info from the modem
5968 */
5969 @Override
5970 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005971 final long identity = Binder.clearCallingIdentity();
5972 try {
5973 Phone p = getPhone(subId);
5974 if (p == null) {
5975 return null;
5976 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005978 return p.getSignalStrength();
5979 } finally {
5980 Binder.restoreCallingIdentity(identity);
5981 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005982 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005983
Pengquan Meng77b7f132018-08-22 14:49:57 -07005984 /**
Chen Xuf792fd62018-10-17 17:54:36 +00005985 * Get the current modem radio state for the given slot.
5986 * @param slotIndex slot index.
5987 * @param callingPackage the name of the package making the call.
5988 * @return the current radio power state from the modem
5989 */
5990 @Override
5991 public int getRadioPowerState(int slotIndex, String callingPackage) {
5992 Phone phone = PhoneFactory.getPhone(slotIndex);
5993 if (phone != null) {
5994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5995 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5996 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5997 }
5998
5999 final long identity = Binder.clearCallingIdentity();
6000 try {
6001 return phone.getRadioPowerState();
6002 } finally {
6003 Binder.restoreCallingIdentity(identity);
6004 }
6005 }
6006 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6007 }
6008
6009 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006010 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6011 *
6012 * <p>Requires one of the following permissions:
6013 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6014 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6015 * privileges.
6016 *
6017 * @param subId subscription id
6018 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6019 * {@code false}.
6020 */
6021 @Override
6022 public boolean isDataRoamingEnabled(int subId) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006023 boolean isEnabled = false;
6024 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006025 try {
6026 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Menga1bb6272018-09-06 09:59:22 -07006027 null /* message */);
6028 Phone phone = getPhone(subId);
6029 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006030 } catch (Exception e) {
6031 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6032 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006035 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006036 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006037 }
6038
6039
6040 /**
6041 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6042 *
6043 * <p> Requires permission:
6044 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6045 * privileges.
6046 *
6047 * @param subId subscription id
6048 * @param isEnabled {@code true} means enable, {@code false} means disable.
6049 */
6050 @Override
6051 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6055 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng77b7f132018-08-22 14:49:57 -07006056
Pengquan Menga1bb6272018-09-06 09:59:22 -07006057 Phone phone = getPhone(subId);
6058 if (phone != null) {
6059 phone.setDataRoamingEnabled(isEnabled);
6060 }
6061 } finally {
6062 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006063 }
6064 }
6065
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006066 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006067 public boolean isManualNetworkSelectionAllowed(int subId) {
6068 boolean isAllowed = true;
6069 final long identity = Binder.clearCallingIdentity();
6070 try {
6071 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6072 mApp, subId, "isManualNetworkSelectionAllowed");
6073 Phone phone = getPhone(subId);
6074 if (phone != null) {
6075 isAllowed = phone.isCspPlmnEnabled();
6076 }
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
6079 }
6080 return isAllowed;
6081 }
6082
6083 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006084 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liuc65bc952019-02-12 17:54:02 -08006085 try {
6086 enforceReadPrivilegedPermission("getUiccCardsInfo");
6087 } catch (SecurityException e) {
6088 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6089 // has carrier privileges on an active UICC
6090 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6091 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6092 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6093 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006094 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006095
6096 final long identity = Binder.clearCallingIdentity();
6097 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006098 UiccController uiccController = UiccController.getInstance();
6099 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6100
6101 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6102 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6103 // Remove private info if the caller doesn't have access
6104 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6105 for (UiccCardInfo cardInfo : cardInfos) {
6106 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6107 UiccProfile profile = card.getUiccProfile();
6108 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6109 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6110 filteredInfos.add(cardInfo.getUnprivileged());
6111 } else {
6112 filteredInfos.add(cardInfo);
6113 }
6114 }
6115 return filteredInfos;
6116 }
6117 return cardInfos;
6118 } catch (PackageManager.NameNotFoundException e) {
6119 // This should not happen since we pass the package info in from TelephonyManager
6120 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006121 } finally {
6122 Binder.restoreCallingIdentity(identity);
6123 }
6124 }
6125
6126 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006127 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006128 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006129
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6133 if (slots == null) {
6134 Rlog.i(LOG_TAG, "slots is null.");
6135 return null;
6136 }
6137
6138 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6139 for (int i = 0; i < slots.length; i++) {
6140 UiccSlot slot = slots[i];
6141 if (slot == null) {
6142 continue;
6143 }
6144
6145 String cardId;
6146 UiccCard card = slot.getUiccCard();
6147 if (card != null) {
6148 cardId = card.getCardId();
6149 } else {
6150 cardId = slot.getIccId();
6151 }
6152
6153 int cardState = 0;
6154 switch (slot.getCardState()) {
6155 case CARDSTATE_ABSENT:
6156 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6157 break;
6158 case CARDSTATE_PRESENT:
6159 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6160 break;
6161 case CARDSTATE_ERROR:
6162 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6163 break;
6164 case CARDSTATE_RESTRICTED:
6165 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6166 break;
6167 default:
6168 break;
6169
6170 }
6171
6172 infos[i] = new UiccSlotInfo(
6173 slot.isActive(),
6174 slot.isEuicc(),
6175 cardId,
6176 cardState,
6177 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006178 slot.isExtendedApduSupported(),
6179 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 }
6181 return infos;
6182 } finally {
6183 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006184 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006185 }
6186
6187 @Override
6188 public boolean switchSlots(int[] physicalSlots) {
6189 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190
6191 final long identity = Binder.clearCallingIdentity();
6192 try {
6193 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6194 } finally {
6195 Binder.restoreCallingIdentity(identity);
6196 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006197 }
Jack Yu4c988042018-02-27 15:30:01 -08006198
6199 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006200 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006201 final long identity = Binder.clearCallingIdentity();
6202 try {
6203 return UiccController.getInstance().getCardIdForDefaultEuicc();
6204 } finally {
6205 Binder.restoreCallingIdentity(identity);
6206 }
6207 }
6208
6209 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006210 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6211 enforceModifyPermission();
6212 final Phone phone = getPhone(subId);
6213 if (phone == null) {
6214 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6215 return;
6216 }
6217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006218 final long identity = Binder.clearCallingIdentity();
6219 try {
6220 phone.setRadioIndicationUpdateMode(filters, mode);
6221 } finally {
6222 Binder.restoreCallingIdentity(identity);
6223 }
Jack Yu4c988042018-02-27 15:30:01 -08006224 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006225
6226 /**
goneil47ffb6e2018-04-06 15:40:58 -07006227 * A test API to reload the UICC profile.
6228 *
6229 * <p>Requires that the calling app has permission
6230 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6231 * @hide
6232 */
6233 @Override
6234 public void refreshUiccProfile(int subId) {
6235 enforceModifyPermission();
6236
6237 final long identity = Binder.clearCallingIdentity();
6238 try {
6239 Phone phone = getPhone(subId);
6240 if (phone == null) {
6241 return;
6242 }
6243 UiccCard uiccCard = phone.getUiccCard();
6244 if (uiccCard == null) {
6245 return;
6246 }
6247 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6248 if (uiccProfile == null) {
6249 return;
6250 }
6251 uiccProfile.refresh();
6252 } finally {
6253 Binder.restoreCallingIdentity(identity);
6254 }
6255 }
6256
6257 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006258 * Returns false if the mobile data is disabled by default, otherwise return true.
6259 */
6260 private boolean getDefaultDataEnabled() {
6261 return "true".equalsIgnoreCase(
6262 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6263 }
6264
6265 /**
6266 * Returns true if the data roaming is enabled by default, i.e the system property
6267 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6268 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6269 */
6270 private boolean getDefaultDataRoamingEnabled(int subId) {
6271 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006272 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006273 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6274 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6275 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6276 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6277 return isDataRoamingEnabled;
6278 }
6279
6280 /**
6281 * Returns the default network type for the given {@code subId}, if the default network type is
6282 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6283 */
6284 private int getDefaultNetworkType(int subId) {
6285 return Integer.parseInt(
6286 TelephonyManager.getTelephonyProperty(
6287 mSubscriptionController.getPhoneId(subId),
6288 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6289 String.valueOf(Phone.PREFERRED_NT_MODE)));
6290 }
fionaxua13278b2018-03-21 00:08:13 -07006291
6292 @Override
6293 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006294 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006295 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296
6297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 final Phone phone = getPhone(subId);
6300 if (phone == null) {
6301 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6302 return;
6303 }
chen xueaba88a2019-03-15 13:15:10 -07006304 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6305 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 } finally {
6307 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006308 }
fionaxua13278b2018-03-21 00:08:13 -07006309 }
6310
6311 @Override
6312 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006313 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314
6315 final long identity = Binder.clearCallingIdentity();
6316 try {
6317 final Phone phone = getPhone(subId);
6318 if (phone == null) {
6319 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6320 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6321 }
6322 return phone.getCarrierIdListVersion();
6323 } finally {
6324 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006325 }
fionaxua13278b2018-03-21 00:08:13 -07006326 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006327
6328 @Override
6329 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6331 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6332 return -1;
6333 }
6334
6335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
6340 }
6341 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006342
6343 @Override
6344 public int getCdmaRoamingMode(int subId) {
6345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6346 mApp, subId, "getCdmaRoamingMode");
6347
6348 final long identity = Binder.clearCallingIdentity();
6349 try {
6350 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6351 } finally {
6352 Binder.restoreCallingIdentity(identity);
6353 }
6354 }
6355
6356 @Override
6357 public boolean setCdmaRoamingMode(int subId, int mode) {
6358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6359 mApp, subId, "setCdmaRoamingMode");
6360
6361 final long identity = Binder.clearCallingIdentity();
6362 try {
6363 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
6367 }
6368
6369 @Override
6370 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6371 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6372 mApp, subId, "setCdmaSubscriptionMode");
6373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
6376 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
6380 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006381
6382 private void ensureUserRunning(int userId) {
6383 if (!mUserManager.isUserRunning(userId)) {
6384 throw new IllegalStateException("User " + userId + " does not exist or not running");
6385 }
6386 }
6387
6388 /**
6389 * Returns a list of SMS apps on a given user.
6390 *
6391 * Only the shell user (UID 2000 or 0) can call it.
6392 * Target user must be running.
6393 */
6394 @Override
6395 public String[] getSmsApps(int userId) {
6396 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6397 ensureUserRunning(userId);
6398
6399 final Collection<SmsApplicationData> apps =
6400 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6401
6402 String[] ret = new String[apps.size()];
6403 int i = 0;
6404 for (SmsApplicationData app : apps) {
6405 ret[i++] = app.mPackageName;
6406 }
6407 return ret;
6408 }
6409
6410 /**
6411 * Returns the default SMS app package name on a given user.
6412 *
6413 * Only the shell user (UID 2000 or 0) can call it.
6414 * Target user must be running.
6415 */
6416 @Override
6417 public String getDefaultSmsApp(int userId) {
6418 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6419 ensureUserRunning(userId);
6420
6421 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6422 /* updateIfNeeded= */ true, userId);
6423 return cn == null ? null : cn.getPackageName();
6424 }
6425
6426 /**
6427 * Set a package as the default SMS app on a given user.
6428 *
6429 * Only the shell user (UID 2000 or 0) can call it.
6430 * Target user must be running.
6431 */
6432 @Override
6433 public void setDefaultSmsApp(int userId, String packageName) {
6434 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6435 ensureUserRunning(userId);
6436
6437 boolean found = false;
6438 for (String pkg : getSmsApps(userId)) {
6439 if (TextUtils.equals(packageName, pkg)) {
6440 found = true;
6441 break;
6442 }
6443 }
6444 if (!found) {
6445 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6446 }
6447
6448 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6449 }
sqianc5eccab2018-10-19 18:46:41 -07006450
6451 @Override
6452 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6453 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006454 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6455 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6456 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6457 }
6458 final long identity = Binder.clearCallingIdentity();
6459 try {
sqian854d44b2018-12-12 16:48:18 -08006460 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6461 for (Phone phone: PhoneFactory.getPhones()) {
6462 if (phone.getEmergencyNumberTracker() != null
6463 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6464 emergencyNumberListInternal.put(
6465 phone.getSubId(),
6466 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6467 }
sqian11b7a0e2018-12-05 18:48:28 -08006468 }
sqian854d44b2018-12-12 16:48:18 -08006469 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
sqianc5eccab2018-10-19 18:46:41 -07006473 }
6474
6475 @Override
sqian11b7a0e2018-12-05 18:48:28 -08006476 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006477 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006478 if (!exactMatch) {
6479 TelephonyPermissions
6480 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006481 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006482 }
6483 final long identity = Binder.clearCallingIdentity();
6484 try {
sqian854d44b2018-12-12 16:48:18 -08006485 for (Phone phone: PhoneFactory.getPhones()) {
6486 if (phone.getEmergencyNumberTracker() != null
6487 && phone.getEmergencyNumberTracker() != null) {
6488 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6489 number, exactMatch)) {
6490 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006491 }
6492 }
sqian11b7a0e2018-12-05 18:48:28 -08006493 }
6494 return false;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
sqianf4ca7ed2019-01-15 18:32:07 -08006500 /**
6501 * Update emergency number list for test mode.
6502 */
6503 @Override
6504 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6505 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6506 "updateEmergencyNumberListTestMode");
6507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 for (Phone phone: PhoneFactory.getPhones()) {
6511 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6512 if (tracker != null) {
6513 tracker.executeEmergencyNumberTestModeCommand(action, num);
6514 }
6515 }
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
6520
6521 /**
6522 * Get the full emergency number list for test mode.
6523 */
6524 @Override
6525 public List<String> getEmergencyNumberListTestMode() {
6526 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6527 "getEmergencyNumberListTestMode");
6528
6529 final long identity = Binder.clearCallingIdentity();
6530 try {
6531 Set<String> emergencyNumbers = new HashSet<>();
6532 for (Phone phone: PhoneFactory.getPhones()) {
6533 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6534 if (tracker != null) {
6535 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6536 emergencyNumbers.add(num.getNumber());
6537 }
6538 }
6539 }
6540 return new ArrayList<>(emergencyNumbers);
6541 } finally {
6542 Binder.restoreCallingIdentity(identity);
6543 }
6544 }
6545
chen xud6b45bd2018-10-30 22:27:10 -07006546 @Override
6547 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6548 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6549 Phone phone = getPhone(subId);
6550 if (phone == null) {
6551 return null;
6552 }
6553 final long identity = Binder.clearCallingIdentity();
6554 try {
6555 UiccProfile profile = UiccController.getInstance()
6556 .getUiccProfileForPhone(phone.getPhoneId());
6557 if (profile != null) {
6558 return profile.getCertsFromCarrierPrivilegeAccessRules();
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 return null;
6564 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006565
6566 /**
6567 * Enable or disable a modem stack.
6568 */
6569 @Override
6570 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6571 enforceModifyPermission();
6572
6573 final long identity = Binder.clearCallingIdentity();
6574 try {
6575 Phone phone = PhoneFactory.getPhone(slotIndex);
6576 if (phone == null) {
6577 return false;
6578 } else {
6579 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6580 }
6581 } finally {
6582 Binder.restoreCallingIdentity(identity);
6583 }
6584 }
Michelecea4cf22018-12-21 15:00:11 -08006585
6586 @Override
6587 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6588 enforceModifyPermission();
6589
6590 final long identity = Binder.clearCallingIdentity();
6591 try {
6592 mTelephonySharedPreferences.edit()
6593 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6594 .commit();
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
6597 }
6598 }
6599
6600 @Override
Michele4245e952019-02-04 11:36:23 -08006601 public boolean isMultisimSupported(String callingPackage) {
6602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6603 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6604 return false;
6605 }
Michelecea4cf22018-12-21 15:00:11 -08006606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
Michele30b57b22019-03-01 12:01:14 -08006609 return isMultisimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006614
Michele30b57b22019-03-01 12:01:14 -08006615 private boolean isMultisimSupportedInternal() {
6616 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6617 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6618 if (numPhysicalSlots < 2) {
6619 loge("isMultisimSupportedInternal: requires at least 2 cards");
6620 return false;
6621 }
6622 // Check if the hardware supports multisim functionality. If usage of multisim is not
6623 // supported by the modem, indicate that it is restricted.
6624 PhoneCapability staticCapability =
6625 mPhoneConfigurationManager.getStaticPhoneCapability();
6626 if (staticCapability == null) {
6627 loge("isMultisimSupportedInternal: no static configuration available");
6628 return false;
6629 }
6630 if (staticCapability.logicalModemList.size() < 2) {
6631 loge("isMultisimSupportedInternal: maximum number of modem is < 2");
6632 return false;
6633 }
6634 // Check if support of multiple SIMs is restricted by carrier
6635 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6636 return false;
6637 }
6638
6639 return true;
6640 }
6641
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006642 /**
6643 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006644 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6645 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6646 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006647 * @param numOfSims number of active sims we want to switch to
6648 */
6649 @Override
6650 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08006651 if (numOfSims == 1) {
6652 enforceModifyPermission();
6653 } else {
6654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6655 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6656 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006657 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006658
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006659 try {
Michele30b57b22019-03-01 12:01:14 -08006660 //only proceed if multi-sim is not restricted
6661 if (!isMultisimSupportedInternal()) {
6662 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6663 return;
6664 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006665 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
6668 }
6669 }
6670
6671 /**
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006672 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006673 * Return value defaults to true
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08006674 */
6675 @Override
6676 public boolean isRebootRequiredForModemConfigChange() {
6677 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6678 final long identity = Binder.clearCallingIdentity();
6679 try {
6680 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 }
6685
Nathan Harold29f5f052019-02-15 13:41:57 -08006686 private void updateModemStateMetrics() {
6687 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6688 // TODO: check the state for each modem if the api is ready.
6689 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6690 }
6691
Pengquan Meng3889a572019-01-23 11:16:29 -08006692 @Override
6693 public int[] getSlotsMapping() {
6694 enforceReadPrivilegedPermission("getSlotsMapping");
6695
6696 final long identity = Binder.clearCallingIdentity();
6697 try {
6698 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6699 // All logical slots should have a mapping to a physical slot.
6700 int[] logicalSlotsMapping = new int[phoneCount];
6701 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6702 for (int i = 0; i < slotInfos.length; i++) {
6703 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6704 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6705 }
6706 }
6707 return logicalSlotsMapping;
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
6710 }
6711 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006712
6713 /**
6714 * Get the IRadio HAL Version
6715 */
6716 @Override
6717 public int getRadioHalVersion() {
6718 Phone phone = getDefaultPhone();
6719 if (phone == null) return -1;
6720 HalVersion hv = phone.getHalVersion();
6721 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6722 return hv.major * 100 + hv.minor;
6723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006724}