blob: a1456c171afa567947322ae708be490213baa114 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070027import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.content.Context;
29import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070030import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070031import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070032import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080033import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070034import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070035import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070036import android.net.Uri;
37import android.os.AsyncResult;
38import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080039import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.os.Bundle;
41import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070042import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043import android.os.Looper;
44import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070045import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070046import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080047import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070048import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070049import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070050import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070051import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070053import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070054import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070055import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080056import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070057import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080058import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080059import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070060import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070061import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080062import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070064import android.telephony.CellInfoGsm;
65import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070066import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070067import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070068import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070069import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080070import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070071import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080072import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070073import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080074import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080075import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070076import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070077import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070078import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080079import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070080import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080081import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080082import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070083import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070084import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080085import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000086import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070087import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070088import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070089import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080090import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080091import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070092import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080093import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070094import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080095import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070096import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsMmTelFeature;
98import android.telephony.ims.aidl.IImsRcsFeature;
99import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.feature.MmTelFeature;
102import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800103import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800105import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800107import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800108import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800109
Brad Ebinger4c460712018-10-01 10:40:55 -0700110import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700111import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800112import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700113import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700114import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700115import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800116import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700117import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800120import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800121import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800123import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700124import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100125import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700126import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700129import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800130import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700131import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700132import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700133import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700134import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700135import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700136import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800137import com.android.internal.telephony.SmsApplication;
138import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800139import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800140import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800141import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700142import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800143import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800144import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700145import com.android.internal.telephony.uicc.IccIoResult;
146import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800147import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700148import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800149import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700150import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800151import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000152import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700153import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800154import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700155import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800156import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700157import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700158import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800159
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700160import java.io.FileDescriptor;
161import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800162import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700163import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800164import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800165import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800166import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800167import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800168import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100169import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800170import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800171import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172
173/**
174 * Implementation of the ITelephony interface.
175 */
Santos Cordon117fee72014-05-16 17:56:12 -0700176public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177 private static final String LOG_TAG = "PhoneInterfaceManager";
178 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
179 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800180 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700181
182 // Message codes used with mMainThreadHandler
183 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700184 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
185 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700186 private static final int CMD_OPEN_CHANNEL = 9;
187 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
188 private static final int CMD_CLOSE_CHANNEL = 11;
189 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800190 private static final int CMD_NV_READ_ITEM = 13;
191 private static final int EVENT_NV_READ_ITEM_DONE = 14;
192 private static final int CMD_NV_WRITE_ITEM = 15;
193 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
194 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
195 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700196 private static final int CMD_RESET_MODEM_CONFIG = 19;
197 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800198 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
199 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
200 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
201 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800202 private static final int CMD_SEND_ENVELOPE = 25;
203 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000204 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
205 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700206 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
207 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
208 private static final int CMD_EXCHANGE_SIM_IO = 31;
209 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800210 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
211 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700212 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
213 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700214 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
215 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700216 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
217 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
218 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
219 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700220 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
221 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
222 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
223 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700224 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800225 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
226 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000227 private static final int CMD_SWITCH_SLOTS = 50;
228 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700229 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
230 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
231 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
232 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
233 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
234 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
235 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
236 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700237 private static final int CMD_GET_ALL_CELL_INFO = 60;
238 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
239 private static final int CMD_GET_CELL_LOCATION = 62;
240 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700241 private static final int CMD_MODEM_REBOOT = 64;
242 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700243 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
244 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800245 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
246 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700247
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800248 // Parameters of select command.
249 private static final int SELECT_COMMAND = 0xA4;
250 private static final int SELECT_P1 = 0x04;
251 private static final int SELECT_P2 = 0;
252 private static final int SELECT_P3 = 0x10;
253
Pengquan Meng85728fb2018-03-12 16:31:21 -0700254 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
255 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
256 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
257
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700258 /** The singleton instance. */
259 private static PhoneInterfaceManager sInstance;
260
Wink Saville3ab207e2014-11-20 13:07:20 -0800261 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800262 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700263 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private AppOpsManager mAppOps;
265 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800266 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800267 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700268 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700269
Derek Tan97ebb422014-09-05 16:55:38 -0700270 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
271 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800272 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800273 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700274
Micheled3107c52018-12-21 15:00:11 -0800275 // String to store multi SIM allowed
276 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
277
Derek Tan740e1672017-06-27 14:56:27 -0700278 // The AID of ISD-R.
279 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
280
yinxub1bed742017-04-17 11:45:04 -0700281 private NetworkScanRequestTracker mNetworkScanRequestTracker;
282
David Kelly5e06a7f2018-03-12 14:10:59 +0000283 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
284 private static final int MANUFACTURER_CODE_LENGTH = 8;
285
Derek Tan89e89d42014-07-08 17:00:10 -0700286 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700287 * A request object to use for transmitting data to an ICC.
288 */
289 private static final class IccAPDUArgument {
290 public int channel, cla, command, p1, p2, p3;
291 public String data;
292
293 public IccAPDUArgument(int channel, int cla, int command,
294 int p1, int p2, int p3, String data) {
295 this.channel = channel;
296 this.cla = cla;
297 this.command = command;
298 this.p1 = p1;
299 this.p2 = p2;
300 this.p3 = p3;
301 this.data = data;
302 }
303 }
304
305 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700306 * A request object to use for transmitting data to an ICC.
307 */
308 private static final class ManualNetworkSelectionArgument {
309 public OperatorInfo operatorInfo;
310 public boolean persistSelection;
311
312 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
313 this.operatorInfo = operatorInfo;
314 this.persistSelection = persistSelection;
315 }
316 }
317
318 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700319 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
320 * request after sending. The main thread will notify the request when it is complete.
321 */
322 private static final class MainThreadRequest {
323 /** The argument to use for the request */
324 public Object argument;
325 /** The result of the request that is run on the main thread */
326 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800327 // The subscriber id that this request applies to. Defaults to
328 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
329 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700330
Nathan Harold92bed182018-10-12 18:16:49 -0700331 // In cases where subId is unavailable, the caller needs to specify the phone.
332 public Phone phone;
333
vagdevie435a3e2018-08-15 16:01:53 -0700334 public WorkSource workSource;
335
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700336 public MainThreadRequest(Object argument) {
337 this.argument = argument;
338 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800339
Nathan Harold92bed182018-10-12 18:16:49 -0700340 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
341 this.argument = argument;
342 if (phone != null) {
343 this.phone = phone;
344 }
345 this.workSource = workSource;
346 }
347
vagdevie435a3e2018-08-15 16:01:53 -0700348 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800349 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 if (subId != null) {
351 this.subId = subId;
352 }
vagdevie435a3e2018-08-15 16:01:53 -0700353 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800354 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700355 }
356
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800357 private static final class IncomingThirdPartyCallArgs {
358 public final ComponentName component;
359 public final String callId;
360 public final String callerDisplayName;
361
362 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
363 String callerDisplayName) {
364 this.component = component;
365 this.callId = callId;
366 this.callerDisplayName = callerDisplayName;
367 }
368 }
369
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370 /**
371 * A handler that processes messages on the main thread in the phone process. Since many
372 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
373 * inbound binder threads to the main thread in the phone process. The Binder thread
374 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
375 * on, which will be notified when the operation completes and will contain the result of the
376 * request.
377 *
378 * <p>If a MainThreadRequest object is provided in the msg.obj field,
379 * note that request.result must be set to something non-null for the calling thread to
380 * unblock.
381 */
382 private final class MainThreadHandler extends Handler {
383 @Override
384 public void handleMessage(Message msg) {
385 MainThreadRequest request;
386 Message onCompleted;
387 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800388 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700389 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800390 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391
392 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700393 case CMD_HANDLE_USSD_REQUEST: {
394 request = (MainThreadRequest) msg.obj;
395 final Phone phone = getPhoneFromRequest(request);
396 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
397 String ussdRequest = ussdObject.first;
398 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700399
Pengquan Meng0c05b502018-09-06 09:59:22 -0700400 if (!isUssdApiAllowed(request.subId)) {
401 // Carrier does not support use of this API, return failure.
402 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
403 UssdResponse response = new UssdResponse(ussdRequest, null);
404 Bundle returnData = new Bundle();
405 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
406 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700407
Pengquan Meng0c05b502018-09-06 09:59:22 -0700408 request.result = true;
409 notifyRequester(request);
410 return;
411 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700412
Pengquan Meng0c05b502018-09-06 09:59:22 -0700413 try {
414 request.result = phone != null
415 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
416 } catch (CallStateException cse) {
417 request.result = false;
418 }
419 // Wake up the requesting thread
420 notifyRequester(request);
421 break;
pkanwar32d516d2016-10-14 19:37:38 -0700422 }
423
Yorke Lee716f67e2015-06-17 15:39:16 -0700424 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 final Phone phone = getPhoneFromRequest(request);
427 request.result = phone != null ?
428 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
429 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700431 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700436 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800438 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700439 if (uiccCard == null) {
440 loge("iccTransmitApduLogicalChannel: No UICC");
441 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700442 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700443 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
445 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700446 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 iccArgument.channel, iccArgument.cla, iccArgument.command,
448 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700450 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 break;
452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 ar = (AsyncResult) msg.obj;
455 request = (MainThreadRequest) ar.userObj;
456 if (ar.exception == null && ar.result != null) {
457 request.result = ar.result;
458 } else {
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
460 if (ar.result == null) {
461 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800462 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800464 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 } else {
466 loge("iccTransmitApduLogicalChannel: Unknown exception");
467 }
468 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700469 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700470 break;
471
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700472 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
473 request = (MainThreadRequest) msg.obj;
474 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800475 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 if (uiccCard == null) {
477 loge("iccTransmitApduBasicChannel: No UICC");
478 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700479 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 } else {
481 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
482 request);
483 uiccCard.iccTransmitApduBasicChannel(
484 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
485 iccArgument.p3, iccArgument.data, onCompleted);
486 }
487 break;
488
489 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
490 ar = (AsyncResult) msg.obj;
491 request = (MainThreadRequest) ar.userObj;
492 if (ar.exception == null && ar.result != null) {
493 request.result = ar.result;
494 } else {
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
496 if (ar.result == null) {
497 loge("iccTransmitApduBasicChannel: Empty response");
498 } else if (ar.exception instanceof CommandException) {
499 loge("iccTransmitApduBasicChannel: CommandException: " +
500 ar.exception);
501 } else {
502 loge("iccTransmitApduBasicChannel: Unknown exception");
503 }
504 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700505 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700506 break;
507
508 case CMD_EXCHANGE_SIM_IO:
509 request = (MainThreadRequest) msg.obj;
510 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800511 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 if (uiccCard == null) {
513 loge("iccExchangeSimIO: No UICC");
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 } else {
517 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
518 request);
519 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
520 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
521 iccArgument.data, onCompleted);
522 }
523 break;
524
525 case EVENT_EXCHANGE_SIM_IO_DONE:
526 ar = (AsyncResult) msg.obj;
527 request = (MainThreadRequest) ar.userObj;
528 if (ar.exception == null && ar.result != null) {
529 request.result = ar.result;
530 } else {
531 request.result = new IccIoResult(0x6f, 0, (byte[])null);
532 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 break;
535
Derek Tan4d5e5c12014-02-04 11:54:58 -0800536 case CMD_SEND_ENVELOPE:
537 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800538 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700539 if (uiccCard == null) {
540 loge("sendEnvelopeWithStatus: No UICC");
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700542 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700543 } else {
544 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
545 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
546 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800547 break;
548
549 case EVENT_SEND_ENVELOPE_DONE:
550 ar = (AsyncResult) msg.obj;
551 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700552 if (ar.exception == null && ar.result != null) {
553 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700555 request.result = new IccIoResult(0x6F, 0, (byte[])null);
556 if (ar.result == null) {
557 loge("sendEnvelopeWithStatus: Empty response");
558 } else if (ar.exception instanceof CommandException) {
559 loge("sendEnvelopeWithStatus: CommandException: " +
560 ar.exception);
561 } else {
562 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
563 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700565 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 break;
567
Shishir Agrawal566b7612013-10-28 14:41:00 -0700568 case CMD_OPEN_CHANNEL:
569 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800570 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800571 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700572 if (uiccCard == null) {
573 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800574 request.result = new IccOpenLogicalChannelResponse(-1,
575 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700576 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700577 } else {
578 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800579 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
580 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700581 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700582 break;
583
584 case EVENT_OPEN_CHANNEL_DONE:
585 ar = (AsyncResult) msg.obj;
586 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700588 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 int[] result = (int[]) ar.result;
590 int channelId = result[0];
591 byte[] selectResponse = null;
592 if (result.length > 1) {
593 selectResponse = new byte[result.length - 1];
594 for (int i = 1; i < result.length; ++i) {
595 selectResponse[i - 1] = (byte) result[i];
596 }
597 }
598 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700599 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 if (ar.result == null) {
602 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700604 if (ar.exception != null) {
605 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
606 }
607
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700608 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700609 if (ar.exception instanceof CommandException) {
610 CommandException.Error error =
611 ((CommandException) (ar.exception)).getCommandError();
612 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700614 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 }
617 }
618 openChannelResp = new IccOpenLogicalChannelResponse(
619 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700621 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 break;
624
625 case CMD_CLOSE_CHANNEL:
626 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800627 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 if (uiccCard == null) {
629 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900630 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
634 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800639 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
640 break;
641
642 case CMD_NV_READ_ITEM:
643 request = (MainThreadRequest) msg.obj;
644 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800645 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
646 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800647 break;
648
649 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 ar = (AsyncResult) msg.obj;
651 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800652 if (ar.exception == null && ar.result != null) {
653 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800655 request.result = "";
656 if (ar.result == null) {
657 loge("nvReadItem: Empty response");
658 } else if (ar.exception instanceof CommandException) {
659 loge("nvReadItem: CommandException: " +
660 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800662 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 }
664 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700665 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 break;
667
Jake Hambye994d462014-02-03 13:10:13 -0800668 case CMD_NV_WRITE_ITEM:
669 request = (MainThreadRequest) msg.obj;
670 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
671 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800672 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700673 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800674 break;
675
676 case EVENT_NV_WRITE_ITEM_DONE:
677 handleNullReturnEvent(msg, "nvWriteItem");
678 break;
679
680 case CMD_NV_WRITE_CDMA_PRL:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800683 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800684 break;
685
686 case EVENT_NV_WRITE_CDMA_PRL_DONE:
687 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
688 break;
689
chen xu1cc0abe2018-10-26 17:39:23 -0700690 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800691 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700692 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800693 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
chen xu1cc0abe2018-10-26 17:39:23 -0700696 case EVENT_RESET_MODEM_CONFIG_DONE:
697 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800698 break;
699
Jake Hamby7c27be32014-03-03 13:25:59 -0800700 case CMD_GET_PREFERRED_NETWORK_TYPE:
701 request = (MainThreadRequest) msg.obj;
702 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700703 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800704 break;
705
706 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
707 ar = (AsyncResult) msg.obj;
708 request = (MainThreadRequest) ar.userObj;
709 if (ar.exception == null && ar.result != null) {
710 request.result = ar.result; // Integer
711 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800712 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800713 if (ar.result == null) {
714 loge("getPreferredNetworkType: Empty response");
715 } else if (ar.exception instanceof CommandException) {
716 loge("getPreferredNetworkType: CommandException: " +
717 ar.exception);
718 } else {
719 loge("getPreferredNetworkType: Unknown exception");
720 }
721 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700722 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 break;
724
725 case CMD_SET_PREFERRED_NETWORK_TYPE:
726 request = (MainThreadRequest) msg.obj;
727 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
728 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700729 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800730 break;
731
732 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
733 handleNullReturnEvent(msg, "setPreferredNetworkType");
734 break;
735
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000736 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
737 request = (MainThreadRequest)msg.obj;
738 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800739 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000740 break;
741
742 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
743 ar = (AsyncResult)msg.obj;
744 request = (MainThreadRequest)ar.userObj;
745 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700746 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000747 break;
748
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800749 case CMD_SET_VOICEMAIL_NUMBER:
750 request = (MainThreadRequest) msg.obj;
751 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
752 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800753 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
754 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800755 break;
756
757 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
758 handleNullReturnEvent(msg, "setVoicemailNumber");
759 break;
760
Stuart Scott54788802015-03-30 13:18:01 -0700761 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
764 request);
765 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
766 break;
767
768 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
769 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
770 break;
771
Shishir Agrawal302c8692015-06-19 13:49:39 -0700772 case CMD_PERFORM_NETWORK_SCAN:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
775 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
776 break;
777
778 case EVENT_PERFORM_NETWORK_SCAN_DONE:
779 ar = (AsyncResult) msg.obj;
780 request = (MainThreadRequest) ar.userObj;
781 CellNetworkScanResult cellScanResult;
782 if (ar.exception == null && ar.result != null) {
783 cellScanResult = new CellNetworkScanResult(
784 CellNetworkScanResult.STATUS_SUCCESS,
785 (List<OperatorInfo>) ar.result);
786 } else {
787 if (ar.result == null) {
788 loge("getCellNetworkScanResults: Empty response");
789 }
790 if (ar.exception != null) {
791 loge("getCellNetworkScanResults: Exception: " + ar.exception);
792 }
793 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
794 if (ar.exception instanceof CommandException) {
795 CommandException.Error error =
796 ((CommandException) (ar.exception)).getCommandError();
797 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
799 } else if (error == CommandException.Error.GENERIC_FAILURE) {
800 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
801 }
802 }
803 cellScanResult = new CellNetworkScanResult(errorCode, null);
804 }
805 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700806 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700807 break;
808
809 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
810 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700811 ManualNetworkSelectionArgument selArg =
812 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700813 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
814 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700815 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
816 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700817 break;
818
819 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700820 ar = (AsyncResult) msg.obj;
821 request = (MainThreadRequest) ar.userObj;
822 if (ar.exception == null) {
823 request.result = true;
824 } else {
825 request.result = false;
826 loge("setNetworkSelectionModeManual " + ar.exception);
827 }
828 notifyRequester(request);
829 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700832 case CMD_GET_MODEM_ACTIVITY_INFO:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800835 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700836 break;
837
838 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 if (ar.exception == null && ar.result != null) {
842 request.result = ar.result;
843 } else {
844 if (ar.result == null) {
845 loge("queryModemActivityInfo: Empty response");
846 } else if (ar.exception instanceof CommandException) {
847 loge("queryModemActivityInfo: CommandException: " +
848 ar.exception);
849 } else {
850 loge("queryModemActivityInfo: Unknown exception");
851 }
852 }
Amit Mahajand4766222016-01-28 15:28:28 -0800853 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
854 if (request.result == null) {
855 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
856 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700857 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700858 break;
859
Meng Wang1a7c35a2016-05-05 20:56:15 -0700860 case CMD_SET_ALLOWED_CARRIERS:
861 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800862 CarrierRestrictionRules argument =
863 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800865 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 break;
867
868 case EVENT_SET_ALLOWED_CARRIERS_DONE:
869 ar = (AsyncResult) msg.obj;
870 request = (MainThreadRequest) ar.userObj;
871 if (ar.exception == null && ar.result != null) {
872 request.result = ar.result;
873 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800874 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
875 if (ar.exception instanceof CommandException) {
876 loge("setAllowedCarriers: CommandException: " + ar.exception);
877 CommandException.Error error =
878 ((CommandException) (ar.exception)).getCommandError();
879 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
880 request.result =
881 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
882 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700883 } else {
884 loge("setAllowedCarriers: Unknown exception");
885 }
886 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700887 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700888 break;
889
890 case CMD_GET_ALLOWED_CARRIERS:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800893 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700894 break;
895
896 case EVENT_GET_ALLOWED_CARRIERS_DONE:
897 ar = (AsyncResult) msg.obj;
898 request = (MainThreadRequest) ar.userObj;
899 if (ar.exception == null && ar.result != null) {
900 request.result = ar.result;
901 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800902 request.result = new IllegalStateException(
903 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700904 if (ar.result == null) {
905 loge("getAllowedCarriers: Empty response");
906 } else if (ar.exception instanceof CommandException) {
907 loge("getAllowedCarriers: CommandException: " +
908 ar.exception);
909 } else {
910 loge("getAllowedCarriers: Unknown exception");
911 }
912 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700913 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
Nathan Haroldb3014052017-01-25 15:57:32 -0800916 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
922 request.result = new IllegalArgumentException(
923 "Failed to retrieve Forbidden Plmns");
924 if (ar.result == null) {
925 loge("getForbiddenPlmns: Empty response");
926 } else {
927 loge("getForbiddenPlmns: Unknown exception");
928 }
929 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700930 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800931 break;
932
933 case CMD_GET_FORBIDDEN_PLMNS:
934 request = (MainThreadRequest) msg.obj;
935 uiccCard = getUiccCardFromRequest(request);
936 if (uiccCard == null) {
937 loge("getForbiddenPlmns() UiccCard is null");
938 request.result = new IllegalArgumentException(
939 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700940 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 break;
942 }
943 Integer appType = (Integer) request.argument;
944 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
945 if (uiccApp == null) {
946 loge("getForbiddenPlmns() no app with specified type -- "
947 + appType);
948 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700949 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800950 break;
951 } else {
952 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
953 + " specified type -- " + appType);
954 }
955 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
956 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
957 onCompleted);
958 break;
959
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000960 case CMD_SWITCH_SLOTS:
961 request = (MainThreadRequest) msg.obj;
962 int[] physicalSlots = (int[]) request.argument;
963 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
964 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
965 break;
966
967 case EVENT_SWITCH_SLOTS_DONE:
968 ar = (AsyncResult) msg.obj;
969 request = (MainThreadRequest) ar.userObj;
970 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700971 notifyRequester(request);
972 break;
973 case CMD_GET_NETWORK_SELECTION_MODE:
974 request = (MainThreadRequest) msg.obj;
975 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
976 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
977 break;
978
979 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
980 ar = (AsyncResult) msg.obj;
981 request = (MainThreadRequest) ar.userObj;
982 if (ar.exception != null) {
983 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
984 } else {
985 int mode = ((int[]) ar.result)[0];
986 if (mode == 0) {
987 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
988 } else {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
990 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000991 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700992 notifyRequester(request);
993 break;
994 case CMD_GET_CDMA_ROAMING_MODE:
995 request = (MainThreadRequest) msg.obj;
996 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
997 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
998 break;
999 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1004 } else {
1005 request.result = ((int[]) ar.result)[0];
1006 }
1007 notifyRequester(request);
1008 break;
1009 case CMD_SET_CDMA_ROAMING_MODE:
1010 request = (MainThreadRequest) msg.obj;
1011 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1012 int mode = (int) request.argument;
1013 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1014 break;
1015 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 request.result = ar.exception == null;
1019 notifyRequester(request);
1020 break;
1021 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1022 request = (MainThreadRequest) msg.obj;
1023 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1024 int subscriptionMode = (int) request.argument;
1025 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1026 break;
1027 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1028 ar = (AsyncResult) msg.obj;
1029 request = (MainThreadRequest) ar.userObj;
1030 request.result = ar.exception == null;
1031 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001032 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001033 case CMD_GET_ALL_CELL_INFO:
1034 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001036 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001038 case EVENT_GET_ALL_CELL_INFO_DONE:
1039 ar = (AsyncResult) msg.obj;
1040 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001041 // If a timeout occurs, the response will be null
1042 request.result = (ar.exception == null && ar.result != null)
1043 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001044 synchronized (request) {
1045 request.notifyAll();
1046 }
1047 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001048 case CMD_REQUEST_CELL_INFO_UPDATE:
1049 request = (MainThreadRequest) msg.obj;
1050 request.phone.requestCellInfoUpdate(request.workSource,
1051 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1052 break;
1053 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1054 ar = (AsyncResult) msg.obj;
1055 request = (MainThreadRequest) ar.userObj;
1056 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1057 try {
1058 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001059 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001060 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1061 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001064 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 } else {
1066 // use the result as returned
1067 cb.onCellInfo((List<CellInfo>) ar.result);
1068 }
1069 } catch (RemoteException re) {
1070 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1071 }
1072 break;
1073 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001074 request = (MainThreadRequest) msg.obj;
1075 WorkSource ws = (WorkSource) request.argument;
1076 Phone phone = getPhoneFromRequest(request);
1077 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1078 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
1082 if (ar.exception == null) {
1083 request.result = ar.result;
1084 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001086 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1087 ? new CdmaCellLocation() : new GsmCellLocation();
1088 }
1089
1090 synchronized (request) {
1091 request.notifyAll();
1092 }
1093 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001094 case CMD_MODEM_REBOOT:
1095 request = (MainThreadRequest) msg.obj;
1096 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001097 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001098 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001099 case EVENT_CMD_MODEM_REBOOT_DONE:
1100 handleNullReturnEvent(msg, "rebootModem");
1101 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001102 case CMD_REQUEST_ENABLE_MODEM:
1103 request = (MainThreadRequest) msg.obj;
1104 boolean enable = (boolean) request.argument;
1105 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001106 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001107 PhoneConfigurationManager.getInstance()
1108 .enablePhone(request.phone, enable, onCompleted);
1109 break;
1110 case EVENT_ENABLE_MODEM_DONE:
1111 ar = (AsyncResult) msg.obj;
1112 request = (MainThreadRequest) ar.userObj;
1113 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001114 //update the cache as modem status has changed
1115 mPhoneConfigurationManager.addToPhoneStatusCache(
1116 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001117 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001118 notifyRequester(request);
1119 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001120 default:
1121 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1122 break;
1123 }
1124 }
Jake Hambye994d462014-02-03 13:10:13 -08001125
Pengquan Meng0c05b502018-09-06 09:59:22 -07001126 private void notifyRequester(MainThreadRequest request) {
1127 synchronized (request) {
1128 request.notifyAll();
1129 }
1130 }
1131
Jake Hambye994d462014-02-03 13:10:13 -08001132 private void handleNullReturnEvent(Message msg, String command) {
1133 AsyncResult ar = (AsyncResult) msg.obj;
1134 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1135 if (ar.exception == null) {
1136 request.result = true;
1137 } else {
1138 request.result = false;
1139 if (ar.exception instanceof CommandException) {
1140 loge(command + ": CommandException: " + ar.exception);
1141 } else {
1142 loge(command + ": Unknown exception");
1143 }
1144 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001145 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001146 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001147 }
1148
1149 /**
1150 * Posts the specified command to be executed on the main thread,
1151 * waits for the request to complete, and returns the result.
1152 * @see #sendRequestAsync
1153 */
1154 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001155 return sendRequest(
1156 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001157 }
1158
1159 /**
1160 * Posts the specified command to be executed on the main thread,
1161 * waits for the request to complete, and returns the result.
1162 * @see #sendRequestAsync
1163 */
1164 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1165 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001166 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001167 }
1168
1169 /**
1170 * Posts the specified command to be executed on the main thread,
1171 * waits for the request to complete, and returns the result.
1172 * @see #sendRequestAsync
1173 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001174 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001175 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001176 }
1177
1178 /**
1179 * Posts the specified command to be executed on the main thread,
1180 * waits for the request to complete, and returns the result.
1181 * @see #sendRequestAsync
1182 */
Nathan Harold92bed182018-10-12 18:16:49 -07001183 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1184 return sendRequest(command, argument, subId, null, workSource);
1185 }
1186
1187 /**
1188 * Posts the specified command to be executed on the main thread,
1189 * waits for the request to complete, and returns the result.
1190 * @see #sendRequestAsync
1191 */
1192 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1193 return sendRequest(
1194 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1195 }
1196
1197 /**
1198 * Posts the specified command to be executed on the main thread,
1199 * waits for the request to complete, and returns the result.
1200 * @see #sendRequestAsync
1201 */
1202 private Object sendRequest(
1203 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001204 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1205 throw new RuntimeException("This method will deadlock if called from the main thread.");
1206 }
1207
Nathan Harold92bed182018-10-12 18:16:49 -07001208 MainThreadRequest request = null;
1209 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1210 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1211 } else if (phone != null) {
1212 request = new MainThreadRequest(argument, phone, workSource);
1213 } else {
1214 request = new MainThreadRequest(argument, subId, workSource);
1215 }
1216
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001217 Message msg = mMainThreadHandler.obtainMessage(command, request);
1218 msg.sendToTarget();
1219
1220 // Wait for the request to complete
1221 synchronized (request) {
1222 while (request.result == null) {
1223 try {
1224 request.wait();
1225 } catch (InterruptedException e) {
1226 // Do nothing, go back and wait until the request is complete
1227 }
1228 }
1229 }
1230 return request.result;
1231 }
1232
1233 /**
1234 * Asynchronous ("fire and forget") version of sendRequest():
1235 * Posts the specified command to be executed on the main thread, and
1236 * returns immediately.
1237 * @see #sendRequest
1238 */
1239 private void sendRequestAsync(int command) {
1240 mMainThreadHandler.sendEmptyMessage(command);
1241 }
1242
1243 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001244 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001245 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 */
1247 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 sendRequestAsync(command, argument, null, null);
1249 }
1250
1251 /**
1252 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1253 * @see {@link #sendRequest(int,Object)}
1254 */
1255 private void sendRequestAsync(
1256 int command, Object argument, Phone phone, WorkSource workSource) {
1257 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001258 Message msg = mMainThreadHandler.obtainMessage(command, request);
1259 msg.sendToTarget();
1260 }
1261
1262 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 * Initialize the singleton PhoneInterfaceManager instance.
1264 * This is only done once, at startup, from PhoneApp.onCreate().
1265 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001266 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001267 synchronized (PhoneInterfaceManager.class) {
1268 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001269 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001270 } else {
1271 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1272 }
1273 return sInstance;
1274 }
1275 }
1276
1277 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001278 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001279 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001281 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1283 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001284 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001285 mTelephonySharedPreferences =
1286 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001287 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001288 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001289
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001290 publish();
1291 }
1292
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001293 private Phone getDefaultPhone() {
1294 Phone thePhone = getPhone(getDefaultSubscription());
1295 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1296 }
1297
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001298 private void publish() {
1299 if (DBG) log("publish: " + this);
1300
1301 ServiceManager.addService("phone", this);
1302 }
1303
Stuart Scott584921c2015-01-15 17:10:34 -08001304 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001305 if (request.phone != null) {
1306 return request.phone;
1307 } else {
1308 return getPhoneFromSubId(request.subId);
1309 }
1310 }
1311
1312 private Phone getPhoneFromSubId(int subId) {
1313 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1314 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001315 }
1316
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001317 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1318 Phone phone = getPhoneFromRequest(request);
1319 return phone == null ? null :
1320 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1321 }
1322
Wink Saville36469e72014-06-11 15:17:00 -07001323 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001324 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001325 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001327
1328 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001329 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001330 }
1331
Wink Savilleb564aae2014-10-23 10:18:09 -07001332 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001333 if (DBG) log("dial: " + number);
1334 // No permission check needed here: This is just a wrapper around the
1335 // ACTION_DIAL intent, which is available to any app since it puts up
1336 // the UI before it does anything.
1337
Malcolm Chend965c8b2018-02-28 15:00:40 -08001338 final long identity = Binder.clearCallingIdentity();
1339 try {
1340 String url = createTelUrl(number);
1341 if (url == null) {
1342 return;
1343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344
Malcolm Chend965c8b2018-02-28 15:00:40 -08001345 // PENDING: should we just silently fail if phone is offhook or ringing?
1346 PhoneConstants.State state = mCM.getState(subId);
1347 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1348 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1349 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1350 mApp.startActivity(intent);
1351 }
1352 } finally {
1353 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001354 }
1355 }
1356
1357 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001358 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001359 }
1360
Wink Savilleb564aae2014-10-23 10:18:09 -07001361 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001362 if (DBG) log("call: " + number);
1363
1364 // This is just a wrapper around the ACTION_CALL intent, but we still
1365 // need to do a permission check since we're calling startActivity()
1366 // from the context of the phone app.
1367 enforceCallPermission();
1368
1369 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1370 != AppOpsManager.MODE_ALLOWED) {
1371 return;
1372 }
1373
Malcolm Chend965c8b2018-02-28 15:00:40 -08001374 final long identity = Binder.clearCallingIdentity();
1375 try {
1376 String url = createTelUrl(number);
1377 if (url == null) {
1378 return;
1379 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380
Malcolm Chend965c8b2018-02-28 15:00:40 -08001381 boolean isValid = false;
1382 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1383 if (slist != null) {
1384 for (SubscriptionInfo subInfoRecord : slist) {
1385 if (subInfoRecord.getSubscriptionId() == subId) {
1386 isValid = true;
1387 break;
1388 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001389 }
Wink Saville08874612014-08-31 19:19:58 -07001390 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001391 if (!isValid) {
1392 return;
1393 }
Wink Saville08874612014-08-31 19:19:58 -07001394
Malcolm Chend965c8b2018-02-28 15:00:40 -08001395 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1396 intent.putExtra(SUBSCRIPTION_KEY, subId);
1397 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1398 mApp.startActivity(intent);
1399 } finally {
1400 Binder.restoreCallingIdentity(identity);
1401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 }
1403
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001405 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001406 }
1407
Wink Savilleb564aae2014-10-23 10:18:09 -07001408 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001409 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001410 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1411 }
1412
1413 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001415 }
1416
Wink Savilleb564aae2014-10-23 10:18:09 -07001417 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001418 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001419 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1420 }
1421
1422 /** {@hide} */
1423 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001424 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001425 }
1426
Wink Savilleb564aae2014-10-23 10:18:09 -07001427 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001429
1430 final long identity = Binder.clearCallingIdentity();
1431 try {
1432 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1433 checkSimPin.start();
1434 return checkSimPin.unlockSim(null, pin);
1435 } finally {
1436 Binder.restoreCallingIdentity(identity);
1437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001438 }
1439
Wink Saville9de0f752013-10-22 19:04:03 -07001440 /** {@hide} */
1441 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001442 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001443 }
1444
Wink Savilleb564aae2014-10-23 10:18:09 -07001445 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001447
1448 final long identity = Binder.clearCallingIdentity();
1449 try {
1450 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1451 checkSimPuk.start();
1452 return checkSimPuk.unlockSim(puk, pin);
1453 } finally {
1454 Binder.restoreCallingIdentity(identity);
1455 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001456 }
1457
1458 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001459 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 * a synchronous one.
1461 */
1462 private static class UnlockSim extends Thread {
1463
1464 private final IccCard mSimCard;
1465
1466 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001467 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1468 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001469
1470 // For replies from SimCard interface
1471 private Handler mHandler;
1472
1473 // For async handler to identify request type
1474 private static final int SUPPLY_PIN_COMPLETE = 100;
1475
1476 public UnlockSim(IccCard simCard) {
1477 mSimCard = simCard;
1478 }
1479
1480 @Override
1481 public void run() {
1482 Looper.prepare();
1483 synchronized (UnlockSim.this) {
1484 mHandler = new Handler() {
1485 @Override
1486 public void handleMessage(Message msg) {
1487 AsyncResult ar = (AsyncResult) msg.obj;
1488 switch (msg.what) {
1489 case SUPPLY_PIN_COMPLETE:
1490 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1491 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001492 mRetryCount = msg.arg1;
1493 if (ar.exception != null) {
1494 if (ar.exception instanceof CommandException &&
1495 ((CommandException)(ar.exception)).getCommandError()
1496 == CommandException.Error.PASSWORD_INCORRECT) {
1497 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1498 } else {
1499 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1500 }
1501 } else {
1502 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1503 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001504 mDone = true;
1505 UnlockSim.this.notifyAll();
1506 }
1507 break;
1508 }
1509 }
1510 };
1511 UnlockSim.this.notifyAll();
1512 }
1513 Looper.loop();
1514 }
1515
1516 /*
1517 * Use PIN or PUK to unlock SIM card
1518 *
1519 * If PUK is null, unlock SIM card with PIN
1520 *
1521 * If PUK is not null, unlock SIM card with PUK and set PIN code
1522 */
Wink Saville9de0f752013-10-22 19:04:03 -07001523 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524
1525 while (mHandler == null) {
1526 try {
1527 wait();
1528 } catch (InterruptedException e) {
1529 Thread.currentThread().interrupt();
1530 }
1531 }
1532 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1533
1534 if (puk == null) {
1535 mSimCard.supplyPin(pin, callback);
1536 } else {
1537 mSimCard.supplyPuk(puk, pin, callback);
1538 }
1539
1540 while (!mDone) {
1541 try {
1542 Log.d(LOG_TAG, "wait for done");
1543 wait();
1544 } catch (InterruptedException e) {
1545 // Restore the interrupted status
1546 Thread.currentThread().interrupt();
1547 }
1548 }
1549 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001550 int[] resultArray = new int[2];
1551 resultArray[0] = mResult;
1552 resultArray[1] = mRetryCount;
1553 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555 }
1556
1557 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001558 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001559
1560 }
1561
Wink Savilleb564aae2014-10-23 10:18:09 -07001562 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001563 // No permission check needed here: this call is harmless, and it's
1564 // needed for the ServiceState.requestStateUpdate() call (which is
1565 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001566 final long identity = Binder.clearCallingIdentity();
1567 try {
1568 final Phone phone = getPhone(subId);
1569 if (phone != null) {
1570 phone.updateServiceLocation();
1571 }
1572 } finally {
1573 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001574 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001575 }
1576
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001577 @Override
1578 public boolean isRadioOn(String callingPackage) {
1579 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001580 }
1581
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001582 @Override
1583 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001585 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001586 return false;
1587 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001588
1589 final long identity = Binder.clearCallingIdentity();
1590 try {
1591 return isRadioOnForSubscriber(subId);
1592 } finally {
1593 Binder.restoreCallingIdentity(identity);
1594 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001595 }
1596
1597 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001598 final long identity = Binder.clearCallingIdentity();
1599 try {
1600 final Phone phone = getPhone(subId);
1601 if (phone != null) {
1602 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1603 } else {
1604 return false;
1605 }
1606 } finally {
1607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 }
1610
1611 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001612 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001613 }
Wink Saville36469e72014-06-11 15:17:00 -07001614
Wink Savilleb564aae2014-10-23 10:18:09 -07001615 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001616 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001617
1618 final long identity = Binder.clearCallingIdentity();
1619 try {
1620 final Phone phone = getPhone(subId);
1621 if (phone != null) {
1622 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1623 }
1624 } finally {
1625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001626 }
Wink Saville36469e72014-06-11 15:17:00 -07001627 }
1628
1629 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001630 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001631 }
1632
Wink Savilleb564aae2014-10-23 10:18:09 -07001633 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001634 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001635
1636 final long identity = Binder.clearCallingIdentity();
1637 try {
1638 final Phone phone = getPhone(subId);
1639 if (phone == null) {
1640 return false;
1641 }
1642 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1643 toggleRadioOnOffForSubscriber(subId);
1644 }
1645 return true;
1646 } finally {
1647 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 }
Wink Saville36469e72014-06-11 15:17:00 -07001650
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001651 public boolean needMobileRadioShutdown() {
1652 /*
1653 * If any of the Radios are available, it will need to be
1654 * shutdown. So return true if any Radio is available.
1655 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001656 final long identity = Binder.clearCallingIdentity();
1657 try {
1658 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1659 Phone phone = PhoneFactory.getPhone(i);
1660 if (phone != null && phone.isRadioAvailable()) return true;
1661 }
1662 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1663 return false;
1664 } finally {
1665 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001666 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001667 }
1668
Malcolm Chend965c8b2018-02-28 15:00:40 -08001669 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001670 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001671 enforceModifyPermission();
1672
1673 final long identity = Binder.clearCallingIdentity();
1674 try {
1675 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1676 logv("Shutting down Phone " + i);
1677 shutdownRadioUsingPhoneId(i);
1678 }
1679 } finally {
1680 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001681 }
1682 }
1683
1684 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001685 Phone phone = PhoneFactory.getPhone(phoneId);
1686 if (phone != null && phone.isRadioAvailable()) {
1687 phone.shutdownRadio();
1688 }
1689 }
1690
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001691 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001692 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001693
1694 final long identity = Binder.clearCallingIdentity();
1695 try {
1696 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1697 if (defaultPhone != null) {
1698 defaultPhone.setRadioPower(turnOn);
1699 return true;
1700 } else {
1701 loge("There's no default phone.");
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001706 }
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Wink Savilleb564aae2014-10-23 10:18:09 -07001709 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001711
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 final Phone phone = getPhone(subId);
1715 if (phone != null) {
1716 phone.setRadioPower(turnOn);
1717 return true;
1718 } else {
1719 return false;
1720 }
1721 } finally {
1722 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 }
1725
Wink Saville36469e72014-06-11 15:17:00 -07001726 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001727 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001728 public boolean enableDataConnectivity() {
1729 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001730
1731 final long identity = Binder.clearCallingIdentity();
1732 try {
1733 int subId = mSubscriptionController.getDefaultDataSubId();
1734 final Phone phone = getPhone(subId);
1735 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001736 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001737 return true;
1738 } else {
1739 return false;
1740 }
1741 } finally {
1742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745
Wink Saville36469e72014-06-11 15:17:00 -07001746 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001747 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748 public boolean disableDataConnectivity() {
1749 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001750
1751 final long identity = Binder.clearCallingIdentity();
1752 try {
1753 int subId = mSubscriptionController.getDefaultDataSubId();
1754 final Phone phone = getPhone(subId);
1755 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001756 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001757 return true;
1758 } 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
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001767 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001768 final long identity = Binder.clearCallingIdentity();
1769 try {
1770 final Phone phone = getPhone(subId);
1771 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001772 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001773 } else {
1774 return false;
1775 }
1776 } finally {
1777 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001778 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001779 }
1780
1781 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001782 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001783 }
1784
pkanwarae03a6b2016-11-06 20:37:09 -08001785 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001786 enforceCallPermission();
1787
1788 final long identity = Binder.clearCallingIdentity();
1789 try {
1790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1791 return;
1792 }
1793 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1794 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1795 } finally {
1796 Binder.restoreCallingIdentity(identity);
1797 }
pkanwar32d516d2016-10-14 19:37:38 -07001798 };
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001801 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001802
1803 final long identity = Binder.clearCallingIdentity();
1804 try {
1805 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1806 return false;
1807 }
1808 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1809 } finally {
1810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001812 }
1813
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001815 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001816 }
1817
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001818 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001819 final long identity = Binder.clearCallingIdentity();
1820 try {
1821 Phone phone = PhoneFactory.getPhone(slotIndex);
1822 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1823 PhoneConstantConversions.convertCallState(phone.getState());
1824 } finally {
1825 Binder.restoreCallingIdentity(identity);
1826 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001827 }
1828
Sanket Padawe356d7632015-06-22 14:03:32 -07001829 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001830 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001831 final long identity = Binder.clearCallingIdentity();
1832 try {
1833 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1834 if (phone != null) {
1835 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1836 } else {
1837 return PhoneConstantConversions.convertDataState(
1838 PhoneConstants.DataState.DISCONNECTED);
1839 }
1840 } finally {
1841 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001842 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001843 }
1844
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001847 final long identity = Binder.clearCallingIdentity();
1848 try {
1849 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1850 if (phone != null) {
1851 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1852 } else {
1853 return TelephonyManager.DATA_ACTIVITY_NONE;
1854 }
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
1860 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001861 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001862 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001863 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001864
1865 LocationAccessPolicy.LocationPermissionResult locationResult =
1866 LocationAccessPolicy.checkLocationPermission(mApp,
1867 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1868 .setCallingPackage(callingPackage)
1869 .setCallingPid(Binder.getCallingPid())
1870 .setCallingUid(Binder.getCallingUid())
1871 .setMethod("getCellLocation")
1872 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1873 .build());
1874 switch (locationResult) {
1875 case DENIED_HARD:
1876 throw new SecurityException("Not allowed to access cell location");
1877 case DENIED_SOFT:
1878 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 }
1880
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001881 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001882 final long identity = Binder.clearCallingIdentity();
1883 try {
1884 if (DBG_LOC) log("getCellLocation: is active user");
1885 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001886 int subId = mSubscriptionController.getDefaultDataSubId();
1887 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1888 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001889 return data;
1890 } finally {
1891 Binder.restoreCallingIdentity(identity);
1892 }
Svetoslav64fad262015-04-14 14:35:21 -07001893 }
1894
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001896 public String getNetworkCountryIsoForPhone(int phoneId) {
1897 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1898 // registered cell info, so return a NULL country instead.
1899 final long identity = Binder.clearCallingIdentity();
1900 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001901 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1902 // Get default phone in this case.
1903 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1904 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001905 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001906 // Todo: fix this when we can get the actual cellular network info when the device
1907 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001908 if (TelephonyManager.NETWORK_TYPE_IWLAN
1909 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1910 return "";
1911 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001912 Phone phone = PhoneFactory.getPhone(phoneId);
1913 if (phone != null) {
1914 ServiceStateTracker sst = phone.getServiceStateTracker();
1915 if (sst != null) {
1916 LocaleTracker lt = sst.getLocaleTracker();
1917 if (lt != null) {
1918 return lt.getCurrentCountry();
1919 }
1920 }
1921 }
1922 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001923 } finally {
1924 Binder.restoreCallingIdentity(identity);
1925 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001926 }
1927
1928 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001929 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001930 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001931 }
1932
Sanket Padawe356d7632015-06-22 14:03:32 -07001933 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001934 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 mApp.enforceCallingOrSelfPermission(
1936 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001937
1938 final long identity = Binder.clearCallingIdentity();
1939 try {
1940 final Phone phone = getPhone(subId);
1941 if (phone != null) {
1942 phone.enableLocationUpdates();
1943 }
1944 } finally {
1945 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001946 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948
1949 @Override
1950 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001951 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952 }
1953
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001955 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 mApp.enforceCallingOrSelfPermission(
1957 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001958
1959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 phone.disableLocationUpdates();
1964 }
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Nathan Harold31d7ff32018-10-15 20:20:30 -07001970 /**
1971 * Returns the target SDK version number for a given package name.
1972 *
1973 * @return target SDK if the package is found or INT_MAX.
1974 */
1975 private int getTargetSdk(String packageName) {
1976 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001977 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1978 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001979 if (ai != null) return ai.targetSdkVersion;
1980 } catch (PackageManager.NameNotFoundException unexpected) {
1981 }
1982 return Integer.MAX_VALUE;
1983 }
1984
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 @Override
1986 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001987 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1988 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001989 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1990 throw new SecurityException(
1991 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1992 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001993
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001994 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1995 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1996 return null;
1997 }
Svetoslav64fad262015-04-14 14:35:21 -07001998
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001999 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000
Nathan Haroldf180aac2018-06-01 18:43:55 -07002001 List<CellInfo> info = getAllCellInfo(callingPackage);
2002 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003
Nathan Haroldf180aac2018-06-01 18:43:55 -07002004 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2005 for (CellInfo ci : info) {
2006 if (ci instanceof CellInfoGsm) {
2007 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2008 } else if (ci instanceof CellInfoWcdma) {
2009 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2010 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002011 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002012 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002015 private List<CellInfo> getCachedCellInfo() {
2016 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2017 for (Phone phone : PhoneFactory.getPhones()) {
2018 List<CellInfo> info = phone.getAllCellInfo();
2019 if (info != null) cellInfos.addAll(info);
2020 }
2021 return cellInfos;
2022 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002023
2024 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002025 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002026 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002027 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002028
2029 LocationAccessPolicy.LocationPermissionResult locationResult =
2030 LocationAccessPolicy.checkLocationPermission(mApp,
2031 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2032 .setCallingPackage(callingPackage)
2033 .setCallingPid(Binder.getCallingPid())
2034 .setCallingUid(Binder.getCallingUid())
2035 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002036 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002037 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2038 .build());
2039 switch (locationResult) {
2040 case DENIED_HARD:
2041 throw new SecurityException("Not allowed to access cell info");
2042 case DENIED_SOFT:
2043 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002044 }
2045
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002046 final int targetSdk = getTargetSdk(callingPackage);
2047 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2048 return getCachedCellInfo();
2049 }
2050
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002051 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002052 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002053 final long identity = Binder.clearCallingIdentity();
2054 try {
2055 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2056 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002057 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002058 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002059 if (info != null) cellInfos.addAll(info);
2060 }
2061 return cellInfos;
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002064 }
2065 }
2066
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002067 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002068 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2069 requestCellInfoUpdateInternal(
2070 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2071 }
2072
2073 @Override
2074 public void requestCellInfoUpdateWithWorkSource(
2075 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2076 enforceModifyPermission();
2077 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2078 }
2079
2080 private void requestCellInfoUpdateInternal(
2081 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002082 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002083 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002084
2085 LocationAccessPolicy.LocationPermissionResult locationResult =
2086 LocationAccessPolicy.checkLocationPermission(mApp,
2087 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2088 .setCallingPackage(callingPackage)
2089 .setCallingPid(Binder.getCallingPid())
2090 .setCallingUid(Binder.getCallingUid())
2091 .setMethod("requestCellInfoUpdate")
2092 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2093 .build());
2094 switch (locationResult) {
2095 case DENIED_HARD:
2096 throw new SecurityException("Not allowed to access cell info");
2097 case DENIED_SOFT:
2098 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002099 }
2100
2101 final Phone phone = getPhone(subId);
2102 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2103
2104 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2105 }
2106
2107 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002109 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002114 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002115 } finally {
2116 Binder.restoreCallingIdentity(identity);
2117 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002118 }
2119
Shishir Agrawala9f32182016-04-12 12:00:16 -07002120 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002121 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002122 Phone phone = PhoneFactory.getPhone(slotIndex);
2123 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002124 return null;
2125 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002126 int subId = phone.getSubId();
2127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2128 mApp, subId, callingPackage, "getImeiForSlot")) {
2129 return null;
2130 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 return phone.getImei();
2135 } finally {
2136 Binder.restoreCallingIdentity(identity);
2137 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002138 }
2139
2140 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002141 public String getTypeAllocationCodeForSlot(int slotIndex) {
2142 Phone phone = PhoneFactory.getPhone(slotIndex);
2143 String tac = null;
2144 if (phone != null) {
2145 String imei = phone.getImei();
2146 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2147 }
2148 return tac;
2149 }
2150
2151 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002152 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002153 Phone phone = PhoneFactory.getPhone(slotIndex);
2154 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002155 return null;
2156 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002157
Jeff Davidson913390f2018-02-23 17:11:49 -08002158 int subId = phone.getSubId();
2159 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2160 mApp, subId, callingPackage, "getMeidForSlot")) {
2161 return null;
2162 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002163
2164 final long identity = Binder.clearCallingIdentity();
2165 try {
2166 return phone.getMeid();
2167 } finally {
2168 Binder.restoreCallingIdentity(identity);
2169 }
Jack Yu2af8d712017-03-15 17:14:14 -07002170 }
2171
2172 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002173 public String getManufacturerCodeForSlot(int slotIndex) {
2174 Phone phone = PhoneFactory.getPhone(slotIndex);
2175 String manufacturerCode = null;
2176 if (phone != null) {
2177 String meid = phone.getMeid();
2178 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2179 }
2180 return manufacturerCode;
2181 }
2182
2183 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002184 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002185 Phone phone = PhoneFactory.getPhone(slotIndex);
2186 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002187 return null;
2188 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002189 int subId = phone.getSubId();
2190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2191 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2192 return null;
2193 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002194
2195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 return phone.getDeviceSvn();
2198 } finally {
2199 Binder.restoreCallingIdentity(identity);
2200 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002201 }
2202
fionaxu43304da2017-11-27 22:51:16 -08002203 @Override
2204 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002205 final long identity = Binder.clearCallingIdentity();
2206 try {
2207 final Phone phone = getPhone(subId);
2208 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2209 } finally {
2210 Binder.restoreCallingIdentity(identity);
2211 }
fionaxu43304da2017-11-27 22:51:16 -08002212 }
2213
2214 @Override
2215 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002216 final long identity = Binder.clearCallingIdentity();
2217 try {
2218 final Phone phone = getPhone(subId);
2219 return phone == null ? null : phone.getCarrierName();
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
fionaxu43304da2017-11-27 22:51:16 -08002223 }
2224
calvinpaneed9ae82018-11-01 19:43:06 +08002225 @Override
chen xua31f22b2019-03-06 15:28:50 -08002226 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 final Phone phone = getPhone(subId);
2230 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002231 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
2235 }
2236
2237 @Override
chen xua31f22b2019-03-06 15:28:50 -08002238 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002239 final long identity = Binder.clearCallingIdentity();
2240 try {
2241 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002242 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002243 } finally {
2244 Binder.restoreCallingIdentity(identity);
2245 }
2246 }
2247
chen xu02581692018-11-11 19:03:44 -08002248 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002249 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2250 if (!isSubscriptionMccMnc) {
2251 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2252 }
chen xu02581692018-11-11 19:03:44 -08002253 final Phone phone = PhoneFactory.getPhone(slotIndex);
2254 if (phone == null) {
2255 return TelephonyManager.UNKNOWN_CARRIER_ID;
2256 }
2257 final long identity = Binder.clearCallingIdentity();
2258 try {
2259 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
2263 }
2264
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002265 //
2266 // Internal helper methods.
2267 //
2268
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002269 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002270 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2271 *
2272 * @throws SecurityException if the caller does not have the required permission
2273 */
2274 private void enforceModifyPermission() {
2275 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2276 }
2277
2278 /**
2279 * Make sure the caller has the CALL_PHONE permission.
2280 *
2281 * @throws SecurityException if the caller does not have the required permission
2282 */
2283 private void enforceCallPermission() {
2284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2285 }
2286
Stuart Scott8eef64f2015-04-08 15:13:54 -07002287 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002288 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002289 "ConnectivityService");
2290 }
2291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 private String createTelUrl(String number) {
2293 if (TextUtils.isEmpty(number)) {
2294 return null;
2295 }
2296
Jake Hambye994d462014-02-03 13:10:13 -08002297 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Ihab Awadf9e92732013-12-05 18:02:52 -08002300 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002301 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2302 }
2303
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002304 private static void logv(String msg) {
2305 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2306 }
2307
Ihab Awadf9e92732013-12-05 18:02:52 -08002308 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2310 }
2311
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002312 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002314 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002315 }
2316
Sanket Padawe356d7632015-06-22 14:03:32 -07002317 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002318 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 final Phone phone = PhoneFactory.getPhone(slotIndex);
2322 if (phone == null) {
2323 return PhoneConstants.PHONE_TYPE_NONE;
2324 } else {
2325 return phone.getPhoneType();
2326 }
2327 } finally {
2328 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002329 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 }
2331
2332 /**
2333 * Returns the CDMA ERI icon index to display
2334 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002335 @Override
2336 public int getCdmaEriIconIndex(String callingPackage) {
2337 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002341 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002342 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002343 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002344 return -1;
2345 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002346
2347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
2350 if (phone != null) {
2351 return phone.getCdmaEriIconIndex();
2352 } else {
2353 return -1;
2354 }
2355 } finally {
2356 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002357 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 }
2359
2360 /**
2361 * Returns the CDMA ERI icon mode,
2362 * 0 - ON
2363 * 1 - FLASHING
2364 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002365 @Override
2366 public int getCdmaEriIconMode(String callingPackage) {
2367 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002368 }
2369
Sanket Padawe356d7632015-06-22 14:03:32 -07002370 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002371 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002372 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002374 return -1;
2375 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002376
2377 final long identity = Binder.clearCallingIdentity();
2378 try {
2379 final Phone phone = getPhone(subId);
2380 if (phone != null) {
2381 return phone.getCdmaEriIconMode();
2382 } else {
2383 return -1;
2384 }
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
2389
2390 /**
2391 * Returns the CDMA ERI text,
2392 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002393 @Override
2394 public String getCdmaEriText(String callingPackage) {
2395 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002396 }
2397
Sanket Padawe356d7632015-06-22 14:03:32 -07002398 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002401 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002402 return null;
2403 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002404
2405 final long identity = Binder.clearCallingIdentity();
2406 try {
2407 final Phone phone = getPhone(subId);
2408 if (phone != null) {
2409 return phone.getCdmaEriText();
2410 } else {
2411 return null;
2412 }
2413 } finally {
2414 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002415 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 }
2417
2418 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002419 * Returns the CDMA MDN.
2420 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002421 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002422 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2424 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002429 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002430 return phone.getLine1Number();
2431 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002432 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002433 return null;
2434 }
2435 } finally {
2436 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002437 }
2438 }
2439
2440 /**
2441 * Returns the CDMA MIN.
2442 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002443 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002444 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2446 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002447
2448 final long identity = Binder.clearCallingIdentity();
2449 try {
2450 final Phone phone = getPhone(subId);
2451 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2452 return phone.getCdmaMin();
2453 } else {
2454 return null;
2455 }
2456 } finally {
2457 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002458 }
2459 }
2460
Hall Liud892bec2018-11-30 14:51:45 -08002461 @Override
2462 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2463 INumberVerificationCallback callback, String callingPackage) {
2464 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2465 != PERMISSION_GRANTED) {
2466 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2467 }
2468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2469
2470 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2471 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2472 throw new SecurityException("Calling package must be configured in the device config");
2473 }
2474
2475 if (range == null) {
2476 throw new NullPointerException("Range must be non-null");
2477 }
2478
2479 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002480 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002481
2482 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2483 }
2484
Junda Liuca05d5d2014-08-14 22:36:34 -07002485 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 * Returns true if CDMA provisioning needs to run.
2487 */
2488 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002489 final long identity = Binder.clearCallingIdentity();
2490 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002491 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002492 } finally {
2493 Binder.restoreCallingIdentity(identity);
2494 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496
2497 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002498 * Sets the voice mail number of a given subId.
2499 */
2500 @Override
2501 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002502 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002503
2504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2507 new Pair<String, String>(alphaTag, number), new Integer(subId));
2508 return success;
2509 } finally {
2510 Binder.restoreCallingIdentity(identity);
2511 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002512 }
2513
Ta-wei Yen87c49842016-05-13 21:19:52 -07002514 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002515 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2516 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002517 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002518 if (!TextUtils.equals(callingPackage, systemDialer)) {
2519 throw new SecurityException("caller must be system dialer");
2520 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002521
2522 final long identity = Binder.clearCallingIdentity();
2523 try {
2524 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2525 if (phoneAccountHandle == null) {
2526 return null;
2527 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002528 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002529 } finally {
2530 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002531 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002532 }
2533
2534 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002535 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002536 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002537 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002538 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002539 return null;
2540 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002541
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002542 final long identity = Binder.clearCallingIdentity();
2543 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002544 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002548 }
2549
2550 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002551 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2552 VisualVoicemailSmsFilterSettings settings) {
2553 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002554
2555 final long identity = Binder.clearCallingIdentity();
2556 try {
2557 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002558 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002562 }
2563
2564 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002565 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2566 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002571 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002572 } finally {
2573 Binder.restoreCallingIdentity(identity);
2574 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002575 }
2576
2577 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002578 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2579 String callingPackage, int subId) {
2580 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002585 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002586 } finally {
2587 Binder.restoreCallingIdentity(identity);
2588 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002589 }
2590
2591 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002592 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002593 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002594
2595 final long identity = Binder.clearCallingIdentity();
2596 try {
2597 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002598 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002599 } finally {
2600 Binder.restoreCallingIdentity(identity);
2601 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002602 }
2603
2604 @Override
2605 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2606 String number, int port, String text, PendingIntent sentIntent) {
2607 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002608 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002609 enforceSendSmsPermission();
2610 // Make the calls as the phone process.
2611 final long identity = Binder.clearCallingIdentity();
2612 try {
2613 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2614 if (port == 0) {
2615 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2616 sentIntent, null, false);
2617 } else {
2618 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2619 smsManager.sendDataMessageWithSelfPermissions(number, null,
2620 (short) port, data, sentIntent, null);
2621 }
2622 } finally {
2623 Binder.restoreCallingIdentity(identity);
2624 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002625 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002626 /**
fionaxu0152e512016-11-14 13:36:14 -08002627 * Sets the voice activation state of a given subId.
2628 */
2629 @Override
2630 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2632 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 final Phone phone = getPhone(subId);
2637 if (phone != null) {
2638 phone.setVoiceActivationState(activationState);
2639 } else {
2640 loge("setVoiceActivationState fails with invalid subId: " + subId);
2641 }
2642 } finally {
2643 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002644 }
2645 }
2646
2647 /**
2648 * Sets the data activation state of a given subId.
2649 */
2650 @Override
2651 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2653 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002654
2655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 if (phone != null) {
2659 phone.setDataActivationState(activationState);
2660 } else {
2661 loge("setVoiceActivationState fails with invalid subId: " + subId);
2662 }
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002665 }
2666 }
2667
2668 /**
2669 * Returns the voice activation state of a given subId.
2670 */
2671 @Override
2672 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002673 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002674
fionaxu0152e512016-11-14 13:36:14 -08002675 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002676 final long identity = Binder.clearCallingIdentity();
2677 try {
2678 if (phone != null) {
2679 return phone.getVoiceActivationState();
2680 } else {
2681 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2682 }
2683 } finally {
2684 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002685 }
2686 }
2687
2688 /**
2689 * Returns the data activation state of a given subId.
2690 */
2691 @Override
2692 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002693 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002694
fionaxu0152e512016-11-14 13:36:14 -08002695 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
2698 if (phone != null) {
2699 return phone.getDataActivationState();
2700 } else {
2701 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2702 }
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002705 }
2706 }
2707
2708 /**
Wink Saville36469e72014-06-11 15:17:00 -07002709 * Returns the unread count of voicemails for a subId
2710 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002711 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002712 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2713 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2714 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2715 return 0;
2716 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 final Phone phone = getPhone(subId);
2720 if (phone != null) {
2721 return phone.getVoiceMessageCount();
2722 } else {
2723 return 0;
2724 }
2725 } finally {
2726 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002727 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 }
2729
2730 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002731 * returns true, if the device is in a state where both voice and data
2732 * are supported simultaneously. This can change based on location or network condition.
2733 */
2734 @Override
2735 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
2738 final Phone phone = getPhone(subId);
2739 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2740 } finally {
2741 Binder.restoreCallingIdentity(identity);
2742 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002743 }
2744
2745 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002746 * Send the dialer code if called from the current default dialer or the caller has
2747 * carrier privilege.
2748 * @param inputCode The dialer code to send
2749 */
2750 @Override
2751 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002752 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002753 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002754 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2755 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002756 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002757 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2758 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002759 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002760
2761 final long identity = Binder.clearCallingIdentity();
2762 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002763 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
fionaxu235cc5e2017-03-06 22:25:57 -08002767 }
2768
2769 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002770 * Returns the data network type.
2771 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 *
2773 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2774 */
2775 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002776 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002777 final long identity = Binder.clearCallingIdentity();
2778 try {
2779 final Phone phone = getPhone(getDefaultSubscription());
2780 if (phone != null) {
2781 return phone.getServiceState().getDataNetworkType();
2782 } else {
2783 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2784 }
2785 } finally {
2786 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002787 }
Wink Saville36469e72014-06-11 15:17:00 -07002788 }
2789
Pengquan Meng0c05b502018-09-06 09:59:22 -07002790 @Override
2791 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002792 if (!isActiveSubscription(subId)) {
2793 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2794 }
2795
Pengquan Meng0c05b502018-09-06 09:59:22 -07002796 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2797 }
2798
Brad Ebinger4c460712018-10-01 10:40:55 -07002799 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002800 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2801 throws RemoteException {
2802 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002803 final long token = Binder.clearCallingIdentity();
2804 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002805 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002806 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002807 .addRegistrationCallbackForSubscription(c, subId);
2808 } finally {
2809 Binder.restoreCallingIdentity(token);
2810 }
2811 }
2812
2813 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002814 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2815 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002816 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2817 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2818 }
2819 Binder.withCleanCallingIdentity(() -> {
2820 try {
2821 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002822 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002823 .removeRegistrationCallbackForSubscription(c, subId);
2824 } catch (IllegalArgumentException e) {
2825 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2826 + "is inactive, ignoring unregister.");
2827 // If the subscription is no longer active, just return, since the callback
2828 // will already have been removed internally.
2829 }
2830 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002831 }
2832
2833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002834 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2835 throws RemoteException {
2836 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2838 final long token = Binder.clearCallingIdentity();
2839 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002841 .addCapabilitiesCallbackForSubscription(c, subId);
2842 } finally {
2843 Binder.restoreCallingIdentity(token);
2844 }
2845 }
2846
2847 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002848 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2849 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002850
2851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2852 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2853 }
2854 Binder.withCleanCallingIdentity(() -> {
2855 try {
2856 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002857 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002858 .removeCapabilitiesCallbackForSubscription(c, subId);
2859 } catch (IllegalArgumentException e) {
2860 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2861 + "is inactive, ignoring unregister.");
2862 // If the subscription is no longer active, just return, since the callback
2863 // will already have been removed internally.
2864 }
2865 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002866 }
2867
2868 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002869 public boolean isCapable(int subId, int capability, int regTech) {
2870 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2872 final long token = Binder.clearCallingIdentity();
2873 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002874 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002875 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2876 } catch (ImsException e) {
2877 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2878 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002879 } catch (IllegalArgumentException e) {
2880 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2881 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002882 } finally {
2883 Binder.restoreCallingIdentity(token);
2884 }
2885 }
2886
2887 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002888 public boolean isAvailable(int subId, int capability, int regTech) {
2889 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002890 final long token = Binder.clearCallingIdentity();
2891 try {
2892 Phone phone = getPhone(subId);
2893 if (phone == null) return false;
2894 return phone.isImsCapabilityAvailable(capability, regTech);
2895 } finally {
2896 Binder.restoreCallingIdentity(token);
2897 }
2898 }
2899
2900 @Override
2901 public boolean isAdvancedCallingSettingEnabled(int subId) {
2902 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2904 final long token = Binder.clearCallingIdentity();
2905 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002906 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002907 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2908 } finally {
2909 Binder.restoreCallingIdentity(token);
2910 }
2911 }
2912
2913 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002914 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002916 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002920 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002921 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2922 } finally {
2923 Binder.restoreCallingIdentity(identity);
2924 }
2925 }
2926
2927 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002928 public boolean isVtSettingEnabled(int subId) {
2929 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002933 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 getSlotIndexOrException(subId)).isVtEnabledByUser();
2935 } finally {
2936 Binder.restoreCallingIdentity(identity);
2937 }
2938 }
2939
2940 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002941 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002942 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002943 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002947 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
2951 }
2952
2953 @Override
2954 public boolean isVoWiFiSettingEnabled(int subId) {
2955 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2956 final long identity = Binder.clearCallingIdentity();
2957 try {
2958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002959 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2961 } finally {
2962 Binder.restoreCallingIdentity(identity);
2963 }
2964 }
2965
2966 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002967 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002969 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002970 final long identity = Binder.clearCallingIdentity();
2971 try {
2972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002973 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002974 } finally {
2975 Binder.restoreCallingIdentity(identity);
2976 }
2977 }
2978
2979 @Override
2980 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2981 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
2984 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002985 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2987 } finally {
2988 Binder.restoreCallingIdentity(identity);
2989 }
2990 }
2991
2992 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002993 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002995 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002996 final long identity = Binder.clearCallingIdentity();
2997 try {
2998 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002999 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003000 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3001 } finally {
3002 Binder.restoreCallingIdentity(identity);
3003 }
3004 }
3005
3006 @Override
3007 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3009 "setVoWiFiNonPersistent");
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003013 boolean isRoaming = TelephonyManager.from(
3014 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003015 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003016 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003017 } finally {
3018 Binder.restoreCallingIdentity(identity);
3019 }
3020 }
3021
3022 @Override
3023 public int getVoWiFiModeSetting(int subId) {
3024 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3025 final long identity = Binder.clearCallingIdentity();
3026 try {
3027 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003028 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003029 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3030 } finally {
3031 Binder.restoreCallingIdentity(identity);
3032 }
3033 }
3034
3035 @Override
3036 public void setVoWiFiModeSetting(int subId, int mode) {
3037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3038 "setVoWiFiModeSetting");
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003042 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003043 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3044 } finally {
3045 Binder.restoreCallingIdentity(identity);
3046 }
3047 }
3048
3049 @Override
3050 public int getVoWiFiRoamingModeSetting(int subId) {
3051 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3052 final long identity = Binder.clearCallingIdentity();
3053 try {
3054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003055 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003056 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3057 } finally {
3058 Binder.restoreCallingIdentity(identity);
3059 }
3060 }
3061
3062 @Override
3063 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3064 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3065 "setVoWiFiRoamingModeSetting");
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003069 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003070 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
3074 }
3075
3076 @Override
3077 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3079 "setRttCapabilityEnabled");
3080 final long identity = Binder.clearCallingIdentity();
3081 try {
3082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003083 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003084 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3085 } finally {
3086 Binder.restoreCallingIdentity(identity);
3087 }
3088 }
3089
3090 @Override
3091 public boolean isTtyOverVolteEnabled(int subId) {
3092 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003096 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003097 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
3100 }
3101 }
3102
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003103 @Override
3104 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3105 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3106 final long identity = Binder.clearCallingIdentity();
3107 try {
3108 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003109 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003111 } finally {
3112 Binder.restoreCallingIdentity(identity);
3113 }
3114 }
3115
3116 @Override
3117 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3118 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3119 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003120 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3121 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3122 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003123 try {
3124 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003125 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003126 .removeProvisioningCallbackForSubscription(callback, subId);
3127 } catch (IllegalArgumentException e) {
3128 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3129 + "is inactive, ignoring unregister.");
3130 // If the subscription is no longer active, just return, since the callback will already
3131 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003138 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3139 boolean isProvisioned) {
3140 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3141 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3142 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3143 }
3144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3145 "setProvisioningStatusForCapability");
3146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3149 Phone phone = getPhone(subId);
3150 if (phone == null) {
3151 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3152 + subId);
3153 return;
3154 }
3155 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3156 return;
3157 }
3158
3159 // this capability requires provisioning, route to the correct API.
3160 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3161 switch (capability) {
3162 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3163 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3164 ims.setVolteProvisioned(isProvisioned);
3165 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3166 ims.setWfcProvisioned(isProvisioned);
3167 }
3168 break;
3169 }
3170 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3171 // There is currently no difference in VT provisioning type.
3172 ims.setVtProvisioned(isProvisioned);
3173 break;
3174 }
3175 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3176 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3177 // change the capability of the feature instead if needed.
3178 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3179 == isProvisioned) {
3180 // No change in provisioning.
3181 return;
3182 }
3183 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3184 try {
3185 ims.changeMmTelCapability(capability, tech, isProvisioned);
3186 } catch (ImsException e) {
3187 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3188 + ", Exception" + e.getMessage());
3189 }
3190 break;
3191 }
3192 default: {
3193 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3194 + capability + "', which does not require provisioning.");
3195 }
3196 }
3197
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
3201 }
3202
3203 @Override
3204 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3205 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3206 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3207 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3208 }
3209 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3213 Phone phone = getPhone(subId);
3214 if (phone == null) {
3215 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3216 + subId);
3217 // We will fail with "true" as the provisioning status because this is the default
3218 // if we do not require provisioning.
3219 return true;
3220 }
3221
3222 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3223 return true;
3224 }
3225
3226 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3227 switch (capability) {
3228 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3229 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3230 return ims.isVolteProvisionedOnDevice();
3231 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3232 return ims.isWfcProvisionedOnDevice();
3233 }
3234 // This should never happen, since we are checking tech above to make sure it
3235 // is either LTE or IWLAN.
3236 throw new IllegalArgumentException("Invalid radio technology for voice "
3237 + "capability.");
3238 }
3239 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3240 // There is currently no difference in VT provisioning type.
3241 return ims.isVtProvisionedOnDevice();
3242 }
3243 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3244 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3245 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3246 }
3247 default: {
3248 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3249 + capability + "', which does not require provisioning.");
3250 }
3251 }
3252
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 }
3257
3258 @Override
3259 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3260 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3261 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3262 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3263 }
3264 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3265 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3266 return (provisionedBits & capability) > 0;
3267 }
3268
3269 @Override
3270 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3271 boolean isProvisioned) {
3272 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3273 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3274 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3275 }
3276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3277 "setProvisioningStatusForCapability");
3278 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3279 // If the current provisioning status for capability already matches isProvisioned,
3280 // do nothing.
3281 if (((provisionedBits & capability) > 0) == isProvisioned) {
3282 return;
3283 }
3284 if (isProvisioned) {
3285 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3286 } else {
3287 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3288 }
3289 }
3290
3291 /**
3292 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3293 * technology. The bitfield should mirror the bitfield defined by
3294 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3295 */
3296 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3297 String key = getMmTelProvisioningKey(subId, tech);
3298 // Default is no capabilities are provisioned.
3299 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3300 }
3301
3302 /**
3303 * Sets the MmTel capability provisioning bitfield (defined by
3304 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3305 * technology specified.
3306 *
3307 * Note: This is a synchronous command and should not be called on UI thread.
3308 */
3309 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3310 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3311 String key = getMmTelProvisioningKey(subId, tech);
3312 editor.putInt(key, newField);
3313 editor.commit();
3314 }
3315
3316 private static String getMmTelProvisioningKey(int subId, int tech) {
3317 // resulting key is provision_ims_mmtel_{subId}_{tech}
3318 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3319 }
3320
3321 /**
3322 * Query CarrierConfig to see if the specified capability requires provisioning for the
3323 * carrier associated with the subscription id.
3324 */
3325 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3326 int capability) {
3327 CarrierConfigManager configManager = new CarrierConfigManager(context);
3328 PersistableBundle c = configManager.getConfigForSubId(subId);
3329 boolean requireUtProvisioning = c.getBoolean(
3330 // By default, this config is true (even if there is no SIM). We also check to make
3331 // sure the subscription needs provisioning here, so we do not need to check for
3332 // the no-SIM case, where we would normally shortcut this to false.
3333 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3334 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3335 false);
3336 boolean requireVoiceVtProvisioning = c.getBoolean(
3337 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3338
3339 // First check to make sure that the capability requires provisioning.
3340 switch (capability) {
3341 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3342 // intentional fallthrough
3343 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3344 if (requireVoiceVtProvisioning) {
3345 // Voice and Video requires provisioning
3346 return true;
3347 }
3348 break;
3349 }
3350 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3351 if (requireUtProvisioning) {
3352 // UT requires provisioning
3353 return true;
3354 }
3355 break;
3356 }
3357 }
3358 return false;
3359 }
3360
3361 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003362 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003363 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3364 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3365 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003366 enforceReadPrivilegedPermission("getImsProvisioningInt");
3367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003370 int slotId = getSlotIndex(subId);
3371 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3372 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3373 + subId + "' for key:" + key);
3374 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3375 }
3376 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003377 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003378 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3379 + subId + "' for key:" + key);
3380 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3389 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3390 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003391 enforceReadPrivilegedPermission("getImsProvisioningString");
3392 final long identity = Binder.clearCallingIdentity();
3393 try {
3394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003395 int slotId = getSlotIndex(subId);
3396 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3397 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3398 + subId + "' for key:" + key);
3399 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3400 }
3401 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003402 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3404 + subId + "' for key:" + key);
3405 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003406 } finally {
3407 Binder.restoreCallingIdentity(identity);
3408 }
3409 }
3410
3411 @Override
3412 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3414 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3415 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3417 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 int slotId = getSlotIndex(subId);
3422 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3423 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3424 + subId + "' for key:" + key);
3425 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3426 }
3427 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003428 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3430 + "' for key:" + key);
3431 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
3434 }
3435 }
3436
3437 @Override
3438 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3440 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3441 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3443 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 final long identity = Binder.clearCallingIdentity();
3445 try {
3446 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 int slotId = getSlotIndex(subId);
3448 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3449 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3450 + subId + "' for key:" + key);
3451 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3452 }
3453 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003455 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3456 + "' for key:" + key);
3457 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003458 } finally {
3459 Binder.restoreCallingIdentity(identity);
3460 }
3461 }
3462
Brad Ebinger4c460712018-10-01 10:40:55 -07003463 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3464 int slotId = SubscriptionManager.getSlotIndex(subId);
3465 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003466 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003467 }
3468 return slotId;
3469 }
3470
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003471 private int getSlotIndex(int subId) {
3472 int slotId = SubscriptionManager.getSlotIndex(subId);
3473 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3474 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3475 }
3476 return slotId;
3477 }
3478
Wink Saville36469e72014-06-11 15:17:00 -07003479 /**
3480 * Returns the network type for a subId
3481 */
3482 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003483 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003484 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003485 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003486 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3487 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003488
Malcolm Chend965c8b2018-02-28 15:00:40 -08003489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 final Phone phone = getPhone(subId);
3492 if (phone != null) {
3493 return phone.getServiceState().getDataNetworkType();
3494 } else {
3495 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3496 }
3497 } finally {
3498 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003500 }
3501
3502 /**
3503 * Returns the data network type
3504 */
3505 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003506 public int getDataNetworkType(String callingPackage) {
3507 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003508 }
3509
3510 /**
3511 * Returns the data network type for a subId
3512 */
3513 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003514 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003515 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003516 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003517 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3518 }
3519
Malcolm Chend965c8b2018-02-28 15:00:40 -08003520 final long identity = Binder.clearCallingIdentity();
3521 try {
3522 final Phone phone = getPhone(subId);
3523 if (phone != null) {
3524 return phone.getServiceState().getDataNetworkType();
3525 } else {
3526 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3527 }
3528 } finally {
3529 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003531 }
3532
3533 /**
Wink Saville36469e72014-06-11 15:17:00 -07003534 * Returns the Voice network type for a subId
3535 */
3536 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003537 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003538 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003539 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003540 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3541 }
3542
Malcolm Chend965c8b2018-02-28 15:00:40 -08003543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 final Phone phone = getPhone(subId);
3546 if (phone != null) {
3547 return phone.getServiceState().getVoiceNetworkType();
3548 } else {
3549 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3550 }
3551 } finally {
3552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003554 }
3555
3556 /**
3557 * @return true if a ICC card is present
3558 */
3559 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003560 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003561 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3562 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003563 }
3564
3565 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003566 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003567 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003568 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003569 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003570 final long identity = Binder.clearCallingIdentity();
3571 try {
3572 final Phone phone = PhoneFactory.getPhone(slotIndex);
3573 if (phone != null) {
3574 return phone.getIccCard().hasIccCard();
3575 } else {
3576 return false;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003580 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003581 }
3582
3583 /**
3584 * Return if the current radio is LTE on CDMA. This
3585 * is a tri-state return value as for a period of time
3586 * the mode may be unknown.
3587 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003588 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003589 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003590 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003591 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003592 @Override
3593 public int getLteOnCdmaMode(String callingPackage) {
3594 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003595 }
3596
Sanket Padawe356d7632015-06-22 14:03:32 -07003597 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003600 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003601 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3602 }
3603
Malcolm Chend965c8b2018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone == null) {
3608 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3609 } else {
3610 return phone.getLteOnCdmaMode();
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 }
Wink Saville36469e72014-06-11 15:17:00 -07003615 }
3616
Wink Saville36469e72014-06-11 15:17:00 -07003617 /**
3618 * {@hide}
3619 * Returns Default subId, 0 in the case of single standby.
3620 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003621 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003622 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003623 }
3624
Shishir Agrawala9f32182016-04-12 12:00:16 -07003625 private int getSlotForDefaultSubscription() {
3626 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3627 }
3628
Wink Savilleb564aae2014-10-23 10:18:09 -07003629 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003630 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003632
Pengquan Meng466e2482018-09-21 15:54:48 -07003633 private boolean isActiveSubscription(int subId) {
3634 return mSubscriptionController.isActiveSubId(subId);
3635 }
3636
Ihab Awadf2177b72013-11-25 13:33:23 -08003637 /**
3638 * @see android.telephony.TelephonyManager.WifiCallingChoices
3639 */
3640 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003641 final long identity = Binder.clearCallingIdentity();
3642 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003643 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003644 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3645 getWhenToMakeWifiCallsDefaultPreference());
3646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003649 }
3650
3651 /**
3652 * @see android.telephony.TelephonyManager.WifiCallingChoices
3653 */
3654 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003658 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003663 }
3664
Sailesh Nepald1e68152013-12-12 19:08:02 -08003665 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003666 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003667 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003668 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003669
Jordan Liu73b078d2019-02-28 12:03:40 -08003670 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3671 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3672 if (phoneId == -1) {
3673 throw new IllegalArgumentException("Given slot index: " + slotIndex
3674 + " does not correspond to an active phone");
3675 }
3676 return PhoneFactory.getPhone(phoneId);
3677 }
3678
Shishir Agrawal566b7612013-10-28 14:41:00 -07003679 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003680 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3681 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3683 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003684 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003685 if (DBG) {
3686 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3687 }
3688 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3689 p2);
3690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003691
Jordan Liu73b078d2019-02-28 12:03:40 -08003692
3693 @Override
3694 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3695 int slotIndex, String callingPackage, String aid, int p2) {
3696 enforceModifyPermission();
3697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3698 if (DBG) {
3699 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3700 }
3701 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3702 callingPackage, aid, p2);
3703 }
3704
3705 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3706 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003707 final long identity = Binder.clearCallingIdentity();
3708 try {
3709 if (TextUtils.equals(ISDR_AID, aid)) {
3710 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003711 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3712 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003713 if (bestComponent == null
3714 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3715 loge("The calling package is not allowed to access ISD-R.");
3716 throw new SecurityException(
3717 "The calling package is not allowed to access ISD-R.");
3718 }
Derek Tan740e1672017-06-27 14:56:27 -07003719 }
Derek Tan740e1672017-06-27 14:56:27 -07003720
Malcolm Chend965c8b2018-02-28 15:00:40 -08003721 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003722 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3723 null /* workSource */);
3724 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725 return response;
3726 } finally {
3727 Binder.restoreCallingIdentity(identity);
3728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003729 }
3730
3731 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003732 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003733 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3734 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003735 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3736 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3737 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003738
Jordan Liu73b078d2019-02-28 12:03:40 -08003739 @Override
3740 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3741 enforceModifyPermission();
3742 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3743 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3744 channel);
3745 }
3746
3747 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003748 final long identity = Binder.clearCallingIdentity();
3749 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003750 if (channel < 0) {
3751 return false;
3752 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003753 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3754 null /* workSource */);
3755 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003756 return success;
3757 } finally {
3758 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003759 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003760 }
3761
3762 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003763 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003764 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3766 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003767 if (DBG) {
3768 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3769 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3770 + p3 + " data=" + data);
3771 }
3772 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3773 command, p1, p2, p3, data);
3774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003775
Jordan Liu73b078d2019-02-28 12:03:40 -08003776 @Override
3777 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3778 int command, int p1, int p2, int p3, String data) {
3779 enforceModifyPermission();
3780 if (DBG) {
3781 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3782 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3783 + p3 + " data=" + data);
3784 }
3785 return iccTransmitApduLogicalChannelWithPermission(
3786 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3787 data);
3788 }
3789
3790 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3791 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003792 final long identity = Binder.clearCallingIdentity();
3793 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003794 if (channel < 0) {
3795 return "";
3796 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003797
Malcolm Chend965c8b2018-02-28 15:00:40 -08003798 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003799 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3800 null /* workSource */);
3801 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003802
Malcolm Chend965c8b2018-02-28 15:00:40 -08003803 // Append the returned status code to the end of the response payload.
3804 String s = Integer.toHexString(
3805 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3806 if (response.payload != null) {
3807 s = IccUtils.bytesToHexString(response.payload) + s;
3808 }
3809 return s;
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813 }
Jake Hambye994d462014-02-03 13:10:13 -08003814
Evan Charltonc66da362014-05-16 14:06:40 -07003815 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003816 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3817 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3819 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003820 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003821 if (DBG) {
3822 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3823 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3824 }
3825 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3826 cla, command, p1, p2, p3, data);
3827 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003828
Jordan Liu73b078d2019-02-28 12:03:40 -08003829 @Override
3830 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3831 int command, int p1, int p2, int p3, String data) {
3832 enforceModifyPermission();
3833 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3834 if (DBG) {
3835 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3836 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3837 + " data=" + data);
3838 }
3839
3840 return iccTransmitApduBasicChannelWithPermission(
3841 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3842 p2, p3, data);
3843 }
3844
3845 // open APDU basic channel assuming the caller has sufficient permissions
3846 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3847 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003848 final long identity = Binder.clearCallingIdentity();
3849 try {
3850 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3851 && TextUtils.equals(ISDR_AID, data)) {
3852 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003853 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3854 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003855 if (bestComponent == null
3856 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3857 loge("The calling package is not allowed to select ISD-R.");
3858 throw new SecurityException(
3859 "The calling package is not allowed to select ISD-R.");
3860 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003861 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003862
Malcolm Chend965c8b2018-02-28 15:00:40 -08003863 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003864 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3865 null /* workSource */);
3866 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003867
Malcolm Chend965c8b2018-02-28 15:00:40 -08003868 // Append the returned status code to the end of the response payload.
3869 String s = Integer.toHexString(
3870 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3871 if (response.payload != null) {
3872 s = IccUtils.bytesToHexString(response.payload) + s;
3873 }
3874 return s;
3875 } finally {
3876 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003877 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003878 }
3879
3880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003881 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003882 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3884 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003885
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886 final long identity = Binder.clearCallingIdentity();
3887 try {
3888 if (DBG) {
3889 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3890 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3891 }
3892
3893 IccIoResult response =
3894 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3895 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3896 subId);
3897
3898 if (DBG) {
3899 log("Exchange SIM_IO [R]" + response);
3900 }
3901
3902 byte[] result = null;
3903 int length = 2;
3904 if (response.payload != null) {
3905 length = 2 + response.payload.length;
3906 result = new byte[length];
3907 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3908 } else {
3909 result = new byte[length];
3910 }
3911
3912 result[length - 1] = (byte) response.sw2;
3913 result[length - 2] = (byte) response.sw1;
3914 return result;
3915 } finally {
3916 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003917 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003918 }
3919
Nathan Haroldb3014052017-01-25 15:57:32 -08003920 /**
3921 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3922 * on a particular subscription
3923 */
sqianb6e41952018-03-12 14:54:01 -07003924 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3925 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3926 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3927 return null;
3928 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003929
3930 final long identity = Binder.clearCallingIdentity();
3931 try {
3932 if (appType != TelephonyManager.APPTYPE_USIM
3933 && appType != TelephonyManager.APPTYPE_SIM) {
3934 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3935 return null;
3936 }
3937 Object response = sendRequest(
3938 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3939 if (response instanceof String[]) {
3940 return (String[]) response;
3941 }
3942 // Response is an Exception of some kind,
3943 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003944 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003947 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003948 }
3949
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003950 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003951 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3953 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003954
Malcolm Chend965c8b2018-02-28 15:00:40 -08003955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3958 if (response.payload == null) {
3959 return "";
3960 }
Evan Charltonc66da362014-05-16 14:06:40 -07003961
Malcolm Chend965c8b2018-02-28 15:00:40 -08003962 // Append the returned status code to the end of the response payload.
3963 String s = Integer.toHexString(
3964 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3965 s = IccUtils.bytesToHexString(response.payload) + s;
3966 return s;
3967 } finally {
3968 Binder.restoreCallingIdentity(identity);
3969 }
Evan Charltonc66da362014-05-16 14:06:40 -07003970 }
3971
Jake Hambye994d462014-02-03 13:10:13 -08003972 /**
3973 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3974 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3975 *
3976 * @param itemID the ID of the item to read
3977 * @return the NV item as a String, or null on error.
3978 */
3979 @Override
3980 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003982 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3983 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003984
3985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003988 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003989 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3990 return value;
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Jake Hambye994d462014-02-03 13:10:13 -08003994 }
3995
3996 /**
3997 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3998 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3999 *
4000 * @param itemID the ID of the item to read
4001 * @param itemValue the value to write, as a String
4002 * @return true on success; false on any failure
4003 */
4004 @Override
4005 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004006 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4008 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004009
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4013 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004014 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004015 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4016 return success;
4017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Jake Hambye994d462014-02-03 13:10:13 -08004020 }
4021
4022 /**
4023 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4024 * Used for device configuration by some CDMA operators.
4025 *
4026 * @param preferredRoamingList byte array containing the new PRL
4027 * @return true on success; false on any failure
4028 */
4029 @Override
4030 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4032 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033
4034 final long identity = Binder.clearCallingIdentity();
4035 try {
4036 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4037 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4038 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4039 return success;
4040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
Jake Hambye994d462014-02-03 13:10:13 -08004043 }
4044
4045 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004046 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004047 * Used for device configuration by some CDMA operators.
4048 *
chen xu1cc0abe2018-10-26 17:39:23 -07004049 * @param slotIndex - device slot.
4050 *
Jake Hambye994d462014-02-03 13:10:13 -08004051 * @return true on success; false on any failure
4052 */
4053 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004054 public boolean resetModemConfig(int slotIndex) {
4055 Phone phone = PhoneFactory.getPhone(slotIndex);
4056 if (phone != null) {
4057 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4058 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004059
chen xu1cc0abe2018-10-26 17:39:23 -07004060 final long identity = Binder.clearCallingIdentity();
4061 try {
4062 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4063 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4064 return success;
4065 } finally {
4066 Binder.restoreCallingIdentity(identity);
4067 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004068 }
chen xu1cc0abe2018-10-26 17:39:23 -07004069 return false;
4070 }
4071
4072 /**
4073 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4074 *
4075 * @param slotIndex - device slot.
4076 *
4077 * @return true on success; false on any failure
4078 */
4079 @Override
4080 public boolean rebootModem(int slotIndex) {
4081 Phone phone = PhoneFactory.getPhone(slotIndex);
4082 if (phone != null) {
4083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, phone.getSubId(), "rebootModem");
4085
4086 final long identity = Binder.clearCallingIdentity();
4087 try {
4088 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4089 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4090 return success;
4091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004096 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004097
Svet Ganovb320e182015-04-16 12:30:10 -07004098 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004099 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004101 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004102 return new String[0];
4103 }
4104
Malcolm Chend965c8b2018-02-28 15:00:40 -08004105 final long identity = Binder.clearCallingIdentity();
4106 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004107 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004108 } finally {
4109 Binder.restoreCallingIdentity(identity);
4110 }
Wink Saville36469e72014-06-11 15:17:00 -07004111 }
4112
Brad Ebinger51f743a2017-01-23 13:50:20 -08004113 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004114 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4115 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004116 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004117 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004118 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004119
4120 final long identity = Binder.clearCallingIdentity();
4121 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004122 ImsResolver resolver = PhoneFactory.getImsResolver();
4123 if (resolver == null) {
4124 // may happen if the device does not support IMS.
4125 return;
4126 }
4127 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004128 } finally {
4129 Binder.restoreCallingIdentity(identity);
4130 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004131 }
4132
4133 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004134 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4135 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004136 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004137 public void disableIms(int slotId) {
4138 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004139
4140 final long identity = Binder.clearCallingIdentity();
4141 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004142 ImsResolver resolver = PhoneFactory.getImsResolver();
4143 if (resolver == null) {
4144 // may happen if the device does not support IMS.
4145 return;
4146 }
4147 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004151 }
4152
4153 /**
4154 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4155 * feature or {@link null} if the service is not available. If the feature is available, the
4156 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4157 */
4158 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004159 IImsServiceFeatureCallback callback) {
4160 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004161
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004164 ImsResolver resolver = PhoneFactory.getImsResolver();
4165 if (resolver == null) {
4166 // may happen if the device does not support IMS.
4167 return null;
4168 }
4169 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004173 }
4174
4175 /**
4176 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4177 * feature during emergency calling or {@link null} if the service is not available. If the
4178 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4179 * listener for feature updates.
4180 */
4181 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4182 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004183
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004186 ImsResolver resolver = PhoneFactory.getImsResolver();
4187 if (resolver == null) {
4188 // may happen if the device does not support IMS.
4189 return null;
4190 }
4191 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004195 }
4196
Brad Ebinger5f64b052017-12-14 14:26:15 -08004197 /**
4198 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004199 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004200 */
4201 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4202 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004203
4204 final long identity = Binder.clearCallingIdentity();
4205 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004206 ImsResolver resolver = PhoneFactory.getImsResolver();
4207 if (resolver == null) {
4208 // may happen if the device does not support IMS.
4209 return null;
4210 }
4211 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004215 }
4216
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004217 /**
4218 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004219 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004220 */
4221 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4222 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004223
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004226 ImsResolver resolver = PhoneFactory.getImsResolver();
4227 if (resolver == null) {
4228 // may happen if the device does not support IMS.
4229 return null;
4230 }
4231 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004235 }
4236
Brad Ebinger884c07b2018-02-15 16:17:40 -08004237 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004238 * Sets the ImsService Package Name that Telephony will bind to.
4239 *
4240 * @param slotId the slot ID that the ImsService should bind for.
4241 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4242 * ImsService is the device default ImsService.
4243 * @param packageName The package name of the application that contains the ImsService to bind
4244 * to.
4245 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4246 * @hide
4247 */
4248 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004249 int[] subIds = SubscriptionManager.getSubId(slotId);
4250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4251 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4252 "setImsService");
4253
Malcolm Chend965c8b2018-02-28 15:00:40 -08004254 final long identity = Binder.clearCallingIdentity();
4255 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004256 ImsResolver resolver = PhoneFactory.getImsResolver();
4257 if (resolver == null) {
4258 // may happen if the device does not support IMS.
4259 return false;
4260 }
4261 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4262 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004263 } finally {
4264 Binder.restoreCallingIdentity(identity);
4265 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004266 }
4267
4268 /**
4269 * Return the ImsService configuration.
4270 *
4271 * @param slotId The slot that the ImsService is associated with.
4272 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4273 * the device default.
4274 * @return the package name of the ImsService configuration.
4275 */
4276 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004277 int[] subIds = SubscriptionManager.getSubId(slotId);
4278 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4279 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4280 "getImsService");
4281
Malcolm Chend965c8b2018-02-28 15:00:40 -08004282 final long identity = Binder.clearCallingIdentity();
4283 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004284 ImsResolver resolver = PhoneFactory.getImsResolver();
4285 if (resolver == null) {
4286 // may happen if the device does not support IMS.
4287 return "";
4288 }
4289 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004290 } finally {
4291 Binder.restoreCallingIdentity(identity);
4292 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004293 }
4294
Wink Saville36469e72014-06-11 15:17:00 -07004295 public void setImsRegistrationState(boolean registered) {
4296 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004297
4298 final long identity = Binder.clearCallingIdentity();
4299 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004300 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004301 } finally {
4302 Binder.restoreCallingIdentity(identity);
4303 }
Wink Saville36469e72014-06-11 15:17:00 -07004304 }
4305
4306 /**
Stuart Scott54788802015-03-30 13:18:01 -07004307 * Set the network selection mode to automatic.
4308 *
4309 */
4310 @Override
4311 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004312 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4313 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004314
Pengquan Meng466e2482018-09-21 15:54:48 -07004315 if (!isActiveSubscription(subId)) {
4316 return;
4317 }
4318
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319 final long identity = Binder.clearCallingIdentity();
4320 try {
4321 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4322 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Stuart Scott54788802015-03-30 13:18:01 -07004326 }
4327
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004328 /**
4329 * Ask the radio to connect to the input network and change selection mode to manual.
4330 *
4331 * @param subId the id of the subscription.
4332 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4333 * the operator to attach to.
4334 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4335 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4336 * normal network selection next time.
4337 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004338 */
4339 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004340 public boolean setNetworkSelectionModeManual(
4341 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004342 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4343 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004344
4345 if (!isActiveSubscription(subId)) {
4346 return false;
4347 }
4348
Malcolm Chend965c8b2018-02-28 15:00:40 -08004349 final long identity = Binder.clearCallingIdentity();
4350 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004351 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004352 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004353 if (DBG) {
4354 log("setNetworkSelectionModeManual: subId: " + subId
4355 + " operator: " + operatorInfo);
4356 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004357 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4358 } finally {
4359 Binder.restoreCallingIdentity(identity);
4360 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004361 }
4362
4363 /**
4364 * Scans for available networks.
4365 */
4366 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004367 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4369 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004370 LocationAccessPolicy.LocationPermissionResult locationResult =
4371 LocationAccessPolicy.checkLocationPermission(mApp,
4372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4373 .setCallingPackage(callingPackage)
4374 .setCallingPid(Binder.getCallingPid())
4375 .setCallingUid(Binder.getCallingUid())
4376 .setMethod("getCellNetworkScanResults")
4377 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4378 .build());
4379 switch (locationResult) {
4380 case DENIED_HARD:
4381 throw new SecurityException("Not allowed to access scan results -- location");
4382 case DENIED_SOFT:
4383 return null;
4384 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004385
Pengquan Meng0c05b502018-09-06 09:59:22 -07004386 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004387 try {
4388 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004389 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004390 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004391 } finally {
4392 Binder.restoreCallingIdentity(identity);
4393 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004394 }
4395
4396 /**
yinxub1bed742017-04-17 11:45:04 -07004397 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004398 *
yinxub1bed742017-04-17 11:45:04 -07004399 * @param subId id of the subscription
4400 * @param request contains the radio access networks with bands/channels to scan
4401 * @param messenger callback messenger for scan results or errors
4402 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004403 * @return the id of the requested scan which can be used to stop the scan.
4404 */
4405 @Override
4406 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004407 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004408 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4409 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004410
Hall Liuf19c44f2018-11-27 14:38:17 -08004411 LocationAccessPolicy.LocationPermissionResult locationResult =
4412 LocationAccessPolicy.checkLocationPermission(mApp,
4413 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4414 .setCallingPackage(callingPackage)
4415 .setCallingPid(Binder.getCallingPid())
4416 .setCallingUid(Binder.getCallingUid())
4417 .setMethod("requestNetworkScan")
4418 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4419 .build());
4420 switch (locationResult) {
4421 case DENIED_HARD:
4422 throw new SecurityException("Not allowed to request network scan -- location");
4423 case DENIED_SOFT:
4424 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004425 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004426
4427 return mNetworkScanRequestTracker.startNetworkScan(
4428 request, messenger, binder, getPhone(subId),
4429 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004430 }
4431
4432 /**
4433 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004434 *
4435 * @param subId id of the subscription
4436 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004437 */
4438 @Override
4439 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004440 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4441 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004442
4443 final long identity = Binder.clearCallingIdentity();
4444 try {
4445 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4446 } finally {
4447 Binder.restoreCallingIdentity(identity);
4448 }
yinxu504e1392017-04-12 16:03:22 -07004449 }
4450
4451 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004452 * Get the calculated preferred network type.
4453 * Used for debugging incorrect network type.
4454 *
4455 * @return the preferred network type, defined in RILConstants.java.
4456 */
4457 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004458 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004459 final Phone defaultPhone = getDefaultPhone();
4460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4461 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004462 return RILConstants.PREFERRED_NETWORK_MODE;
4463 }
4464
Malcolm Chend965c8b2018-02-28 15:00:40 -08004465 final long identity = Binder.clearCallingIdentity();
4466 try {
4467 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004468 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004469 } finally {
4470 Binder.restoreCallingIdentity(identity);
4471 }
Junda Liu84d15a22014-07-02 11:21:04 -07004472 }
4473
4474 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004475 * Get the preferred network type.
4476 * Used for device configuration by some CDMA operators.
4477 *
4478 * @return the preferred network type, defined in RILConstants.java.
4479 */
4480 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004481 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004482 TelephonyPermissions
4483 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4484 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004485
4486 final long identity = Binder.clearCallingIdentity();
4487 try {
4488 if (DBG) log("getPreferredNetworkType");
4489 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4490 int networkType = (result != null ? result[0] : -1);
4491 if (DBG) log("getPreferredNetworkType: " + networkType);
4492 return networkType;
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004496 }
4497
4498 /**
4499 * Set the preferred network type.
4500 * Used for device configuration by some CDMA operators.
4501 *
4502 * @param networkType the preferred network type, defined in RILConstants.java.
4503 * @return true on success; false on any failure.
4504 */
4505 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004506 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004507 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4508 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
4512 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4513 Boolean success = (Boolean) sendRequest(
4514 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4515 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4516 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004517 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004518 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4519 }
4520 return success;
4521 } finally {
4522 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004523 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004524 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004525
4526 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004527 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004528 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004529 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004530 * @hide
4531 */
4532 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004533 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004534 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004535 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004536 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004537 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004538 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004539 } finally {
4540 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004541 }
Junda Liu475951f2014-11-07 16:45:03 -08004542 }
4543
4544 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004545 * Set mobile data enabled
4546 * Used by the user through settings etc to turn on/off mobile data
4547 *
4548 * @param enable {@code true} turn turn data on, else {@code false}
4549 */
4550 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004551 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4553 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004554
4555 final long identity = Binder.clearCallingIdentity();
4556 try {
4557 int phoneId = mSubscriptionController.getPhoneId(subId);
4558 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4559 Phone phone = PhoneFactory.getPhone(phoneId);
4560 if (phone != null) {
4561 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004562 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004564 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004565 }
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004568 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004569 }
4570
4571 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004572 * Get the user enabled state of Mobile Data.
4573 *
4574 * TODO: remove and use isUserDataEnabled.
4575 * This can't be removed now because some vendor codes
4576 * calls through ITelephony directly while they should
4577 * use TelephonyManager.
4578 *
4579 * @return true on enabled
4580 */
4581 @Override
4582 public boolean getDataEnabled(int subId) {
4583 return isUserDataEnabled(subId);
4584 }
4585
4586 /**
4587 * Get whether mobile data is enabled per user setting.
4588 *
4589 * There are other factors deciding whether mobile data is actually enabled, but they are
4590 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004591 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004592 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004593 *
4594 * @return {@code true} if data is enabled else {@code false}
4595 */
4596 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004597 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004598 try {
4599 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4600 null);
4601 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4603 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004604 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 int phoneId = mSubscriptionController.getPhoneId(subId);
4609 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4610 Phone phone = PhoneFactory.getPhone(phoneId);
4611 if (phone != null) {
4612 boolean retVal = phone.isUserDataEnabled();
4613 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4614 return retVal;
4615 } else {
4616 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4617 return false;
4618 }
4619 } finally {
4620 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004621 }
4622 }
4623
4624 /**
4625 * Get whether mobile data is enabled.
4626 *
4627 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4628 * whether mobile data is actually enabled.
4629 *
4630 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4631 *
4632 * @return {@code true} if data is enabled else {@code false}
4633 */
4634 @Override
4635 public boolean isDataEnabled(int subId) {
4636 try {
4637 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4638 null);
4639 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004640 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4641 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004642 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004643
4644 final long identity = Binder.clearCallingIdentity();
4645 try {
4646 int phoneId = mSubscriptionController.getPhoneId(subId);
4647 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4648 Phone phone = PhoneFactory.getPhone(phoneId);
4649 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004650 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004651 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4652 return retVal;
4653 } else {
4654 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4655 return false;
4656 }
4657 } finally {
4658 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004659 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004660 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004661
4662 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004663 public int getCarrierPrivilegeStatus(int subId) {
4664 final Phone phone = getPhone(subId);
4665 if (phone == null) {
4666 loge("getCarrierPrivilegeStatus: Invalid subId");
4667 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4668 }
4669 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004670 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004671 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004672 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4673 }
4674 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004675 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004676 }
Junda Liu29340342014-07-10 15:23:27 -07004677
4678 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004679 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4680 final Phone phone = getPhone(subId);
4681 if (phone == null) {
4682 loge("getCarrierPrivilegeStatus: Invalid subId");
4683 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4684 }
4685 UiccProfile profile =
4686 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4687 if (profile == null) {
4688 loge("getCarrierPrivilegeStatus: No UICC");
4689 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4690 }
4691 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4692 }
4693
4694 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004695 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004696 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004697 if (TextUtils.isEmpty(pkgName))
4698 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004699 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004700 if (card == null) {
4701 loge("checkCarrierPrivilegesForPackage: No UICC");
4702 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4703 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004704 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4705 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004706 }
4707
4708 @Override
4709 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004710 if (TextUtils.isEmpty(pkgName))
4711 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004712 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4713 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4714 UiccCard card = UiccController.getInstance().getUiccCard(i);
4715 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004716 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004717 continue;
4718 }
4719
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004720 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004721 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4722 break;
4723 }
4724 }
4725
4726 return result;
Junda Liu29340342014-07-10 15:23:27 -07004727 }
Derek Tan89e89d42014-07-08 17:00:10 -07004728
4729 @Override
Junda Liue64de782015-04-16 17:19:16 -07004730 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4731 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4732 loge("phoneId " + phoneId + " is not valid.");
4733 return null;
4734 }
4735 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004736 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004737 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004738 return null ;
4739 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004740 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004741 }
4742
Amith Yamasani6e118872016-02-19 12:53:51 -08004743 @Override
4744 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004745 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004746 List<String> privilegedPackages = new ArrayList<>();
4747 List<PackageInfo> packages = null;
4748 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4749 UiccCard card = UiccController.getInstance().getUiccCard(i);
4750 if (card == null) {
4751 // No UICC in that slot.
4752 continue;
4753 }
4754 if (card.hasCarrierPrivilegeRules()) {
4755 if (packages == null) {
4756 // Only check packages in user 0 for now
4757 packages = pm.getInstalledPackagesAsUser(
4758 PackageManager.MATCH_DISABLED_COMPONENTS
4759 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4760 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4761 }
4762 for (int p = packages.size() - 1; p >= 0; p--) {
4763 PackageInfo pkgInfo = packages.get(p);
4764 if (pkgInfo != null && pkgInfo.packageName != null
4765 && card.getCarrierPrivilegeStatus(pkgInfo)
4766 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4767 privilegedPackages.add(pkgInfo.packageName);
4768 }
4769 }
4770 }
4771 }
4772 return privilegedPackages;
4773 }
4774
Wink Savilleb564aae2014-10-23 10:18:09 -07004775 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004776 final Phone phone = getPhone(subId);
4777 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004778 if (card == null) {
4779 loge("getIccId: No UICC");
4780 return null;
4781 }
4782 String iccId = card.getIccId();
4783 if (TextUtils.isEmpty(iccId)) {
4784 loge("getIccId: ICC ID is null or empty.");
4785 return null;
4786 }
4787 return iccId;
4788 }
4789
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004790 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004791 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4792 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004793 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4794 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004795
Malcolm Chend965c8b2018-02-28 15:00:40 -08004796 final long identity = Binder.clearCallingIdentity();
4797 try {
4798 final String iccId = getIccId(subId);
4799 final Phone phone = getPhone(subId);
4800 if (phone == null) {
4801 return false;
4802 }
4803 final String subscriberId = phone.getSubscriberId();
4804
4805 if (DBG_MERGE) {
4806 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4807 + subscriberId + " to " + number);
4808 }
4809
4810 if (TextUtils.isEmpty(iccId)) {
4811 return false;
4812 }
4813
4814 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4815
4816 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4817 if (alphaTag == null) {
4818 editor.remove(alphaTagPrefKey);
4819 } else {
4820 editor.putString(alphaTagPrefKey, alphaTag);
4821 }
4822
4823 // Record both the line number and IMSI for this ICCID, since we need to
4824 // track all merged IMSIs based on line number
4825 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4826 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4827 if (number == null) {
4828 editor.remove(numberPrefKey);
4829 editor.remove(subscriberPrefKey);
4830 } else {
4831 editor.putString(numberPrefKey, number);
4832 editor.putString(subscriberPrefKey, subscriberId);
4833 }
4834
4835 editor.commit();
4836 return true;
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004839 }
Derek Tan7226c842014-07-02 17:42:23 -07004840 }
4841
4842 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004843 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004844 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004845 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004846 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004847 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004848 return null;
4849 }
Derek Tan97ebb422014-09-05 16:55:38 -07004850
Malcolm Chend965c8b2018-02-28 15:00:40 -08004851 final long identity = Binder.clearCallingIdentity();
4852 try {
4853 String iccId = getIccId(subId);
4854 if (iccId != null) {
4855 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4856 if (DBG_MERGE) {
4857 log("getLine1NumberForDisplay returning "
4858 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4859 }
4860 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004861 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004862 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4863 return null;
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004866 }
Derek Tan7226c842014-07-02 17:42:23 -07004867 }
4868
4869 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004870 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004871 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004872 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004873 return null;
4874 }
Derek Tan97ebb422014-09-05 16:55:38 -07004875
Malcolm Chend965c8b2018-02-28 15:00:40 -08004876 final long identity = Binder.clearCallingIdentity();
4877 try {
4878 String iccId = getIccId(subId);
4879 if (iccId != null) {
4880 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4881 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4882 }
4883 return null;
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004886 }
Derek Tan7226c842014-07-02 17:42:23 -07004887 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004888
4889 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004890 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004891 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4892 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004893 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004894 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4895 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004896 return null;
4897 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004898
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004899 final long identity = Binder.clearCallingIdentity();
4900 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004901 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004902 final TelephonyManager tele = TelephonyManager.from(context);
4903 final SubscriptionManager sub = SubscriptionManager.from(context);
4904
4905 // Figure out what subscribers are currently active
4906 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4907 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4908 // the process, where TelephonyManager was instantiated.
4909 // Otherwise AppOps check will fail.
4910
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004911 final int[] subIds = sub.getActiveSubscriptionIdList();
4912 for (int subId : subIds) {
4913 activeSubscriberIds.add(tele.getSubscriberId(subId));
4914 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004915
4916 // First pass, find a number override for an active subscriber
4917 String mergeNumber = null;
4918 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4919 for (String key : prefs.keySet()) {
4920 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4921 final String subscriberId = (String) prefs.get(key);
4922 if (activeSubscriberIds.contains(subscriberId)) {
4923 final String iccId = key.substring(
4924 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4925 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4926 mergeNumber = (String) prefs.get(numberKey);
4927 if (DBG_MERGE) {
4928 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4929 + " for active subscriber " + subscriberId);
4930 }
4931 if (!TextUtils.isEmpty(mergeNumber)) {
4932 break;
4933 }
4934 }
4935 }
4936 }
4937
4938 // Shortcut when no active merged subscribers
4939 if (TextUtils.isEmpty(mergeNumber)) {
4940 return null;
4941 }
4942
4943 // Second pass, find all subscribers under that line override
4944 final ArraySet<String> result = new ArraySet<>();
4945 for (String key : prefs.keySet()) {
4946 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4947 final String number = (String) prefs.get(key);
4948 if (mergeNumber.equals(number)) {
4949 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4950 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4951 final String subscriberId = (String) prefs.get(subscriberKey);
4952 if (!TextUtils.isEmpty(subscriberId)) {
4953 result.add(subscriberId);
4954 }
4955 }
4956 }
4957 }
4958
4959 final String[] resultArray = result.toArray(new String[result.size()]);
4960 Arrays.sort(resultArray);
4961 if (DBG_MERGE) {
4962 Slog.d(LOG_TAG,
4963 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4964 }
4965 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004966 } finally {
4967 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004968 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004969 }
4970
4971 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004972 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004973 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4974 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
4978 final Phone phone = getPhone(subId);
4979 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4980 } finally {
4981 Binder.restoreCallingIdentity(identity);
4982 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004983 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004984
4985 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004986 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004987 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4988 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004990
4991 final long identity = Binder.clearCallingIdentity();
4992 try {
4993 final Phone phone = getPhone(subId);
4994 if (phone == null) {
4995 return false;
4996 }
4997 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4998 cdmaNonRoamingList);
4999 } finally {
5000 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005001 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005002 }
5003
5004 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005005 @Deprecated
5006 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5007 enforceModifyPermission();
5008
5009 int returnValue = 0;
5010 try {
vagdevie435a3e2018-08-15 16:01:53 -07005011 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005012 if(result.exception == null) {
5013 if (result.result != null) {
5014 byte[] responseData = (byte[])(result.result);
5015 if(responseData.length > oemResp.length) {
5016 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5017 responseData.length + "bytes. Buffer Size is " +
5018 oemResp.length + "bytes.");
5019 }
5020 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5021 returnValue = responseData.length;
5022 }
5023 } else {
5024 CommandException ex = (CommandException) result.exception;
5025 returnValue = ex.getCommandError().ordinal();
5026 if(returnValue > 0) returnValue *= -1;
5027 }
5028 } catch (RuntimeException e) {
5029 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5030 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5031 if(returnValue > 0) returnValue *= -1;
5032 }
5033
5034 return returnValue;
5035 }
5036
5037 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005038 public void setRadioCapability(RadioAccessFamily[] rafs) {
5039 try {
5040 ProxyController.getInstance().setRadioCapability(rafs);
5041 } catch (RuntimeException e) {
5042 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5043 }
5044 }
5045
5046 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005047 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005048 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005049 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005050 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005051 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005052 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005053 final long identity = Binder.clearCallingIdentity();
5054 try {
chen xufeeed752018-10-26 14:17:57 -07005055 TelephonyPermissions
5056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5057 mApp, phone.getSubId(), "getRadioAccessFamily");
5058 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
chen xufeeed752018-10-26 14:17:57 -07005062 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005063 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005064
5065 @Override
5066 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005067 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005068 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005072 ImsManager.getInstance(defaultPhone.getContext(),
5073 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005077 }
5078
5079 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005080 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005081 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005083 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005084 return false;
5085 }
Svet Ganovb320e182015-04-16 12:30:10 -07005086
Malcolm Chend965c8b2018-02-28 15:00:40 -08005087 final long identity = Binder.clearCallingIdentity();
5088 try {
5089 // Check the user preference and the system-level IMS setting. Even if the user has
5090 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5091 // In the long run, we may instead need to check if there exists a connection service
5092 // which can support video calling.
5093 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005094 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005095 return imsManager.isVtEnabledByPlatform()
5096 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5097 && imsManager.isVtEnabledByUser();
5098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005101 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005102
Andrew Leea1239f22015-03-02 17:44:07 -08005103 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005104 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5106 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5107 return false;
5108 }
5109
5110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 CarrierConfigManager configManager =
5113 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005114 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005115 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Andrew Leea1239f22015-03-02 17:44:07 -08005119 }
5120
5121 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005122 public boolean isWorldPhone(int subId, String callingPackage) {
5123 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5124 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5125 return false;
5126 }
5127
5128 final long identity = Binder.clearCallingIdentity();
5129 try {
5130 CarrierConfigManager configManager =
5131 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005132 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005133 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
5136 }
Andrew Leea1239f22015-03-02 17:44:07 -08005137 }
5138
Andrew Lee9431b832015-03-09 18:46:45 -07005139 @Override
5140 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005141 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005142 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005143 }
5144
5145 @Override
5146 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005149 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Andrew Lee9431b832015-03-09 18:46:45 -07005153 }
5154
Hall Liuf6668912018-10-31 17:05:23 -07005155 /**
5156 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5157 * support for the feature and device firmware support.
5158 *
5159 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5160 */
5161 @Override
5162 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005164 final Phone phone = getPhone(subscriptionId);
5165 if (phone == null) {
5166 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5167 return false;
5168 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005169 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005170 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005171 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5172 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005173 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 return isCarrierSupported && isDeviceSupported;
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Hall Liu98187582018-01-22 19:15:32 -08005178 }
5179
Hall Liuf6668912018-10-31 17:05:23 -07005180 /**
5181 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5182 * both also support RTT.
5183 */
5184 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005185 final long identity = Binder.clearCallingIdentity();
5186 try {
Hall Liuf6668912018-10-31 17:05:23 -07005187 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005188 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005192 }
5193
Sanket Padawe7310cc72015-01-14 09:53:20 -08005194 /**
5195 * Returns the unique device ID of phone, for example, the IMEI for
5196 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5197 *
5198 * <p>Requires Permission:
5199 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5200 */
5201 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005202 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005203 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005204 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005205 return null;
5206 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005207 int subId = phone.getSubId();
5208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5209 mApp, subId, callingPackage, "getDeviceId")) {
5210 return null;
5211 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005212
5213 final long identity = Binder.clearCallingIdentity();
5214 try {
5215 return phone.getDeviceId();
5216 } finally {
5217 Binder.restoreCallingIdentity(identity);
5218 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005219 }
5220
Ping Sunc67b7c22016-03-02 19:16:45 +08005221 /**
5222 * {@hide}
5223 * Returns the IMS Registration Status on a particular subid
5224 *
5225 * @param subId
5226 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005227 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005228 Phone phone = getPhone(subId);
5229 if (phone != null) {
5230 return phone.isImsRegistered();
5231 } else {
5232 return false;
5233 }
5234 }
5235
Santos Cordon7a1885b2015-02-03 11:15:19 -08005236 @Override
5237 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
5240 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5241 } finally {
5242 Binder.restoreCallingIdentity(identity);
5243 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005244 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005245
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005246 /**
5247 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005248 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005249 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005250 final long identity = Binder.clearCallingIdentity();
5251 try {
5252 Phone phone = getPhone(subId);
5253 if (phone != null) {
5254 return phone.isWifiCallingEnabled();
5255 } else {
5256 return false;
5257 }
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005260 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005261 }
5262
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005263 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005264 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005265 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005266 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005267 final long identity = Binder.clearCallingIdentity();
5268 try {
5269 Phone phone = getPhone(subId);
5270 if (phone != null) {
5271 return phone.isVideoEnabled();
5272 } else {
5273 return false;
5274 }
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005277 }
5278 }
5279
5280 /**
5281 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5282 * defined in {@link ImsRegistrationImplBase}.
5283 */
5284 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 Phone phone = getPhone(subId);
5288 if (phone != null) {
5289 return phone.getImsRegistrationTech();
5290 } else {
5291 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5292 }
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005295 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005296 }
5297
Stuart Scott8eef64f2015-04-08 15:13:54 -07005298 @Override
5299 public void factoryReset(int subId) {
5300 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005301 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5302 return;
5303 }
5304
Svet Ganovcc087f82015-05-12 20:35:54 -07005305 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005306
Svet Ganovcc087f82015-05-12 20:35:54 -07005307 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005308 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5309 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005310 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005311 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005312 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005313 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5314 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005315 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005316 // There has been issues when Sms raw table somehow stores orphan
5317 // fragments. They lead to garbled message when new fragments come
5318 // in and combined with those stale ones. In case this happens again,
5319 // user can reset all network settings which will clean up this table.
5320 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005321 } finally {
5322 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005323 }
5324 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005325
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005326 private void cleanUpSmsRawTable(Context context) {
5327 ContentResolver resolver = context.getContentResolver();
5328 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5329 resolver.delete(uri, null, null);
5330 }
5331
Narayan Kamath1c496c22015-04-16 14:40:19 +01005332 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005333 public String getSimLocaleForSubscriber(int subId) {
5334 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5335 final Phone phone = getPhone(subId);
5336 if (phone == null) {
5337 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005338 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005339 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
5341 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005342 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5343 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005344 // Try and fetch the locale from the carrier properties or from the SIM language
5345 // preferences (EF-PL and EF-LI)...
5346 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005347 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005348 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5349 if (localeFromDefaultSim != null) {
5350 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5351 if (DBG) log("Using locale from subId: " + subId + " locale: "
5352 + localeFromDefaultSim);
5353 return localeFromDefaultSim.toLanguageTag();
5354 } else {
5355 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005356 }
5357 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005358
Malcolm Chend965c8b2018-02-28 15:00:40 -08005359 // The SIM language preferences only store a language (e.g. fr = French), not an
5360 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5361 // the SIM and carrier preferences does not include a country we add the country
5362 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005363 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005364 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005365 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005366 return mccLocale.toLanguageTag();
5367 }
5368
5369 if (DBG) log("No locale found - returning null");
5370 return null;
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005374 }
5375
5376 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005377 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005378 }
5379
Malcolm Chend965c8b2018-02-28 15:00:40 -08005380 /**
5381 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5382 */
5383 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005384 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005385 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005386
Chenjie Yu1ba97252018-01-11 18:16:20 -08005387 private final ModemActivityInfo mLastModemActivityInfo =
5388 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5389
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005390 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005391 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5392 * representing the state of the modem.
5393 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005394 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5395 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005396 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005397 */
5398 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005399 public void requestModemActivityInfo(ResultReceiver result) {
5400 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005401 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005402
5403 final long identity = Binder.clearCallingIdentity();
5404 try {
5405 ModemActivityInfo ret = null;
5406 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005407 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5408 CMD_GET_MODEM_ACTIVITY_INFO,
5409 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005410 if (isModemActivityInfoValid(info)) {
5411 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5412 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5413 mergedTxTimeMs[i] =
5414 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5415 }
5416 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5417 mLastModemActivityInfo.setSleepTimeMillis(
5418 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5419 mLastModemActivityInfo.setIdleTimeMillis(
5420 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5421 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5422 mLastModemActivityInfo.setRxTimeMillis(
5423 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5424 mLastModemActivityInfo.setEnergyUsed(
5425 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005426 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005427 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5428 mLastModemActivityInfo.getSleepTimeMillis(),
5429 mLastModemActivityInfo.getIdleTimeMillis(),
5430 mLastModemActivityInfo.getTxTimeMillis(),
5431 mLastModemActivityInfo.getRxTimeMillis(),
5432 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005433 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005434 Bundle bundle = new Bundle();
5435 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5436 result.send(0, bundle);
5437 } finally {
5438 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005439 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005440 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005441
Siddharth Rayf5d29552018-06-17 15:02:38 -07005442 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5443 // less than total activity duration.
5444 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5445 if (info == null) {
5446 return false;
5447 }
5448 int activityDurationMs =
5449 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5450 int totalTxTimeMs = 0;
5451 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5452 totalTxTimeMs += info.getTxTimeMillis()[i];
5453 }
5454 return (info.isValid()
5455 && (info.getSleepTimeMillis() <= activityDurationMs)
5456 && (info.getIdleTimeMillis() <= activityDurationMs)
5457 && (info.getRxTimeMillis() <= activityDurationMs)
5458 && (totalTxTimeMs <= activityDurationMs));
5459 }
5460
Jack Yu85bd38a2015-11-09 11:34:32 -08005461 /**
5462 * {@hide}
5463 * Returns the service state information on specified subscription.
5464 */
5465 @Override
5466 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005468 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005469 return null;
5470 }
5471
Hall Liuf19c44f2018-11-27 14:38:17 -08005472 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5473 LocationAccessPolicy.checkLocationPermission(mApp,
5474 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5475 .setCallingPackage(callingPackage)
5476 .setCallingPid(Binder.getCallingPid())
5477 .setCallingUid(Binder.getCallingUid())
5478 .setMethod("getServiceStateForSubscriber")
5479 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5480 .build());
5481
5482 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5483 LocationAccessPolicy.checkLocationPermission(mApp,
5484 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5485 .setCallingPackage(callingPackage)
5486 .setCallingPid(Binder.getCallingPid())
5487 .setCallingUid(Binder.getCallingUid())
5488 .setMethod("getServiceStateForSubscriber")
5489 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5490 .build());
5491 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5492 boolean hasFinePermission =
5493 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5494 boolean hasCoarsePermission =
5495 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5496
Malcolm Chend965c8b2018-02-28 15:00:40 -08005497 final long identity = Binder.clearCallingIdentity();
5498 try {
5499 final Phone phone = getPhone(subId);
5500 if (phone == null) {
5501 return null;
5502 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005503
Hall Liuf19c44f2018-11-27 14:38:17 -08005504 ServiceState ss = phone.getServiceState();
5505
5506 // Scrub out the location info in ServiceState depending on what level of access
5507 // the caller has.
5508 if (hasFinePermission) return ss;
5509 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5510 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005511 } finally {
5512 Binder.restoreCallingIdentity(identity);
5513 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005514 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005515
5516 /**
5517 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5518 *
5519 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5520 * voicemail ringtone.
5521 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5522 * PhoneAccount.
5523 */
5524 @Override
5525 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
5528 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5529 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005530 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005532
Malcolm Chend965c8b2018-02-28 15:00:40 -08005533 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5534 } finally {
5535 Binder.restoreCallingIdentity(identity);
5536 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005537 }
5538
5539 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005540 * Sets the per-account voicemail ringtone.
5541 *
5542 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5543 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5544 *
5545 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5546 * voicemail ringtone.
5547 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5548 * PhoneAccount.
5549 */
5550 @Override
5551 public void setVoicemailRingtoneUri(String callingPackage,
5552 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005553 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005554 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5555 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005556 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5558 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5559 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005560 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5565 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005566 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005567 }
5568 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005571 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005572 }
5573
5574 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005575 * Returns whether vibration is set for voicemail notification in Phone settings.
5576 *
5577 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5578 * voicemail vibration setting.
5579 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5580 */
5581 @Override
5582 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5586 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005587 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005588 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005589
Malcolm Chend965c8b2018-02-28 15:00:40 -08005590 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5591 } finally {
5592 Binder.restoreCallingIdentity(identity);
5593 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005594 }
5595
Youhan Wange64578a2016-05-02 15:32:42 -07005596 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005597 * Sets the per-account voicemail vibration.
5598 *
5599 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5600 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5601 *
5602 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5603 * voicemail vibration setting.
5604 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5605 * specific PhoneAccount.
5606 */
5607 @Override
5608 public void setVoicemailVibrationEnabled(String callingPackage,
5609 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005610 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005611 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5612 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005613 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5615 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5616 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005617 }
5618
Malcolm Chend965c8b2018-02-28 15:00:40 -08005619 final long identity = Binder.clearCallingIdentity();
5620 try {
5621 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5622 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005623 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005624 }
5625 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005628 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005629 }
5630
5631 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005632 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5633 *
5634 * @throws SecurityException if the caller does not have the required permission
5635 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005636 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005637 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005638 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005639 }
5640
5641 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005642 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5643 * permission.
5644 *
5645 * @throws SecurityException if the caller does not have the required permission
5646 */
5647 private void enforceSendSmsPermission() {
5648 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5649 }
5650
5651 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005652 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005653 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005654 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005655 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005656 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005660 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005661 if (componentName == null) {
5662 throw new SecurityException(
5663 "Caller not current active visual voicemail package[null]");
5664 }
5665 String vvmPackage = componentName.getPackageName();
5666 if (!callingPackage.equals(vvmPackage)) {
5667 throw new SecurityException("Caller not current active visual voicemail package["
5668 + vvmPackage + "]");
5669 }
5670 } finally {
5671 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005672 }
5673 }
5674
5675 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005676 * Return the application ID for the app type.
5677 *
5678 * @param subId the subscription ID that this request applies to.
5679 * @param appType the uicc app type.
5680 * @return Application ID for specificied app type, or null if no uicc.
5681 */
5682 @Override
5683 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005684 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005685 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005688 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005689 if (phone == null) {
5690 return null;
5691 }
5692 String aid = null;
5693 try {
5694 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5695 .getApplicationByType(appType).getAid();
5696 } catch (Exception e) {
5697 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5698 }
5699 return aid;
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005702 }
Youhan Wange64578a2016-05-02 15:32:42 -07005703 }
5704
Youhan Wang4001d252016-05-11 10:29:41 -07005705 /**
5706 * Return the Electronic Serial Number.
5707 *
5708 * @param subId the subscription ID that this request applies to.
5709 * @return ESN or null if error.
5710 */
5711 @Override
5712 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005713 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005714 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005717 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005718 if (phone == null) {
5719 return null;
5720 }
5721 String esn = null;
5722 try {
5723 esn = phone.getEsn();
5724 } catch (Exception e) {
5725 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5726 }
5727 return esn;
5728 } finally {
5729 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005730 }
Youhan Wang4001d252016-05-11 10:29:41 -07005731 }
5732
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005733 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005734 * Return the Preferred Roaming List Version.
5735 *
5736 * @param subId the subscription ID that this request applies to.
5737 * @return PRLVersion or null if error.
5738 */
5739 @Override
5740 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005741 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005742 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005743
5744 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005745 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005746 if (phone == null) {
5747 return null;
5748 }
5749 String cdmaPrlVersion = null;
5750 try {
5751 cdmaPrlVersion = phone.getCdmaPrlVersion();
5752 } catch (Exception e) {
5753 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5754 }
5755 return cdmaPrlVersion;
5756 } finally {
5757 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005758 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005759 }
5760
5761 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005762 * Get snapshot of Telephony histograms
5763 * @return List of Telephony histograms
5764 * @hide
5765 */
5766 @Override
5767 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5769 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005770
5771 final long identity = Binder.clearCallingIdentity();
5772 try {
5773 return RIL.getTelephonyRILTimingHistograms();
5774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005777 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005778
5779 /**
5780 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005781 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5782 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005783 * Require system privileges. In the future we may add this to carrier APIs.
5784 *
Michele Berionne0963c862018-11-27 18:57:59 -08005785 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005786 */
5787 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005788 @TelephonyManager.SetCarrierRestrictionResult
5789 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005790 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005792
Michele Berionne0963c862018-11-27 18:57:59 -08005793 if (carrierRestrictionRules == null) {
5794 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005795 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005796
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797 final long identity = Binder.clearCallingIdentity();
5798 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005799 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005800 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005801 } finally {
5802 Binder.restoreCallingIdentity(identity);
5803 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005804 }
5805
5806 /**
5807 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005808 * Get the allowed carrier list and the excluded carrier list, including the priority between
5809 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005810 * Require system privileges. In the future we may add this to carrier APIs.
5811 *
Michele Berionne0963c862018-11-27 18:57:59 -08005812 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005813 */
5814 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005815 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005816 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005817 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005818
5819 final long identity = Binder.clearCallingIdentity();
5820 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005821 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5822 if (response instanceof CarrierRestrictionRules) {
5823 return (CarrierRestrictionRules) response;
5824 }
5825 // Response is an Exception of some kind,
5826 // which is signalled to the user as a NULL retval
5827 return null;
5828 } catch (Exception e) {
5829 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5830 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005834 }
5835
fionaxu59545b42016-05-25 15:53:37 -07005836 /**
5837 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5838 * @param subId the subscription ID that this action applies to.
5839 * @param enabled control enable or disable metered apns.
5840 * {@hide}
5841 */
5842 @Override
5843 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5844 enforceModifyPermission();
5845 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005846
5847 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005848 if (phone == null) {
5849 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5850 return;
5851 }
5852 try {
5853 phone.carrierActionSetMeteredApnsEnabled(enabled);
5854 } catch (Exception e) {
5855 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005856 } finally {
5857 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005858 }
5859 }
5860
5861 /**
5862 * Action set from carrier signalling broadcast receivers to enable/disable radio
5863 * @param subId the subscription ID that this action applies to.
5864 * @param enabled control enable or disable radio.
5865 * {@hide}
5866 */
5867 @Override
5868 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5869 enforceModifyPermission();
5870 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005871
5872 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005873 if (phone == null) {
5874 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5875 return;
5876 }
5877 try {
5878 phone.carrierActionSetRadioEnabled(enabled);
5879 } catch (Exception e) {
5880 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005881 } finally {
5882 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005883 }
5884 }
5885
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005886 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005887 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5888 * network status based on which carrier apps could apply actions accordingly,
5889 * enable/disable default url handler for example.
5890 *
5891 * @param subId the subscription ID that this action applies to.
5892 * @param report control start/stop reporting the default network status.
5893 * {@hide}
5894 */
5895 @Override
5896 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5897 enforceModifyPermission();
5898 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005899
5900 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005901 if (phone == null) {
5902 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5903 return;
5904 }
5905 try {
5906 phone.carrierActionReportDefaultNetworkStatus(report);
5907 } catch (Exception e) {
5908 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005909 } finally {
5910 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005911 }
5912 }
5913
5914 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005915 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5916 * bug report is being generated.
5917 */
5918 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005919 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005920 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5921 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005922 writer.println("Permission Denial: can't dump Phone from pid="
5923 + Binder.getCallingPid()
5924 + ", uid=" + Binder.getCallingUid()
5925 + "without permission "
5926 + android.Manifest.permission.DUMP);
5927 return;
5928 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005929 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005930 }
Jack Yueb89b242016-06-22 13:27:47 -07005931
Brad Ebingerdac2f002018-04-03 15:17:52 -07005932 @Override
5933 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5934 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5935 throws RemoteException {
5936 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5937 }
5938
Jack Yueb89b242016-06-22 13:27:47 -07005939 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005940 * Get aggregated video call data usage since boot.
5941 *
5942 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5943 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005944 * {@hide}
5945 */
5946 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005947 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005948 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5949 null);
5950
Malcolm Chend965c8b2018-02-28 15:00:40 -08005951 final long identity = Binder.clearCallingIdentity();
5952 try {
5953 // NetworkStatsService keeps tracking the active network interface and identity. It
5954 // records the delta with the corresponding network identity.
5955 // We just return the total video call data usage snapshot since boot.
5956 Phone phone = getPhone(subId);
5957 if (phone != null) {
5958 return phone.getVtDataUsage(perUidStats);
5959 }
5960 return null;
5961 } finally {
5962 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005963 }
Jack Yueb89b242016-06-22 13:27:47 -07005964 }
Jack Yu75ab2952016-07-08 14:29:33 -07005965
5966 /**
5967 * Policy control of data connection. Usually used when data limit is passed.
5968 * @param enabled True if enabling the data, otherwise disabling.
5969 * @param subId Subscription index
5970 * {@hide}
5971 */
5972 @Override
5973 public void setPolicyDataEnabled(boolean enabled, int subId) {
5974 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005975
5976 final long identity = Binder.clearCallingIdentity();
5977 try {
5978 Phone phone = getPhone(subId);
5979 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005980 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005981 }
5982 } finally {
5983 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005984 }
5985 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005986
5987 /**
5988 * Get Client request stats
5989 * @return List of Client Request Stats
5990 * @hide
5991 */
5992 @Override
5993 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005994 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005995 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005996 return null;
5997 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005998 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005999
Malcolm Chend965c8b2018-02-28 15:00:40 -08006000 final long identity = Binder.clearCallingIdentity();
6001 try {
6002 if (phone != null) {
6003 return phone.getClientRequestStats();
6004 }
6005
6006 return null;
6007 } finally {
6008 Binder.restoreCallingIdentity(identity);
6009 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006010 }
6011
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006012 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006013 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006014 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006015 }
Jack Yueb4124c2017-02-16 15:32:43 -08006016
6017 /**
Grace Chen70990072017-03-24 17:21:30 -07006018 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006019 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006020 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006021 * @param state State of SIM (power down, power up, pass through)
6022 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6023 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6024 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006025 *
6026 **/
6027 @Override
Grace Chen70990072017-03-24 17:21:30 -07006028 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006029 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006030 Phone phone = PhoneFactory.getPhone(slotIndex);
6031
vagdevie435a3e2018-08-15 16:01:53 -07006032 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6033
Malcolm Chend965c8b2018-02-28 15:00:40 -08006034 final long identity = Binder.clearCallingIdentity();
6035 try {
6036 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006037 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006038 }
6039 } finally {
6040 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006041 }
6042 }
Shuo Qiandd210312017-04-12 22:11:33 +00006043
Tyler Gunn65d45c22017-06-05 11:22:26 -07006044 private boolean isUssdApiAllowed(int subId) {
6045 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006046 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006047 if (configManager == null) {
6048 return false;
6049 }
6050 PersistableBundle pb = configManager.getConfigForSubId(subId);
6051 if (pb == null) {
6052 return false;
6053 }
6054 return pb.getBoolean(
6055 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6056 }
6057
Shuo Qiandd210312017-04-12 22:11:33 +00006058 /**
6059 * Check if phone is in emergency callback mode
6060 * @return true if phone is in emergency callback mode
6061 * @param subId sub id
6062 */
goneil9c5f4872017-12-05 14:07:56 -08006063 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006064 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006065 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006066 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006067
6068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 if (phone != null) {
6071 return phone.isInEcm();
6072 } else {
6073 return false;
6074 }
6075 } finally {
6076 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006077 }
6078 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006079
6080 /**
6081 * Get the current signal strength information for the given subscription.
6082 * Because this information is not updated when the device is in a low power state
6083 * it should not be relied-upon to be current.
6084 * @param subId Subscription index
6085 * @return the most recent cached signal strength info from the modem
6086 */
6087 @Override
6088 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 Phone p = getPhone(subId);
6092 if (p == null) {
6093 return null;
6094 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006095
Malcolm Chend965c8b2018-02-28 15:00:40 -08006096 return p.getSignalStrength();
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006100 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006101
Pengquan Meng9140aec2018-08-22 14:49:57 -07006102 /**
chen xu907e5a22018-10-11 13:21:04 -07006103 * Get the current modem radio state for the given slot.
6104 * @param slotIndex slot index.
6105 * @param callingPackage the name of the package making the call.
6106 * @return the current radio power state from the modem
6107 */
6108 @Override
6109 public int getRadioPowerState(int slotIndex, String callingPackage) {
6110 Phone phone = PhoneFactory.getPhone(slotIndex);
6111 if (phone != null) {
6112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6113 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6114 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6115 }
6116
6117 final long identity = Binder.clearCallingIdentity();
6118 try {
6119 return phone.getRadioPowerState();
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
6122 }
6123 }
6124 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6125 }
6126
6127 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006128 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6129 *
6130 * <p>Requires one of the following permissions:
6131 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6132 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6133 * privileges.
6134 *
6135 * @param subId subscription id
6136 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6137 * {@code false}.
6138 */
6139 @Override
6140 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006141 boolean isEnabled = false;
6142 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006143 try {
6144 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006145 null /* message */);
6146 Phone phone = getPhone(subId);
6147 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006148 } catch (Exception e) {
6149 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6150 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006151 } finally {
6152 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006153 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006154 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006155 }
6156
6157
6158 /**
6159 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6160 *
6161 * <p> Requires permission:
6162 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6163 * privileges.
6164 *
6165 * @param subId subscription id
6166 * @param isEnabled {@code true} means enable, {@code false} means disable.
6167 */
6168 @Override
6169 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006170 final long identity = Binder.clearCallingIdentity();
6171 try {
6172 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6173 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006174
Pengquan Meng0c05b502018-09-06 09:59:22 -07006175 Phone phone = getPhone(subId);
6176 if (phone != null) {
6177 phone.setDataRoamingEnabled(isEnabled);
6178 }
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006181 }
6182 }
6183
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006184 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006185 public boolean isManualNetworkSelectionAllowed(int subId) {
6186 boolean isAllowed = true;
6187 final long identity = Binder.clearCallingIdentity();
6188 try {
6189 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6190 mApp, subId, "isManualNetworkSelectionAllowed");
6191 Phone phone = getPhone(subId);
6192 if (phone != null) {
6193 isAllowed = phone.isCspPlmnEnabled();
6194 }
6195 } finally {
6196 Binder.restoreCallingIdentity(identity);
6197 }
6198 return isAllowed;
6199 }
6200
6201 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006202 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006203 try {
6204 enforceReadPrivilegedPermission("getUiccCardsInfo");
6205 } catch (SecurityException e) {
6206 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6207 // has carrier privileges on an active UICC
6208 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6209 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6210 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6211 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006212 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006213
6214 final long identity = Binder.clearCallingIdentity();
6215 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006216 UiccController uiccController = UiccController.getInstance();
6217 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6218
6219 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6220 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6221 // Remove private info if the caller doesn't have access
6222 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6223 for (UiccCardInfo cardInfo : cardInfos) {
6224 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6225 UiccProfile profile = card.getUiccProfile();
6226 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6227 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6228 filteredInfos.add(cardInfo.getUnprivileged());
6229 } else {
6230 filteredInfos.add(cardInfo);
6231 }
6232 }
6233 return filteredInfos;
6234 }
6235 return cardInfos;
6236 } catch (PackageManager.NameNotFoundException e) {
6237 // This should not happen since we pass the package info in from TelephonyManager
6238 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
6241 }
6242 }
6243
6244 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006245 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006246 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006247
Malcolm Chend965c8b2018-02-28 15:00:40 -08006248 final long identity = Binder.clearCallingIdentity();
6249 try {
6250 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6251 if (slots == null) {
6252 Rlog.i(LOG_TAG, "slots is null.");
6253 return null;
6254 }
6255
6256 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6257 for (int i = 0; i < slots.length; i++) {
6258 UiccSlot slot = slots[i];
6259 if (slot == null) {
6260 continue;
6261 }
6262
6263 String cardId;
6264 UiccCard card = slot.getUiccCard();
6265 if (card != null) {
6266 cardId = card.getCardId();
6267 } else {
6268 cardId = slot.getIccId();
6269 }
6270
6271 int cardState = 0;
6272 switch (slot.getCardState()) {
6273 case CARDSTATE_ABSENT:
6274 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6275 break;
6276 case CARDSTATE_PRESENT:
6277 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6278 break;
6279 case CARDSTATE_ERROR:
6280 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6281 break;
6282 case CARDSTATE_RESTRICTED:
6283 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6284 break;
6285 default:
6286 break;
6287
6288 }
6289
6290 infos[i] = new UiccSlotInfo(
6291 slot.isActive(),
6292 slot.isEuicc(),
6293 cardId,
6294 cardState,
6295 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006296 slot.isExtendedApduSupported(),
6297 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006298 }
6299 return infos;
6300 } finally {
6301 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006302 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006303 }
6304
6305 @Override
6306 public boolean switchSlots(int[] physicalSlots) {
6307 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006308
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6312 } finally {
6313 Binder.restoreCallingIdentity(identity);
6314 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006315 }
Jack Yu4c988042018-02-27 15:30:01 -08006316
6317 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006318 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006319 final long identity = Binder.clearCallingIdentity();
6320 try {
6321 return UiccController.getInstance().getCardIdForDefaultEuicc();
6322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
6325 }
6326
6327 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006328 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6329 enforceModifyPermission();
6330 final Phone phone = getPhone(subId);
6331 if (phone == null) {
6332 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6333 return;
6334 }
6335
Malcolm Chend965c8b2018-02-28 15:00:40 -08006336 final long identity = Binder.clearCallingIdentity();
6337 try {
6338 phone.setRadioIndicationUpdateMode(filters, mode);
6339 } finally {
6340 Binder.restoreCallingIdentity(identity);
6341 }
Jack Yu4c988042018-02-27 15:30:01 -08006342 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006343
6344 /**
goneil47ffb6e2018-04-06 15:40:58 -07006345 * A test API to reload the UICC profile.
6346 *
6347 * <p>Requires that the calling app has permission
6348 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6349 * @hide
6350 */
6351 @Override
6352 public void refreshUiccProfile(int subId) {
6353 enforceModifyPermission();
6354
6355 final long identity = Binder.clearCallingIdentity();
6356 try {
6357 Phone phone = getPhone(subId);
6358 if (phone == null) {
6359 return;
6360 }
6361 UiccCard uiccCard = phone.getUiccCard();
6362 if (uiccCard == null) {
6363 return;
6364 }
6365 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6366 if (uiccProfile == null) {
6367 return;
6368 }
6369 uiccProfile.refresh();
6370 } finally {
6371 Binder.restoreCallingIdentity(identity);
6372 }
6373 }
6374
6375 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006376 * Returns false if the mobile data is disabled by default, otherwise return true.
6377 */
6378 private boolean getDefaultDataEnabled() {
6379 return "true".equalsIgnoreCase(
6380 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6381 }
6382
6383 /**
6384 * Returns true if the data roaming is enabled by default, i.e the system property
6385 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6386 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6387 */
6388 private boolean getDefaultDataRoamingEnabled(int subId) {
6389 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006390 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006391 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6392 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6393 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6394 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6395 return isDataRoamingEnabled;
6396 }
6397
6398 /**
6399 * Returns the default network type for the given {@code subId}, if the default network type is
6400 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6401 */
6402 private int getDefaultNetworkType(int subId) {
6403 return Integer.parseInt(
6404 TelephonyManager.getTelephonyProperty(
6405 mSubscriptionController.getPhoneId(subId),
6406 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6407 String.valueOf(Phone.PREFERRED_NT_MODE)));
6408 }
fionaxua13278b2018-03-21 00:08:13 -07006409
6410 @Override
6411 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6412 gid1, String gid2, String plmn, String spn) {
6413 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006414
6415 final long identity = Binder.clearCallingIdentity();
6416 try {
6417 final Phone phone = getPhone(subId);
6418 if (phone == null) {
6419 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6420 return;
6421 }
6422 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6423 } finally {
6424 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006425 }
fionaxua13278b2018-03-21 00:08:13 -07006426 }
6427
6428 @Override
6429 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006430 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 final Phone phone = getPhone(subId);
6435 if (phone == null) {
6436 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6437 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6438 }
6439 return phone.getCarrierIdListVersion();
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006442 }
fionaxua13278b2018-03-21 00:08:13 -07006443 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006444
6445 @Override
6446 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6448 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6449 return -1;
6450 }
6451
6452 final long identity = Binder.clearCallingIdentity();
6453 try {
6454 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
6458 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006459
6460 @Override
6461 public int getCdmaRoamingMode(int subId) {
6462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6463 mApp, subId, "getCdmaRoamingMode");
6464
6465 final long identity = Binder.clearCallingIdentity();
6466 try {
6467 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6468 } finally {
6469 Binder.restoreCallingIdentity(identity);
6470 }
6471 }
6472
6473 @Override
6474 public boolean setCdmaRoamingMode(int subId, int mode) {
6475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6476 mApp, subId, "setCdmaRoamingMode");
6477
6478 final long identity = Binder.clearCallingIdentity();
6479 try {
6480 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
6484 }
6485
6486 @Override
6487 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6489 mApp, subId, "setCdmaSubscriptionMode");
6490
6491 final long identity = Binder.clearCallingIdentity();
6492 try {
6493 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6494 } finally {
6495 Binder.restoreCallingIdentity(identity);
6496 }
6497 }
chen xu7ee67862018-10-30 22:27:10 -07006498
sqian2fff4a32018-11-05 14:18:37 -08006499 private void ensureUserRunning(int userId) {
6500 if (!mUserManager.isUserRunning(userId)) {
6501 throw new IllegalStateException("User " + userId + " does not exist or not running");
6502 }
6503 }
6504
6505 /**
6506 * Returns a list of SMS apps on a given user.
6507 *
6508 * Only the shell user (UID 2000 or 0) can call it.
6509 * Target user must be running.
6510 */
6511 @Override
6512 public String[] getSmsApps(int userId) {
6513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6514 ensureUserRunning(userId);
6515
6516 final Collection<SmsApplicationData> apps =
6517 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6518
6519 String[] ret = new String[apps.size()];
6520 int i = 0;
6521 for (SmsApplicationData app : apps) {
6522 ret[i++] = app.mPackageName;
6523 }
6524 return ret;
6525 }
6526
6527 /**
6528 * Returns the default SMS app package name on a given user.
6529 *
6530 * Only the shell user (UID 2000 or 0) can call it.
6531 * Target user must be running.
6532 */
6533 @Override
6534 public String getDefaultSmsApp(int userId) {
6535 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6536 ensureUserRunning(userId);
6537
6538 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6539 /* updateIfNeeded= */ true, userId);
6540 return cn == null ? null : cn.getPackageName();
6541 }
6542
6543 /**
6544 * Set a package as the default SMS app on a given user.
6545 *
6546 * Only the shell user (UID 2000 or 0) can call it.
6547 * Target user must be running.
6548 */
6549 @Override
6550 public void setDefaultSmsApp(int userId, String packageName) {
6551 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6552 ensureUserRunning(userId);
6553
6554 boolean found = false;
6555 for (String pkg : getSmsApps(userId)) {
6556 if (TextUtils.equals(packageName, pkg)) {
6557 found = true;
6558 break;
6559 }
6560 }
6561 if (!found) {
6562 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6563 }
6564
6565 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6566 }
6567
chen xu7ee67862018-10-30 22:27:10 -07006568 @Override
sqian65eefe12019-02-22 15:55:18 -08006569 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006570 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006571 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006572 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006573 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6574 }
6575 final long identity = Binder.clearCallingIdentity();
6576 try {
sqian991b35e2018-12-12 16:48:18 -08006577 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6578 for (Phone phone: PhoneFactory.getPhones()) {
6579 if (phone.getEmergencyNumberTracker() != null
6580 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6581 emergencyNumberListInternal.put(
6582 phone.getSubId(),
6583 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6584 }
sqian03bca152018-12-05 18:48:28 -08006585 }
sqian991b35e2018-12-12 16:48:18 -08006586 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
sqian04b86072018-11-07 14:02:21 -08006590 }
6591
6592 @Override
sqian65eefe12019-02-22 15:55:18 -08006593 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006594 final Phone defaultPhone = getDefaultPhone();
6595 if (!exactMatch) {
6596 TelephonyPermissions
6597 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006598 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006599 }
6600 final long identity = Binder.clearCallingIdentity();
6601 try {
sqian991b35e2018-12-12 16:48:18 -08006602 for (Phone phone: PhoneFactory.getPhones()) {
6603 if (phone.getEmergencyNumberTracker() != null
6604 && phone.getEmergencyNumberTracker() != null) {
6605 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6606 number, exactMatch)) {
6607 return true;
sqian03bca152018-12-05 18:48:28 -08006608 }
6609 }
sqian03bca152018-12-05 18:48:28 -08006610 }
6611 return false;
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
6615 }
6616
sqian9d4df8b2019-01-15 18:32:07 -08006617 /**
6618 * Update emergency number list for test mode.
6619 */
6620 @Override
6621 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6622 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6623 "updateEmergencyNumberListTestMode");
6624
6625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 for (Phone phone: PhoneFactory.getPhones()) {
6628 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6629 if (tracker != null) {
6630 tracker.executeEmergencyNumberTestModeCommand(action, num);
6631 }
6632 }
6633 } finally {
6634 Binder.restoreCallingIdentity(identity);
6635 }
6636 }
6637
6638 /**
6639 * Get the full emergency number list for test mode.
6640 */
6641 @Override
6642 public List<String> getEmergencyNumberListTestMode() {
6643 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6644 "getEmergencyNumberListTestMode");
6645
6646 final long identity = Binder.clearCallingIdentity();
6647 try {
6648 Set<String> emergencyNumbers = new HashSet<>();
6649 for (Phone phone: PhoneFactory.getPhones()) {
6650 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6651 if (tracker != null) {
6652 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6653 emergencyNumbers.add(num.getNumber());
6654 }
6655 }
6656 }
6657 return new ArrayList<>(emergencyNumbers);
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
6661 }
6662
sqian04b86072018-11-07 14:02:21 -08006663 @Override
chen xu7ee67862018-10-30 22:27:10 -07006664 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6665 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6666 Phone phone = getPhone(subId);
6667 if (phone == null) {
6668 return null;
6669 }
6670 final long identity = Binder.clearCallingIdentity();
6671 try {
6672 UiccProfile profile = UiccController.getInstance()
6673 .getUiccProfileForPhone(phone.getPhoneId());
6674 if (profile != null) {
6675 return profile.getCertsFromCarrierPrivilegeAccessRules();
6676 }
6677 } finally {
6678 Binder.restoreCallingIdentity(identity);
6679 }
6680 return null;
6681 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006682
6683 /**
6684 * Enable or disable a modem stack.
6685 */
6686 @Override
6687 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6688 enforceModifyPermission();
6689
6690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 Phone phone = PhoneFactory.getPhone(slotIndex);
6693 if (phone == null) {
6694 return false;
6695 } else {
6696 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6697 }
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
6700 }
6701 }
Micheled3107c52018-12-21 15:00:11 -08006702
6703 @Override
6704 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6705 enforceModifyPermission();
6706
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
6709 mTelephonySharedPreferences.edit()
6710 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6711 .commit();
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 }
6716
6717 @Override
Michelebcb01bc2019-02-04 11:36:23 -08006718 public boolean isMultisimSupported(String callingPackage) {
6719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6720 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6721 return false;
6722 }
Micheled3107c52018-12-21 15:00:11 -08006723
6724 final long identity = Binder.clearCallingIdentity();
6725 try {
Michele30b57b22019-03-01 12:01:14 -08006726 return isMultisimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006727 } finally {
6728 Binder.restoreCallingIdentity(identity);
6729 }
6730 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006731
Michele30b57b22019-03-01 12:01:14 -08006732 private boolean isMultisimSupportedInternal() {
6733 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6734 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6735 if (numPhysicalSlots < 2) {
6736 loge("isMultisimSupportedInternal: requires at least 2 cards");
6737 return false;
6738 }
6739 // Check if the hardware supports multisim functionality. If usage of multisim is not
6740 // supported by the modem, indicate that it is restricted.
6741 PhoneCapability staticCapability =
6742 mPhoneConfigurationManager.getStaticPhoneCapability();
6743 if (staticCapability == null) {
6744 loge("isMultisimSupportedInternal: no static configuration available");
6745 return false;
6746 }
6747 if (staticCapability.logicalModemList.size() < 2) {
6748 loge("isMultisimSupportedInternal: maximum number of modem is < 2");
6749 return false;
6750 }
6751 // Check if support of multiple SIMs is restricted by carrier
6752 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6753 return false;
6754 }
6755
6756 return true;
6757 }
6758
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006759 /**
6760 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006761 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6762 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6763 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006764 * @param numOfSims number of active sims we want to switch to
6765 */
6766 @Override
6767 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006768 if (numOfSims == 1) {
6769 enforceModifyPermission();
6770 } else {
6771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6772 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6773 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006774 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006775
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006776 try {
Michele30b57b22019-03-01 12:01:14 -08006777 //only proceed if multi-sim is not restricted
6778 if (!isMultisimSupportedInternal()) {
6779 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6780 return;
6781 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006782 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
6786 }
6787
6788 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006789 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006790 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006791 */
6792 @Override
6793 public boolean isRebootRequiredForModemConfigChange() {
6794 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6798 } finally {
6799 Binder.restoreCallingIdentity(identity);
6800 }
6801 }
6802
Pengquan Meng92d253b2019-02-06 11:12:53 -08006803 private void updateModemStateMetrics() {
6804 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6805 // TODO: check the state for each modem if the api is ready.
6806 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6807 }
6808
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006809 @Override
6810 public int[] getSlotsMapping() {
6811 enforceReadPrivilegedPermission("getSlotsMapping");
6812
6813 final long identity = Binder.clearCallingIdentity();
6814 try {
6815 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6816 // All logical slots should have a mapping to a physical slot.
6817 int[] logicalSlotsMapping = new int[phoneCount];
6818 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6819 for (int i = 0; i < slotInfos.length; i++) {
6820 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6821 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6822 }
6823 }
6824 return logicalSlotsMapping;
6825 } finally {
6826 Binder.restoreCallingIdentity(identity);
6827 }
6828 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006829
6830 /**
6831 * Get the IRadio HAL Version
6832 */
6833 @Override
6834 public int getRadioHalVersion() {
6835 Phone phone = getDefaultPhone();
6836 if (phone == null) return -1;
6837 HalVersion hv = phone.getHalVersion();
6838 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6839 return hv.major * 100 + hv.minor;
6840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006841}