blob: 2c40568ad1cc48d6a308593554e919751c45e065 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080038import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Bundle;
40import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Looper;
43import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070045import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080046import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070047import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070049import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070050import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070052import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080055import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080060import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070062import android.telephony.CellInfoGsm;
63import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070064import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070066import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070067import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080068import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070069import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080070import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070071import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080072import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080073import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070074import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070075import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080077import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070078import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080079import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070081import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070082import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080083import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000084import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070087import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080088import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080089import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070090import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080091import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070092import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070094import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080095import android.telephony.ims.aidl.IImsMmTelFeature;
96import android.telephony.ims.aidl.IImsRcsFeature;
97import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.feature.MmTelFeature;
100import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800101import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800107
Brad Ebinger4c460712018-10-01 10:40:55 -0700108import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700109import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800110import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700112import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700113import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800114import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700115import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800118import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800119import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700122import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100123import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700124import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700125import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700127import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800128import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700129import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700130import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700131import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700132import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700133import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800135import com.android.internal.telephony.SmsApplication;
136import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800137import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800138import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800139import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700140import com.android.internal.telephony.euicc.EuiccConnector;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800141import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700142import com.android.internal.telephony.uicc.IccIoResult;
143import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800144import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700145import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800146import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000149import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700150import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700152import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800153import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700154import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700155import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800156
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700157import java.io.FileDescriptor;
158import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800159import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700160import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800161import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800162import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800163import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800164import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800165import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100166import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800167import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800168import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700169
170/**
171 * Implementation of the ITelephony interface.
172 */
Santos Cordon117fee72014-05-16 17:56:12 -0700173public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174 private static final String LOG_TAG = "PhoneInterfaceManager";
175 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
176 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800177 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700178
179 // Message codes used with mMainThreadHandler
180 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700181 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
182 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183 private static final int CMD_OPEN_CHANNEL = 9;
184 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
185 private static final int CMD_CLOSE_CHANNEL = 11;
186 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800187 private static final int CMD_NV_READ_ITEM = 13;
188 private static final int EVENT_NV_READ_ITEM_DONE = 14;
189 private static final int CMD_NV_WRITE_ITEM = 15;
190 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
191 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
192 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700193 private static final int CMD_RESET_MODEM_CONFIG = 19;
194 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800195 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
196 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
197 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
198 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800199 private static final int CMD_SEND_ENVELOPE = 25;
200 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000201 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
202 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700203 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
204 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
205 private static final int CMD_EXCHANGE_SIM_IO = 31;
206 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800207 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
208 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700209 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
210 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700211 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
212 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700213 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
214 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
215 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
216 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700217 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
218 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
219 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
220 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700221 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800222 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
223 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000224 private static final int CMD_SWITCH_SLOTS = 50;
225 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700226 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
227 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
228 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
229 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
230 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
231 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
232 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
233 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700234 private static final int CMD_GET_ALL_CELL_INFO = 60;
235 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
236 private static final int CMD_GET_CELL_LOCATION = 62;
237 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700238 private static final int CMD_MODEM_REBOOT = 64;
239 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700240 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
241 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800242 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
243 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700244
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800245 // Parameters of select command.
246 private static final int SELECT_COMMAND = 0xA4;
247 private static final int SELECT_P1 = 0x04;
248 private static final int SELECT_P2 = 0;
249 private static final int SELECT_P3 = 0x10;
250
Pengquan Meng85728fb2018-03-12 16:31:21 -0700251 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
252 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
253 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
254
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700255 /** The singleton instance. */
256 private static PhoneInterfaceManager sInstance;
257
Wink Saville3ab207e2014-11-20 13:07:20 -0800258 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800259 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700260 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private AppOpsManager mAppOps;
262 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800263 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700265 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700266
Derek Tan97ebb422014-09-05 16:55:38 -0700267 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
268 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800269 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800270 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700271
Micheled3107c52018-12-21 15:00:11 -0800272 // String to store multi SIM allowed
273 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
274
Derek Tan740e1672017-06-27 14:56:27 -0700275 // The AID of ISD-R.
276 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
277
yinxub1bed742017-04-17 11:45:04 -0700278 private NetworkScanRequestTracker mNetworkScanRequestTracker;
279
David Kelly5e06a7f2018-03-12 14:10:59 +0000280 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
281 private static final int MANUFACTURER_CODE_LENGTH = 8;
282
Derek Tan89e89d42014-07-08 17:00:10 -0700283 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700284 * A request object to use for transmitting data to an ICC.
285 */
286 private static final class IccAPDUArgument {
287 public int channel, cla, command, p1, p2, p3;
288 public String data;
289
290 public IccAPDUArgument(int channel, int cla, int command,
291 int p1, int p2, int p3, String data) {
292 this.channel = channel;
293 this.cla = cla;
294 this.command = command;
295 this.p1 = p1;
296 this.p2 = p2;
297 this.p3 = p3;
298 this.data = data;
299 }
300 }
301
302 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700303 * A request object to use for transmitting data to an ICC.
304 */
305 private static final class ManualNetworkSelectionArgument {
306 public OperatorInfo operatorInfo;
307 public boolean persistSelection;
308
309 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
310 this.operatorInfo = operatorInfo;
311 this.persistSelection = persistSelection;
312 }
313 }
314
315 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
317 * request after sending. The main thread will notify the request when it is complete.
318 */
319 private static final class MainThreadRequest {
320 /** The argument to use for the request */
321 public Object argument;
322 /** The result of the request that is run on the main thread */
323 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800324 // The subscriber id that this request applies to. Defaults to
325 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
326 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700327
Nathan Harold92bed182018-10-12 18:16:49 -0700328 // In cases where subId is unavailable, the caller needs to specify the phone.
329 public Phone phone;
330
vagdevie435a3e2018-08-15 16:01:53 -0700331 public WorkSource workSource;
332
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700333 public MainThreadRequest(Object argument) {
334 this.argument = argument;
335 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800336
Nathan Harold92bed182018-10-12 18:16:49 -0700337 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
338 this.argument = argument;
339 if (phone != null) {
340 this.phone = phone;
341 }
342 this.workSource = workSource;
343 }
344
vagdevie435a3e2018-08-15 16:01:53 -0700345 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800346 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800347 if (subId != null) {
348 this.subId = subId;
349 }
vagdevie435a3e2018-08-15 16:01:53 -0700350 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700352 }
353
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800354 private static final class IncomingThirdPartyCallArgs {
355 public final ComponentName component;
356 public final String callId;
357 public final String callerDisplayName;
358
359 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
360 String callerDisplayName) {
361 this.component = component;
362 this.callId = callId;
363 this.callerDisplayName = callerDisplayName;
364 }
365 }
366
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 /**
368 * A handler that processes messages on the main thread in the phone process. Since many
369 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
370 * inbound binder threads to the main thread in the phone process. The Binder thread
371 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
372 * on, which will be notified when the operation completes and will contain the result of the
373 * request.
374 *
375 * <p>If a MainThreadRequest object is provided in the msg.obj field,
376 * note that request.result must be set to something non-null for the calling thread to
377 * unblock.
378 */
379 private final class MainThreadHandler extends Handler {
380 @Override
381 public void handleMessage(Message msg) {
382 MainThreadRequest request;
383 Message onCompleted;
384 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800385 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700386 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800387 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388
389 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700390 case CMD_HANDLE_USSD_REQUEST: {
391 request = (MainThreadRequest) msg.obj;
392 final Phone phone = getPhoneFromRequest(request);
393 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
394 String ussdRequest = ussdObject.first;
395 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700396
Pengquan Meng0c05b502018-09-06 09:59:22 -0700397 if (!isUssdApiAllowed(request.subId)) {
398 // Carrier does not support use of this API, return failure.
399 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
400 UssdResponse response = new UssdResponse(ussdRequest, null);
401 Bundle returnData = new Bundle();
402 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
403 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700404
Pengquan Meng0c05b502018-09-06 09:59:22 -0700405 request.result = true;
406 notifyRequester(request);
407 return;
408 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 try {
411 request.result = phone != null
412 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
413 } catch (CallStateException cse) {
414 request.result = false;
415 }
416 // Wake up the requesting thread
417 notifyRequester(request);
418 break;
pkanwar32d516d2016-10-14 19:37:38 -0700419 }
420
Yorke Lee716f67e2015-06-17 15:39:16 -0700421 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700423 final Phone phone = getPhoneFromRequest(request);
424 request.result = phone != null ?
425 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
426 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700428 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700429 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700430 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700432 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700433 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700434 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800435 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700436 if (uiccCard == null) {
437 loge("iccTransmitApduLogicalChannel: No UICC");
438 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700439 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700440 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
442 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 iccArgument.channel, iccArgument.cla, iccArgument.command,
445 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700446 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700447 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 break;
449
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700450 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 ar = (AsyncResult) msg.obj;
452 request = (MainThreadRequest) ar.userObj;
453 if (ar.exception == null && ar.result != null) {
454 request.result = ar.result;
455 } else {
456 request.result = new IccIoResult(0x6F, 0, (byte[])null);
457 if (ar.result == null) {
458 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800459 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700460 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800461 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700462 } else {
463 loge("iccTransmitApduLogicalChannel: Unknown exception");
464 }
465 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700466 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 break;
468
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
470 request = (MainThreadRequest) msg.obj;
471 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800472 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700473 if (uiccCard == null) {
474 loge("iccTransmitApduBasicChannel: No UICC");
475 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700476 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 } else {
478 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
479 request);
480 uiccCard.iccTransmitApduBasicChannel(
481 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
482 iccArgument.p3, iccArgument.data, onCompleted);
483 }
484 break;
485
486 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
487 ar = (AsyncResult) msg.obj;
488 request = (MainThreadRequest) ar.userObj;
489 if (ar.exception == null && ar.result != null) {
490 request.result = ar.result;
491 } else {
492 request.result = new IccIoResult(0x6F, 0, (byte[])null);
493 if (ar.result == null) {
494 loge("iccTransmitApduBasicChannel: Empty response");
495 } else if (ar.exception instanceof CommandException) {
496 loge("iccTransmitApduBasicChannel: CommandException: " +
497 ar.exception);
498 } else {
499 loge("iccTransmitApduBasicChannel: Unknown exception");
500 }
501 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 break;
504
505 case CMD_EXCHANGE_SIM_IO:
506 request = (MainThreadRequest) msg.obj;
507 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800508 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700509 if (uiccCard == null) {
510 loge("iccExchangeSimIO: No UICC");
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700512 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700513 } else {
514 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
515 request);
516 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
517 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
518 iccArgument.data, onCompleted);
519 }
520 break;
521
522 case EVENT_EXCHANGE_SIM_IO_DONE:
523 ar = (AsyncResult) msg.obj;
524 request = (MainThreadRequest) ar.userObj;
525 if (ar.exception == null && ar.result != null) {
526 request.result = ar.result;
527 } else {
528 request.result = new IccIoResult(0x6f, 0, (byte[])null);
529 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700530 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 break;
532
Derek Tan4d5e5c12014-02-04 11:54:58 -0800533 case CMD_SEND_ENVELOPE:
534 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800535 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 if (uiccCard == null) {
537 loge("sendEnvelopeWithStatus: No UICC");
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700539 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 } else {
541 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
542 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
543 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800544 break;
545
546 case EVENT_SEND_ENVELOPE_DONE:
547 ar = (AsyncResult) msg.obj;
548 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700549 if (ar.exception == null && ar.result != null) {
550 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800551 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700552 request.result = new IccIoResult(0x6F, 0, (byte[])null);
553 if (ar.result == null) {
554 loge("sendEnvelopeWithStatus: Empty response");
555 } else if (ar.exception instanceof CommandException) {
556 loge("sendEnvelopeWithStatus: CommandException: " +
557 ar.exception);
558 } else {
559 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
560 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800561 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700562 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800563 break;
564
Shishir Agrawal566b7612013-10-28 14:41:00 -0700565 case CMD_OPEN_CHANNEL:
566 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800567 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800568 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700569 if (uiccCard == null) {
570 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800571 request.result = new IccOpenLogicalChannelResponse(-1,
572 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 } else {
575 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800576 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
577 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700578 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700579 break;
580
581 case EVENT_OPEN_CHANNEL_DONE:
582 ar = (AsyncResult) msg.obj;
583 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700585 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 int[] result = (int[]) ar.result;
587 int channelId = result[0];
588 byte[] selectResponse = null;
589 if (result.length > 1) {
590 selectResponse = new byte[result.length - 1];
591 for (int i = 1; i < result.length; ++i) {
592 selectResponse[i - 1] = (byte) result[i];
593 }
594 }
595 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700596 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700597 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 if (ar.result == null) {
599 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 if (ar.exception != null) {
602 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
603 }
604
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700605 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700606 if (ar.exception instanceof CommandException) {
607 CommandException.Error error =
608 ((CommandException) (ar.exception)).getCommandError();
609 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700611 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700612 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 }
614 }
615 openChannelResp = new IccOpenLogicalChannelResponse(
616 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700617 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700618 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700619 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 break;
621
622 case CMD_CLOSE_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700625 if (uiccCard == null) {
626 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900627 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
631 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
632 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700633 break;
634
635 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800636 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
637 break;
638
639 case CMD_NV_READ_ITEM:
640 request = (MainThreadRequest) msg.obj;
641 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800642 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
643 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800644 break;
645
646 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 ar = (AsyncResult) msg.obj;
648 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800649 if (ar.exception == null && ar.result != null) {
650 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800652 request.result = "";
653 if (ar.result == null) {
654 loge("nvReadItem: Empty response");
655 } else if (ar.exception instanceof CommandException) {
656 loge("nvReadItem: CommandException: " +
657 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800659 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
661 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
Jake Hambye994d462014-02-03 13:10:13 -0800665 case CMD_NV_WRITE_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
668 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800669 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700670 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800671 break;
672
673 case EVENT_NV_WRITE_ITEM_DONE:
674 handleNullReturnEvent(msg, "nvWriteItem");
675 break;
676
677 case CMD_NV_WRITE_CDMA_PRL:
678 request = (MainThreadRequest) msg.obj;
679 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800680 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800681 break;
682
683 case EVENT_NV_WRITE_CDMA_PRL_DONE:
684 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
685 break;
686
chen xu1cc0abe2018-10-26 17:39:23 -0700687 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800688 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700689 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800690 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800691 break;
692
chen xu1cc0abe2018-10-26 17:39:23 -0700693 case EVENT_RESET_MODEM_CONFIG_DONE:
694 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800695 break;
696
Jake Hamby7c27be32014-03-03 13:25:59 -0800697 case CMD_GET_PREFERRED_NETWORK_TYPE:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700700 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800701 break;
702
703 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // Integer
708 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800709 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800710 if (ar.result == null) {
711 loge("getPreferredNetworkType: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("getPreferredNetworkType: CommandException: " +
714 ar.exception);
715 } else {
716 loge("getPreferredNetworkType: Unknown exception");
717 }
718 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700719 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800720 break;
721
722 case CMD_SET_PREFERRED_NETWORK_TYPE:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
725 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
730 handleNullReturnEvent(msg, "setPreferredNetworkType");
731 break;
732
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000733 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
734 request = (MainThreadRequest)msg.obj;
735 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800736 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000737 break;
738
739 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
740 ar = (AsyncResult)msg.obj;
741 request = (MainThreadRequest)ar.userObj;
742 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700743 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000744 break;
745
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800746 case CMD_SET_VOICEMAIL_NUMBER:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
749 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800750 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
751 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800752 break;
753
754 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
755 handleNullReturnEvent(msg, "setVoicemailNumber");
756 break;
757
Stuart Scott54788802015-03-30 13:18:01 -0700758 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
761 request);
762 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
763 break;
764
765 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
766 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
767 break;
768
Shishir Agrawal302c8692015-06-19 13:49:39 -0700769 case CMD_PERFORM_NETWORK_SCAN:
770 request = (MainThreadRequest) msg.obj;
771 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
772 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
773 break;
774
775 case EVENT_PERFORM_NETWORK_SCAN_DONE:
776 ar = (AsyncResult) msg.obj;
777 request = (MainThreadRequest) ar.userObj;
778 CellNetworkScanResult cellScanResult;
779 if (ar.exception == null && ar.result != null) {
780 cellScanResult = new CellNetworkScanResult(
781 CellNetworkScanResult.STATUS_SUCCESS,
782 (List<OperatorInfo>) ar.result);
783 } else {
784 if (ar.result == null) {
785 loge("getCellNetworkScanResults: Empty response");
786 }
787 if (ar.exception != null) {
788 loge("getCellNetworkScanResults: Exception: " + ar.exception);
789 }
790 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
791 if (ar.exception instanceof CommandException) {
792 CommandException.Error error =
793 ((CommandException) (ar.exception)).getCommandError();
794 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
795 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
796 } else if (error == CommandException.Error.GENERIC_FAILURE) {
797 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
798 }
799 }
800 cellScanResult = new CellNetworkScanResult(errorCode, null);
801 }
802 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700803 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700804 break;
805
806 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
807 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700808 ManualNetworkSelectionArgument selArg =
809 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700810 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
811 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700812 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
813 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700814 break;
815
816 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700817 ar = (AsyncResult) msg.obj;
818 request = (MainThreadRequest) ar.userObj;
819 if (ar.exception == null) {
820 request.result = true;
821 } else {
822 request.result = false;
823 loge("setNetworkSelectionModeManual " + ar.exception);
824 }
825 notifyRequester(request);
826 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 break;
828
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700829 case CMD_GET_MODEM_ACTIVITY_INFO:
830 request = (MainThreadRequest) msg.obj;
831 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800832 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700833 break;
834
835 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null && ar.result != null) {
839 request.result = ar.result;
840 } else {
841 if (ar.result == null) {
842 loge("queryModemActivityInfo: Empty response");
843 } else if (ar.exception instanceof CommandException) {
844 loge("queryModemActivityInfo: CommandException: " +
845 ar.exception);
846 } else {
847 loge("queryModemActivityInfo: Unknown exception");
848 }
849 }
Amit Mahajand4766222016-01-28 15:28:28 -0800850 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
851 if (request.result == null) {
852 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
853 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700854 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 break;
856
Meng Wang1a7c35a2016-05-05 20:56:15 -0700857 case CMD_SET_ALLOWED_CARRIERS:
858 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800859 CarrierRestrictionRules argument =
860 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700861 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800862 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700863 break;
864
865 case EVENT_SET_ALLOWED_CARRIERS_DONE:
866 ar = (AsyncResult) msg.obj;
867 request = (MainThreadRequest) ar.userObj;
868 if (ar.exception == null && ar.result != null) {
869 request.result = ar.result;
870 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800871 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
872 if (ar.exception instanceof CommandException) {
873 loge("setAllowedCarriers: CommandException: " + ar.exception);
874 CommandException.Error error =
875 ((CommandException) (ar.exception)).getCommandError();
876 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
877 request.result =
878 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
879 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 } else {
881 loge("setAllowedCarriers: Unknown exception");
882 }
883 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700884 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 break;
886
887 case CMD_GET_ALLOWED_CARRIERS:
888 request = (MainThreadRequest) msg.obj;
889 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800890 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_GET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800899 request.result = new IllegalStateException(
900 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700901 if (ar.result == null) {
902 loge("getAllowedCarriers: Empty response");
903 } else if (ar.exception instanceof CommandException) {
904 loge("getAllowedCarriers: CommandException: " +
905 ar.exception);
906 } else {
907 loge("getAllowedCarriers: Unknown exception");
908 }
909 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700910 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700911 break;
912
Nathan Haroldb3014052017-01-25 15:57:32 -0800913 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 if (ar.exception == null && ar.result != null) {
917 request.result = ar.result;
918 } else {
919 request.result = new IllegalArgumentException(
920 "Failed to retrieve Forbidden Plmns");
921 if (ar.result == null) {
922 loge("getForbiddenPlmns: Empty response");
923 } else {
924 loge("getForbiddenPlmns: Unknown exception");
925 }
926 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700927 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800928 break;
929
930 case CMD_GET_FORBIDDEN_PLMNS:
931 request = (MainThreadRequest) msg.obj;
932 uiccCard = getUiccCardFromRequest(request);
933 if (uiccCard == null) {
934 loge("getForbiddenPlmns() UiccCard is null");
935 request.result = new IllegalArgumentException(
936 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700937 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800938 break;
939 }
940 Integer appType = (Integer) request.argument;
941 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
942 if (uiccApp == null) {
943 loge("getForbiddenPlmns() no app with specified type -- "
944 + appType);
945 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700946 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800947 break;
948 } else {
949 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
950 + " specified type -- " + appType);
951 }
952 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
953 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
954 onCompleted);
955 break;
956
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000957 case CMD_SWITCH_SLOTS:
958 request = (MainThreadRequest) msg.obj;
959 int[] physicalSlots = (int[]) request.argument;
960 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
961 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
962 break;
963
964 case EVENT_SWITCH_SLOTS_DONE:
965 ar = (AsyncResult) msg.obj;
966 request = (MainThreadRequest) ar.userObj;
967 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700968 notifyRequester(request);
969 break;
970 case CMD_GET_NETWORK_SELECTION_MODE:
971 request = (MainThreadRequest) msg.obj;
972 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
973 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
974 break;
975
976 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
977 ar = (AsyncResult) msg.obj;
978 request = (MainThreadRequest) ar.userObj;
979 if (ar.exception != null) {
980 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
981 } else {
982 int mode = ((int[]) ar.result)[0];
983 if (mode == 0) {
984 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
985 } else {
986 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
987 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000988 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700989 notifyRequester(request);
990 break;
991 case CMD_GET_CDMA_ROAMING_MODE:
992 request = (MainThreadRequest) msg.obj;
993 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
994 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
995 break;
996 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
997 ar = (AsyncResult) msg.obj;
998 request = (MainThreadRequest) ar.userObj;
999 if (ar.exception != null) {
1000 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1001 } else {
1002 request.result = ((int[]) ar.result)[0];
1003 }
1004 notifyRequester(request);
1005 break;
1006 case CMD_SET_CDMA_ROAMING_MODE:
1007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1009 int mode = (int) request.argument;
1010 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1011 break;
1012 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1013 ar = (AsyncResult) msg.obj;
1014 request = (MainThreadRequest) ar.userObj;
1015 request.result = ar.exception == null;
1016 notifyRequester(request);
1017 break;
1018 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1019 request = (MainThreadRequest) msg.obj;
1020 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1021 int subscriptionMode = (int) request.argument;
1022 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1023 break;
1024 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 request.result = ar.exception == null;
1028 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001029 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001030 case CMD_GET_ALL_CELL_INFO:
1031 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001032 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001033 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001034 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 case EVENT_GET_ALL_CELL_INFO_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001038 // If a timeout occurs, the response will be null
1039 request.result = (ar.exception == null && ar.result != null)
1040 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001041 synchronized (request) {
1042 request.notifyAll();
1043 }
1044 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001045 case CMD_REQUEST_CELL_INFO_UPDATE:
1046 request = (MainThreadRequest) msg.obj;
1047 request.phone.requestCellInfoUpdate(request.workSource,
1048 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1049 break;
1050 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1051 ar = (AsyncResult) msg.obj;
1052 request = (MainThreadRequest) ar.userObj;
1053 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1054 try {
1055 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001056 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001057 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1058 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001061 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 } else {
1063 // use the result as returned
1064 cb.onCellInfo((List<CellInfo>) ar.result);
1065 }
1066 } catch (RemoteException re) {
1067 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1068 }
1069 break;
1070 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001071 request = (MainThreadRequest) msg.obj;
1072 WorkSource ws = (WorkSource) request.argument;
1073 Phone phone = getPhoneFromRequest(request);
1074 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1075 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001077 ar = (AsyncResult) msg.obj;
1078 request = (MainThreadRequest) ar.userObj;
1079 if (ar.exception == null) {
1080 request.result = ar.result;
1081 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001082 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001083 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1084 ? new CdmaCellLocation() : new GsmCellLocation();
1085 }
1086
1087 synchronized (request) {
1088 request.notifyAll();
1089 }
1090 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001091 case CMD_MODEM_REBOOT:
1092 request = (MainThreadRequest) msg.obj;
1093 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001094 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001095 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001096 case EVENT_CMD_MODEM_REBOOT_DONE:
1097 handleNullReturnEvent(msg, "rebootModem");
1098 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001099 case CMD_REQUEST_ENABLE_MODEM:
1100 request = (MainThreadRequest) msg.obj;
1101 boolean enable = (boolean) request.argument;
1102 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
1103 PhoneConfigurationManager.getInstance()
1104 .enablePhone(request.phone, enable, onCompleted);
1105 break;
1106 case EVENT_ENABLE_MODEM_DONE:
1107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 request.result = (ar.exception == null);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001110 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001111 notifyRequester(request);
1112 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001113 default:
1114 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1115 break;
1116 }
1117 }
Jake Hambye994d462014-02-03 13:10:13 -08001118
Pengquan Meng0c05b502018-09-06 09:59:22 -07001119 private void notifyRequester(MainThreadRequest request) {
1120 synchronized (request) {
1121 request.notifyAll();
1122 }
1123 }
1124
Jake Hambye994d462014-02-03 13:10:13 -08001125 private void handleNullReturnEvent(Message msg, String command) {
1126 AsyncResult ar = (AsyncResult) msg.obj;
1127 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1128 if (ar.exception == null) {
1129 request.result = true;
1130 } else {
1131 request.result = false;
1132 if (ar.exception instanceof CommandException) {
1133 loge(command + ": CommandException: " + ar.exception);
1134 } else {
1135 loge(command + ": Unknown exception");
1136 }
1137 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001138 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001140 }
1141
1142 /**
1143 * Posts the specified command to be executed on the main thread,
1144 * waits for the request to complete, and returns the result.
1145 * @see #sendRequestAsync
1146 */
1147 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001148 return sendRequest(
1149 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001150 }
1151
1152 /**
1153 * Posts the specified command to be executed on the main thread,
1154 * waits for the request to complete, and returns the result.
1155 * @see #sendRequestAsync
1156 */
1157 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1158 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001159 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001160 }
1161
1162 /**
1163 * Posts the specified command to be executed on the main thread,
1164 * waits for the request to complete, and returns the result.
1165 * @see #sendRequestAsync
1166 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001167 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001168 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001169 }
1170
1171 /**
1172 * Posts the specified command to be executed on the main thread,
1173 * waits for the request to complete, and returns the result.
1174 * @see #sendRequestAsync
1175 */
Nathan Harold92bed182018-10-12 18:16:49 -07001176 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1177 return sendRequest(command, argument, subId, null, workSource);
1178 }
1179
1180 /**
1181 * Posts the specified command to be executed on the main thread,
1182 * waits for the request to complete, and returns the result.
1183 * @see #sendRequestAsync
1184 */
1185 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1186 return sendRequest(
1187 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1188 }
1189
1190 /**
1191 * Posts the specified command to be executed on the main thread,
1192 * waits for the request to complete, and returns the result.
1193 * @see #sendRequestAsync
1194 */
1195 private Object sendRequest(
1196 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001197 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1198 throw new RuntimeException("This method will deadlock if called from the main thread.");
1199 }
1200
Nathan Harold92bed182018-10-12 18:16:49 -07001201 MainThreadRequest request = null;
1202 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1203 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1204 } else if (phone != null) {
1205 request = new MainThreadRequest(argument, phone, workSource);
1206 } else {
1207 request = new MainThreadRequest(argument, subId, workSource);
1208 }
1209
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001210 Message msg = mMainThreadHandler.obtainMessage(command, request);
1211 msg.sendToTarget();
1212
1213 // Wait for the request to complete
1214 synchronized (request) {
1215 while (request.result == null) {
1216 try {
1217 request.wait();
1218 } catch (InterruptedException e) {
1219 // Do nothing, go back and wait until the request is complete
1220 }
1221 }
1222 }
1223 return request.result;
1224 }
1225
1226 /**
1227 * Asynchronous ("fire and forget") version of sendRequest():
1228 * Posts the specified command to be executed on the main thread, and
1229 * returns immediately.
1230 * @see #sendRequest
1231 */
1232 private void sendRequestAsync(int command) {
1233 mMainThreadHandler.sendEmptyMessage(command);
1234 }
1235
1236 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001237 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001238 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001239 */
1240 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001241 sendRequestAsync(command, argument, null, null);
1242 }
1243
1244 /**
1245 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1246 * @see {@link #sendRequest(int,Object)}
1247 */
1248 private void sendRequestAsync(
1249 int command, Object argument, Phone phone, WorkSource workSource) {
1250 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001251 Message msg = mMainThreadHandler.obtainMessage(command, request);
1252 msg.sendToTarget();
1253 }
1254
1255 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001256 * Initialize the singleton PhoneInterfaceManager instance.
1257 * This is only done once, at startup, from PhoneApp.onCreate().
1258 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001259 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001260 synchronized (PhoneInterfaceManager.class) {
1261 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001262 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 } else {
1264 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1265 }
1266 return sInstance;
1267 }
1268 }
1269
1270 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001273 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001274 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001275 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1276 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001277 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001278 mTelephonySharedPreferences =
1279 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001280 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001281 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001282
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001283 publish();
1284 }
1285
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001286 private Phone getDefaultPhone() {
1287 Phone thePhone = getPhone(getDefaultSubscription());
1288 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1289 }
1290
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001291 private void publish() {
1292 if (DBG) log("publish: " + this);
1293
1294 ServiceManager.addService("phone", this);
1295 }
1296
Stuart Scott584921c2015-01-15 17:10:34 -08001297 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001298 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001299 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001300 }
1301
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001302 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1303 Phone phone = getPhoneFromRequest(request);
1304 return phone == null ? null :
1305 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1306 }
1307
Wink Saville36469e72014-06-11 15:17:00 -07001308 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001309 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001310 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001312
1313 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001314 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001315 }
1316
Wink Savilleb564aae2014-10-23 10:18:09 -07001317 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001318 if (DBG) log("dial: " + number);
1319 // No permission check needed here: This is just a wrapper around the
1320 // ACTION_DIAL intent, which is available to any app since it puts up
1321 // the UI before it does anything.
1322
Malcolm Chend965c8b2018-02-28 15:00:40 -08001323 final long identity = Binder.clearCallingIdentity();
1324 try {
1325 String url = createTelUrl(number);
1326 if (url == null) {
1327 return;
1328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329
Malcolm Chend965c8b2018-02-28 15:00:40 -08001330 // PENDING: should we just silently fail if phone is offhook or ringing?
1331 PhoneConstants.State state = mCM.getState(subId);
1332 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1333 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1334 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1335 mApp.startActivity(intent);
1336 }
1337 } finally {
1338 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001339 }
1340 }
1341
1342 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001343 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001344 }
1345
Wink Savilleb564aae2014-10-23 10:18:09 -07001346 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001347 if (DBG) log("call: " + number);
1348
1349 // This is just a wrapper around the ACTION_CALL intent, but we still
1350 // need to do a permission check since we're calling startActivity()
1351 // from the context of the phone app.
1352 enforceCallPermission();
1353
1354 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1355 != AppOpsManager.MODE_ALLOWED) {
1356 return;
1357 }
1358
Malcolm Chend965c8b2018-02-28 15:00:40 -08001359 final long identity = Binder.clearCallingIdentity();
1360 try {
1361 String url = createTelUrl(number);
1362 if (url == null) {
1363 return;
1364 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365
Malcolm Chend965c8b2018-02-28 15:00:40 -08001366 boolean isValid = false;
1367 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1368 if (slist != null) {
1369 for (SubscriptionInfo subInfoRecord : slist) {
1370 if (subInfoRecord.getSubscriptionId() == subId) {
1371 isValid = true;
1372 break;
1373 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001374 }
Wink Saville08874612014-08-31 19:19:58 -07001375 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001376 if (!isValid) {
1377 return;
1378 }
Wink Saville08874612014-08-31 19:19:58 -07001379
Malcolm Chend965c8b2018-02-28 15:00:40 -08001380 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1381 intent.putExtra(SUBSCRIPTION_KEY, subId);
1382 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1383 mApp.startActivity(intent);
1384 } finally {
1385 Binder.restoreCallingIdentity(identity);
1386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001387 }
1388
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001389 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001390 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001391 }
1392
Wink Savilleb564aae2014-10-23 10:18:09 -07001393 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001394 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001395 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1396 }
1397
1398 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001400 }
1401
Wink Savilleb564aae2014-10-23 10:18:09 -07001402 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001403 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001404 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1405 }
1406
1407 /** {@hide} */
1408 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001409 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001410 }
1411
Wink Savilleb564aae2014-10-23 10:18:09 -07001412 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001413 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001414
1415 final long identity = Binder.clearCallingIdentity();
1416 try {
1417 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1418 checkSimPin.start();
1419 return checkSimPin.unlockSim(null, pin);
1420 } finally {
1421 Binder.restoreCallingIdentity(identity);
1422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001423 }
1424
Wink Saville9de0f752013-10-22 19:04:03 -07001425 /** {@hide} */
1426 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001432
1433 final long identity = Binder.clearCallingIdentity();
1434 try {
1435 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1436 checkSimPuk.start();
1437 return checkSimPuk.unlockSim(puk, pin);
1438 } finally {
1439 Binder.restoreCallingIdentity(identity);
1440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001441 }
1442
1443 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001444 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001445 * a synchronous one.
1446 */
1447 private static class UnlockSim extends Thread {
1448
1449 private final IccCard mSimCard;
1450
1451 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001452 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1453 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454
1455 // For replies from SimCard interface
1456 private Handler mHandler;
1457
1458 // For async handler to identify request type
1459 private static final int SUPPLY_PIN_COMPLETE = 100;
1460
1461 public UnlockSim(IccCard simCard) {
1462 mSimCard = simCard;
1463 }
1464
1465 @Override
1466 public void run() {
1467 Looper.prepare();
1468 synchronized (UnlockSim.this) {
1469 mHandler = new Handler() {
1470 @Override
1471 public void handleMessage(Message msg) {
1472 AsyncResult ar = (AsyncResult) msg.obj;
1473 switch (msg.what) {
1474 case SUPPLY_PIN_COMPLETE:
1475 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1476 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001477 mRetryCount = msg.arg1;
1478 if (ar.exception != null) {
1479 if (ar.exception instanceof CommandException &&
1480 ((CommandException)(ar.exception)).getCommandError()
1481 == CommandException.Error.PASSWORD_INCORRECT) {
1482 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1483 } else {
1484 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1485 }
1486 } else {
1487 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001489 mDone = true;
1490 UnlockSim.this.notifyAll();
1491 }
1492 break;
1493 }
1494 }
1495 };
1496 UnlockSim.this.notifyAll();
1497 }
1498 Looper.loop();
1499 }
1500
1501 /*
1502 * Use PIN or PUK to unlock SIM card
1503 *
1504 * If PUK is null, unlock SIM card with PIN
1505 *
1506 * If PUK is not null, unlock SIM card with PUK and set PIN code
1507 */
Wink Saville9de0f752013-10-22 19:04:03 -07001508 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001509
1510 while (mHandler == null) {
1511 try {
1512 wait();
1513 } catch (InterruptedException e) {
1514 Thread.currentThread().interrupt();
1515 }
1516 }
1517 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1518
1519 if (puk == null) {
1520 mSimCard.supplyPin(pin, callback);
1521 } else {
1522 mSimCard.supplyPuk(puk, pin, callback);
1523 }
1524
1525 while (!mDone) {
1526 try {
1527 Log.d(LOG_TAG, "wait for done");
1528 wait();
1529 } catch (InterruptedException e) {
1530 // Restore the interrupted status
1531 Thread.currentThread().interrupt();
1532 }
1533 }
1534 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001535 int[] resultArray = new int[2];
1536 resultArray[0] = mResult;
1537 resultArray[1] = mRetryCount;
1538 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001539 }
1540 }
1541
1542 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001543 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001544
1545 }
1546
Wink Savilleb564aae2014-10-23 10:18:09 -07001547 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001548 // No permission check needed here: this call is harmless, and it's
1549 // needed for the ServiceState.requestStateUpdate() call (which is
1550 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001551 final long identity = Binder.clearCallingIdentity();
1552 try {
1553 final Phone phone = getPhone(subId);
1554 if (phone != null) {
1555 phone.updateServiceLocation();
1556 }
1557 } finally {
1558 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001559 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001560 }
1561
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001562 @Override
1563 public boolean isRadioOn(String callingPackage) {
1564 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001565 }
1566
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 @Override
1568 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001570 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001571 return false;
1572 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 return isRadioOnForSubscriber(subId);
1577 } finally {
1578 Binder.restoreCallingIdentity(identity);
1579 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001580 }
1581
1582 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001583 final long identity = Binder.clearCallingIdentity();
1584 try {
1585 final Phone phone = getPhone(subId);
1586 if (phone != null) {
1587 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1588 } else {
1589 return false;
1590 }
1591 } finally {
1592 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001593 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 }
1595
1596 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001597 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 }
Wink Saville36469e72014-06-11 15:17:00 -07001599
Wink Savilleb564aae2014-10-23 10:18:09 -07001600 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001601 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001602
1603 final long identity = Binder.clearCallingIdentity();
1604 try {
1605 final Phone phone = getPhone(subId);
1606 if (phone != null) {
1607 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1608 }
1609 } finally {
1610 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001611 }
Wink Saville36469e72014-06-11 15:17:00 -07001612 }
1613
1614 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001615 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001616 }
1617
Wink Savilleb564aae2014-10-23 10:18:09 -07001618 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001619 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001620
1621 final long identity = Binder.clearCallingIdentity();
1622 try {
1623 final Phone phone = getPhone(subId);
1624 if (phone == null) {
1625 return false;
1626 }
1627 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1628 toggleRadioOnOffForSubscriber(subId);
1629 }
1630 return true;
1631 } finally {
1632 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001633 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 }
Wink Saville36469e72014-06-11 15:17:00 -07001635
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001636 public boolean needMobileRadioShutdown() {
1637 /*
1638 * If any of the Radios are available, it will need to be
1639 * shutdown. So return true if any Radio is available.
1640 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001641 final long identity = Binder.clearCallingIdentity();
1642 try {
1643 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1644 Phone phone = PhoneFactory.getPhone(i);
1645 if (phone != null && phone.isRadioAvailable()) return true;
1646 }
1647 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1648 return false;
1649 } finally {
1650 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001652 }
1653
Malcolm Chend965c8b2018-02-28 15:00:40 -08001654 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001655 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001656 enforceModifyPermission();
1657
1658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1661 logv("Shutting down Phone " + i);
1662 shutdownRadioUsingPhoneId(i);
1663 }
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 }
1667 }
1668
1669 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 Phone phone = PhoneFactory.getPhone(phoneId);
1671 if (phone != null && phone.isRadioAvailable()) {
1672 phone.shutdownRadio();
1673 }
1674 }
1675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001677 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001678
1679 final long identity = Binder.clearCallingIdentity();
1680 try {
1681 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1682 if (defaultPhone != null) {
1683 defaultPhone.setRadioPower(turnOn);
1684 return true;
1685 } else {
1686 loge("There's no default phone.");
1687 return false;
1688 }
1689 } finally {
1690 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001691 }
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
1693
Wink Savilleb564aae2014-10-23 10:18:09 -07001694 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001696
1697 final long identity = Binder.clearCallingIdentity();
1698 try {
1699 final Phone phone = getPhone(subId);
1700 if (phone != null) {
1701 phone.setRadioPower(turnOn);
1702 return true;
1703 } else {
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709 }
1710
Wink Saville36469e72014-06-11 15:17:00 -07001711 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001712 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001713 public boolean enableDataConnectivity() {
1714 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 int subId = mSubscriptionController.getDefaultDataSubId();
1719 final Phone phone = getPhone(subId);
1720 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001721 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001722 return true;
1723 } else {
1724 return false;
1725 }
1726 } finally {
1727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001728 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001729 }
1730
Wink Saville36469e72014-06-11 15:17:00 -07001731 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001732 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001733 public boolean disableDataConnectivity() {
1734 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001735
1736 final long identity = Binder.clearCallingIdentity();
1737 try {
1738 int subId = mSubscriptionController.getDefaultDataSubId();
1739 final Phone phone = getPhone(subId);
1740 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001741 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001742 return true;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
Sanket Padawe356d7632015-06-22 14:03:32 -07001751 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001752 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 final Phone phone = getPhone(subId);
1756 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001757 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001758 } else {
1759 return false;
1760 }
1761 } finally {
1762 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001763 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001764 }
1765
1766 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001767 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001768 }
1769
pkanwarae03a6b2016-11-06 20:37:09 -08001770 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001771 enforceCallPermission();
1772
1773 final long identity = Binder.clearCallingIdentity();
1774 try {
1775 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1776 return;
1777 }
1778 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1779 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1780 } finally {
1781 Binder.restoreCallingIdentity(identity);
1782 }
pkanwar32d516d2016-10-14 19:37:38 -07001783 };
1784
Wink Savilleb564aae2014-10-23 10:18:09 -07001785 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1791 return false;
1792 }
1793 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1794 } finally {
1795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001797 }
1798
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001799 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001800 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001801 }
1802
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001803 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001804 final long identity = Binder.clearCallingIdentity();
1805 try {
1806 Phone phone = PhoneFactory.getPhone(slotIndex);
1807 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1808 PhoneConstantConversions.convertCallState(phone.getState());
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
1811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
Sanket Padawe356d7632015-06-22 14:03:32 -07001814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001816 final long identity = Binder.clearCallingIdentity();
1817 try {
1818 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1819 if (phone != null) {
1820 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1821 } else {
1822 return PhoneConstantConversions.convertDataState(
1823 PhoneConstants.DataState.DISCONNECTED);
1824 }
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
Sanket Padawe356d7632015-06-22 14:03:32 -07001830 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001832 final long identity = Binder.clearCallingIdentity();
1833 try {
1834 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1835 if (phone != null) {
1836 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1837 } else {
1838 return TelephonyManager.DATA_ACTIVITY_NONE;
1839 }
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
1845 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001846 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001847 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001848 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001849
1850 LocationAccessPolicy.LocationPermissionResult locationResult =
1851 LocationAccessPolicy.checkLocationPermission(mApp,
1852 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1853 .setCallingPackage(callingPackage)
1854 .setCallingPid(Binder.getCallingPid())
1855 .setCallingUid(Binder.getCallingUid())
1856 .setMethod("getCellLocation")
1857 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1858 .build());
1859 switch (locationResult) {
1860 case DENIED_HARD:
1861 throw new SecurityException("Not allowed to access cell location");
1862 case DENIED_SOFT:
1863 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001864 }
1865
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001866 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001867 final long identity = Binder.clearCallingIdentity();
1868 try {
1869 if (DBG_LOC) log("getCellLocation: is active user");
1870 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001871 int subId = mSubscriptionController.getDefaultDataSubId();
1872 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1873 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001874 return data;
1875 } finally {
1876 Binder.restoreCallingIdentity(identity);
1877 }
Svetoslav64fad262015-04-14 14:35:21 -07001878 }
1879
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001881 public String getNetworkCountryIsoForPhone(int phoneId) {
1882 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1883 // registered cell info, so return a NULL country instead.
1884 final long identity = Binder.clearCallingIdentity();
1885 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001886 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1887 // Get default phone in this case.
1888 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1889 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001890 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001891 // Todo: fix this when we can get the actual cellular network info when the device
1892 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001893 if (TelephonyManager.NETWORK_TYPE_IWLAN
1894 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1895 return "";
1896 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001897 Phone phone = PhoneFactory.getPhone(phoneId);
1898 if (phone != null) {
1899 ServiceStateTracker sst = phone.getServiceStateTracker();
1900 if (sst != null) {
1901 LocaleTracker lt = sst.getLocaleTracker();
1902 if (lt != null) {
1903 return lt.getCurrentCountry();
1904 }
1905 }
1906 }
1907 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001908 } finally {
1909 Binder.restoreCallingIdentity(identity);
1910 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001911 }
1912
1913 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001915 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001916 }
1917
Sanket Padawe356d7632015-06-22 14:03:32 -07001918 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001919 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 mApp.enforceCallingOrSelfPermission(
1921 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001922
1923 final long identity = Binder.clearCallingIdentity();
1924 try {
1925 final Phone phone = getPhone(subId);
1926 if (phone != null) {
1927 phone.enableLocationUpdates();
1928 }
1929 } finally {
1930 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001931 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 }
1933
1934 @Override
1935 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001936 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001937 }
1938
Sanket Padawe356d7632015-06-22 14:03:32 -07001939 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001940 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 mApp.enforceCallingOrSelfPermission(
1942 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 final Phone phone = getPhone(subId);
1947 if (phone != null) {
1948 phone.disableLocationUpdates();
1949 }
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Nathan Harold31d7ff32018-10-15 20:20:30 -07001955 /**
1956 * Returns the target SDK version number for a given package name.
1957 *
1958 * @return target SDK if the package is found or INT_MAX.
1959 */
1960 private int getTargetSdk(String packageName) {
1961 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001962 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1963 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001964 if (ai != null) return ai.targetSdkVersion;
1965 } catch (PackageManager.NameNotFoundException unexpected) {
1966 }
1967 return Integer.MAX_VALUE;
1968 }
1969
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 @Override
1971 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001972 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1973 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001974 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1975 throw new SecurityException(
1976 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1977 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001978
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001979 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1980 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1981 return null;
1982 }
Svetoslav64fad262015-04-14 14:35:21 -07001983
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001984 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985
Nathan Haroldf180aac2018-06-01 18:43:55 -07001986 List<CellInfo> info = getAllCellInfo(callingPackage);
1987 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988
Nathan Haroldf180aac2018-06-01 18:43:55 -07001989 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1990 for (CellInfo ci : info) {
1991 if (ci instanceof CellInfoGsm) {
1992 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1993 } else if (ci instanceof CellInfoWcdma) {
1994 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
1995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07001997 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002000 private List<CellInfo> getCachedCellInfo() {
2001 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2002 for (Phone phone : PhoneFactory.getPhones()) {
2003 List<CellInfo> info = phone.getAllCellInfo();
2004 if (info != null) cellInfos.addAll(info);
2005 }
2006 return cellInfos;
2007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008
2009 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002010 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002011 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002012 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002013
2014 LocationAccessPolicy.LocationPermissionResult locationResult =
2015 LocationAccessPolicy.checkLocationPermission(mApp,
2016 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2017 .setCallingPackage(callingPackage)
2018 .setCallingPid(Binder.getCallingPid())
2019 .setCallingUid(Binder.getCallingUid())
2020 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002021 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002022 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2023 .build());
2024 switch (locationResult) {
2025 case DENIED_HARD:
2026 throw new SecurityException("Not allowed to access cell info");
2027 case DENIED_SOFT:
2028 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002029 }
2030
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002031 final int targetSdk = getTargetSdk(callingPackage);
2032 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2033 return getCachedCellInfo();
2034 }
2035
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002036 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002037 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2041 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002042 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002043 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002044 if (info != null) cellInfos.addAll(info);
2045 }
2046 return cellInfos;
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050 }
2051
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002052 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002053 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2054 requestCellInfoUpdateInternal(
2055 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2056 }
2057
2058 @Override
2059 public void requestCellInfoUpdateWithWorkSource(
2060 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2061 enforceModifyPermission();
2062 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2063 }
2064
2065 private void requestCellInfoUpdateInternal(
2066 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002067 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002068 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002069
2070 LocationAccessPolicy.LocationPermissionResult locationResult =
2071 LocationAccessPolicy.checkLocationPermission(mApp,
2072 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2073 .setCallingPackage(callingPackage)
2074 .setCallingPid(Binder.getCallingPid())
2075 .setCallingUid(Binder.getCallingUid())
2076 .setMethod("requestCellInfoUpdate")
2077 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2078 .build());
2079 switch (locationResult) {
2080 case DENIED_HARD:
2081 throw new SecurityException("Not allowed to access cell info");
2082 case DENIED_SOFT:
2083 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002084 }
2085
2086 final Phone phone = getPhone(subId);
2087 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2088
2089 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2090 }
2091
2092 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002094 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002095 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002099 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002100 } finally {
2101 Binder.restoreCallingIdentity(identity);
2102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 }
2104
Shishir Agrawala9f32182016-04-12 12:00:16 -07002105 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002106 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002107 Phone phone = PhoneFactory.getPhone(slotIndex);
2108 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002109 return null;
2110 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002111 int subId = phone.getSubId();
2112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2113 mApp, subId, callingPackage, "getImeiForSlot")) {
2114 return null;
2115 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 return phone.getImei();
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
2122 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002123 }
2124
2125 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002126 public String getTypeAllocationCodeForSlot(int slotIndex) {
2127 Phone phone = PhoneFactory.getPhone(slotIndex);
2128 String tac = null;
2129 if (phone != null) {
2130 String imei = phone.getImei();
2131 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2132 }
2133 return tac;
2134 }
2135
2136 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002137 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002138 Phone phone = PhoneFactory.getPhone(slotIndex);
2139 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002140 return null;
2141 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002142
Jeff Davidson913390f2018-02-23 17:11:49 -08002143 int subId = phone.getSubId();
2144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2145 mApp, subId, callingPackage, "getMeidForSlot")) {
2146 return null;
2147 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002148
2149 final long identity = Binder.clearCallingIdentity();
2150 try {
2151 return phone.getMeid();
2152 } finally {
2153 Binder.restoreCallingIdentity(identity);
2154 }
Jack Yu2af8d712017-03-15 17:14:14 -07002155 }
2156
2157 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002158 public String getManufacturerCodeForSlot(int slotIndex) {
2159 Phone phone = PhoneFactory.getPhone(slotIndex);
2160 String manufacturerCode = null;
2161 if (phone != null) {
2162 String meid = phone.getMeid();
2163 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2164 }
2165 return manufacturerCode;
2166 }
2167
2168 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002169 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002170 Phone phone = PhoneFactory.getPhone(slotIndex);
2171 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002172 return null;
2173 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002174 int subId = phone.getSubId();
2175 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2176 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2177 return null;
2178 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002179
2180 final long identity = Binder.clearCallingIdentity();
2181 try {
2182 return phone.getDeviceSvn();
2183 } finally {
2184 Binder.restoreCallingIdentity(identity);
2185 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 }
2187
fionaxu43304da2017-11-27 22:51:16 -08002188 @Override
2189 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 final Phone phone = getPhone(subId);
2193 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
2196 }
fionaxu43304da2017-11-27 22:51:16 -08002197 }
2198
2199 @Override
2200 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002201 final long identity = Binder.clearCallingIdentity();
2202 try {
2203 final Phone phone = getPhone(subId);
2204 return phone == null ? null : phone.getCarrierName();
2205 } finally {
2206 Binder.restoreCallingIdentity(identity);
2207 }
fionaxu43304da2017-11-27 22:51:16 -08002208 }
2209
calvinpaneed9ae82018-11-01 19:43:06 +08002210 @Override
chen xuc93cc282018-11-04 17:17:00 -08002211 public int getSubscriptionPreciseCarrierId(int subId) {
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 final Phone phone = getPhone(subId);
2215 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
2216 : phone.getPreciseCarrierId();
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
2219 }
2220 }
2221
2222 @Override
2223 public String getSubscriptionPreciseCarrierName(int subId) {
2224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 final Phone phone = getPhone(subId);
2227 return phone == null ? null : phone.getPreciseCarrierName();
2228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
2231 }
2232
chen xu02581692018-11-11 19:03:44 -08002233 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002234 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2235 if (!isSubscriptionMccMnc) {
2236 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2237 }
chen xu02581692018-11-11 19:03:44 -08002238 final Phone phone = PhoneFactory.getPhone(slotIndex);
2239 if (phone == null) {
2240 return TelephonyManager.UNKNOWN_CARRIER_ID;
2241 }
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
2248 }
2249
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002250 //
2251 // Internal helper methods.
2252 //
2253
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002254 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2256 *
2257 * @throws SecurityException if the caller does not have the required permission
2258 */
2259 private void enforceModifyPermission() {
2260 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2261 }
2262
2263 /**
2264 * Make sure the caller has the CALL_PHONE permission.
2265 *
2266 * @throws SecurityException if the caller does not have the required permission
2267 */
2268 private void enforceCallPermission() {
2269 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2270 }
2271
Stuart Scott8eef64f2015-04-08 15:13:54 -07002272 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002273 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002274 "ConnectivityService");
2275 }
2276
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 private String createTelUrl(String number) {
2278 if (TextUtils.isEmpty(number)) {
2279 return null;
2280 }
2281
Jake Hambye994d462014-02-03 13:10:13 -08002282 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283 }
2284
Ihab Awadf9e92732013-12-05 18:02:52 -08002285 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2287 }
2288
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002289 private static void logv(String msg) {
2290 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2291 }
2292
Ihab Awadf9e92732013-12-05 18:02:52 -08002293 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2295 }
2296
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002297 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002300 }
2301
Sanket Padawe356d7632015-06-22 14:03:32 -07002302 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002303 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002304 final long identity = Binder.clearCallingIdentity();
2305 try {
2306 final Phone phone = PhoneFactory.getPhone(slotIndex);
2307 if (phone == null) {
2308 return PhoneConstants.PHONE_TYPE_NONE;
2309 } else {
2310 return phone.getPhoneType();
2311 }
2312 } finally {
2313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 }
2316
2317 /**
2318 * Returns the CDMA ERI icon index to display
2319 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002320 @Override
2321 public int getCdmaEriIconIndex(String callingPackage) {
2322 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002323 }
2324
Sanket Padawe356d7632015-06-22 14:03:32 -07002325 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002326 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002327 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002328 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002329 return -1;
2330 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002331
2332 final long identity = Binder.clearCallingIdentity();
2333 try {
2334 final Phone phone = getPhone(subId);
2335 if (phone != null) {
2336 return phone.getCdmaEriIconIndex();
2337 } else {
2338 return -1;
2339 }
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344
2345 /**
2346 * Returns the CDMA ERI icon mode,
2347 * 0 - ON
2348 * 1 - FLASHING
2349 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002350 @Override
2351 public int getCdmaEriIconMode(String callingPackage) {
2352 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002353 }
2354
Sanket Padawe356d7632015-06-22 14:03:32 -07002355 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002356 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002357 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002358 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002359 return -1;
2360 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002361
2362 final long identity = Binder.clearCallingIdentity();
2363 try {
2364 final Phone phone = getPhone(subId);
2365 if (phone != null) {
2366 return phone.getCdmaEriIconMode();
2367 } else {
2368 return -1;
2369 }
2370 } finally {
2371 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002373 }
2374
2375 /**
2376 * Returns the CDMA ERI text,
2377 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002378 @Override
2379 public String getCdmaEriText(String callingPackage) {
2380 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002384 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002385 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002386 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002387 return null;
2388 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002389
2390 final long identity = Binder.clearCallingIdentity();
2391 try {
2392 final Phone phone = getPhone(subId);
2393 if (phone != null) {
2394 return phone.getCdmaEriText();
2395 } else {
2396 return null;
2397 }
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
2402
2403 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002404 * Returns the CDMA MDN.
2405 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002406 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002407 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2409 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002410
2411 final long identity = Binder.clearCallingIdentity();
2412 try {
2413 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002414 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002415 return phone.getLine1Number();
2416 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002417 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002418 return null;
2419 }
2420 } finally {
2421 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002422 }
2423 }
2424
2425 /**
2426 * Returns the CDMA MIN.
2427 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002428 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002429 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002430 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2431 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 final Phone phone = getPhone(subId);
2436 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2437 return phone.getCdmaMin();
2438 } else {
2439 return null;
2440 }
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002443 }
2444 }
2445
Hall Liud892bec2018-11-30 14:51:45 -08002446 @Override
2447 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2448 INumberVerificationCallback callback, String callingPackage) {
2449 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2450 != PERMISSION_GRANTED) {
2451 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2452 }
2453 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2454
2455 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2456 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2457 throw new SecurityException("Calling package must be configured in the device config");
2458 }
2459
2460 if (range == null) {
2461 throw new NullPointerException("Range must be non-null");
2462 }
2463
2464 timeoutMillis = Math.min(timeoutMillis,
2465 TelephonyManager.MAX_NUMBER_VERIFICATION_TIMEOUT_MILLIS);
2466
2467 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2468 }
2469
Junda Liuca05d5d2014-08-14 22:36:34 -07002470 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002471 * Returns true if CDMA provisioning needs to run.
2472 */
2473 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002476 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002477 } finally {
2478 Binder.restoreCallingIdentity(identity);
2479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481
2482 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002483 * Sets the voice mail number of a given subId.
2484 */
2485 @Override
2486 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002487 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002488
2489 final long identity = Binder.clearCallingIdentity();
2490 try {
2491 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2492 new Pair<String, String>(alphaTag, number), new Integer(subId));
2493 return success;
2494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002497 }
2498
Ta-wei Yen87c49842016-05-13 21:19:52 -07002499 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002500 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2501 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002502 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002503 if (!TextUtils.equals(callingPackage, systemDialer)) {
2504 throw new SecurityException("caller must be system dialer");
2505 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002506
2507 final long identity = Binder.clearCallingIdentity();
2508 try {
2509 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2510 if (phoneAccountHandle == null) {
2511 return null;
2512 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002513 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002514 } finally {
2515 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002516 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002517 }
2518
2519 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002520 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002521 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002522 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002523 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002524 return null;
2525 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002526
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002527 final long identity = Binder.clearCallingIdentity();
2528 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002529 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002530 } finally {
2531 Binder.restoreCallingIdentity(identity);
2532 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002533 }
2534
2535 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002536 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2537 VisualVoicemailSmsFilterSettings settings) {
2538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002539
2540 final long identity = Binder.clearCallingIdentity();
2541 try {
2542 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002543 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002544 } finally {
2545 Binder.restoreCallingIdentity(identity);
2546 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002547 }
2548
2549 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002550 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2551 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002552
2553 final long identity = Binder.clearCallingIdentity();
2554 try {
2555 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002556 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557 } finally {
2558 Binder.restoreCallingIdentity(identity);
2559 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002560 }
2561
2562 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002563 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2564 String callingPackage, int subId) {
2565 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002566
2567 final long identity = Binder.clearCallingIdentity();
2568 try {
2569 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002570 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002571 } finally {
2572 Binder.restoreCallingIdentity(identity);
2573 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002574 }
2575
2576 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002577 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002578 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002583 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002584 } finally {
2585 Binder.restoreCallingIdentity(identity);
2586 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002587 }
2588
2589 @Override
2590 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2591 String number, int port, String text, PendingIntent sentIntent) {
2592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002593 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002594 enforceSendSmsPermission();
2595 // Make the calls as the phone process.
2596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2599 if (port == 0) {
2600 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2601 sentIntent, null, false);
2602 } else {
2603 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2604 smsManager.sendDataMessageWithSelfPermissions(number, null,
2605 (short) port, data, sentIntent, null);
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
2609 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002610 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002611 /**
fionaxu0152e512016-11-14 13:36:14 -08002612 * Sets the voice activation state of a given subId.
2613 */
2614 @Override
2615 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2617 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002618
2619 final long identity = Binder.clearCallingIdentity();
2620 try {
2621 final Phone phone = getPhone(subId);
2622 if (phone != null) {
2623 phone.setVoiceActivationState(activationState);
2624 } else {
2625 loge("setVoiceActivationState fails with invalid subId: " + subId);
2626 }
2627 } finally {
2628 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002629 }
2630 }
2631
2632 /**
2633 * Sets the data activation state of a given subId.
2634 */
2635 @Override
2636 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2638 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002639
2640 final long identity = Binder.clearCallingIdentity();
2641 try {
2642 final Phone phone = getPhone(subId);
2643 if (phone != null) {
2644 phone.setDataActivationState(activationState);
2645 } else {
2646 loge("setVoiceActivationState fails with invalid subId: " + subId);
2647 }
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002650 }
2651 }
2652
2653 /**
2654 * Returns the voice activation state of a given subId.
2655 */
2656 @Override
2657 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002658 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002659
fionaxu0152e512016-11-14 13:36:14 -08002660 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 if (phone != null) {
2664 return phone.getVoiceActivationState();
2665 } else {
2666 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2667 }
2668 } finally {
2669 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002670 }
2671 }
2672
2673 /**
2674 * Returns the data activation state of a given subId.
2675 */
2676 @Override
2677 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002678 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002679
fionaxu0152e512016-11-14 13:36:14 -08002680 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 if (phone != null) {
2684 return phone.getDataActivationState();
2685 } else {
2686 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2687 }
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002690 }
2691 }
2692
2693 /**
Wink Saville36469e72014-06-11 15:17:00 -07002694 * Returns the unread count of voicemails for a subId
2695 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002696 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002697 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2699 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2700 return 0;
2701 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 final Phone phone = getPhone(subId);
2705 if (phone != null) {
2706 return phone.getVoiceMessageCount();
2707 } else {
2708 return 0;
2709 }
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713 }
2714
2715 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002716 * returns true, if the device is in a state where both voice and data
2717 * are supported simultaneously. This can change based on location or network condition.
2718 */
2719 @Override
2720 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002721 final long identity = Binder.clearCallingIdentity();
2722 try {
2723 final Phone phone = getPhone(subId);
2724 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
2727 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002728 }
2729
2730 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002731 * Send the dialer code if called from the current default dialer or the caller has
2732 * carrier privilege.
2733 * @param inputCode The dialer code to send
2734 */
2735 @Override
2736 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002737 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002739 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2740 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002741 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002742 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2743 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002744 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002745
2746 final long identity = Binder.clearCallingIdentity();
2747 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002748 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002749 } finally {
2750 Binder.restoreCallingIdentity(identity);
2751 }
fionaxu235cc5e2017-03-06 22:25:57 -08002752 }
2753
2754 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002755 * Returns the data network type.
2756 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 *
2758 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2759 */
2760 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002761 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002762 final long identity = Binder.clearCallingIdentity();
2763 try {
2764 final Phone phone = getPhone(getDefaultSubscription());
2765 if (phone != null) {
2766 return phone.getServiceState().getDataNetworkType();
2767 } else {
2768 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2769 }
2770 } finally {
2771 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002772 }
Wink Saville36469e72014-06-11 15:17:00 -07002773 }
2774
Pengquan Meng0c05b502018-09-06 09:59:22 -07002775 @Override
2776 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002777 if (!isActiveSubscription(subId)) {
2778 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2779 }
2780
Pengquan Meng0c05b502018-09-06 09:59:22 -07002781 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2782 }
2783
Brad Ebinger4c460712018-10-01 10:40:55 -07002784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002785 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2786 throws RemoteException {
2787 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002788 final long token = Binder.clearCallingIdentity();
2789 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002791 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002792 .addRegistrationCallbackForSubscription(c, subId);
2793 } finally {
2794 Binder.restoreCallingIdentity(token);
2795 }
2796 }
2797
2798 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002799 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2800 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002801 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2802 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2803 }
2804 Binder.withCleanCallingIdentity(() -> {
2805 try {
2806 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002807 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002808 .removeRegistrationCallbackForSubscription(c, subId);
2809 } catch (IllegalArgumentException e) {
2810 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2811 + "is inactive, ignoring unregister.");
2812 // If the subscription is no longer active, just return, since the callback
2813 // will already have been removed internally.
2814 }
2815 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002816 }
2817
2818 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002819 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2820 throws RemoteException {
2821 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002822 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2823 final long token = Binder.clearCallingIdentity();
2824 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002825 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002826 .addCapabilitiesCallbackForSubscription(c, subId);
2827 } finally {
2828 Binder.restoreCallingIdentity(token);
2829 }
2830 }
2831
2832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002833 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2834 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002835
2836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2837 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2838 }
2839 Binder.withCleanCallingIdentity(() -> {
2840 try {
2841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002842 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002843 .removeCapabilitiesCallbackForSubscription(c, subId);
2844 } catch (IllegalArgumentException e) {
2845 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2846 + "is inactive, ignoring unregister.");
2847 // If the subscription is no longer active, just return, since the callback
2848 // will already have been removed internally.
2849 }
2850 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002851 }
2852
2853 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002854 public boolean isCapable(int subId, int capability, int regTech) {
2855 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2857 final long token = Binder.clearCallingIdentity();
2858 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002859 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002860 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2861 } catch (ImsException e) {
2862 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2863 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002864 } catch (IllegalArgumentException e) {
2865 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2866 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002867 } finally {
2868 Binder.restoreCallingIdentity(token);
2869 }
2870 }
2871
2872 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002873 public boolean isAvailable(int subId, int capability, int regTech) {
2874 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 final long token = Binder.clearCallingIdentity();
2876 try {
2877 Phone phone = getPhone(subId);
2878 if (phone == null) return false;
2879 return phone.isImsCapabilityAvailable(capability, regTech);
2880 } finally {
2881 Binder.restoreCallingIdentity(token);
2882 }
2883 }
2884
2885 @Override
2886 public boolean isAdvancedCallingSettingEnabled(int subId) {
2887 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2888 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2889 final long token = Binder.clearCallingIdentity();
2890 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002891 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002892 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2893 } finally {
2894 Binder.restoreCallingIdentity(token);
2895 }
2896 }
2897
2898 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002899 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002901 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002905 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002906 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2907 } finally {
2908 Binder.restoreCallingIdentity(identity);
2909 }
2910 }
2911
2912 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002913 public boolean isVtSettingEnabled(int subId) {
2914 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002918 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002919 getSlotIndexOrException(subId)).isVtEnabledByUser();
2920 } finally {
2921 Binder.restoreCallingIdentity(identity);
2922 }
2923 }
2924
2925 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002926 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002927 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002928 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002929 final long identity = Binder.clearCallingIdentity();
2930 try {
2931 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002932 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
2936 }
2937
2938 @Override
2939 public boolean isVoWiFiSettingEnabled(int subId) {
2940 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2941 final long identity = Binder.clearCallingIdentity();
2942 try {
2943 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002944 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002945 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
2949 }
2950
2951 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002952 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002954 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002958 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002959 } finally {
2960 Binder.restoreCallingIdentity(identity);
2961 }
2962 }
2963
2964 @Override
2965 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2966 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002970 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002971 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
2975 }
2976
2977 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002978 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002979 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002980 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002984 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002985 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
2989 }
2990
2991 @Override
2992 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2993 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2994 "setVoWiFiNonPersistent");
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08002998 boolean isRoaming = TelephonyManager.from(
2999 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003000 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003001 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003002 } finally {
3003 Binder.restoreCallingIdentity(identity);
3004 }
3005 }
3006
3007 @Override
3008 public int getVoWiFiModeSetting(int subId) {
3009 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003013 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003014 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3015 } finally {
3016 Binder.restoreCallingIdentity(identity);
3017 }
3018 }
3019
3020 @Override
3021 public void setVoWiFiModeSetting(int subId, int mode) {
3022 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3023 "setVoWiFiModeSetting");
3024 final long identity = Binder.clearCallingIdentity();
3025 try {
3026 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003027 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003028 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3029 } finally {
3030 Binder.restoreCallingIdentity(identity);
3031 }
3032 }
3033
3034 @Override
3035 public int getVoWiFiRoamingModeSetting(int subId) {
3036 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3037 final long identity = Binder.clearCallingIdentity();
3038 try {
3039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003040 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003041 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
3045 }
3046
3047 @Override
3048 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3050 "setVoWiFiRoamingModeSetting");
3051 final long identity = Binder.clearCallingIdentity();
3052 try {
3053 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003054 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003055 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3056 } finally {
3057 Binder.restoreCallingIdentity(identity);
3058 }
3059 }
3060
3061 @Override
3062 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3064 "setRttCapabilityEnabled");
3065 final long identity = Binder.clearCallingIdentity();
3066 try {
3067 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003068 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003069 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
3073 }
3074
3075 @Override
3076 public boolean isTtyOverVolteEnabled(int subId) {
3077 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003081 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003082 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3083 } finally {
3084 Binder.restoreCallingIdentity(identity);
3085 }
3086 }
3087
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003088 @Override
3089 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3090 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3091 final long identity = Binder.clearCallingIdentity();
3092 try {
3093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003094 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003095 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003096 } finally {
3097 Binder.restoreCallingIdentity(identity);
3098 }
3099 }
3100
3101 @Override
3102 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3103 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3104 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003105 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3106 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3107 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003108 try {
3109 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003110 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003111 .removeProvisioningCallbackForSubscription(callback, subId);
3112 } catch (IllegalArgumentException e) {
3113 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3114 + "is inactive, ignoring unregister.");
3115 // If the subscription is no longer active, just return, since the callback will already
3116 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003123 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3124 boolean isProvisioned) {
3125 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3126 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3127 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3128 }
3129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3130 "setProvisioningStatusForCapability");
3131 final long identity = Binder.clearCallingIdentity();
3132 try {
3133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3134 Phone phone = getPhone(subId);
3135 if (phone == null) {
3136 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3137 + subId);
3138 return;
3139 }
3140 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3141 return;
3142 }
3143
3144 // this capability requires provisioning, route to the correct API.
3145 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3146 switch (capability) {
3147 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3148 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3149 ims.setVolteProvisioned(isProvisioned);
3150 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3151 ims.setWfcProvisioned(isProvisioned);
3152 }
3153 break;
3154 }
3155 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3156 // There is currently no difference in VT provisioning type.
3157 ims.setVtProvisioned(isProvisioned);
3158 break;
3159 }
3160 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3161 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3162 // change the capability of the feature instead if needed.
3163 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3164 == isProvisioned) {
3165 // No change in provisioning.
3166 return;
3167 }
3168 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3169 try {
3170 ims.changeMmTelCapability(capability, tech, isProvisioned);
3171 } catch (ImsException e) {
3172 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3173 + ", Exception" + e.getMessage());
3174 }
3175 break;
3176 }
3177 default: {
3178 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3179 + capability + "', which does not require provisioning.");
3180 }
3181 }
3182
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 }
3187
3188 @Override
3189 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3190 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3191 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3192 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3193 }
3194 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3195 final long identity = Binder.clearCallingIdentity();
3196 try {
3197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3198 Phone phone = getPhone(subId);
3199 if (phone == null) {
3200 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3201 + subId);
3202 // We will fail with "true" as the provisioning status because this is the default
3203 // if we do not require provisioning.
3204 return true;
3205 }
3206
3207 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3208 return true;
3209 }
3210
3211 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3212 switch (capability) {
3213 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3214 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3215 return ims.isVolteProvisionedOnDevice();
3216 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3217 return ims.isWfcProvisionedOnDevice();
3218 }
3219 // This should never happen, since we are checking tech above to make sure it
3220 // is either LTE or IWLAN.
3221 throw new IllegalArgumentException("Invalid radio technology for voice "
3222 + "capability.");
3223 }
3224 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3225 // There is currently no difference in VT provisioning type.
3226 return ims.isVtProvisionedOnDevice();
3227 }
3228 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3229 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3230 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3231 }
3232 default: {
3233 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3234 + capability + "', which does not require provisioning.");
3235 }
3236 }
3237
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
3240 }
3241 }
3242
3243 @Override
3244 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3245 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3246 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3247 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3248 }
3249 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3250 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3251 return (provisionedBits & capability) > 0;
3252 }
3253
3254 @Override
3255 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3256 boolean isProvisioned) {
3257 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3258 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3259 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3260 }
3261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3262 "setProvisioningStatusForCapability");
3263 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3264 // If the current provisioning status for capability already matches isProvisioned,
3265 // do nothing.
3266 if (((provisionedBits & capability) > 0) == isProvisioned) {
3267 return;
3268 }
3269 if (isProvisioned) {
3270 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3271 } else {
3272 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3273 }
3274 }
3275
3276 /**
3277 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3278 * technology. The bitfield should mirror the bitfield defined by
3279 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3280 */
3281 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3282 String key = getMmTelProvisioningKey(subId, tech);
3283 // Default is no capabilities are provisioned.
3284 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3285 }
3286
3287 /**
3288 * Sets the MmTel capability provisioning bitfield (defined by
3289 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3290 * technology specified.
3291 *
3292 * Note: This is a synchronous command and should not be called on UI thread.
3293 */
3294 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3295 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3296 String key = getMmTelProvisioningKey(subId, tech);
3297 editor.putInt(key, newField);
3298 editor.commit();
3299 }
3300
3301 private static String getMmTelProvisioningKey(int subId, int tech) {
3302 // resulting key is provision_ims_mmtel_{subId}_{tech}
3303 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3304 }
3305
3306 /**
3307 * Query CarrierConfig to see if the specified capability requires provisioning for the
3308 * carrier associated with the subscription id.
3309 */
3310 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3311 int capability) {
3312 CarrierConfigManager configManager = new CarrierConfigManager(context);
3313 PersistableBundle c = configManager.getConfigForSubId(subId);
3314 boolean requireUtProvisioning = c.getBoolean(
3315 // By default, this config is true (even if there is no SIM). We also check to make
3316 // sure the subscription needs provisioning here, so we do not need to check for
3317 // the no-SIM case, where we would normally shortcut this to false.
3318 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3319 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3320 false);
3321 boolean requireVoiceVtProvisioning = c.getBoolean(
3322 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3323
3324 // First check to make sure that the capability requires provisioning.
3325 switch (capability) {
3326 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3327 // intentional fallthrough
3328 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3329 if (requireVoiceVtProvisioning) {
3330 // Voice and Video requires provisioning
3331 return true;
3332 }
3333 break;
3334 }
3335 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3336 if (requireUtProvisioning) {
3337 // UT requires provisioning
3338 return true;
3339 }
3340 break;
3341 }
3342 }
3343 return false;
3344 }
3345
3346 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003347 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003348 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3349 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3350 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003351 enforceReadPrivilegedPermission("getImsProvisioningInt");
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003355 int slotId = getSlotIndex(subId);
3356 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3357 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3358 + subId + "' for key:" + key);
3359 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3360 }
3361 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003362 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003363 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3364 + subId + "' for key:" + key);
3365 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003373 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3374 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3375 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003376 enforceReadPrivilegedPermission("getImsProvisioningString");
3377 final long identity = Binder.clearCallingIdentity();
3378 try {
3379 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003380 int slotId = getSlotIndex(subId);
3381 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3382 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3383 + subId + "' for key:" + key);
3384 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3385 }
3386 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003387 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3389 + subId + "' for key:" + key);
3390 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 } finally {
3392 Binder.restoreCallingIdentity(identity);
3393 }
3394 }
3395
3396 @Override
3397 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003398 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3399 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3400 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003401 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3402 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003403 final long identity = Binder.clearCallingIdentity();
3404 try {
3405 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003406 int slotId = getSlotIndex(subId);
3407 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3408 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3409 + subId + "' for key:" + key);
3410 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3411 }
3412 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003413 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003414 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3415 + "' for key:" + key);
3416 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
3420 }
3421
3422 @Override
3423 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003424 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3425 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3426 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003427 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3428 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003432 int slotId = getSlotIndex(subId);
3433 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3434 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3435 + subId + "' for key:" + key);
3436 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3437 }
3438 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003439 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003440 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3441 + "' for key:" + key);
3442 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003443 } finally {
3444 Binder.restoreCallingIdentity(identity);
3445 }
3446 }
3447
Brad Ebinger4c460712018-10-01 10:40:55 -07003448 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3449 int slotId = SubscriptionManager.getSlotIndex(subId);
3450 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003451 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003452 }
3453 return slotId;
3454 }
3455
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003456 private int getSlotIndex(int subId) {
3457 int slotId = SubscriptionManager.getSlotIndex(subId);
3458 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3459 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3460 }
3461 return slotId;
3462 }
3463
Wink Saville36469e72014-06-11 15:17:00 -07003464 /**
3465 * Returns the network type for a subId
3466 */
3467 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003468 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003470 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003471 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3472 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003473
Malcolm Chend965c8b2018-02-28 15:00:40 -08003474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 final Phone phone = getPhone(subId);
3477 if (phone != null) {
3478 return phone.getServiceState().getDataNetworkType();
3479 } else {
3480 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3481 }
3482 } finally {
3483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003485 }
3486
3487 /**
3488 * Returns the data network type
3489 */
3490 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003491 public int getDataNetworkType(String callingPackage) {
3492 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003493 }
3494
3495 /**
3496 * Returns the data network type for a subId
3497 */
3498 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003499 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003500 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003501 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003502 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3503 }
3504
Malcolm Chend965c8b2018-02-28 15:00:40 -08003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 final Phone phone = getPhone(subId);
3508 if (phone != null) {
3509 return phone.getServiceState().getDataNetworkType();
3510 } else {
3511 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3512 }
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003515 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003516 }
3517
3518 /**
Wink Saville36469e72014-06-11 15:17:00 -07003519 * Returns the Voice network type for a subId
3520 */
3521 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003522 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003523 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003524 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003525 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3526 }
3527
Malcolm Chend965c8b2018-02-28 15:00:40 -08003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 final Phone phone = getPhone(subId);
3531 if (phone != null) {
3532 return phone.getServiceState().getVoiceNetworkType();
3533 } else {
3534 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003538 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003539 }
3540
3541 /**
3542 * @return true if a ICC card is present
3543 */
3544 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003545 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003546 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3547 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003548 }
3549
3550 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003551 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003552 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003554 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003555 final long identity = Binder.clearCallingIdentity();
3556 try {
3557 final Phone phone = PhoneFactory.getPhone(slotIndex);
3558 if (phone != null) {
3559 return phone.getIccCard().hasIccCard();
3560 } else {
3561 return false;
3562 }
3563 } finally {
3564 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003566 }
3567
3568 /**
3569 * Return if the current radio is LTE on CDMA. This
3570 * is a tri-state return value as for a period of time
3571 * the mode may be unknown.
3572 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003573 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003574 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003575 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003576 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003577 @Override
3578 public int getLteOnCdmaMode(String callingPackage) {
3579 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003580 }
3581
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003583 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003585 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003586 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3587 }
3588
Malcolm Chend965c8b2018-02-28 15:00:40 -08003589 final long identity = Binder.clearCallingIdentity();
3590 try {
3591 final Phone phone = getPhone(subId);
3592 if (phone == null) {
3593 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3594 } else {
3595 return phone.getLteOnCdmaMode();
3596 }
3597 } finally {
3598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003599 }
Wink Saville36469e72014-06-11 15:17:00 -07003600 }
3601
Wink Saville36469e72014-06-11 15:17:00 -07003602 /**
3603 * {@hide}
3604 * Returns Default subId, 0 in the case of single standby.
3605 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003606 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003607 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003608 }
3609
Shishir Agrawala9f32182016-04-12 12:00:16 -07003610 private int getSlotForDefaultSubscription() {
3611 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3612 }
3613
Wink Savilleb564aae2014-10-23 10:18:09 -07003614 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003615 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003616 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003617
Pengquan Meng466e2482018-09-21 15:54:48 -07003618 private boolean isActiveSubscription(int subId) {
3619 return mSubscriptionController.isActiveSubId(subId);
3620 }
3621
Ihab Awadf2177b72013-11-25 13:33:23 -08003622 /**
3623 * @see android.telephony.TelephonyManager.WifiCallingChoices
3624 */
3625 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003626 final long identity = Binder.clearCallingIdentity();
3627 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003628 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003629 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3630 getWhenToMakeWifiCallsDefaultPreference());
3631 } finally {
3632 Binder.restoreCallingIdentity(identity);
3633 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003634 }
3635
3636 /**
3637 * @see android.telephony.TelephonyManager.WifiCallingChoices
3638 */
3639 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003640 final long identity = Binder.clearCallingIdentity();
3641 try {
3642 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003643 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003644 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3645 } finally {
3646 Binder.restoreCallingIdentity(identity);
3647 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003648 }
3649
Sailesh Nepald1e68152013-12-12 19:08:02 -08003650 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003651 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003652 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003653 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003654
Shishir Agrawal566b7612013-10-28 14:41:00 -07003655 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003656 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3657 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003658 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3659 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003660 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003661
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 final long identity = Binder.clearCallingIdentity();
3663 try {
3664 if (TextUtils.equals(ISDR_AID, aid)) {
3665 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003666 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3667 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003668 if (bestComponent == null
3669 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3670 loge("The calling package is not allowed to access ISD-R.");
3671 throw new SecurityException(
3672 "The calling package is not allowed to access ISD-R.");
3673 }
Derek Tan740e1672017-06-27 14:56:27 -07003674 }
Derek Tan740e1672017-06-27 14:56:27 -07003675
Malcolm Chend965c8b2018-02-28 15:00:40 -08003676 if (DBG) {
3677 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3678 }
3679 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3680 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3681 if (DBG) log("iccOpenLogicalChannel: " + response);
3682 return response;
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
3685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003686 }
3687
3688 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003689 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3691 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003692
Malcolm Chend965c8b2018-02-28 15:00:40 -08003693 final long identity = Binder.clearCallingIdentity();
3694 try {
3695 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3696 if (channel < 0) {
3697 return false;
3698 }
3699 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3700 if (DBG) log("iccCloseLogicalChannel: " + success);
3701 return success;
3702 } finally {
3703 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003704 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003705 }
3706
3707 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003708 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3711 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003712
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 final long identity = Binder.clearCallingIdentity();
3714 try {
3715 if (DBG) {
3716 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3717 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3718 + p3 + " data=" + data);
3719 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003720
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 if (channel < 0) {
3722 return "";
3723 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003724
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3726 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3727 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003728
Malcolm Chend965c8b2018-02-28 15:00:40 -08003729 // Append the returned status code to the end of the response payload.
3730 String s = Integer.toHexString(
3731 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3732 if (response.payload != null) {
3733 s = IccUtils.bytesToHexString(response.payload) + s;
3734 }
3735 return s;
3736 } finally {
3737 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003738 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003739 }
Jake Hambye994d462014-02-03 13:10:13 -08003740
Evan Charltonc66da362014-05-16 14:06:40 -07003741 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003742 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3743 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3745 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003746 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003747
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
3750 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3751 && TextUtils.equals(ISDR_AID, data)) {
3752 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003753 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3754 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003755 if (bestComponent == null
3756 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3757 loge("The calling package is not allowed to select ISD-R.");
3758 throw new SecurityException(
3759 "The calling package is not allowed to select ISD-R.");
3760 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003761 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003762
Malcolm Chend965c8b2018-02-28 15:00:40 -08003763 if (DBG) {
3764 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3765 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3766 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003767
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3769 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3770 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003771
Malcolm Chend965c8b2018-02-28 15:00:40 -08003772 // Append the returned status code to the end of the response payload.
3773 String s = Integer.toHexString(
3774 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3775 if (response.payload != null) {
3776 s = IccUtils.bytesToHexString(response.payload) + s;
3777 }
3778 return s;
3779 } finally {
3780 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003781 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003782 }
3783
3784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003785 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003786 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003787 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3788 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003789
Malcolm Chend965c8b2018-02-28 15:00:40 -08003790 final long identity = Binder.clearCallingIdentity();
3791 try {
3792 if (DBG) {
3793 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3794 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3795 }
3796
3797 IccIoResult response =
3798 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3799 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3800 subId);
3801
3802 if (DBG) {
3803 log("Exchange SIM_IO [R]" + response);
3804 }
3805
3806 byte[] result = null;
3807 int length = 2;
3808 if (response.payload != null) {
3809 length = 2 + response.payload.length;
3810 result = new byte[length];
3811 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3812 } else {
3813 result = new byte[length];
3814 }
3815
3816 result[length - 1] = (byte) response.sw2;
3817 result[length - 2] = (byte) response.sw1;
3818 return result;
3819 } finally {
3820 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003821 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003822 }
3823
Nathan Haroldb3014052017-01-25 15:57:32 -08003824 /**
3825 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3826 * on a particular subscription
3827 */
sqianb6e41952018-03-12 14:54:01 -07003828 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3830 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3831 return null;
3832 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003833
3834 final long identity = Binder.clearCallingIdentity();
3835 try {
3836 if (appType != TelephonyManager.APPTYPE_USIM
3837 && appType != TelephonyManager.APPTYPE_SIM) {
3838 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3839 return null;
3840 }
3841 Object response = sendRequest(
3842 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3843 if (response instanceof String[]) {
3844 return (String[]) response;
3845 }
3846 // Response is an Exception of some kind,
3847 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003848 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003849 } finally {
3850 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003851 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003852 }
3853
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003854 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003855 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003856 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3857 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003858
Malcolm Chend965c8b2018-02-28 15:00:40 -08003859 final long identity = Binder.clearCallingIdentity();
3860 try {
3861 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3862 if (response.payload == null) {
3863 return "";
3864 }
Evan Charltonc66da362014-05-16 14:06:40 -07003865
Malcolm Chend965c8b2018-02-28 15:00:40 -08003866 // Append the returned status code to the end of the response payload.
3867 String s = Integer.toHexString(
3868 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3869 s = IccUtils.bytesToHexString(response.payload) + s;
3870 return s;
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
Evan Charltonc66da362014-05-16 14:06:40 -07003874 }
3875
Jake Hambye994d462014-02-03 13:10:13 -08003876 /**
3877 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3878 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3879 *
3880 * @param itemID the ID of the item to read
3881 * @return the NV item as a String, or null on error.
3882 */
3883 @Override
3884 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003885 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003886 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3887 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003888
3889 final long identity = Binder.clearCallingIdentity();
3890 try {
3891 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003892 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3894 return value;
3895 } finally {
3896 Binder.restoreCallingIdentity(identity);
3897 }
Jake Hambye994d462014-02-03 13:10:13 -08003898 }
3899
3900 /**
3901 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3902 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3903 *
3904 * @param itemID the ID of the item to read
3905 * @param itemValue the value to write, as a String
3906 * @return true on success; false on any failure
3907 */
3908 @Override
3909 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003910 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3912 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003913
3914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3917 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003918 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003919 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3920 return success;
3921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
Jake Hambye994d462014-02-03 13:10:13 -08003924 }
3925
3926 /**
3927 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3928 * Used for device configuration by some CDMA operators.
3929 *
3930 * @param preferredRoamingList byte array containing the new PRL
3931 * @return true on success; false on any failure
3932 */
3933 @Override
3934 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3936 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003937
3938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3941 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3942 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3943 return success;
3944 } finally {
3945 Binder.restoreCallingIdentity(identity);
3946 }
Jake Hambye994d462014-02-03 13:10:13 -08003947 }
3948
3949 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003950 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003951 * Used for device configuration by some CDMA operators.
3952 *
chen xu1cc0abe2018-10-26 17:39:23 -07003953 * @param slotIndex - device slot.
3954 *
Jake Hambye994d462014-02-03 13:10:13 -08003955 * @return true on success; false on any failure
3956 */
3957 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003958 public boolean resetModemConfig(int slotIndex) {
3959 Phone phone = PhoneFactory.getPhone(slotIndex);
3960 if (phone != null) {
3961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3962 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003963
chen xu1cc0abe2018-10-26 17:39:23 -07003964 final long identity = Binder.clearCallingIdentity();
3965 try {
3966 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3967 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3968 return success;
3969 } finally {
3970 Binder.restoreCallingIdentity(identity);
3971 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003972 }
chen xu1cc0abe2018-10-26 17:39:23 -07003973 return false;
3974 }
3975
3976 /**
3977 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3978 *
3979 * @param slotIndex - device slot.
3980 *
3981 * @return true on success; false on any failure
3982 */
3983 @Override
3984 public boolean rebootModem(int slotIndex) {
3985 Phone phone = PhoneFactory.getPhone(slotIndex);
3986 if (phone != null) {
3987 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3988 mApp, phone.getSubId(), "rebootModem");
3989
3990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3993 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3994 return success;
3995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004000 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004001
Svet Ganovb320e182015-04-16 12:30:10 -07004002 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004003 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004005 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004006 return new String[0];
4007 }
4008
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009 final long identity = Binder.clearCallingIdentity();
4010 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004011 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004012 } finally {
4013 Binder.restoreCallingIdentity(identity);
4014 }
Wink Saville36469e72014-06-11 15:17:00 -07004015 }
4016
Brad Ebinger51f743a2017-01-23 13:50:20 -08004017 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004018 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4019 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004020 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004021 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004022 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004023
4024 final long identity = Binder.clearCallingIdentity();
4025 try {
4026 PhoneFactory.getImsResolver().enableIms(slotId);
4027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004030 }
4031
4032 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004033 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4034 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004035 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004036 public void disableIms(int slotId) {
4037 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004038
4039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 PhoneFactory.getImsResolver().disableIms(slotId);
4042 } finally {
4043 Binder.restoreCallingIdentity(identity);
4044 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004045 }
4046
4047 /**
4048 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4049 * feature or {@link null} if the service is not available. If the feature is available, the
4050 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4051 */
4052 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004053 IImsServiceFeatureCallback callback) {
4054 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004055
4056 final long identity = Binder.clearCallingIdentity();
4057 try {
4058 return PhoneFactory.getImsResolver().getMmTelFeatureAndListen(slotId, callback);
4059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004062 }
4063
4064 /**
4065 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4066 * feature during emergency calling or {@link null} if the service is not available. If the
4067 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4068 * listener for feature updates.
4069 */
4070 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4071 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004072
4073 final long identity = Binder.clearCallingIdentity();
4074 try {
4075 return PhoneFactory.getImsResolver().getRcsFeatureAndListen(slotId, callback);
4076 } finally {
4077 Binder.restoreCallingIdentity(identity);
4078 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004079 }
4080
Brad Ebinger5f64b052017-12-14 14:26:15 -08004081 /**
4082 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
4083 * specified.
4084 */
4085 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4086 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004087
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 return PhoneFactory.getImsResolver().getImsRegistration(slotId, feature);
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004094 }
4095
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004096 /**
4097 * Returns the {@link IImsConfig} structure associated with the slotId and feature
4098 * specified.
4099 */
4100 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4101 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004102
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 return PhoneFactory.getImsResolver().getImsConfig(slotId, feature);
4106 } finally {
4107 Binder.restoreCallingIdentity(identity);
4108 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004109 }
4110
Brad Ebinger884c07b2018-02-15 16:17:40 -08004111 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004112 * Sets the ImsService Package Name that Telephony will bind to.
4113 *
4114 * @param slotId the slot ID that the ImsService should bind for.
4115 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4116 * ImsService is the device default ImsService.
4117 * @param packageName The package name of the application that contains the ImsService to bind
4118 * to.
4119 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4120 * @hide
4121 */
4122 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004123 int[] subIds = SubscriptionManager.getSubId(slotId);
4124 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4125 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4126 "setImsService");
4127
Malcolm Chend965c8b2018-02-28 15:00:40 -08004128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 return PhoneFactory.getImsResolver().overrideImsServiceConfiguration(slotId,
4131 isCarrierImsService, packageName);
4132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004135 }
4136
4137 /**
4138 * Return the ImsService configuration.
4139 *
4140 * @param slotId The slot that the ImsService is associated with.
4141 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4142 * the device default.
4143 * @return the package name of the ImsService configuration.
4144 */
4145 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004146 int[] subIds = SubscriptionManager.getSubId(slotId);
4147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4148 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4149 "getImsService");
4150
Malcolm Chend965c8b2018-02-28 15:00:40 -08004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 return PhoneFactory.getImsResolver().getImsServiceConfiguration(slotId,
4154 isCarrierImsService);
4155 } finally {
4156 Binder.restoreCallingIdentity(identity);
4157 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004158 }
4159
Wink Saville36469e72014-06-11 15:17:00 -07004160 public void setImsRegistrationState(boolean registered) {
4161 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004162
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004165 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Wink Saville36469e72014-06-11 15:17:00 -07004169 }
4170
4171 /**
Stuart Scott54788802015-03-30 13:18:01 -07004172 * Set the network selection mode to automatic.
4173 *
4174 */
4175 @Override
4176 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4178 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004179
Pengquan Meng466e2482018-09-21 15:54:48 -07004180 if (!isActiveSubscription(subId)) {
4181 return;
4182 }
4183
Malcolm Chend965c8b2018-02-28 15:00:40 -08004184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4187 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
Stuart Scott54788802015-03-30 13:18:01 -07004191 }
4192
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004193 /**
4194 * Ask the radio to connect to the input network and change selection mode to manual.
4195 *
4196 * @param subId the id of the subscription.
4197 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4198 * the operator to attach to.
4199 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4200 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4201 * normal network selection next time.
4202 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004203 */
4204 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004205 public boolean setNetworkSelectionModeManual(
4206 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4208 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004209
4210 if (!isActiveSubscription(subId)) {
4211 return false;
4212 }
4213
Malcolm Chend965c8b2018-02-28 15:00:40 -08004214 final long identity = Binder.clearCallingIdentity();
4215 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004216 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004217 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004218 if (DBG) {
4219 log("setNetworkSelectionModeManual: subId: " + subId
4220 + " operator: " + operatorInfo);
4221 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004222 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004226 }
4227
4228 /**
4229 * Scans for available networks.
4230 */
4231 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004232 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004233 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4234 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004235 LocationAccessPolicy.LocationPermissionResult locationResult =
4236 LocationAccessPolicy.checkLocationPermission(mApp,
4237 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4238 .setCallingPackage(callingPackage)
4239 .setCallingPid(Binder.getCallingPid())
4240 .setCallingUid(Binder.getCallingUid())
4241 .setMethod("getCellNetworkScanResults")
4242 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4243 .build());
4244 switch (locationResult) {
4245 case DENIED_HARD:
4246 throw new SecurityException("Not allowed to access scan results -- location");
4247 case DENIED_SOFT:
4248 return null;
4249 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250
Pengquan Meng0c05b502018-09-06 09:59:22 -07004251 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004252 try {
4253 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004254 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004255 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004259 }
4260
4261 /**
yinxub1bed742017-04-17 11:45:04 -07004262 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004263 *
yinxub1bed742017-04-17 11:45:04 -07004264 * @param subId id of the subscription
4265 * @param request contains the radio access networks with bands/channels to scan
4266 * @param messenger callback messenger for scan results or errors
4267 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004268 * @return the id of the requested scan which can be used to stop the scan.
4269 */
4270 @Override
4271 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004272 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004273 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4274 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004275
Hall Liuf19c44f2018-11-27 14:38:17 -08004276 LocationAccessPolicy.LocationPermissionResult locationResult =
4277 LocationAccessPolicy.checkLocationPermission(mApp,
4278 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4279 .setCallingPackage(callingPackage)
4280 .setCallingPid(Binder.getCallingPid())
4281 .setCallingUid(Binder.getCallingUid())
4282 .setMethod("requestNetworkScan")
4283 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4284 .build());
4285 switch (locationResult) {
4286 case DENIED_HARD:
4287 throw new SecurityException("Not allowed to request network scan -- location");
4288 case DENIED_SOFT:
4289 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004290 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004291
4292 return mNetworkScanRequestTracker.startNetworkScan(
4293 request, messenger, binder, getPhone(subId),
4294 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004295 }
4296
4297 /**
4298 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004299 *
4300 * @param subId id of the subscription
4301 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004302 */
4303 @Override
4304 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004305 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4306 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
yinxu504e1392017-04-12 16:03:22 -07004314 }
4315
4316 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004317 * Get the calculated preferred network type.
4318 * Used for debugging incorrect network type.
4319 *
4320 * @return the preferred network type, defined in RILConstants.java.
4321 */
4322 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004323 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004324 final Phone defaultPhone = getDefaultPhone();
4325 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4326 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004327 return RILConstants.PREFERRED_NETWORK_MODE;
4328 }
4329
Malcolm Chend965c8b2018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004333 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
Junda Liu84d15a22014-07-02 11:21:04 -07004337 }
4338
4339 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004340 * Get the preferred network type.
4341 * Used for device configuration by some CDMA operators.
4342 *
4343 * @return the preferred network type, defined in RILConstants.java.
4344 */
4345 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004346 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004347 TelephonyPermissions
4348 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4349 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004350
4351 final long identity = Binder.clearCallingIdentity();
4352 try {
4353 if (DBG) log("getPreferredNetworkType");
4354 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4355 int networkType = (result != null ? result[0] : -1);
4356 if (DBG) log("getPreferredNetworkType: " + networkType);
4357 return networkType;
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004361 }
4362
4363 /**
4364 * Set the preferred network type.
4365 * Used for device configuration by some CDMA operators.
4366 *
4367 * @param networkType the preferred network type, defined in RILConstants.java.
4368 * @return true on success; false on any failure.
4369 */
4370 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004371 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004372 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4373 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004374
4375 final long identity = Binder.clearCallingIdentity();
4376 try {
4377 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4378 Boolean success = (Boolean) sendRequest(
4379 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4380 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4381 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004382 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004383 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4384 }
4385 return success;
4386 } finally {
4387 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004388 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004389 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004390
4391 /**
Junda Liu475951f2014-11-07 16:45:03 -08004392 * Check TETHER_DUN_REQUIRED and TETHER_DUN_APN settings, net.tethering.noprovisioning
Jack Yu13db0fe2018-10-30 17:41:31 -07004393 * SystemProperty to decide whether DUN APN is required for
Junda Liu475951f2014-11-07 16:45:03 -08004394 * tethering.
4395 *
4396 * @return 0: Not required. 1: required. 2: Not set.
4397 * @hide
4398 */
4399 @Override
4400 public int getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004401 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004402
4403 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004404 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004405 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004406 int dunRequired = Settings.Global.getInt(defaultPhone.getContext().getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004407 Settings.Global.TETHER_DUN_REQUIRED, 2);
Jack Yu13db0fe2018-10-30 17:41:31 -07004408 // If not set, check net.tethering.noprovisioning, TETHER_DUN_APN setting
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004409 if (dunRequired == 2 && defaultPhone.hasMatchedTetherApnSetting()) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08004410 dunRequired = 1;
4411 }
4412 return dunRequired;
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004415 }
Junda Liu475951f2014-11-07 16:45:03 -08004416 }
4417
4418 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004419 * Set mobile data enabled
4420 * Used by the user through settings etc to turn on/off mobile data
4421 *
4422 * @param enable {@code true} turn turn data on, else {@code false}
4423 */
4424 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004425 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004428
4429 final long identity = Binder.clearCallingIdentity();
4430 try {
4431 int phoneId = mSubscriptionController.getPhoneId(subId);
4432 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4433 Phone phone = PhoneFactory.getPhone(phoneId);
4434 if (phone != null) {
4435 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004436 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004437 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004438 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004439 }
4440 } finally {
4441 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004442 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004443 }
4444
4445 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004446 * Get the user enabled state of Mobile Data.
4447 *
4448 * TODO: remove and use isUserDataEnabled.
4449 * This can't be removed now because some vendor codes
4450 * calls through ITelephony directly while they should
4451 * use TelephonyManager.
4452 *
4453 * @return true on enabled
4454 */
4455 @Override
4456 public boolean getDataEnabled(int subId) {
4457 return isUserDataEnabled(subId);
4458 }
4459
4460 /**
4461 * Get whether mobile data is enabled per user setting.
4462 *
4463 * There are other factors deciding whether mobile data is actually enabled, but they are
4464 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004465 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004466 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004467 *
4468 * @return {@code true} if data is enabled else {@code false}
4469 */
4470 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004471 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004472 try {
4473 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4474 null);
4475 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4477 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004478 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004479
4480 final long identity = Binder.clearCallingIdentity();
4481 try {
4482 int phoneId = mSubscriptionController.getPhoneId(subId);
4483 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4484 Phone phone = PhoneFactory.getPhone(phoneId);
4485 if (phone != null) {
4486 boolean retVal = phone.isUserDataEnabled();
4487 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4488 return retVal;
4489 } else {
4490 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4491 return false;
4492 }
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004495 }
4496 }
4497
4498 /**
4499 * Get whether mobile data is enabled.
4500 *
4501 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4502 * whether mobile data is actually enabled.
4503 *
4504 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4505 *
4506 * @return {@code true} if data is enabled else {@code false}
4507 */
4508 @Override
4509 public boolean isDataEnabled(int subId) {
4510 try {
4511 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4512 null);
4513 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004514 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4515 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004516 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004517
4518 final long identity = Binder.clearCallingIdentity();
4519 try {
4520 int phoneId = mSubscriptionController.getPhoneId(subId);
4521 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4522 Phone phone = PhoneFactory.getPhone(phoneId);
4523 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004524 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004525 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4526 return retVal;
4527 } else {
4528 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4529 return false;
4530 }
4531 } finally {
4532 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004533 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004534 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004535
4536 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004537 public int getCarrierPrivilegeStatus(int subId) {
4538 final Phone phone = getPhone(subId);
4539 if (phone == null) {
4540 loge("getCarrierPrivilegeStatus: Invalid subId");
4541 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4542 }
4543 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004544 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004545 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004546 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4547 }
4548 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004549 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004550 }
Junda Liu29340342014-07-10 15:23:27 -07004551
4552 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004553 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4554 final Phone phone = getPhone(subId);
4555 if (phone == null) {
4556 loge("getCarrierPrivilegeStatus: Invalid subId");
4557 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4558 }
4559 UiccProfile profile =
4560 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4561 if (profile == null) {
4562 loge("getCarrierPrivilegeStatus: No UICC");
4563 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4564 }
4565 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4566 }
4567
4568 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004569 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004570 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004571 if (TextUtils.isEmpty(pkgName))
4572 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004573 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004574 if (card == null) {
4575 loge("checkCarrierPrivilegesForPackage: No UICC");
4576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4577 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004578 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4579 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004580 }
4581
4582 @Override
4583 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004584 if (TextUtils.isEmpty(pkgName))
4585 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004586 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4587 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4588 UiccCard card = UiccController.getInstance().getUiccCard(i);
4589 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004590 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004591 continue;
4592 }
4593
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004594 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004595 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4596 break;
4597 }
4598 }
4599
4600 return result;
Junda Liu29340342014-07-10 15:23:27 -07004601 }
Derek Tan89e89d42014-07-08 17:00:10 -07004602
4603 @Override
Junda Liue64de782015-04-16 17:19:16 -07004604 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4605 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4606 loge("phoneId " + phoneId + " is not valid.");
4607 return null;
4608 }
4609 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004610 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004611 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004612 return null ;
4613 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004614 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004615 }
4616
Amith Yamasani6e118872016-02-19 12:53:51 -08004617 @Override
4618 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004619 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004620 List<String> privilegedPackages = new ArrayList<>();
4621 List<PackageInfo> packages = null;
4622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4623 UiccCard card = UiccController.getInstance().getUiccCard(i);
4624 if (card == null) {
4625 // No UICC in that slot.
4626 continue;
4627 }
4628 if (card.hasCarrierPrivilegeRules()) {
4629 if (packages == null) {
4630 // Only check packages in user 0 for now
4631 packages = pm.getInstalledPackagesAsUser(
4632 PackageManager.MATCH_DISABLED_COMPONENTS
4633 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4634 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4635 }
4636 for (int p = packages.size() - 1; p >= 0; p--) {
4637 PackageInfo pkgInfo = packages.get(p);
4638 if (pkgInfo != null && pkgInfo.packageName != null
4639 && card.getCarrierPrivilegeStatus(pkgInfo)
4640 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4641 privilegedPackages.add(pkgInfo.packageName);
4642 }
4643 }
4644 }
4645 }
4646 return privilegedPackages;
4647 }
4648
Wink Savilleb564aae2014-10-23 10:18:09 -07004649 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004650 final Phone phone = getPhone(subId);
4651 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004652 if (card == null) {
4653 loge("getIccId: No UICC");
4654 return null;
4655 }
4656 String iccId = card.getIccId();
4657 if (TextUtils.isEmpty(iccId)) {
4658 loge("getIccId: ICC ID is null or empty.");
4659 return null;
4660 }
4661 return iccId;
4662 }
4663
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004664 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004665 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4666 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004667 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4668 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004669
Malcolm Chend965c8b2018-02-28 15:00:40 -08004670 final long identity = Binder.clearCallingIdentity();
4671 try {
4672 final String iccId = getIccId(subId);
4673 final Phone phone = getPhone(subId);
4674 if (phone == null) {
4675 return false;
4676 }
4677 final String subscriberId = phone.getSubscriberId();
4678
4679 if (DBG_MERGE) {
4680 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4681 + subscriberId + " to " + number);
4682 }
4683
4684 if (TextUtils.isEmpty(iccId)) {
4685 return false;
4686 }
4687
4688 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4689
4690 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4691 if (alphaTag == null) {
4692 editor.remove(alphaTagPrefKey);
4693 } else {
4694 editor.putString(alphaTagPrefKey, alphaTag);
4695 }
4696
4697 // Record both the line number and IMSI for this ICCID, since we need to
4698 // track all merged IMSIs based on line number
4699 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4700 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4701 if (number == null) {
4702 editor.remove(numberPrefKey);
4703 editor.remove(subscriberPrefKey);
4704 } else {
4705 editor.putString(numberPrefKey, number);
4706 editor.putString(subscriberPrefKey, subscriberId);
4707 }
4708
4709 editor.commit();
4710 return true;
4711 } finally {
4712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004713 }
Derek Tan7226c842014-07-02 17:42:23 -07004714 }
4715
4716 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004717 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004718 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004720 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004721 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004722 return null;
4723 }
Derek Tan97ebb422014-09-05 16:55:38 -07004724
Malcolm Chend965c8b2018-02-28 15:00:40 -08004725 final long identity = Binder.clearCallingIdentity();
4726 try {
4727 String iccId = getIccId(subId);
4728 if (iccId != null) {
4729 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4730 if (DBG_MERGE) {
4731 log("getLine1NumberForDisplay returning "
4732 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4733 }
4734 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004735 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004736 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4737 return null;
4738 } finally {
4739 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004740 }
Derek Tan7226c842014-07-02 17:42:23 -07004741 }
4742
4743 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004744 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004746 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004747 return null;
4748 }
Derek Tan97ebb422014-09-05 16:55:38 -07004749
Malcolm Chend965c8b2018-02-28 15:00:40 -08004750 final long identity = Binder.clearCallingIdentity();
4751 try {
4752 String iccId = getIccId(subId);
4753 if (iccId != null) {
4754 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4755 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4756 }
4757 return null;
4758 } finally {
4759 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004760 }
Derek Tan7226c842014-07-02 17:42:23 -07004761 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004762
4763 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004764 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004765 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4766 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004768 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4769 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004770 return null;
4771 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004772
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004775 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004776 final TelephonyManager tele = TelephonyManager.from(context);
4777 final SubscriptionManager sub = SubscriptionManager.from(context);
4778
4779 // Figure out what subscribers are currently active
4780 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4781 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4782 // the process, where TelephonyManager was instantiated.
4783 // Otherwise AppOps check will fail.
4784
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004785 final int[] subIds = sub.getActiveSubscriptionIdList();
4786 for (int subId : subIds) {
4787 activeSubscriberIds.add(tele.getSubscriberId(subId));
4788 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004789
4790 // First pass, find a number override for an active subscriber
4791 String mergeNumber = null;
4792 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4793 for (String key : prefs.keySet()) {
4794 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4795 final String subscriberId = (String) prefs.get(key);
4796 if (activeSubscriberIds.contains(subscriberId)) {
4797 final String iccId = key.substring(
4798 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4799 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4800 mergeNumber = (String) prefs.get(numberKey);
4801 if (DBG_MERGE) {
4802 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4803 + " for active subscriber " + subscriberId);
4804 }
4805 if (!TextUtils.isEmpty(mergeNumber)) {
4806 break;
4807 }
4808 }
4809 }
4810 }
4811
4812 // Shortcut when no active merged subscribers
4813 if (TextUtils.isEmpty(mergeNumber)) {
4814 return null;
4815 }
4816
4817 // Second pass, find all subscribers under that line override
4818 final ArraySet<String> result = new ArraySet<>();
4819 for (String key : prefs.keySet()) {
4820 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4821 final String number = (String) prefs.get(key);
4822 if (mergeNumber.equals(number)) {
4823 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4824 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4825 final String subscriberId = (String) prefs.get(subscriberKey);
4826 if (!TextUtils.isEmpty(subscriberId)) {
4827 result.add(subscriberId);
4828 }
4829 }
4830 }
4831 }
4832
4833 final String[] resultArray = result.toArray(new String[result.size()]);
4834 Arrays.sort(resultArray);
4835 if (DBG_MERGE) {
4836 Slog.d(LOG_TAG,
4837 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4838 }
4839 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004840 } finally {
4841 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004842 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004843 }
4844
4845 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004846 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004847 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4848 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004849
4850 final long identity = Binder.clearCallingIdentity();
4851 try {
4852 final Phone phone = getPhone(subId);
4853 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4854 } finally {
4855 Binder.restoreCallingIdentity(identity);
4856 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004857 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004858
4859 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004860 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004861 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4862 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004863 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004864
4865 final long identity = Binder.clearCallingIdentity();
4866 try {
4867 final Phone phone = getPhone(subId);
4868 if (phone == null) {
4869 return false;
4870 }
4871 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4872 cdmaNonRoamingList);
4873 } finally {
4874 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004875 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004876 }
4877
4878 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004879 @Deprecated
4880 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4881 enforceModifyPermission();
4882
4883 int returnValue = 0;
4884 try {
vagdevie435a3e2018-08-15 16:01:53 -07004885 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004886 if(result.exception == null) {
4887 if (result.result != null) {
4888 byte[] responseData = (byte[])(result.result);
4889 if(responseData.length > oemResp.length) {
4890 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4891 responseData.length + "bytes. Buffer Size is " +
4892 oemResp.length + "bytes.");
4893 }
4894 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4895 returnValue = responseData.length;
4896 }
4897 } else {
4898 CommandException ex = (CommandException) result.exception;
4899 returnValue = ex.getCommandError().ordinal();
4900 if(returnValue > 0) returnValue *= -1;
4901 }
4902 } catch (RuntimeException e) {
4903 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4904 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4905 if(returnValue > 0) returnValue *= -1;
4906 }
4907
4908 return returnValue;
4909 }
4910
4911 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004912 public void setRadioCapability(RadioAccessFamily[] rafs) {
4913 try {
4914 ProxyController.getInstance().setRadioCapability(rafs);
4915 } catch (RuntimeException e) {
4916 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4917 }
4918 }
4919
4920 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004921 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004922 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004923 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004924 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004925 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004926 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
chen xufeeed752018-10-26 14:17:57 -07004929 TelephonyPermissions
4930 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4931 mApp, phone.getSubId(), "getRadioAccessFamily");
4932 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004933 } finally {
4934 Binder.restoreCallingIdentity(identity);
4935 }
chen xufeeed752018-10-26 14:17:57 -07004936 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004937 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004938
4939 @Override
4940 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004941 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004942 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004943
4944 final long identity = Binder.clearCallingIdentity();
4945 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004946 ImsManager.getInstance(defaultPhone.getContext(),
4947 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004948 } finally {
4949 Binder.restoreCallingIdentity(identity);
4950 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004951 }
4952
4953 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004954 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004955 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004956 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004957 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004958 return false;
4959 }
Svet Ganovb320e182015-04-16 12:30:10 -07004960
Malcolm Chend965c8b2018-02-28 15:00:40 -08004961 final long identity = Binder.clearCallingIdentity();
4962 try {
4963 // Check the user preference and the system-level IMS setting. Even if the user has
4964 // enabled video calling, if IMS is disabled we aren't able to support video calling.
4965 // In the long run, we may instead need to check if there exists a connection service
4966 // which can support video calling.
4967 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004968 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08004969 return imsManager.isVtEnabledByPlatform()
4970 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
4971 && imsManager.isVtEnabledByUser();
4972 } finally {
4973 Binder.restoreCallingIdentity(identity);
4974 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004975 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06004976
Andrew Leea1239f22015-03-02 17:44:07 -08004977 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004978 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
4979 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4980 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4981 return false;
4982 }
4983
4984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 CarrierConfigManager configManager =
4987 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004988 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08004989 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
4990 } finally {
4991 Binder.restoreCallingIdentity(identity);
4992 }
Andrew Leea1239f22015-03-02 17:44:07 -08004993 }
4994
4995 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 public boolean isWorldPhone(int subId, String callingPackage) {
4997 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4998 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
4999 return false;
5000 }
5001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
5004 CarrierConfigManager configManager =
5005 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005006 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005007 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5008 } finally {
5009 Binder.restoreCallingIdentity(identity);
5010 }
Andrew Leea1239f22015-03-02 17:44:07 -08005011 }
5012
Andrew Lee9431b832015-03-09 18:46:45 -07005013 @Override
5014 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005015 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005016 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005017 }
5018
5019 @Override
5020 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005021 final long identity = Binder.clearCallingIdentity();
5022 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005023 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
Andrew Lee9431b832015-03-09 18:46:45 -07005027 }
5028
Hall Liuf6668912018-10-31 17:05:23 -07005029 /**
5030 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5031 * support for the feature and device firmware support.
5032 *
5033 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5034 */
5035 @Override
5036 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005037 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005038 final Phone phone = getPhone(subscriptionId);
5039 if (phone == null) {
5040 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5041 return false;
5042 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005043 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005044 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005045 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5046 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005047 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005048 return isCarrierSupported && isDeviceSupported;
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
5051 }
Hall Liu98187582018-01-22 19:15:32 -08005052 }
5053
Hall Liuf6668912018-10-31 17:05:23 -07005054 /**
5055 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5056 * both also support RTT.
5057 */
5058 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005059 final long identity = Binder.clearCallingIdentity();
5060 try {
Hall Liuf6668912018-10-31 17:05:23 -07005061 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005062 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005066 }
5067
Sanket Padawe7310cc72015-01-14 09:53:20 -08005068 /**
5069 * Returns the unique device ID of phone, for example, the IMEI for
5070 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5071 *
5072 * <p>Requires Permission:
5073 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5074 */
5075 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005076 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005077 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005078 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005079 return null;
5080 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005081 int subId = phone.getSubId();
5082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5083 mApp, subId, callingPackage, "getDeviceId")) {
5084 return null;
5085 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005086
5087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 return phone.getDeviceId();
5090 } finally {
5091 Binder.restoreCallingIdentity(identity);
5092 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005093 }
5094
Ping Sunc67b7c22016-03-02 19:16:45 +08005095 /**
5096 * {@hide}
5097 * Returns the IMS Registration Status on a particular subid
5098 *
5099 * @param subId
5100 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005101 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005102 Phone phone = getPhone(subId);
5103 if (phone != null) {
5104 return phone.isImsRegistered();
5105 } else {
5106 return false;
5107 }
5108 }
5109
Santos Cordon7a1885b2015-02-03 11:15:19 -08005110 @Override
5111 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005118 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005119
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005120 /**
5121 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005122 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005123 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
5126 Phone phone = getPhone(subId);
5127 if (phone != null) {
5128 return phone.isWifiCallingEnabled();
5129 } else {
5130 return false;
5131 }
5132 } finally {
5133 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005134 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005135 }
5136
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005137 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005138 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005139 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005140 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 Phone phone = getPhone(subId);
5144 if (phone != null) {
5145 return phone.isVideoEnabled();
5146 } else {
5147 return false;
5148 }
5149 } finally {
5150 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005151 }
5152 }
5153
5154 /**
5155 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5156 * defined in {@link ImsRegistrationImplBase}.
5157 */
5158 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 return phone.getImsRegistrationTech();
5164 } else {
5165 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005169 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005170 }
5171
Stuart Scott8eef64f2015-04-08 15:13:54 -07005172 @Override
5173 public void factoryReset(int subId) {
5174 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005175 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5176 return;
5177 }
5178
Svet Ganovcc087f82015-05-12 20:35:54 -07005179 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005180
Svet Ganovcc087f82015-05-12 20:35:54 -07005181 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005182 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5183 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005184 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005185 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005186 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005187 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5188 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005189 }
5190 } finally {
5191 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005192 }
5193 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005194
5195 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005196 public String getSimLocaleForSubscriber(int subId) {
5197 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5198 final Phone phone = getPhone(subId);
5199 if (phone == null) {
5200 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005201 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005202 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005203 final long identity = Binder.clearCallingIdentity();
5204 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005205 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5206 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005207 // Try and fetch the locale from the carrier properties or from the SIM language
5208 // preferences (EF-PL and EF-LI)...
5209 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005210 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005211 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5212 if (localeFromDefaultSim != null) {
5213 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5214 if (DBG) log("Using locale from subId: " + subId + " locale: "
5215 + localeFromDefaultSim);
5216 return localeFromDefaultSim.toLanguageTag();
5217 } else {
5218 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005219 }
5220 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005221
Malcolm Chend965c8b2018-02-28 15:00:40 -08005222 // The SIM language preferences only store a language (e.g. fr = French), not an
5223 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5224 // the SIM and carrier preferences does not include a country we add the country
5225 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005226 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005227 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005228 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005229 return mccLocale.toLanguageTag();
5230 }
5231
5232 if (DBG) log("No locale found - returning null");
5233 return null;
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005237 }
5238
5239 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005240 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005241 }
5242
Malcolm Chend965c8b2018-02-28 15:00:40 -08005243 /**
5244 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5245 */
5246 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005247 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005248 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005249
Chenjie Yu1ba97252018-01-11 18:16:20 -08005250 private final ModemActivityInfo mLastModemActivityInfo =
5251 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5252
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005253 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005254 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5255 * representing the state of the modem.
5256 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005257 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5258 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005259 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005260 */
5261 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005262 public void requestModemActivityInfo(ResultReceiver result) {
5263 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005264 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005265
5266 final long identity = Binder.clearCallingIdentity();
5267 try {
5268 ModemActivityInfo ret = null;
5269 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005270 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5271 CMD_GET_MODEM_ACTIVITY_INFO,
5272 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005273 if (isModemActivityInfoValid(info)) {
5274 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5275 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5276 mergedTxTimeMs[i] =
5277 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5278 }
5279 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5280 mLastModemActivityInfo.setSleepTimeMillis(
5281 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5282 mLastModemActivityInfo.setIdleTimeMillis(
5283 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5284 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5285 mLastModemActivityInfo.setRxTimeMillis(
5286 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5287 mLastModemActivityInfo.setEnergyUsed(
5288 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005289 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005290 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5291 mLastModemActivityInfo.getSleepTimeMillis(),
5292 mLastModemActivityInfo.getIdleTimeMillis(),
5293 mLastModemActivityInfo.getTxTimeMillis(),
5294 mLastModemActivityInfo.getRxTimeMillis(),
5295 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005296 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005297 Bundle bundle = new Bundle();
5298 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5299 result.send(0, bundle);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005302 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005303 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005304
Siddharth Rayf5d29552018-06-17 15:02:38 -07005305 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5306 // less than total activity duration.
5307 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5308 if (info == null) {
5309 return false;
5310 }
5311 int activityDurationMs =
5312 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5313 int totalTxTimeMs = 0;
5314 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5315 totalTxTimeMs += info.getTxTimeMillis()[i];
5316 }
5317 return (info.isValid()
5318 && (info.getSleepTimeMillis() <= activityDurationMs)
5319 && (info.getIdleTimeMillis() <= activityDurationMs)
5320 && (info.getRxTimeMillis() <= activityDurationMs)
5321 && (totalTxTimeMs <= activityDurationMs));
5322 }
5323
Jack Yu85bd38a2015-11-09 11:34:32 -08005324 /**
5325 * {@hide}
5326 * Returns the service state information on specified subscription.
5327 */
5328 @Override
5329 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005331 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005332 return null;
5333 }
5334
Hall Liuf19c44f2018-11-27 14:38:17 -08005335 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5336 LocationAccessPolicy.checkLocationPermission(mApp,
5337 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5338 .setCallingPackage(callingPackage)
5339 .setCallingPid(Binder.getCallingPid())
5340 .setCallingUid(Binder.getCallingUid())
5341 .setMethod("getServiceStateForSubscriber")
5342 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5343 .build());
5344
5345 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5346 LocationAccessPolicy.checkLocationPermission(mApp,
5347 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5348 .setCallingPackage(callingPackage)
5349 .setCallingPid(Binder.getCallingPid())
5350 .setCallingUid(Binder.getCallingUid())
5351 .setMethod("getServiceStateForSubscriber")
5352 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5353 .build());
5354 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5355 boolean hasFinePermission =
5356 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5357 boolean hasCoarsePermission =
5358 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5359
Malcolm Chend965c8b2018-02-28 15:00:40 -08005360 final long identity = Binder.clearCallingIdentity();
5361 try {
5362 final Phone phone = getPhone(subId);
5363 if (phone == null) {
5364 return null;
5365 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005366
Hall Liuf19c44f2018-11-27 14:38:17 -08005367 ServiceState ss = phone.getServiceState();
5368
5369 // Scrub out the location info in ServiceState depending on what level of access
5370 // the caller has.
5371 if (hasFinePermission) return ss;
5372 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5373 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005374 } finally {
5375 Binder.restoreCallingIdentity(identity);
5376 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005377 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005378
5379 /**
5380 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5381 *
5382 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5383 * voicemail ringtone.
5384 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5385 * PhoneAccount.
5386 */
5387 @Override
5388 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5392 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005393 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005394 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005395
Malcolm Chend965c8b2018-02-28 15:00:40 -08005396 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005400 }
5401
5402 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005403 * Sets the per-account voicemail ringtone.
5404 *
5405 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5406 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5407 *
5408 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5409 * voicemail ringtone.
5410 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5411 * PhoneAccount.
5412 */
5413 @Override
5414 public void setVoicemailRingtoneUri(String callingPackage,
5415 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005416 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005417 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5418 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005419 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005420 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5421 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5422 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005423 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005424
5425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5428 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005429 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005430 }
5431 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005434 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005435 }
5436
5437 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005438 * Returns whether vibration is set for voicemail notification in Phone settings.
5439 *
5440 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5441 * voicemail vibration setting.
5442 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5443 */
5444 @Override
5445 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5449 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005450 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005451 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005452
Malcolm Chend965c8b2018-02-28 15:00:40 -08005453 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005457 }
5458
Youhan Wange64578a2016-05-02 15:32:42 -07005459 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005460 * Sets the per-account voicemail vibration.
5461 *
5462 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5463 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5464 *
5465 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5466 * voicemail vibration setting.
5467 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5468 * specific PhoneAccount.
5469 */
5470 @Override
5471 public void setVoicemailVibrationEnabled(String callingPackage,
5472 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005473 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5475 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005476 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005477 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5478 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5479 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005480 }
5481
Malcolm Chend965c8b2018-02-28 15:00:40 -08005482 final long identity = Binder.clearCallingIdentity();
5483 try {
5484 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5485 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005486 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005487 }
5488 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005491 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005492 }
5493
5494 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005495 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5496 *
5497 * @throws SecurityException if the caller does not have the required permission
5498 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005499 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005500 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005501 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005502 }
5503
5504 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005505 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5506 * permission.
5507 *
5508 * @throws SecurityException if the caller does not have the required permission
5509 */
5510 private void enforceSendSmsPermission() {
5511 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5512 }
5513
5514 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005515 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005516 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005517 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005518 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005519 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005520 final long identity = Binder.clearCallingIdentity();
5521 try {
5522 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005523 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005524 if (componentName == null) {
5525 throw new SecurityException(
5526 "Caller not current active visual voicemail package[null]");
5527 }
5528 String vvmPackage = componentName.getPackageName();
5529 if (!callingPackage.equals(vvmPackage)) {
5530 throw new SecurityException("Caller not current active visual voicemail package["
5531 + vvmPackage + "]");
5532 }
5533 } finally {
5534 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005535 }
5536 }
5537
5538 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005539 * Return the application ID for the app type.
5540 *
5541 * @param subId the subscription ID that this request applies to.
5542 * @param appType the uicc app type.
5543 * @return Application ID for specificied app type, or null if no uicc.
5544 */
5545 @Override
5546 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005547 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005548 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005549
5550 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005551 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005552 if (phone == null) {
5553 return null;
5554 }
5555 String aid = null;
5556 try {
5557 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5558 .getApplicationByType(appType).getAid();
5559 } catch (Exception e) {
5560 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5561 }
5562 return aid;
5563 } finally {
5564 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005565 }
Youhan Wange64578a2016-05-02 15:32:42 -07005566 }
5567
Youhan Wang4001d252016-05-11 10:29:41 -07005568 /**
5569 * Return the Electronic Serial Number.
5570 *
5571 * @param subId the subscription ID that this request applies to.
5572 * @return ESN or null if error.
5573 */
5574 @Override
5575 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005576 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005577 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005578
5579 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005580 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005581 if (phone == null) {
5582 return null;
5583 }
5584 String esn = null;
5585 try {
5586 esn = phone.getEsn();
5587 } catch (Exception e) {
5588 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5589 }
5590 return esn;
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005593 }
Youhan Wang4001d252016-05-11 10:29:41 -07005594 }
5595
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005596 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005597 * Return the Preferred Roaming List Version.
5598 *
5599 * @param subId the subscription ID that this request applies to.
5600 * @return PRLVersion or null if error.
5601 */
5602 @Override
5603 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005604 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005605 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005606
5607 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005608 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005609 if (phone == null) {
5610 return null;
5611 }
5612 String cdmaPrlVersion = null;
5613 try {
5614 cdmaPrlVersion = phone.getCdmaPrlVersion();
5615 } catch (Exception e) {
5616 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5617 }
5618 return cdmaPrlVersion;
5619 } finally {
5620 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005621 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005622 }
5623
5624 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005625 * Get snapshot of Telephony histograms
5626 * @return List of Telephony histograms
5627 * @hide
5628 */
5629 @Override
5630 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5632 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005633
5634 final long identity = Binder.clearCallingIdentity();
5635 try {
5636 return RIL.getTelephonyRILTimingHistograms();
5637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005640 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005641
5642 /**
5643 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005644 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5645 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005646 * Require system privileges. In the future we may add this to carrier APIs.
5647 *
Michele Berionne0963c862018-11-27 18:57:59 -08005648 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005649 */
5650 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005651 @TelephonyManager.SetCarrierRestrictionResult
5652 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005653 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005654 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005655
Michele Berionne0963c862018-11-27 18:57:59 -08005656 if (carrierRestrictionRules == null) {
5657 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005658 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005659
Malcolm Chend965c8b2018-02-28 15:00:40 -08005660 final long identity = Binder.clearCallingIdentity();
5661 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005662 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005663 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005667 }
5668
5669 /**
5670 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005671 * Get the allowed carrier list and the excluded carrier list, including the priority between
5672 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005673 * Require system privileges. In the future we may add this to carrier APIs.
5674 *
Michele Berionne0963c862018-11-27 18:57:59 -08005675 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005676 */
5677 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005678 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005679 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005680 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005681
5682 final long identity = Binder.clearCallingIdentity();
5683 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005684 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5685 if (response instanceof CarrierRestrictionRules) {
5686 return (CarrierRestrictionRules) response;
5687 }
5688 // Response is an Exception of some kind,
5689 // which is signalled to the user as a NULL retval
5690 return null;
5691 } catch (Exception e) {
5692 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5693 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005694 } finally {
5695 Binder.restoreCallingIdentity(identity);
5696 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005697 }
5698
fionaxu59545b42016-05-25 15:53:37 -07005699 /**
5700 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5701 * @param subId the subscription ID that this action applies to.
5702 * @param enabled control enable or disable metered apns.
5703 * {@hide}
5704 */
5705 @Override
5706 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5707 enforceModifyPermission();
5708 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005709
5710 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005711 if (phone == null) {
5712 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5713 return;
5714 }
5715 try {
5716 phone.carrierActionSetMeteredApnsEnabled(enabled);
5717 } catch (Exception e) {
5718 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005719 } finally {
5720 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005721 }
5722 }
5723
5724 /**
5725 * Action set from carrier signalling broadcast receivers to enable/disable radio
5726 * @param subId the subscription ID that this action applies to.
5727 * @param enabled control enable or disable radio.
5728 * {@hide}
5729 */
5730 @Override
5731 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5732 enforceModifyPermission();
5733 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005734
5735 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005736 if (phone == null) {
5737 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5738 return;
5739 }
5740 try {
5741 phone.carrierActionSetRadioEnabled(enabled);
5742 } catch (Exception e) {
5743 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005744 } finally {
5745 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005746 }
5747 }
5748
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005749 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005750 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5751 * network status based on which carrier apps could apply actions accordingly,
5752 * enable/disable default url handler for example.
5753 *
5754 * @param subId the subscription ID that this action applies to.
5755 * @param report control start/stop reporting the default network status.
5756 * {@hide}
5757 */
5758 @Override
5759 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5760 enforceModifyPermission();
5761 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005762
5763 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005764 if (phone == null) {
5765 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5766 return;
5767 }
5768 try {
5769 phone.carrierActionReportDefaultNetworkStatus(report);
5770 } catch (Exception e) {
5771 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005772 } finally {
5773 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005774 }
5775 }
5776
5777 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005778 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5779 * bug report is being generated.
5780 */
5781 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005782 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005783 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5784 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005785 writer.println("Permission Denial: can't dump Phone from pid="
5786 + Binder.getCallingPid()
5787 + ", uid=" + Binder.getCallingUid()
5788 + "without permission "
5789 + android.Manifest.permission.DUMP);
5790 return;
5791 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005792 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005793 }
Jack Yueb89b242016-06-22 13:27:47 -07005794
Brad Ebingerdac2f002018-04-03 15:17:52 -07005795 @Override
5796 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5797 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5798 throws RemoteException {
5799 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5800 }
5801
Jack Yueb89b242016-06-22 13:27:47 -07005802 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005803 * Get aggregated video call data usage since boot.
5804 *
5805 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5806 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005807 * {@hide}
5808 */
5809 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005810 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005811 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5812 null);
5813
Malcolm Chend965c8b2018-02-28 15:00:40 -08005814 final long identity = Binder.clearCallingIdentity();
5815 try {
5816 // NetworkStatsService keeps tracking the active network interface and identity. It
5817 // records the delta with the corresponding network identity.
5818 // We just return the total video call data usage snapshot since boot.
5819 Phone phone = getPhone(subId);
5820 if (phone != null) {
5821 return phone.getVtDataUsage(perUidStats);
5822 }
5823 return null;
5824 } finally {
5825 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005826 }
Jack Yueb89b242016-06-22 13:27:47 -07005827 }
Jack Yu75ab2952016-07-08 14:29:33 -07005828
5829 /**
5830 * Policy control of data connection. Usually used when data limit is passed.
5831 * @param enabled True if enabling the data, otherwise disabling.
5832 * @param subId Subscription index
5833 * {@hide}
5834 */
5835 @Override
5836 public void setPolicyDataEnabled(boolean enabled, int subId) {
5837 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 Phone phone = getPhone(subId);
5842 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005843 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005844 }
5845 } finally {
5846 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005847 }
5848 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005849
5850 /**
5851 * Get Client request stats
5852 * @return List of Client Request Stats
5853 * @hide
5854 */
5855 @Override
5856 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005857 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005858 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005859 return null;
5860 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005861 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005862
Malcolm Chend965c8b2018-02-28 15:00:40 -08005863 final long identity = Binder.clearCallingIdentity();
5864 try {
5865 if (phone != null) {
5866 return phone.getClientRequestStats();
5867 }
5868
5869 return null;
5870 } finally {
5871 Binder.restoreCallingIdentity(identity);
5872 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005873 }
5874
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005875 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005876 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005877 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005878 }
Jack Yueb4124c2017-02-16 15:32:43 -08005879
5880 /**
Grace Chen70990072017-03-24 17:21:30 -07005881 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005882 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005883 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005884 * @param state State of SIM (power down, power up, pass through)
5885 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5886 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5887 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005888 *
5889 **/
5890 @Override
Grace Chen70990072017-03-24 17:21:30 -07005891 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005892 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005893 Phone phone = PhoneFactory.getPhone(slotIndex);
5894
vagdevie435a3e2018-08-15 16:01:53 -07005895 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5896
Malcolm Chend965c8b2018-02-28 15:00:40 -08005897 final long identity = Binder.clearCallingIdentity();
5898 try {
5899 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005900 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005901 }
5902 } finally {
5903 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005904 }
5905 }
Shuo Qiandd210312017-04-12 22:11:33 +00005906
Tyler Gunn65d45c22017-06-05 11:22:26 -07005907 private boolean isUssdApiAllowed(int subId) {
5908 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005909 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005910 if (configManager == null) {
5911 return false;
5912 }
5913 PersistableBundle pb = configManager.getConfigForSubId(subId);
5914 if (pb == null) {
5915 return false;
5916 }
5917 return pb.getBoolean(
5918 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5919 }
5920
Shuo Qiandd210312017-04-12 22:11:33 +00005921 /**
5922 * Check if phone is in emergency callback mode
5923 * @return true if phone is in emergency callback mode
5924 * @param subId sub id
5925 */
goneil9c5f4872017-12-05 14:07:56 -08005926 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005927 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005928 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005929 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005930
5931 final long identity = Binder.clearCallingIdentity();
5932 try {
5933 if (phone != null) {
5934 return phone.isInEcm();
5935 } else {
5936 return false;
5937 }
5938 } finally {
5939 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005940 }
5941 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005942
5943 /**
5944 * Get the current signal strength information for the given subscription.
5945 * Because this information is not updated when the device is in a low power state
5946 * it should not be relied-upon to be current.
5947 * @param subId Subscription index
5948 * @return the most recent cached signal strength info from the modem
5949 */
5950 @Override
5951 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005952 final long identity = Binder.clearCallingIdentity();
5953 try {
5954 Phone p = getPhone(subId);
5955 if (p == null) {
5956 return null;
5957 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005958
Malcolm Chend965c8b2018-02-28 15:00:40 -08005959 return p.getSignalStrength();
5960 } finally {
5961 Binder.restoreCallingIdentity(identity);
5962 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005963 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005964
Pengquan Meng9140aec2018-08-22 14:49:57 -07005965 /**
chen xu907e5a22018-10-11 13:21:04 -07005966 * Get the current modem radio state for the given slot.
5967 * @param slotIndex slot index.
5968 * @param callingPackage the name of the package making the call.
5969 * @return the current radio power state from the modem
5970 */
5971 @Override
5972 public int getRadioPowerState(int slotIndex, String callingPackage) {
5973 Phone phone = PhoneFactory.getPhone(slotIndex);
5974 if (phone != null) {
5975 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5976 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
5977 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5978 }
5979
5980 final long identity = Binder.clearCallingIdentity();
5981 try {
5982 return phone.getRadioPowerState();
5983 } finally {
5984 Binder.restoreCallingIdentity(identity);
5985 }
5986 }
5987 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
5988 }
5989
5990 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07005991 * Checks if data roaming is enabled on the subscription with id {@code subId}.
5992 *
5993 * <p>Requires one of the following permissions:
5994 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
5995 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
5996 * privileges.
5997 *
5998 * @param subId subscription id
5999 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6000 * {@code false}.
6001 */
6002 @Override
6003 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006004 boolean isEnabled = false;
6005 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006006 try {
6007 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006008 null /* message */);
6009 Phone phone = getPhone(subId);
6010 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006011 } catch (Exception e) {
6012 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6013 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006014 } finally {
6015 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006016 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006017 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006018 }
6019
6020
6021 /**
6022 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6023 *
6024 * <p> Requires permission:
6025 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6026 * privileges.
6027 *
6028 * @param subId subscription id
6029 * @param isEnabled {@code true} means enable, {@code false} means disable.
6030 */
6031 @Override
6032 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6036 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006037
Pengquan Meng0c05b502018-09-06 09:59:22 -07006038 Phone phone = getPhone(subId);
6039 if (phone != null) {
6040 phone.setDataRoamingEnabled(isEnabled);
6041 }
6042 } finally {
6043 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006044 }
6045 }
6046
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006047 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006048 public boolean isManualNetworkSelectionAllowed(int subId) {
6049 boolean isAllowed = true;
6050 final long identity = Binder.clearCallingIdentity();
6051 try {
6052 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6053 mApp, subId, "isManualNetworkSelectionAllowed");
6054 Phone phone = getPhone(subId);
6055 if (phone != null) {
6056 isAllowed = phone.isCspPlmnEnabled();
6057 }
6058 } finally {
6059 Binder.restoreCallingIdentity(identity);
6060 }
6061 return isAllowed;
6062 }
6063
6064 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006065 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006066 try {
6067 enforceReadPrivilegedPermission("getUiccCardsInfo");
6068 } catch (SecurityException e) {
6069 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6070 // has carrier privileges on an active UICC
6071 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6072 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6073 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6074 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006075 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006076
6077 final long identity = Binder.clearCallingIdentity();
6078 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006079 UiccController uiccController = UiccController.getInstance();
6080 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6081
6082 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6083 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6084 // Remove private info if the caller doesn't have access
6085 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6086 for (UiccCardInfo cardInfo : cardInfos) {
6087 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6088 UiccProfile profile = card.getUiccProfile();
6089 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6090 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6091 filteredInfos.add(cardInfo.getUnprivileged());
6092 } else {
6093 filteredInfos.add(cardInfo);
6094 }
6095 }
6096 return filteredInfos;
6097 }
6098 return cardInfos;
6099 } catch (PackageManager.NameNotFoundException e) {
6100 // This should not happen since we pass the package info in from TelephonyManager
6101 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006102 } finally {
6103 Binder.restoreCallingIdentity(identity);
6104 }
6105 }
6106
6107 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006108 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006109 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006110
Malcolm Chend965c8b2018-02-28 15:00:40 -08006111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6114 if (slots == null) {
6115 Rlog.i(LOG_TAG, "slots is null.");
6116 return null;
6117 }
6118
6119 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6120 for (int i = 0; i < slots.length; i++) {
6121 UiccSlot slot = slots[i];
6122 if (slot == null) {
6123 continue;
6124 }
6125
6126 String cardId;
6127 UiccCard card = slot.getUiccCard();
6128 if (card != null) {
6129 cardId = card.getCardId();
6130 } else {
6131 cardId = slot.getIccId();
6132 }
6133
6134 int cardState = 0;
6135 switch (slot.getCardState()) {
6136 case CARDSTATE_ABSENT:
6137 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6138 break;
6139 case CARDSTATE_PRESENT:
6140 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6141 break;
6142 case CARDSTATE_ERROR:
6143 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6144 break;
6145 case CARDSTATE_RESTRICTED:
6146 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6147 break;
6148 default:
6149 break;
6150
6151 }
6152
6153 infos[i] = new UiccSlotInfo(
6154 slot.isActive(),
6155 slot.isEuicc(),
6156 cardId,
6157 cardState,
6158 slot.getPhoneId(),
6159 slot.isExtendedApduSupported());
6160 }
6161 return infos;
6162 } finally {
6163 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006164 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006165 }
6166
6167 @Override
6168 public boolean switchSlots(int[] physicalSlots) {
6169 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006170
6171 final long identity = Binder.clearCallingIdentity();
6172 try {
6173 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6174 } finally {
6175 Binder.restoreCallingIdentity(identity);
6176 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006177 }
Jack Yu4c988042018-02-27 15:30:01 -08006178
6179 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006180 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006181 final long identity = Binder.clearCallingIdentity();
6182 try {
6183 return UiccController.getInstance().getCardIdForDefaultEuicc();
6184 } finally {
6185 Binder.restoreCallingIdentity(identity);
6186 }
6187 }
6188
6189 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006190 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6191 enforceModifyPermission();
6192 final Phone phone = getPhone(subId);
6193 if (phone == null) {
6194 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6195 return;
6196 }
6197
Malcolm Chend965c8b2018-02-28 15:00:40 -08006198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 phone.setRadioIndicationUpdateMode(filters, mode);
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
Jack Yu4c988042018-02-27 15:30:01 -08006204 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006205
6206 /**
goneil47ffb6e2018-04-06 15:40:58 -07006207 * A test API to reload the UICC profile.
6208 *
6209 * <p>Requires that the calling app has permission
6210 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6211 * @hide
6212 */
6213 @Override
6214 public void refreshUiccProfile(int subId) {
6215 enforceModifyPermission();
6216
6217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 Phone phone = getPhone(subId);
6220 if (phone == null) {
6221 return;
6222 }
6223 UiccCard uiccCard = phone.getUiccCard();
6224 if (uiccCard == null) {
6225 return;
6226 }
6227 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6228 if (uiccProfile == null) {
6229 return;
6230 }
6231 uiccProfile.refresh();
6232 } finally {
6233 Binder.restoreCallingIdentity(identity);
6234 }
6235 }
6236
6237 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006238 * Returns false if the mobile data is disabled by default, otherwise return true.
6239 */
6240 private boolean getDefaultDataEnabled() {
6241 return "true".equalsIgnoreCase(
6242 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6243 }
6244
6245 /**
6246 * Returns true if the data roaming is enabled by default, i.e the system property
6247 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6248 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6249 */
6250 private boolean getDefaultDataRoamingEnabled(int subId) {
6251 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006252 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006253 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6254 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6255 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6256 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6257 return isDataRoamingEnabled;
6258 }
6259
6260 /**
6261 * Returns the default network type for the given {@code subId}, if the default network type is
6262 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6263 */
6264 private int getDefaultNetworkType(int subId) {
6265 return Integer.parseInt(
6266 TelephonyManager.getTelephonyProperty(
6267 mSubscriptionController.getPhoneId(subId),
6268 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6269 String.valueOf(Phone.PREFERRED_NT_MODE)));
6270 }
fionaxua13278b2018-03-21 00:08:13 -07006271
6272 @Override
6273 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6274 gid1, String gid2, String plmn, String spn) {
6275 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006276
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 final Phone phone = getPhone(subId);
6280 if (phone == null) {
6281 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6282 return;
6283 }
6284 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006287 }
fionaxua13278b2018-03-21 00:08:13 -07006288 }
6289
6290 @Override
6291 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006292 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006293
6294 final long identity = Binder.clearCallingIdentity();
6295 try {
6296 final Phone phone = getPhone(subId);
6297 if (phone == null) {
6298 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6299 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6300 }
6301 return phone.getCarrierIdListVersion();
6302 } finally {
6303 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006304 }
fionaxua13278b2018-03-21 00:08:13 -07006305 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006306
6307 @Override
6308 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6309 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6310 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6311 return -1;
6312 }
6313
6314 final long identity = Binder.clearCallingIdentity();
6315 try {
6316 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
6320 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006321
6322 @Override
6323 public int getCdmaRoamingMode(int subId) {
6324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6325 mApp, subId, "getCdmaRoamingMode");
6326
6327 final long identity = Binder.clearCallingIdentity();
6328 try {
6329 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6330 } finally {
6331 Binder.restoreCallingIdentity(identity);
6332 }
6333 }
6334
6335 @Override
6336 public boolean setCdmaRoamingMode(int subId, int mode) {
6337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6338 mApp, subId, "setCdmaRoamingMode");
6339
6340 final long identity = Binder.clearCallingIdentity();
6341 try {
6342 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
6346 }
6347
6348 @Override
6349 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6351 mApp, subId, "setCdmaSubscriptionMode");
6352
6353 final long identity = Binder.clearCallingIdentity();
6354 try {
6355 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
6359 }
chen xu7ee67862018-10-30 22:27:10 -07006360
sqian2fff4a32018-11-05 14:18:37 -08006361 private void ensureUserRunning(int userId) {
6362 if (!mUserManager.isUserRunning(userId)) {
6363 throw new IllegalStateException("User " + userId + " does not exist or not running");
6364 }
6365 }
6366
6367 /**
6368 * Returns a list of SMS apps on a given user.
6369 *
6370 * Only the shell user (UID 2000 or 0) can call it.
6371 * Target user must be running.
6372 */
6373 @Override
6374 public String[] getSmsApps(int userId) {
6375 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6376 ensureUserRunning(userId);
6377
6378 final Collection<SmsApplicationData> apps =
6379 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6380
6381 String[] ret = new String[apps.size()];
6382 int i = 0;
6383 for (SmsApplicationData app : apps) {
6384 ret[i++] = app.mPackageName;
6385 }
6386 return ret;
6387 }
6388
6389 /**
6390 * Returns the default SMS app package name on a given user.
6391 *
6392 * Only the shell user (UID 2000 or 0) can call it.
6393 * Target user must be running.
6394 */
6395 @Override
6396 public String getDefaultSmsApp(int userId) {
6397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6398 ensureUserRunning(userId);
6399
6400 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6401 /* updateIfNeeded= */ true, userId);
6402 return cn == null ? null : cn.getPackageName();
6403 }
6404
6405 /**
6406 * Set a package as the default SMS app on a given user.
6407 *
6408 * Only the shell user (UID 2000 or 0) can call it.
6409 * Target user must be running.
6410 */
6411 @Override
6412 public void setDefaultSmsApp(int userId, String packageName) {
6413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6414 ensureUserRunning(userId);
6415
6416 boolean found = false;
6417 for (String pkg : getSmsApps(userId)) {
6418 if (TextUtils.equals(packageName, pkg)) {
6419 found = true;
6420 break;
6421 }
6422 }
6423 if (!found) {
6424 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6425 }
6426
6427 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6428 }
6429
chen xu7ee67862018-10-30 22:27:10 -07006430 @Override
sqian04b86072018-11-07 14:02:21 -08006431 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6432 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006433 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6434 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6435 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6436 }
6437 final long identity = Binder.clearCallingIdentity();
6438 try {
sqian991b35e2018-12-12 16:48:18 -08006439 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6440 for (Phone phone: PhoneFactory.getPhones()) {
6441 if (phone.getEmergencyNumberTracker() != null
6442 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6443 emergencyNumberListInternal.put(
6444 phone.getSubId(),
6445 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6446 }
sqian03bca152018-12-05 18:48:28 -08006447 }
sqian991b35e2018-12-12 16:48:18 -08006448 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006449 } finally {
6450 Binder.restoreCallingIdentity(identity);
6451 }
sqian04b86072018-11-07 14:02:21 -08006452 }
6453
6454 @Override
sqian03bca152018-12-05 18:48:28 -08006455 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6456 final Phone defaultPhone = getDefaultPhone();
6457 if (!exactMatch) {
6458 TelephonyPermissions
6459 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6460 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6461 }
6462 final long identity = Binder.clearCallingIdentity();
6463 try {
sqian991b35e2018-12-12 16:48:18 -08006464 for (Phone phone: PhoneFactory.getPhones()) {
6465 if (phone.getEmergencyNumberTracker() != null
6466 && phone.getEmergencyNumberTracker() != null) {
6467 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6468 number, exactMatch)) {
6469 return true;
sqian03bca152018-12-05 18:48:28 -08006470 }
6471 }
sqian03bca152018-12-05 18:48:28 -08006472 }
6473 return false;
6474 } finally {
6475 Binder.restoreCallingIdentity(identity);
6476 }
6477 }
6478
sqian9d4df8b2019-01-15 18:32:07 -08006479 /**
6480 * Update emergency number list for test mode.
6481 */
6482 @Override
6483 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6484 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6485 "updateEmergencyNumberListTestMode");
6486
6487 final long identity = Binder.clearCallingIdentity();
6488 try {
6489 for (Phone phone: PhoneFactory.getPhones()) {
6490 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6491 if (tracker != null) {
6492 tracker.executeEmergencyNumberTestModeCommand(action, num);
6493 }
6494 }
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
6498 }
6499
6500 /**
6501 * Get the full emergency number list for test mode.
6502 */
6503 @Override
6504 public List<String> getEmergencyNumberListTestMode() {
6505 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6506 "getEmergencyNumberListTestMode");
6507
6508 final long identity = Binder.clearCallingIdentity();
6509 try {
6510 Set<String> emergencyNumbers = new HashSet<>();
6511 for (Phone phone: PhoneFactory.getPhones()) {
6512 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6513 if (tracker != null) {
6514 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6515 emergencyNumbers.add(num.getNumber());
6516 }
6517 }
6518 }
6519 return new ArrayList<>(emergencyNumbers);
6520 } finally {
6521 Binder.restoreCallingIdentity(identity);
6522 }
6523 }
6524
sqian04b86072018-11-07 14:02:21 -08006525 @Override
chen xu7ee67862018-10-30 22:27:10 -07006526 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6527 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6528 Phone phone = getPhone(subId);
6529 if (phone == null) {
6530 return null;
6531 }
6532 final long identity = Binder.clearCallingIdentity();
6533 try {
6534 UiccProfile profile = UiccController.getInstance()
6535 .getUiccProfileForPhone(phone.getPhoneId());
6536 if (profile != null) {
6537 return profile.getCertsFromCarrierPrivilegeAccessRules();
6538 }
6539 } finally {
6540 Binder.restoreCallingIdentity(identity);
6541 }
6542 return null;
6543 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006544
6545 /**
6546 * Enable or disable a modem stack.
6547 */
6548 @Override
6549 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6550 enforceModifyPermission();
6551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 Phone phone = PhoneFactory.getPhone(slotIndex);
6555 if (phone == null) {
6556 return false;
6557 } else {
6558 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
6562 }
6563 }
Micheled3107c52018-12-21 15:00:11 -08006564
6565 @Override
6566 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6567 enforceModifyPermission();
6568
6569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 mTelephonySharedPreferences.edit()
6572 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6573 .commit();
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
6577 }
6578
6579 @Override
Michelebcb01bc2019-02-04 11:36:23 -08006580 public boolean isMultisimSupported(String callingPackage) {
6581 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6582 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6583 return false;
6584 }
Micheled3107c52018-12-21 15:00:11 -08006585
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6589 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6590 if (numPhysicalSlots < 2) {
Michelebcb01bc2019-02-04 11:36:23 -08006591 loge("isMultisimSupported: requires at least 2 cards");
6592 return false;
6593 }
6594 // Check if the hardware supports multisim functionality. If usage of multisim is not
6595 // supported by the modem, indicate that it is restricted.
6596 PhoneCapability staticCapability =
6597 mPhoneConfigurationManager.getStaticPhoneCapability();
6598 if (staticCapability == null) {
6599 loge("isMultisimSupported: no static configuration available");
6600 return false;
6601 }
6602 if (staticCapability.logicalModemList.size() < 2) {
6603 loge("isMultisimSupported: maximum number of modem is < 2");
6604 return false;
6605 }
6606 // Check if support of multiple SIMs is restricted by carrier
6607 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6608 return false;
Micheled3107c52018-12-21 15:00:11 -08006609 }
6610
Michelebcb01bc2019-02-04 11:36:23 -08006611 return true;
Micheled3107c52018-12-21 15:00:11 -08006612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
6615 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006616
6617 /**
6618 * Switch configs to enable multi-sim or switch back to single-sim
6619 * @param numOfSims number of active sims we want to switch to
6620 */
6621 @Override
6622 public void switchMultiSimConfig(int numOfSims) {
6623 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6624 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6628 } finally {
6629 Binder.restoreCallingIdentity(identity);
6630 }
6631 }
6632
6633 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006634 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006635 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006636 */
6637 @Override
6638 public boolean isRebootRequiredForModemConfigChange() {
6639 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6643 } finally {
6644 Binder.restoreCallingIdentity(identity);
6645 }
6646 }
6647
Pengquan Meng92d253b2019-02-06 11:12:53 -08006648 private void updateModemStateMetrics() {
6649 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6650 // TODO: check the state for each modem if the api is ready.
6651 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6652 }
6653
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006654 @Override
6655 public int[] getSlotsMapping() {
6656 enforceReadPrivilegedPermission("getSlotsMapping");
6657
6658 final long identity = Binder.clearCallingIdentity();
6659 try {
6660 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6661 // All logical slots should have a mapping to a physical slot.
6662 int[] logicalSlotsMapping = new int[phoneCount];
6663 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6664 for (int i = 0; i < slotInfos.length; i++) {
6665 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6666 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6667 }
6668 }
6669 return logicalSlotsMapping;
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
6672 }
6673 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006674
6675 /**
6676 * Get the IRadio HAL Version
6677 */
6678 @Override
6679 public int getRadioHalVersion() {
6680 Phone phone = getDefaultPhone();
6681 if (phone == null) return -1;
6682 HalVersion hv = phone.getHalVersion();
6683 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6684 return hv.major * 100 + hv.minor;
6685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006686}