blob: 28362fcae62c4d749e9e1b14c6afd9d9fe0bb53a [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;
Hall Liub2ac8ef2019-02-28 15:56:23 -080077import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070078import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070079import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080080import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070081import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080082import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080083import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070084import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070085import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080087import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000088import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070089import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070091import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080092import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080093import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070094import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080095import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070096import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080097import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070098import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080099import android.telephony.ims.aidl.IImsMmTelFeature;
100import android.telephony.ims.aidl.IImsRcsFeature;
101import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -0700102import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.feature.MmTelFeature;
104import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800105import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700106import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800107import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700108import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800109import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800110import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800111
Brad Ebinger4c460712018-10-01 10:40:55 -0700112import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700113import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800114import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700115import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700116import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700117import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800118import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700119import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700120import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800122import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800123import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800125import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700126import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100127import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700128import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700131import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800132import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700133import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700134import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700135import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700136import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700137import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700138import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800139import com.android.internal.telephony.SmsApplication;
140import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800141import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800142import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800143import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700144import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800145import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800146import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700147import com.android.internal.telephony.uicc.IccIoResult;
148import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800149import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700150import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800151import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700152import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000154import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700155import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800156import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700157import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800158import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700159import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700160import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800161
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700162import java.io.FileDescriptor;
163import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800164import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700165import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800166import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800167import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800168import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800169import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800170import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100171import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800172import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800173import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700174
175/**
176 * Implementation of the ITelephony interface.
177 */
Santos Cordon117fee72014-05-16 17:56:12 -0700178public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179 private static final String LOG_TAG = "PhoneInterfaceManager";
180 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
181 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800182 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183
184 // Message codes used with mMainThreadHandler
185 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700186 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
187 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700188 private static final int CMD_OPEN_CHANNEL = 9;
189 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
190 private static final int CMD_CLOSE_CHANNEL = 11;
191 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800192 private static final int CMD_NV_READ_ITEM = 13;
193 private static final int EVENT_NV_READ_ITEM_DONE = 14;
194 private static final int CMD_NV_WRITE_ITEM = 15;
195 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
196 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
197 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700198 private static final int CMD_RESET_MODEM_CONFIG = 19;
199 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800200 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
201 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
202 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
203 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800204 private static final int CMD_SEND_ENVELOPE = 25;
205 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000206 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
207 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700208 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
209 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
210 private static final int CMD_EXCHANGE_SIM_IO = 31;
211 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800212 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
213 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700214 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
215 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700216 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
217 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700218 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
219 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
220 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
221 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700222 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
223 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
224 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
225 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700226 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800227 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
228 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000229 private static final int CMD_SWITCH_SLOTS = 50;
230 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700231 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
232 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
233 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
234 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
235 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
236 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
237 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
238 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700239 private static final int CMD_GET_ALL_CELL_INFO = 60;
240 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
241 private static final int CMD_GET_CELL_LOCATION = 62;
242 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700243 private static final int CMD_MODEM_REBOOT = 64;
244 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700245 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
246 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800247 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
248 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700249
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800250 // Parameters of select command.
251 private static final int SELECT_COMMAND = 0xA4;
252 private static final int SELECT_P1 = 0x04;
253 private static final int SELECT_P2 = 0;
254 private static final int SELECT_P3 = 0x10;
255
Pengquan Meng85728fb2018-03-12 16:31:21 -0700256 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
257 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
258 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
259
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700260 /** The singleton instance. */
261 private static PhoneInterfaceManager sInstance;
262
Wink Saville3ab207e2014-11-20 13:07:20 -0800263 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800264 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700265 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800266 private AppOpsManager mAppOps;
267 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800268 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800269 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700270 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700271
Derek Tan97ebb422014-09-05 16:55:38 -0700272 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
273 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800274 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800275 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700276
Micheled3107c52018-12-21 15:00:11 -0800277 // String to store multi SIM allowed
278 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
279
Derek Tan740e1672017-06-27 14:56:27 -0700280 // The AID of ISD-R.
281 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
282
yinxub1bed742017-04-17 11:45:04 -0700283 private NetworkScanRequestTracker mNetworkScanRequestTracker;
284
David Kelly5e06a7f2018-03-12 14:10:59 +0000285 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
286 private static final int MANUFACTURER_CODE_LENGTH = 8;
287
Derek Tan89e89d42014-07-08 17:00:10 -0700288 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700289 * A request object to use for transmitting data to an ICC.
290 */
291 private static final class IccAPDUArgument {
292 public int channel, cla, command, p1, p2, p3;
293 public String data;
294
295 public IccAPDUArgument(int channel, int cla, int command,
296 int p1, int p2, int p3, String data) {
297 this.channel = channel;
298 this.cla = cla;
299 this.command = command;
300 this.p1 = p1;
301 this.p2 = p2;
302 this.p3 = p3;
303 this.data = data;
304 }
305 }
306
307 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700308 * A request object to use for transmitting data to an ICC.
309 */
310 private static final class ManualNetworkSelectionArgument {
311 public OperatorInfo operatorInfo;
312 public boolean persistSelection;
313
314 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
315 this.operatorInfo = operatorInfo;
316 this.persistSelection = persistSelection;
317 }
318 }
319
320 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700321 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
322 * request after sending. The main thread will notify the request when it is complete.
323 */
324 private static final class MainThreadRequest {
325 /** The argument to use for the request */
326 public Object argument;
327 /** The result of the request that is run on the main thread */
328 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800329 // The subscriber id that this request applies to. Defaults to
330 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
331 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332
Nathan Harold92bed182018-10-12 18:16:49 -0700333 // In cases where subId is unavailable, the caller needs to specify the phone.
334 public Phone phone;
335
vagdevie435a3e2018-08-15 16:01:53 -0700336 public WorkSource workSource;
337
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700338 public MainThreadRequest(Object argument) {
339 this.argument = argument;
340 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800341
Nathan Harold92bed182018-10-12 18:16:49 -0700342 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
343 this.argument = argument;
344 if (phone != null) {
345 this.phone = phone;
346 }
347 this.workSource = workSource;
348 }
349
vagdevie435a3e2018-08-15 16:01:53 -0700350 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800352 if (subId != null) {
353 this.subId = subId;
354 }
vagdevie435a3e2018-08-15 16:01:53 -0700355 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800356 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700357 }
358
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800359 private static final class IncomingThirdPartyCallArgs {
360 public final ComponentName component;
361 public final String callId;
362 public final String callerDisplayName;
363
364 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
365 String callerDisplayName) {
366 this.component = component;
367 this.callId = callId;
368 this.callerDisplayName = callerDisplayName;
369 }
370 }
371
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700372 /**
373 * A handler that processes messages on the main thread in the phone process. Since many
374 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
375 * inbound binder threads to the main thread in the phone process. The Binder thread
376 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
377 * on, which will be notified when the operation completes and will contain the result of the
378 * request.
379 *
380 * <p>If a MainThreadRequest object is provided in the msg.obj field,
381 * note that request.result must be set to something non-null for the calling thread to
382 * unblock.
383 */
384 private final class MainThreadHandler extends Handler {
385 @Override
386 public void handleMessage(Message msg) {
387 MainThreadRequest request;
388 Message onCompleted;
389 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800390 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700391 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800392 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393
394 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700395 case CMD_HANDLE_USSD_REQUEST: {
396 request = (MainThreadRequest) msg.obj;
397 final Phone phone = getPhoneFromRequest(request);
398 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
399 String ussdRequest = ussdObject.first;
400 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700401
Pengquan Meng0c05b502018-09-06 09:59:22 -0700402 if (!isUssdApiAllowed(request.subId)) {
403 // Carrier does not support use of this API, return failure.
404 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
405 UssdResponse response = new UssdResponse(ussdRequest, null);
406 Bundle returnData = new Bundle();
407 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
408 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700409
Pengquan Meng0c05b502018-09-06 09:59:22 -0700410 request.result = true;
411 notifyRequester(request);
412 return;
413 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700414
Pengquan Meng0c05b502018-09-06 09:59:22 -0700415 try {
416 request.result = phone != null
417 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
418 } catch (CallStateException cse) {
419 request.result = false;
420 }
421 // Wake up the requesting thread
422 notifyRequester(request);
423 break;
pkanwar32d516d2016-10-14 19:37:38 -0700424 }
425
Yorke Lee716f67e2015-06-17 15:39:16 -0700426 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700428 final Phone phone = getPhoneFromRequest(request);
429 request.result = phone != null ?
430 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
431 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700433 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700436
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700437 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700438 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 if (uiccCard == null) {
442 loge("iccTransmitApduLogicalChannel: No UICC");
443 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700444 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700445 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700446 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
447 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 iccArgument.channel, iccArgument.cla, iccArgument.command,
450 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700451 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700452 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700453 break;
454
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700456 ar = (AsyncResult) msg.obj;
457 request = (MainThreadRequest) ar.userObj;
458 if (ar.exception == null && ar.result != null) {
459 request.result = ar.result;
460 } else {
461 request.result = new IccIoResult(0x6F, 0, (byte[])null);
462 if (ar.result == null) {
463 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800464 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700465 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800466 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 } else {
468 loge("iccTransmitApduLogicalChannel: Unknown exception");
469 }
470 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700471 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 break;
473
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
475 request = (MainThreadRequest) msg.obj;
476 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800477 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 if (uiccCard == null) {
479 loge("iccTransmitApduBasicChannel: No UICC");
480 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 } else {
483 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
484 request);
485 uiccCard.iccTransmitApduBasicChannel(
486 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
487 iccArgument.p3, iccArgument.data, onCompleted);
488 }
489 break;
490
491 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
492 ar = (AsyncResult) msg.obj;
493 request = (MainThreadRequest) ar.userObj;
494 if (ar.exception == null && ar.result != null) {
495 request.result = ar.result;
496 } else {
497 request.result = new IccIoResult(0x6F, 0, (byte[])null);
498 if (ar.result == null) {
499 loge("iccTransmitApduBasicChannel: Empty response");
500 } else if (ar.exception instanceof CommandException) {
501 loge("iccTransmitApduBasicChannel: CommandException: " +
502 ar.exception);
503 } else {
504 loge("iccTransmitApduBasicChannel: Unknown exception");
505 }
506 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700507 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 break;
509
510 case CMD_EXCHANGE_SIM_IO:
511 request = (MainThreadRequest) msg.obj;
512 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800513 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 if (uiccCard == null) {
515 loge("iccExchangeSimIO: No UICC");
516 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 } else {
519 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
520 request);
521 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
522 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
523 iccArgument.data, onCompleted);
524 }
525 break;
526
527 case EVENT_EXCHANGE_SIM_IO_DONE:
528 ar = (AsyncResult) msg.obj;
529 request = (MainThreadRequest) ar.userObj;
530 if (ar.exception == null && ar.result != null) {
531 request.result = ar.result;
532 } else {
533 request.result = new IccIoResult(0x6f, 0, (byte[])null);
534 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700535 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700536 break;
537
Derek Tan4d5e5c12014-02-04 11:54:58 -0800538 case CMD_SEND_ENVELOPE:
539 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800540 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 if (uiccCard == null) {
542 loge("sendEnvelopeWithStatus: No UICC");
543 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700544 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700545 } else {
546 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
547 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
548 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800549 break;
550
551 case EVENT_SEND_ENVELOPE_DONE:
552 ar = (AsyncResult) msg.obj;
553 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700554 if (ar.exception == null && ar.result != null) {
555 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800556 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
558 if (ar.result == null) {
559 loge("sendEnvelopeWithStatus: Empty response");
560 } else if (ar.exception instanceof CommandException) {
561 loge("sendEnvelopeWithStatus: CommandException: " +
562 ar.exception);
563 } else {
564 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
565 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700567 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800568 break;
569
Shishir Agrawal566b7612013-10-28 14:41:00 -0700570 case CMD_OPEN_CHANNEL:
571 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800572 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800573 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700574 if (uiccCard == null) {
575 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800576 request.result = new IccOpenLogicalChannelResponse(-1,
577 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700578 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 } else {
580 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800581 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
582 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700584 break;
585
586 case EVENT_OPEN_CHANNEL_DONE:
587 ar = (AsyncResult) msg.obj;
588 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700590 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 int[] result = (int[]) ar.result;
592 int channelId = result[0];
593 byte[] selectResponse = null;
594 if (result.length > 1) {
595 selectResponse = new byte[result.length - 1];
596 for (int i = 1; i < result.length; ++i) {
597 selectResponse[i - 1] = (byte) result[i];
598 }
599 }
600 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700601 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700602 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700603 if (ar.result == null) {
604 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 if (ar.exception != null) {
607 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
608 }
609
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700610 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700611 if (ar.exception instanceof CommandException) {
612 CommandException.Error error =
613 ((CommandException) (ar.exception)).getCommandError();
614 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700615 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700616 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700618 }
619 }
620 openChannelResp = new IccOpenLogicalChannelResponse(
621 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700623 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700625 break;
626
627 case CMD_CLOSE_CHANNEL:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900632 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
636 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
637 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 break;
639
640 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800641 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
642 break;
643
644 case CMD_NV_READ_ITEM:
645 request = (MainThreadRequest) msg.obj;
646 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800647 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
648 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800649 break;
650
651 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 ar = (AsyncResult) msg.obj;
653 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800654 if (ar.exception == null && ar.result != null) {
655 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800657 request.result = "";
658 if (ar.result == null) {
659 loge("nvReadItem: Empty response");
660 } else if (ar.exception instanceof CommandException) {
661 loge("nvReadItem: CommandException: " +
662 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800664 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700665 }
666 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 break;
669
Jake Hambye994d462014-02-03 13:10:13 -0800670 case CMD_NV_WRITE_ITEM:
671 request = (MainThreadRequest) msg.obj;
672 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
673 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800674 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700675 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800676 break;
677
678 case EVENT_NV_WRITE_ITEM_DONE:
679 handleNullReturnEvent(msg, "nvWriteItem");
680 break;
681
682 case CMD_NV_WRITE_CDMA_PRL:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800685 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800686 break;
687
688 case EVENT_NV_WRITE_CDMA_PRL_DONE:
689 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
690 break;
691
chen xu1cc0abe2018-10-26 17:39:23 -0700692 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800693 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700694 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800695 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
chen xu1cc0abe2018-10-26 17:39:23 -0700698 case EVENT_RESET_MODEM_CONFIG_DONE:
699 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800700 break;
701
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 case CMD_GET_PREFERRED_NETWORK_TYPE:
703 request = (MainThreadRequest) msg.obj;
704 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700705 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800706 break;
707
708 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
709 ar = (AsyncResult) msg.obj;
710 request = (MainThreadRequest) ar.userObj;
711 if (ar.exception == null && ar.result != null) {
712 request.result = ar.result; // Integer
713 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800714 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800715 if (ar.result == null) {
716 loge("getPreferredNetworkType: Empty response");
717 } else if (ar.exception instanceof CommandException) {
718 loge("getPreferredNetworkType: CommandException: " +
719 ar.exception);
720 } else {
721 loge("getPreferredNetworkType: Unknown exception");
722 }
723 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700724 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 break;
726
727 case CMD_SET_PREFERRED_NETWORK_TYPE:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
730 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700731 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800732 break;
733
734 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
735 handleNullReturnEvent(msg, "setPreferredNetworkType");
736 break;
737
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000738 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
739 request = (MainThreadRequest)msg.obj;
740 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800741 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000742 break;
743
744 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
745 ar = (AsyncResult)msg.obj;
746 request = (MainThreadRequest)ar.userObj;
747 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700748 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000749 break;
750
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800751 case CMD_SET_VOICEMAIL_NUMBER:
752 request = (MainThreadRequest) msg.obj;
753 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
754 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800755 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
756 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800757 break;
758
759 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
760 handleNullReturnEvent(msg, "setVoicemailNumber");
761 break;
762
Stuart Scott54788802015-03-30 13:18:01 -0700763 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
764 request = (MainThreadRequest) msg.obj;
765 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
766 request);
767 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
768 break;
769
770 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
771 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
772 break;
773
Shishir Agrawal302c8692015-06-19 13:49:39 -0700774 case CMD_PERFORM_NETWORK_SCAN:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
777 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
778 break;
779
780 case EVENT_PERFORM_NETWORK_SCAN_DONE:
781 ar = (AsyncResult) msg.obj;
782 request = (MainThreadRequest) ar.userObj;
783 CellNetworkScanResult cellScanResult;
784 if (ar.exception == null && ar.result != null) {
785 cellScanResult = new CellNetworkScanResult(
786 CellNetworkScanResult.STATUS_SUCCESS,
787 (List<OperatorInfo>) ar.result);
788 } else {
789 if (ar.result == null) {
790 loge("getCellNetworkScanResults: Empty response");
791 }
792 if (ar.exception != null) {
793 loge("getCellNetworkScanResults: Exception: " + ar.exception);
794 }
795 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
796 if (ar.exception instanceof CommandException) {
797 CommandException.Error error =
798 ((CommandException) (ar.exception)).getCommandError();
799 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
800 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
801 } else if (error == CommandException.Error.GENERIC_FAILURE) {
802 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
803 }
804 }
805 cellScanResult = new CellNetworkScanResult(errorCode, null);
806 }
807 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700808 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700809 break;
810
811 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
812 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700813 ManualNetworkSelectionArgument selArg =
814 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
816 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700817 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
818 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700819 break;
820
821 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700822 ar = (AsyncResult) msg.obj;
823 request = (MainThreadRequest) ar.userObj;
824 if (ar.exception == null) {
825 request.result = true;
826 } else {
827 request.result = false;
828 loge("setNetworkSelectionModeManual " + ar.exception);
829 }
830 notifyRequester(request);
831 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700832 break;
833
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700834 case CMD_GET_MODEM_ACTIVITY_INFO:
835 request = (MainThreadRequest) msg.obj;
836 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800837 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700838 break;
839
840 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 if (ar.exception == null && ar.result != null) {
844 request.result = ar.result;
845 } else {
846 if (ar.result == null) {
847 loge("queryModemActivityInfo: Empty response");
848 } else if (ar.exception instanceof CommandException) {
849 loge("queryModemActivityInfo: CommandException: " +
850 ar.exception);
851 } else {
852 loge("queryModemActivityInfo: Unknown exception");
853 }
854 }
Amit Mahajand4766222016-01-28 15:28:28 -0800855 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
856 if (request.result == null) {
857 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
858 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700859 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700860 break;
861
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 case CMD_SET_ALLOWED_CARRIERS:
863 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800864 CarrierRestrictionRules argument =
865 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700866 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800867 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700868 break;
869
870 case EVENT_SET_ALLOWED_CARRIERS_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result;
875 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800876 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
877 if (ar.exception instanceof CommandException) {
878 loge("setAllowedCarriers: CommandException: " + ar.exception);
879 CommandException.Error error =
880 ((CommandException) (ar.exception)).getCommandError();
881 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
882 request.result =
883 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
884 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 } else {
886 loge("setAllowedCarriers: Unknown exception");
887 }
888 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700889 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700890 break;
891
892 case CMD_GET_ALLOWED_CARRIERS:
893 request = (MainThreadRequest) msg.obj;
894 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800895 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700896 break;
897
898 case EVENT_GET_ALLOWED_CARRIERS_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null && ar.result != null) {
902 request.result = ar.result;
903 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800904 request.result = new IllegalStateException(
905 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700906 if (ar.result == null) {
907 loge("getAllowedCarriers: Empty response");
908 } else if (ar.exception instanceof CommandException) {
909 loge("getAllowedCarriers: CommandException: " +
910 ar.exception);
911 } else {
912 loge("getAllowedCarriers: Unknown exception");
913 }
914 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700915 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700916 break;
917
Nathan Haroldb3014052017-01-25 15:57:32 -0800918 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 if (ar.exception == null && ar.result != null) {
922 request.result = ar.result;
923 } else {
924 request.result = new IllegalArgumentException(
925 "Failed to retrieve Forbidden Plmns");
926 if (ar.result == null) {
927 loge("getForbiddenPlmns: Empty response");
928 } else {
929 loge("getForbiddenPlmns: Unknown exception");
930 }
931 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700932 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800933 break;
934
935 case CMD_GET_FORBIDDEN_PLMNS:
936 request = (MainThreadRequest) msg.obj;
937 uiccCard = getUiccCardFromRequest(request);
938 if (uiccCard == null) {
939 loge("getForbiddenPlmns() UiccCard is null");
940 request.result = new IllegalArgumentException(
941 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700942 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800943 break;
944 }
945 Integer appType = (Integer) request.argument;
946 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
947 if (uiccApp == null) {
948 loge("getForbiddenPlmns() no app with specified type -- "
949 + appType);
950 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700951 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800952 break;
953 } else {
954 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
955 + " specified type -- " + appType);
956 }
957 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
958 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
959 onCompleted);
960 break;
961
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000962 case CMD_SWITCH_SLOTS:
963 request = (MainThreadRequest) msg.obj;
964 int[] physicalSlots = (int[]) request.argument;
965 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
966 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
967 break;
968
969 case EVENT_SWITCH_SLOTS_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700973 notifyRequester(request);
974 break;
975 case CMD_GET_NETWORK_SELECTION_MODE:
976 request = (MainThreadRequest) msg.obj;
977 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
978 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
979 break;
980
981 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 if (ar.exception != null) {
985 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
986 } else {
987 int mode = ((int[]) ar.result)[0];
988 if (mode == 0) {
989 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
990 } else {
991 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
992 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000993 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700994 notifyRequester(request);
995 break;
996 case CMD_GET_CDMA_ROAMING_MODE:
997 request = (MainThreadRequest) msg.obj;
998 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
999 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1000 break;
1001 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception != null) {
1005 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1006 } else {
1007 request.result = ((int[]) ar.result)[0];
1008 }
1009 notifyRequester(request);
1010 break;
1011 case CMD_SET_CDMA_ROAMING_MODE:
1012 request = (MainThreadRequest) msg.obj;
1013 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1014 int mode = (int) request.argument;
1015 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1016 break;
1017 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1018 ar = (AsyncResult) msg.obj;
1019 request = (MainThreadRequest) ar.userObj;
1020 request.result = ar.exception == null;
1021 notifyRequester(request);
1022 break;
1023 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1026 int subscriptionMode = (int) request.argument;
1027 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1028 break;
1029 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 request.result = ar.exception == null;
1033 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001034 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 case CMD_GET_ALL_CELL_INFO:
1036 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001037 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001038 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001039 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001040 case EVENT_GET_ALL_CELL_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001043 // If a timeout occurs, the response will be null
1044 request.result = (ar.exception == null && ar.result != null)
1045 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001046 synchronized (request) {
1047 request.notifyAll();
1048 }
1049 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001050 case CMD_REQUEST_CELL_INFO_UPDATE:
1051 request = (MainThreadRequest) msg.obj;
1052 request.phone.requestCellInfoUpdate(request.workSource,
1053 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1054 break;
1055 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1056 ar = (AsyncResult) msg.obj;
1057 request = (MainThreadRequest) ar.userObj;
1058 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1059 try {
1060 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001062 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1063 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001064 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001065 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001066 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001067 } else {
1068 // use the result as returned
1069 cb.onCellInfo((List<CellInfo>) ar.result);
1070 }
1071 } catch (RemoteException re) {
1072 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1073 }
1074 break;
1075 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001076 request = (MainThreadRequest) msg.obj;
1077 WorkSource ws = (WorkSource) request.argument;
1078 Phone phone = getPhoneFromRequest(request);
1079 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1080 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001081 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001082 ar = (AsyncResult) msg.obj;
1083 request = (MainThreadRequest) ar.userObj;
1084 if (ar.exception == null) {
1085 request.result = ar.result;
1086 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001088 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1089 ? new CdmaCellLocation() : new GsmCellLocation();
1090 }
1091
1092 synchronized (request) {
1093 request.notifyAll();
1094 }
1095 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001096 case CMD_MODEM_REBOOT:
1097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001099 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001100 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001101 case EVENT_CMD_MODEM_REBOOT_DONE:
1102 handleNullReturnEvent(msg, "rebootModem");
1103 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001104 case CMD_REQUEST_ENABLE_MODEM:
1105 request = (MainThreadRequest) msg.obj;
1106 boolean enable = (boolean) request.argument;
1107 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001108 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001109 PhoneConfigurationManager.getInstance()
1110 .enablePhone(request.phone, enable, onCompleted);
1111 break;
1112 case EVENT_ENABLE_MODEM_DONE:
1113 ar = (AsyncResult) msg.obj;
1114 request = (MainThreadRequest) ar.userObj;
1115 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001116 //update the cache as modem status has changed
1117 mPhoneConfigurationManager.addToPhoneStatusCache(
1118 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001119 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001120 notifyRequester(request);
1121 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001122 default:
1123 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1124 break;
1125 }
1126 }
Jake Hambye994d462014-02-03 13:10:13 -08001127
Pengquan Meng0c05b502018-09-06 09:59:22 -07001128 private void notifyRequester(MainThreadRequest request) {
1129 synchronized (request) {
1130 request.notifyAll();
1131 }
1132 }
1133
Jake Hambye994d462014-02-03 13:10:13 -08001134 private void handleNullReturnEvent(Message msg, String command) {
1135 AsyncResult ar = (AsyncResult) msg.obj;
1136 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1137 if (ar.exception == null) {
1138 request.result = true;
1139 } else {
1140 request.result = false;
1141 if (ar.exception instanceof CommandException) {
1142 loge(command + ": CommandException: " + ar.exception);
1143 } else {
1144 loge(command + ": Unknown exception");
1145 }
1146 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001147 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001149 }
1150
1151 /**
1152 * Posts the specified command to be executed on the main thread,
1153 * waits for the request to complete, and returns the result.
1154 * @see #sendRequestAsync
1155 */
1156 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001157 return sendRequest(
1158 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001159 }
1160
1161 /**
1162 * Posts the specified command to be executed on the main thread,
1163 * waits for the request to complete, and returns the result.
1164 * @see #sendRequestAsync
1165 */
1166 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1167 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001168 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001169 }
1170
1171 /**
1172 * Posts the specified command to be executed on the main thread,
1173 * waits for the request to complete, and returns the result.
1174 * @see #sendRequestAsync
1175 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001176 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001177 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001178 }
1179
1180 /**
1181 * Posts the specified command to be executed on the main thread,
1182 * waits for the request to complete, and returns the result.
1183 * @see #sendRequestAsync
1184 */
Nathan Harold92bed182018-10-12 18:16:49 -07001185 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1186 return sendRequest(command, argument, subId, null, workSource);
1187 }
1188
1189 /**
1190 * Posts the specified command to be executed on the main thread,
1191 * waits for the request to complete, and returns the result.
1192 * @see #sendRequestAsync
1193 */
1194 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1195 return sendRequest(
1196 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1197 }
1198
1199 /**
1200 * Posts the specified command to be executed on the main thread,
1201 * waits for the request to complete, and returns the result.
1202 * @see #sendRequestAsync
1203 */
1204 private Object sendRequest(
1205 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001206 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1207 throw new RuntimeException("This method will deadlock if called from the main thread.");
1208 }
1209
Nathan Harold92bed182018-10-12 18:16:49 -07001210 MainThreadRequest request = null;
1211 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1212 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1213 } else if (phone != null) {
1214 request = new MainThreadRequest(argument, phone, workSource);
1215 } else {
1216 request = new MainThreadRequest(argument, subId, workSource);
1217 }
1218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001219 Message msg = mMainThreadHandler.obtainMessage(command, request);
1220 msg.sendToTarget();
1221
1222 // Wait for the request to complete
1223 synchronized (request) {
1224 while (request.result == null) {
1225 try {
1226 request.wait();
1227 } catch (InterruptedException e) {
1228 // Do nothing, go back and wait until the request is complete
1229 }
1230 }
1231 }
1232 return request.result;
1233 }
1234
1235 /**
1236 * Asynchronous ("fire and forget") version of sendRequest():
1237 * Posts the specified command to be executed on the main thread, and
1238 * returns immediately.
1239 * @see #sendRequest
1240 */
1241 private void sendRequestAsync(int command) {
1242 mMainThreadHandler.sendEmptyMessage(command);
1243 }
1244
1245 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001246 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001247 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001248 */
1249 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001250 sendRequestAsync(command, argument, null, null);
1251 }
1252
1253 /**
1254 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1255 * @see {@link #sendRequest(int,Object)}
1256 */
1257 private void sendRequestAsync(
1258 int command, Object argument, Phone phone, WorkSource workSource) {
1259 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001260 Message msg = mMainThreadHandler.obtainMessage(command, request);
1261 msg.sendToTarget();
1262 }
1263
1264 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 * Initialize the singleton PhoneInterfaceManager instance.
1266 * This is only done once, at startup, from PhoneApp.onCreate().
1267 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001268 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001269 synchronized (PhoneInterfaceManager.class) {
1270 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001271 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001272 } else {
1273 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1274 }
1275 return sInstance;
1276 }
1277 }
1278
1279 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001280 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001281 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001282 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001283 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001284 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1285 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001286 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001287 mTelephonySharedPreferences =
1288 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001289 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001290 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001291
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001292 publish();
1293 }
1294
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001295 private Phone getDefaultPhone() {
1296 Phone thePhone = getPhone(getDefaultSubscription());
1297 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1298 }
1299
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001300 private void publish() {
1301 if (DBG) log("publish: " + this);
1302
1303 ServiceManager.addService("phone", this);
1304 }
1305
Stuart Scott584921c2015-01-15 17:10:34 -08001306 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu73b078d2019-02-28 12:03:40 -08001307 if (request.phone != null) {
1308 return request.phone;
1309 } else {
1310 return getPhoneFromSubId(request.subId);
1311 }
1312 }
1313
1314 private Phone getPhoneFromSubId(int subId) {
1315 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1316 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001317 }
1318
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001319 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1320 Phone phone = getPhoneFromRequest(request);
1321 return phone == null ? null :
1322 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1323 }
1324
Wink Saville36469e72014-06-11 15:17:00 -07001325 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001326 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001327 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001329
1330 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001331 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001332 }
1333
Wink Savilleb564aae2014-10-23 10:18:09 -07001334 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001335 if (DBG) log("dial: " + number);
1336 // No permission check needed here: This is just a wrapper around the
1337 // ACTION_DIAL intent, which is available to any app since it puts up
1338 // the UI before it does anything.
1339
Malcolm Chend965c8b2018-02-28 15:00:40 -08001340 final long identity = Binder.clearCallingIdentity();
1341 try {
1342 String url = createTelUrl(number);
1343 if (url == null) {
1344 return;
1345 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001346
Malcolm Chend965c8b2018-02-28 15:00:40 -08001347 // PENDING: should we just silently fail if phone is offhook or ringing?
1348 PhoneConstants.State state = mCM.getState(subId);
1349 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1350 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1351 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1352 mApp.startActivity(intent);
1353 }
1354 } finally {
1355 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001356 }
1357 }
1358
1359 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001360 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001361 }
1362
Wink Savilleb564aae2014-10-23 10:18:09 -07001363 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001364 if (DBG) log("call: " + number);
1365
1366 // This is just a wrapper around the ACTION_CALL intent, but we still
1367 // need to do a permission check since we're calling startActivity()
1368 // from the context of the phone app.
1369 enforceCallPermission();
1370
1371 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1372 != AppOpsManager.MODE_ALLOWED) {
1373 return;
1374 }
1375
Malcolm Chend965c8b2018-02-28 15:00:40 -08001376 final long identity = Binder.clearCallingIdentity();
1377 try {
1378 String url = createTelUrl(number);
1379 if (url == null) {
1380 return;
1381 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001382
Malcolm Chend965c8b2018-02-28 15:00:40 -08001383 boolean isValid = false;
1384 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1385 if (slist != null) {
1386 for (SubscriptionInfo subInfoRecord : slist) {
1387 if (subInfoRecord.getSubscriptionId() == subId) {
1388 isValid = true;
1389 break;
1390 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001391 }
Wink Saville08874612014-08-31 19:19:58 -07001392 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001393 if (!isValid) {
1394 return;
1395 }
Wink Saville08874612014-08-31 19:19:58 -07001396
Malcolm Chend965c8b2018-02-28 15:00:40 -08001397 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1398 intent.putExtra(SUBSCRIPTION_KEY, subId);
1399 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1400 mApp.startActivity(intent);
1401 } finally {
1402 Binder.restoreCallingIdentity(identity);
1403 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001404 }
1405
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001406 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001407 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001408 }
1409
Wink Savilleb564aae2014-10-23 10:18:09 -07001410 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001411 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001412 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1413 }
1414
1415 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001416 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001417 }
1418
Wink Savilleb564aae2014-10-23 10:18:09 -07001419 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001420 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001421 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1422 }
1423
1424 /** {@hide} */
1425 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001426 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001427 }
1428
Wink Savilleb564aae2014-10-23 10:18:09 -07001429 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001430 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001431
1432 final long identity = Binder.clearCallingIdentity();
1433 try {
1434 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1435 checkSimPin.start();
1436 return checkSimPin.unlockSim(null, pin);
1437 } finally {
1438 Binder.restoreCallingIdentity(identity);
1439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001440 }
1441
Wink Saville9de0f752013-10-22 19:04:03 -07001442 /** {@hide} */
1443 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001444 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001445 }
1446
Wink Savilleb564aae2014-10-23 10:18:09 -07001447 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001449
1450 final long identity = Binder.clearCallingIdentity();
1451 try {
1452 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1453 checkSimPuk.start();
1454 return checkSimPuk.unlockSim(puk, pin);
1455 } finally {
1456 Binder.restoreCallingIdentity(identity);
1457 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001458 }
1459
1460 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001461 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001462 * a synchronous one.
1463 */
1464 private static class UnlockSim extends Thread {
1465
1466 private final IccCard mSimCard;
1467
1468 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001469 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1470 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001471
1472 // For replies from SimCard interface
1473 private Handler mHandler;
1474
1475 // For async handler to identify request type
1476 private static final int SUPPLY_PIN_COMPLETE = 100;
1477
1478 public UnlockSim(IccCard simCard) {
1479 mSimCard = simCard;
1480 }
1481
1482 @Override
1483 public void run() {
1484 Looper.prepare();
1485 synchronized (UnlockSim.this) {
1486 mHandler = new Handler() {
1487 @Override
1488 public void handleMessage(Message msg) {
1489 AsyncResult ar = (AsyncResult) msg.obj;
1490 switch (msg.what) {
1491 case SUPPLY_PIN_COMPLETE:
1492 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1493 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001494 mRetryCount = msg.arg1;
1495 if (ar.exception != null) {
1496 if (ar.exception instanceof CommandException &&
1497 ((CommandException)(ar.exception)).getCommandError()
1498 == CommandException.Error.PASSWORD_INCORRECT) {
1499 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1500 } else {
1501 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1502 }
1503 } else {
1504 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 mDone = true;
1507 UnlockSim.this.notifyAll();
1508 }
1509 break;
1510 }
1511 }
1512 };
1513 UnlockSim.this.notifyAll();
1514 }
1515 Looper.loop();
1516 }
1517
1518 /*
1519 * Use PIN or PUK to unlock SIM card
1520 *
1521 * If PUK is null, unlock SIM card with PIN
1522 *
1523 * If PUK is not null, unlock SIM card with PUK and set PIN code
1524 */
Wink Saville9de0f752013-10-22 19:04:03 -07001525 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526
1527 while (mHandler == null) {
1528 try {
1529 wait();
1530 } catch (InterruptedException e) {
1531 Thread.currentThread().interrupt();
1532 }
1533 }
1534 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1535
1536 if (puk == null) {
1537 mSimCard.supplyPin(pin, callback);
1538 } else {
1539 mSimCard.supplyPuk(puk, pin, callback);
1540 }
1541
1542 while (!mDone) {
1543 try {
1544 Log.d(LOG_TAG, "wait for done");
1545 wait();
1546 } catch (InterruptedException e) {
1547 // Restore the interrupted status
1548 Thread.currentThread().interrupt();
1549 }
1550 }
1551 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001552 int[] resultArray = new int[2];
1553 resultArray[0] = mResult;
1554 resultArray[1] = mRetryCount;
1555 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001556 }
1557 }
1558
1559 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001560 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001561
1562 }
1563
Wink Savilleb564aae2014-10-23 10:18:09 -07001564 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 // No permission check needed here: this call is harmless, and it's
1566 // needed for the ServiceState.requestStateUpdate() call (which is
1567 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001568 final long identity = Binder.clearCallingIdentity();
1569 try {
1570 final Phone phone = getPhone(subId);
1571 if (phone != null) {
1572 phone.updateServiceLocation();
1573 }
1574 } finally {
1575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001576 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 }
1578
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001579 @Override
1580 public boolean isRadioOn(String callingPackage) {
1581 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001582 }
1583
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001584 @Override
1585 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001586 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001587 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001588 return false;
1589 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001590
1591 final long identity = Binder.clearCallingIdentity();
1592 try {
1593 return isRadioOnForSubscriber(subId);
1594 } finally {
1595 Binder.restoreCallingIdentity(identity);
1596 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001597 }
1598
1599 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001600 final long identity = Binder.clearCallingIdentity();
1601 try {
1602 final Phone phone = getPhone(subId);
1603 if (phone != null) {
1604 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1605 } else {
1606 return false;
1607 }
1608 } finally {
1609 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001610 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001611 }
1612
1613 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001614 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001615 }
Wink Saville36469e72014-06-11 15:17:00 -07001616
Wink Savilleb564aae2014-10-23 10:18:09 -07001617 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001618 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001619
1620 final long identity = Binder.clearCallingIdentity();
1621 try {
1622 final Phone phone = getPhone(subId);
1623 if (phone != null) {
1624 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1625 }
1626 } finally {
1627 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001628 }
Wink Saville36469e72014-06-11 15:17:00 -07001629 }
1630
1631 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001632 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001633 }
1634
Wink Savilleb564aae2014-10-23 10:18:09 -07001635 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001636 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001637
1638 final long identity = Binder.clearCallingIdentity();
1639 try {
1640 final Phone phone = getPhone(subId);
1641 if (phone == null) {
1642 return false;
1643 }
1644 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1645 toggleRadioOnOffForSubscriber(subId);
1646 }
1647 return true;
1648 } finally {
1649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001651 }
Wink Saville36469e72014-06-11 15:17:00 -07001652
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001653 public boolean needMobileRadioShutdown() {
1654 /*
1655 * If any of the Radios are available, it will need to be
1656 * shutdown. So return true if any Radio is available.
1657 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001658 final long identity = Binder.clearCallingIdentity();
1659 try {
1660 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1661 Phone phone = PhoneFactory.getPhone(i);
1662 if (phone != null && phone.isRadioAvailable()) return true;
1663 }
1664 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1665 return false;
1666 } finally {
1667 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001668 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001669 }
1670
Malcolm Chend965c8b2018-02-28 15:00:40 -08001671 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001672 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001673 enforceModifyPermission();
1674
1675 final long identity = Binder.clearCallingIdentity();
1676 try {
1677 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1678 logv("Shutting down Phone " + i);
1679 shutdownRadioUsingPhoneId(i);
1680 }
1681 } finally {
1682 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001683 }
1684 }
1685
1686 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001687 Phone phone = PhoneFactory.getPhone(phoneId);
1688 if (phone != null && phone.isRadioAvailable()) {
1689 phone.shutdownRadio();
1690 }
1691 }
1692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001694 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001695
1696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1699 if (defaultPhone != null) {
1700 defaultPhone.setRadioPower(turnOn);
1701 return true;
1702 } else {
1703 loge("There's no default phone.");
1704 return false;
1705 }
1706 } finally {
1707 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001708 }
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
1710
Wink Savilleb564aae2014-10-23 10:18:09 -07001711 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001713
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 final Phone phone = getPhone(subId);
1717 if (phone != null) {
1718 phone.setRadioPower(turnOn);
1719 return true;
1720 } else {
1721 return false;
1722 }
1723 } finally {
1724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001726 }
1727
Wink Saville36469e72014-06-11 15:17:00 -07001728 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001729 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001730 public boolean enableDataConnectivity() {
1731 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001732
1733 final long identity = Binder.clearCallingIdentity();
1734 try {
1735 int subId = mSubscriptionController.getDefaultDataSubId();
1736 final Phone phone = getPhone(subId);
1737 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001738 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001739 return true;
1740 } else {
1741 return false;
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001746 }
1747
Wink Saville36469e72014-06-11 15:17:00 -07001748 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001749 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750 public boolean disableDataConnectivity() {
1751 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001752
1753 final long identity = Binder.clearCallingIdentity();
1754 try {
1755 int subId = mSubscriptionController.getDefaultDataSubId();
1756 final Phone phone = getPhone(subId);
1757 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001758 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001759 return true;
1760 } else {
1761 return false;
1762 }
1763 } finally {
1764 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001765 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 }
1767
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001769 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001770 final long identity = Binder.clearCallingIdentity();
1771 try {
1772 final Phone phone = getPhone(subId);
1773 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001774 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001775 } else {
1776 return false;
1777 }
1778 } finally {
1779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001781 }
1782
1783 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001784 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001785 }
1786
pkanwarae03a6b2016-11-06 20:37:09 -08001787 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001788 enforceCallPermission();
1789
1790 final long identity = Binder.clearCallingIdentity();
1791 try {
1792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1793 return;
1794 }
1795 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1796 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1797 } finally {
1798 Binder.restoreCallingIdentity(identity);
1799 }
pkanwar32d516d2016-10-14 19:37:38 -07001800 };
1801
Wink Savilleb564aae2014-10-23 10:18:09 -07001802 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001803 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001804
1805 final long identity = Binder.clearCallingIdentity();
1806 try {
1807 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1808 return false;
1809 }
1810 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1811 } finally {
1812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001814 }
1815
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001817 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001818 }
1819
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001820 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 Phone phone = PhoneFactory.getPhone(slotIndex);
1824 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1825 PhoneConstantConversions.convertCallState(phone.getState());
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Sanket Padawe356d7632015-06-22 14:03:32 -07001831 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001833 final long identity = Binder.clearCallingIdentity();
1834 try {
1835 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1836 if (phone != null) {
1837 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1838 } else {
1839 return PhoneConstantConversions.convertDataState(
1840 PhoneConstants.DataState.DISCONNECTED);
1841 }
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1852 if (phone != null) {
1853 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1854 } else {
1855 return TelephonyManager.DATA_ACTIVITY_NONE;
1856 }
1857 } finally {
1858 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 }
1861
1862 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001863 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001864 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001865 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001866
1867 LocationAccessPolicy.LocationPermissionResult locationResult =
1868 LocationAccessPolicy.checkLocationPermission(mApp,
1869 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1870 .setCallingPackage(callingPackage)
1871 .setCallingPid(Binder.getCallingPid())
1872 .setCallingUid(Binder.getCallingUid())
1873 .setMethod("getCellLocation")
1874 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1875 .build());
1876 switch (locationResult) {
1877 case DENIED_HARD:
1878 throw new SecurityException("Not allowed to access cell location");
1879 case DENIED_SOFT:
1880 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 }
1882
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001883 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001884 final long identity = Binder.clearCallingIdentity();
1885 try {
1886 if (DBG_LOC) log("getCellLocation: is active user");
1887 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001888 int subId = mSubscriptionController.getDefaultDataSubId();
1889 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1890 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001891 return data;
1892 } finally {
1893 Binder.restoreCallingIdentity(identity);
1894 }
Svetoslav64fad262015-04-14 14:35:21 -07001895 }
1896
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001898 public String getNetworkCountryIsoForPhone(int phoneId) {
1899 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1900 // registered cell info, so return a NULL country instead.
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001903 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1904 // Get default phone in this case.
1905 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1906 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001907 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001908 // Todo: fix this when we can get the actual cellular network info when the device
1909 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001910 if (TelephonyManager.NETWORK_TYPE_IWLAN
1911 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1912 return "";
1913 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001914 Phone phone = PhoneFactory.getPhone(phoneId);
1915 if (phone != null) {
1916 ServiceStateTracker sst = phone.getServiceStateTracker();
1917 if (sst != null) {
1918 LocaleTracker lt = sst.getLocaleTracker();
1919 if (lt != null) {
1920 return lt.getCurrentCountry();
1921 }
1922 }
1923 }
1924 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001925 } finally {
1926 Binder.restoreCallingIdentity(identity);
1927 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001928 }
1929
1930 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001932 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001933 }
1934
Sanket Padawe356d7632015-06-22 14:03:32 -07001935 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001936 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 mApp.enforceCallingOrSelfPermission(
1938 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001939
1940 final long identity = Binder.clearCallingIdentity();
1941 try {
1942 final Phone phone = getPhone(subId);
1943 if (phone != null) {
1944 phone.enableLocationUpdates();
1945 }
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001949 }
1950
1951 @Override
1952 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001953 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001954 }
1955
Sanket Padawe356d7632015-06-22 14:03:32 -07001956 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001957 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 mApp.enforceCallingOrSelfPermission(
1959 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001960
1961 final long identity = Binder.clearCallingIdentity();
1962 try {
1963 final Phone phone = getPhone(subId);
1964 if (phone != null) {
1965 phone.disableLocationUpdates();
1966 }
1967 } finally {
1968 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001969 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 }
1971
Nathan Harold31d7ff32018-10-15 20:20:30 -07001972 /**
1973 * Returns the target SDK version number for a given package name.
1974 *
1975 * @return target SDK if the package is found or INT_MAX.
1976 */
1977 private int getTargetSdk(String packageName) {
1978 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001979 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1980 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001981 if (ai != null) return ai.targetSdkVersion;
1982 } catch (PackageManager.NameNotFoundException unexpected) {
1983 }
1984 return Integer.MAX_VALUE;
1985 }
1986
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 @Override
1988 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001989 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1990 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001991 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1992 throw new SecurityException(
1993 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1994 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001995
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1997 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1998 return null;
1999 }
Svetoslav64fad262015-04-14 14:35:21 -07002000
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002001 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002002
Nathan Haroldf180aac2018-06-01 18:43:55 -07002003 List<CellInfo> info = getAllCellInfo(callingPackage);
2004 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005
Nathan Haroldf180aac2018-06-01 18:43:55 -07002006 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2007 for (CellInfo ci : info) {
2008 if (ci instanceof CellInfoGsm) {
2009 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2010 } else if (ci instanceof CellInfoWcdma) {
2011 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002014 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002015 }
2016
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002017 private List<CellInfo> getCachedCellInfo() {
2018 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2019 for (Phone phone : PhoneFactory.getPhones()) {
2020 List<CellInfo> info = phone.getAllCellInfo();
2021 if (info != null) cellInfos.addAll(info);
2022 }
2023 return cellInfos;
2024 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002025
2026 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002027 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002028 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002029 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002030
2031 LocationAccessPolicy.LocationPermissionResult locationResult =
2032 LocationAccessPolicy.checkLocationPermission(mApp,
2033 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2034 .setCallingPackage(callingPackage)
2035 .setCallingPid(Binder.getCallingPid())
2036 .setCallingUid(Binder.getCallingUid())
2037 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002038 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002039 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2040 .build());
2041 switch (locationResult) {
2042 case DENIED_HARD:
2043 throw new SecurityException("Not allowed to access cell info");
2044 case DENIED_SOFT:
2045 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 }
2047
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002048 final int targetSdk = getTargetSdk(callingPackage);
2049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2050 return getCachedCellInfo();
2051 }
2052
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002053 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002054 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002055 final long identity = Binder.clearCallingIdentity();
2056 try {
2057 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2058 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002059 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002060 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002061 if (info != null) cellInfos.addAll(info);
2062 }
2063 return cellInfos;
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 }
2067 }
2068
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002069 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002070 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2071 requestCellInfoUpdateInternal(
2072 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2073 }
2074
2075 @Override
2076 public void requestCellInfoUpdateWithWorkSource(
2077 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2078 enforceModifyPermission();
2079 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2080 }
2081
2082 private void requestCellInfoUpdateInternal(
2083 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002084 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002085 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002086
2087 LocationAccessPolicy.LocationPermissionResult locationResult =
2088 LocationAccessPolicy.checkLocationPermission(mApp,
2089 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2090 .setCallingPackage(callingPackage)
2091 .setCallingPid(Binder.getCallingPid())
2092 .setCallingUid(Binder.getCallingUid())
2093 .setMethod("requestCellInfoUpdate")
2094 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2095 .build());
2096 switch (locationResult) {
2097 case DENIED_HARD:
2098 throw new SecurityException("Not allowed to access cell info");
2099 case DENIED_SOFT:
2100 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002101 }
2102
2103 final Phone phone = getPhone(subId);
2104 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2105
2106 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2107 }
2108
2109 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002111 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002116 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Shishir Agrawala9f32182016-04-12 12:00:16 -07002122 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002123 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002124 Phone phone = PhoneFactory.getPhone(slotIndex);
2125 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002126 return null;
2127 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002128 int subId = phone.getSubId();
2129 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2130 mApp, subId, callingPackage, "getImeiForSlot")) {
2131 return null;
2132 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 return phone.getImei();
2137 } finally {
2138 Binder.restoreCallingIdentity(identity);
2139 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002140 }
2141
2142 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002143 public String getTypeAllocationCodeForSlot(int slotIndex) {
2144 Phone phone = PhoneFactory.getPhone(slotIndex);
2145 String tac = null;
2146 if (phone != null) {
2147 String imei = phone.getImei();
2148 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2149 }
2150 return tac;
2151 }
2152
2153 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002154 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002155 Phone phone = PhoneFactory.getPhone(slotIndex);
2156 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002157 return null;
2158 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002159
Jeff Davidson913390f2018-02-23 17:11:49 -08002160 int subId = phone.getSubId();
2161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2162 mApp, subId, callingPackage, "getMeidForSlot")) {
2163 return null;
2164 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002165
2166 final long identity = Binder.clearCallingIdentity();
2167 try {
2168 return phone.getMeid();
2169 } finally {
2170 Binder.restoreCallingIdentity(identity);
2171 }
Jack Yu2af8d712017-03-15 17:14:14 -07002172 }
2173
2174 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002175 public String getManufacturerCodeForSlot(int slotIndex) {
2176 Phone phone = PhoneFactory.getPhone(slotIndex);
2177 String manufacturerCode = null;
2178 if (phone != null) {
2179 String meid = phone.getMeid();
2180 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2181 }
2182 return manufacturerCode;
2183 }
2184
2185 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002186 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002187 Phone phone = PhoneFactory.getPhone(slotIndex);
2188 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002189 return null;
2190 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002191 int subId = phone.getSubId();
2192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2193 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2194 return null;
2195 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002196
2197 final long identity = Binder.clearCallingIdentity();
2198 try {
2199 return phone.getDeviceSvn();
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002203 }
2204
fionaxu43304da2017-11-27 22:51:16 -08002205 @Override
2206 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 final Phone phone = getPhone(subId);
2210 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2211 } finally {
2212 Binder.restoreCallingIdentity(identity);
2213 }
fionaxu43304da2017-11-27 22:51:16 -08002214 }
2215
2216 @Override
2217 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002218 final long identity = Binder.clearCallingIdentity();
2219 try {
2220 final Phone phone = getPhone(subId);
2221 return phone == null ? null : phone.getCarrierName();
2222 } finally {
2223 Binder.restoreCallingIdentity(identity);
2224 }
fionaxu43304da2017-11-27 22:51:16 -08002225 }
2226
calvinpaneed9ae82018-11-01 19:43:06 +08002227 @Override
chen xua31f22b2019-03-06 15:28:50 -08002228 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
2232 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002233 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002234 } finally {
2235 Binder.restoreCallingIdentity(identity);
2236 }
2237 }
2238
2239 @Override
chen xua31f22b2019-03-06 15:28:50 -08002240 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
2243 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002244 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002245 } finally {
2246 Binder.restoreCallingIdentity(identity);
2247 }
2248 }
2249
chen xu02581692018-11-11 19:03:44 -08002250 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002251 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2252 if (!isSubscriptionMccMnc) {
2253 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2254 }
chen xu02581692018-11-11 19:03:44 -08002255 final Phone phone = PhoneFactory.getPhone(slotIndex);
2256 if (phone == null) {
2257 return TelephonyManager.UNKNOWN_CARRIER_ID;
2258 }
2259 final long identity = Binder.clearCallingIdentity();
2260 try {
2261 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2262 } finally {
2263 Binder.restoreCallingIdentity(identity);
2264 }
2265 }
2266
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002267 //
2268 // Internal helper methods.
2269 //
2270
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002271 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2273 *
2274 * @throws SecurityException if the caller does not have the required permission
2275 */
2276 private void enforceModifyPermission() {
2277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2278 }
2279
2280 /**
2281 * Make sure the caller has the CALL_PHONE permission.
2282 *
2283 * @throws SecurityException if the caller does not have the required permission
2284 */
2285 private void enforceCallPermission() {
2286 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2287 }
2288
Stuart Scott8eef64f2015-04-08 15:13:54 -07002289 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002290 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002291 "ConnectivityService");
2292 }
2293
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002294 private String createTelUrl(String number) {
2295 if (TextUtils.isEmpty(number)) {
2296 return null;
2297 }
2298
Jake Hambye994d462014-02-03 13:10:13 -08002299 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
Ihab Awadf9e92732013-12-05 18:02:52 -08002302 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2304 }
2305
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002306 private static void logv(String msg) {
2307 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2308 }
2309
Ihab Awadf9e92732013-12-05 18:02:52 -08002310 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002311 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2312 }
2313
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002314 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002315 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002316 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002317 }
2318
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002320 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002321 final long identity = Binder.clearCallingIdentity();
2322 try {
2323 final Phone phone = PhoneFactory.getPhone(slotIndex);
2324 if (phone == null) {
2325 return PhoneConstants.PHONE_TYPE_NONE;
2326 } else {
2327 return phone.getPhoneType();
2328 }
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 }
2333
2334 /**
2335 * Returns the CDMA ERI icon index to display
2336 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002337 @Override
2338 public int getCdmaEriIconIndex(String callingPackage) {
2339 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002340 }
2341
Sanket Padawe356d7632015-06-22 14:03:32 -07002342 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002343 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002344 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002345 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002346 return -1;
2347 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002348
2349 final long identity = Binder.clearCallingIdentity();
2350 try {
2351 final Phone phone = getPhone(subId);
2352 if (phone != null) {
2353 return phone.getCdmaEriIconIndex();
2354 } else {
2355 return -1;
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 /**
2363 * Returns the CDMA ERI icon mode,
2364 * 0 - ON
2365 * 1 - FLASHING
2366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002367 @Override
2368 public int getCdmaEriIconMode(String callingPackage) {
2369 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002370 }
2371
Sanket Padawe356d7632015-06-22 14:03:32 -07002372 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002373 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002375 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002376 return -1;
2377 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002378
2379 final long identity = Binder.clearCallingIdentity();
2380 try {
2381 final Phone phone = getPhone(subId);
2382 if (phone != null) {
2383 return phone.getCdmaEriIconMode();
2384 } else {
2385 return -1;
2386 }
2387 } finally {
2388 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 }
2391
2392 /**
2393 * Returns the CDMA ERI text,
2394 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002395 @Override
2396 public String getCdmaEriText(String callingPackage) {
2397 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002398 }
2399
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002403 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002404 return null;
2405 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002406
2407 final long identity = Binder.clearCallingIdentity();
2408 try {
2409 final Phone phone = getPhone(subId);
2410 if (phone != null) {
2411 return phone.getCdmaEriText();
2412 } else {
2413 return null;
2414 }
2415 } finally {
2416 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002417 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418 }
2419
2420 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002421 * Returns the CDMA MDN.
2422 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002424 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002425 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2426 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002427
2428 final long identity = Binder.clearCallingIdentity();
2429 try {
2430 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002431 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002432 return phone.getLine1Number();
2433 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002434 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002435 return null;
2436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002439 }
2440 }
2441
2442 /**
2443 * Returns the CDMA MIN.
2444 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002445 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002446 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2448 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002449
2450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = getPhone(subId);
2453 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2454 return phone.getCdmaMin();
2455 } else {
2456 return null;
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002460 }
2461 }
2462
Hall Liud892bec2018-11-30 14:51:45 -08002463 @Override
2464 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2465 INumberVerificationCallback callback, String callingPackage) {
2466 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2467 != PERMISSION_GRANTED) {
2468 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2469 }
2470 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2471
2472 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2473 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2474 throw new SecurityException("Calling package must be configured in the device config");
2475 }
2476
2477 if (range == null) {
2478 throw new NullPointerException("Range must be non-null");
2479 }
2480
2481 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002482 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002483
2484 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2485 }
2486
Junda Liuca05d5d2014-08-14 22:36:34 -07002487 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 * Returns true if CDMA provisioning needs to run.
2489 */
2490 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002491 final long identity = Binder.clearCallingIdentity();
2492 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002493 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002494 } finally {
2495 Binder.restoreCallingIdentity(identity);
2496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498
2499 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002500 * Sets the voice mail number of a given subId.
2501 */
2502 @Override
2503 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002504 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002505
2506 final long identity = Binder.clearCallingIdentity();
2507 try {
2508 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2509 new Pair<String, String>(alphaTag, number), new Integer(subId));
2510 return success;
2511 } finally {
2512 Binder.restoreCallingIdentity(identity);
2513 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002514 }
2515
Ta-wei Yen87c49842016-05-13 21:19:52 -07002516 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002517 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2518 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002519 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002520 if (!TextUtils.equals(callingPackage, systemDialer)) {
2521 throw new SecurityException("caller must be system dialer");
2522 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002523
2524 final long identity = Binder.clearCallingIdentity();
2525 try {
2526 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2527 if (phoneAccountHandle == null) {
2528 return null;
2529 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002530 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002533 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002534 }
2535
2536 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002537 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002540 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002541 return null;
2542 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002543
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002544 final long identity = Binder.clearCallingIdentity();
2545 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002546 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002547 } finally {
2548 Binder.restoreCallingIdentity(identity);
2549 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002550 }
2551
2552 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002553 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2554 VisualVoicemailSmsFilterSettings settings) {
2555 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002560 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002561 } finally {
2562 Binder.restoreCallingIdentity(identity);
2563 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002564 }
2565
2566 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002567 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2568 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002573 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002574 } finally {
2575 Binder.restoreCallingIdentity(identity);
2576 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002577 }
2578
2579 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002580 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2581 String callingPackage, int subId) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002583
2584 final long identity = Binder.clearCallingIdentity();
2585 try {
2586 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002587 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002588 } finally {
2589 Binder.restoreCallingIdentity(identity);
2590 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002591 }
2592
2593 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002594 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002595 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002596
2597 final long identity = Binder.clearCallingIdentity();
2598 try {
2599 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002600 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002604 }
2605
2606 @Override
2607 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2608 String number, int port, String text, PendingIntent sentIntent) {
2609 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002610 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002611 enforceSendSmsPermission();
2612 // Make the calls as the phone process.
2613 final long identity = Binder.clearCallingIdentity();
2614 try {
2615 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2616 if (port == 0) {
2617 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2618 sentIntent, null, false);
2619 } else {
2620 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2621 smsManager.sendDataMessageWithSelfPermissions(number, null,
2622 (short) port, data, sentIntent, null);
2623 }
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002627 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002628 /**
fionaxu0152e512016-11-14 13:36:14 -08002629 * Sets the voice activation state of a given subId.
2630 */
2631 @Override
2632 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2634 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002635
2636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 final Phone phone = getPhone(subId);
2639 if (phone != null) {
2640 phone.setVoiceActivationState(activationState);
2641 } else {
2642 loge("setVoiceActivationState fails with invalid subId: " + subId);
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002646 }
2647 }
2648
2649 /**
2650 * Sets the data activation state of a given subId.
2651 */
2652 @Override
2653 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002654 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2655 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002656
2657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 if (phone != null) {
2661 phone.setDataActivationState(activationState);
2662 } else {
2663 loge("setVoiceActivationState fails with invalid subId: " + subId);
2664 }
2665 } finally {
2666 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002667 }
2668 }
2669
2670 /**
2671 * Returns the voice activation state of a given subId.
2672 */
2673 @Override
2674 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002675 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002676
fionaxu0152e512016-11-14 13:36:14 -08002677 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002678 final long identity = Binder.clearCallingIdentity();
2679 try {
2680 if (phone != null) {
2681 return phone.getVoiceActivationState();
2682 } else {
2683 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2684 }
2685 } finally {
2686 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002687 }
2688 }
2689
2690 /**
2691 * Returns the data activation state of a given subId.
2692 */
2693 @Override
2694 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002695 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002696
fionaxu0152e512016-11-14 13:36:14 -08002697 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 if (phone != null) {
2701 return phone.getDataActivationState();
2702 } else {
2703 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2704 }
2705 } finally {
2706 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002707 }
2708 }
2709
2710 /**
Wink Saville36469e72014-06-11 15:17:00 -07002711 * Returns the unread count of voicemails for a subId
2712 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002714 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2716 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2717 return 0;
2718 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
2721 final Phone phone = getPhone(subId);
2722 if (phone != null) {
2723 return phone.getVoiceMessageCount();
2724 } else {
2725 return 0;
2726 }
2727 } finally {
2728 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 }
2731
2732 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002733 * returns true, if the device is in a state where both voice and data
2734 * are supported simultaneously. This can change based on location or network condition.
2735 */
2736 @Override
2737 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002738 final long identity = Binder.clearCallingIdentity();
2739 try {
2740 final Phone phone = getPhone(subId);
2741 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002745 }
2746
2747 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002748 * Send the dialer code if called from the current default dialer or the caller has
2749 * carrier privilege.
2750 * @param inputCode The dialer code to send
2751 */
2752 @Override
2753 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002754 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002755 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002756 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2757 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002758 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002759 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2760 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002761 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002762
2763 final long identity = Binder.clearCallingIdentity();
2764 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002765 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002766 } finally {
2767 Binder.restoreCallingIdentity(identity);
2768 }
fionaxu235cc5e2017-03-06 22:25:57 -08002769 }
2770
2771 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002772 * Returns the data network type.
2773 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 *
2775 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2776 */
2777 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002778 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 final Phone phone = getPhone(getDefaultSubscription());
2782 if (phone != null) {
2783 return phone.getServiceState().getDataNetworkType();
2784 } else {
2785 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2786 }
2787 } finally {
2788 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002789 }
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Pengquan Meng0c05b502018-09-06 09:59:22 -07002792 @Override
2793 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002794 if (!isActiveSubscription(subId)) {
2795 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2796 }
2797
Pengquan Meng0c05b502018-09-06 09:59:22 -07002798 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2799 }
2800
Brad Ebinger4c460712018-10-01 10:40:55 -07002801 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002802 public boolean isInEmergencySmsMode() {
2803 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2804 final long identity = Binder.clearCallingIdentity();
2805 try {
2806 for (Phone phone : PhoneFactory.getPhones()) {
2807 if (phone.isInEmergencySmsMode()) {
2808 return true;
2809 }
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
2813 }
2814 return false;
2815 }
2816
2817 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002818 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2819 throws RemoteException {
2820 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002821 final long token = Binder.clearCallingIdentity();
2822 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002823 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002824 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002825 .addRegistrationCallbackForSubscription(c, subId);
2826 } finally {
2827 Binder.restoreCallingIdentity(token);
2828 }
2829 }
2830
2831 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002832 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2833 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002834 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2835 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2836 }
2837 Binder.withCleanCallingIdentity(() -> {
2838 try {
2839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002841 .removeRegistrationCallbackForSubscription(c, subId);
2842 } catch (IllegalArgumentException e) {
2843 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2844 + "is inactive, ignoring unregister.");
2845 // If the subscription is no longer active, just return, since the callback
2846 // will already have been removed internally.
2847 }
2848 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002849 }
2850
2851 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002852 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2853 throws RemoteException {
2854 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2856 final long token = Binder.clearCallingIdentity();
2857 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002858 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002859 .addCapabilitiesCallbackForSubscription(c, subId);
2860 } finally {
2861 Binder.restoreCallingIdentity(token);
2862 }
2863 }
2864
2865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002866 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2867 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868
2869 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2870 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2871 }
2872 Binder.withCleanCallingIdentity(() -> {
2873 try {
2874 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002875 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002876 .removeCapabilitiesCallbackForSubscription(c, subId);
2877 } catch (IllegalArgumentException e) {
2878 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2879 + "is inactive, ignoring unregister.");
2880 // If the subscription is no longer active, just return, since the callback
2881 // will already have been removed internally.
2882 }
2883 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002884 }
2885
2886 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002887 public boolean isCapable(int subId, int capability, int regTech) {
2888 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2890 final long token = Binder.clearCallingIdentity();
2891 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002892 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002893 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2894 } catch (ImsException e) {
2895 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2896 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002897 } catch (IllegalArgumentException e) {
2898 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2899 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002900 } finally {
2901 Binder.restoreCallingIdentity(token);
2902 }
2903 }
2904
2905 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002906 public boolean isAvailable(int subId, int capability, int regTech) {
2907 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002908 final long token = Binder.clearCallingIdentity();
2909 try {
2910 Phone phone = getPhone(subId);
2911 if (phone == null) return false;
2912 return phone.isImsCapabilityAvailable(capability, regTech);
2913 } finally {
2914 Binder.restoreCallingIdentity(token);
2915 }
2916 }
2917
2918 @Override
2919 public boolean isAdvancedCallingSettingEnabled(int subId) {
2920 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2922 final long token = Binder.clearCallingIdentity();
2923 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002924 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002925 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2926 } finally {
2927 Binder.restoreCallingIdentity(token);
2928 }
2929 }
2930
2931 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002932 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002934 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002935 final long identity = Binder.clearCallingIdentity();
2936 try {
2937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002938 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002939 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2940 } finally {
2941 Binder.restoreCallingIdentity(identity);
2942 }
2943 }
2944
2945 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002946 public boolean isVtSettingEnabled(int subId) {
2947 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002951 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002952 getSlotIndexOrException(subId)).isVtEnabledByUser();
2953 } finally {
2954 Binder.restoreCallingIdentity(identity);
2955 }
2956 }
2957
2958 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002959 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002961 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002965 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
2969 }
2970
2971 @Override
2972 public boolean isVoWiFiSettingEnabled(int subId) {
2973 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002977 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002978 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2979 } finally {
2980 Binder.restoreCallingIdentity(identity);
2981 }
2982 }
2983
2984 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002985 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002987 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002991 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
2997 @Override
2998 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2999 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003003 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003004 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
3008 }
3009
3010 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08003011 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07003012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08003013 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07003014 final long identity = Binder.clearCallingIdentity();
3015 try {
3016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003017 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003018 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
3019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
3022 }
3023
3024 @Override
3025 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3026 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3027 "setVoWiFiNonPersistent");
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003031 boolean isRoaming = TelephonyManager.from(
3032 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003033 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003034 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003035 } finally {
3036 Binder.restoreCallingIdentity(identity);
3037 }
3038 }
3039
3040 @Override
3041 public int getVoWiFiModeSetting(int subId) {
3042 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3043 final long identity = Binder.clearCallingIdentity();
3044 try {
3045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003046 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003047 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3048 } finally {
3049 Binder.restoreCallingIdentity(identity);
3050 }
3051 }
3052
3053 @Override
3054 public void setVoWiFiModeSetting(int subId, int mode) {
3055 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3056 "setVoWiFiModeSetting");
3057 final long identity = Binder.clearCallingIdentity();
3058 try {
3059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003060 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003061 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3062 } finally {
3063 Binder.restoreCallingIdentity(identity);
3064 }
3065 }
3066
3067 @Override
3068 public int getVoWiFiRoamingModeSetting(int subId) {
3069 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3070 final long identity = Binder.clearCallingIdentity();
3071 try {
3072 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003073 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3083 "setVoWiFiRoamingModeSetting");
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003087 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003088 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
3091 }
3092 }
3093
3094 @Override
3095 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3097 "setRttCapabilityEnabled");
3098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003101 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003102 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
3109 public boolean isTtyOverVolteEnabled(int subId) {
3110 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003114 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003115 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003121 @Override
3122 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3123 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003127 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003128 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003129 } finally {
3130 Binder.restoreCallingIdentity(identity);
3131 }
3132 }
3133
3134 @Override
3135 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3136 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3137 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003138 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3139 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3140 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003141 try {
3142 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003143 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003144 .removeProvisioningCallbackForSubscription(callback, subId);
3145 } catch (IllegalArgumentException e) {
3146 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3147 + "is inactive, ignoring unregister.");
3148 // If the subscription is no longer active, just return, since the callback will already
3149 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003150 } finally {
3151 Binder.restoreCallingIdentity(identity);
3152 }
3153 }
3154
3155 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003156 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3157 boolean isProvisioned) {
3158 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3159 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3160 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3161 }
3162 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3163 "setProvisioningStatusForCapability");
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3167 Phone phone = getPhone(subId);
3168 if (phone == null) {
3169 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3170 + subId);
3171 return;
3172 }
3173 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3174 return;
3175 }
3176
3177 // this capability requires provisioning, route to the correct API.
3178 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3179 switch (capability) {
3180 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3181 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3182 ims.setVolteProvisioned(isProvisioned);
3183 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3184 ims.setWfcProvisioned(isProvisioned);
3185 }
3186 break;
3187 }
3188 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3189 // There is currently no difference in VT provisioning type.
3190 ims.setVtProvisioned(isProvisioned);
3191 break;
3192 }
3193 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3194 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3195 // change the capability of the feature instead if needed.
3196 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3197 == isProvisioned) {
3198 // No change in provisioning.
3199 return;
3200 }
3201 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3202 try {
3203 ims.changeMmTelCapability(capability, tech, isProvisioned);
3204 } catch (ImsException e) {
3205 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3206 + ", Exception" + e.getMessage());
3207 }
3208 break;
3209 }
3210 default: {
3211 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3212 + capability + "', which does not require provisioning.");
3213 }
3214 }
3215
3216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
3219 }
3220
3221 @Override
3222 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3223 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3224 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3225 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3226 }
3227 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 Phone phone = getPhone(subId);
3232 if (phone == null) {
3233 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3234 + subId);
3235 // We will fail with "true" as the provisioning status because this is the default
3236 // if we do not require provisioning.
3237 return true;
3238 }
3239
3240 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3241 return true;
3242 }
3243
3244 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3245 switch (capability) {
3246 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3247 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3248 return ims.isVolteProvisionedOnDevice();
3249 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3250 return ims.isWfcProvisionedOnDevice();
3251 }
3252 // This should never happen, since we are checking tech above to make sure it
3253 // is either LTE or IWLAN.
3254 throw new IllegalArgumentException("Invalid radio technology for voice "
3255 + "capability.");
3256 }
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3258 // There is currently no difference in VT provisioning type.
3259 return ims.isVtProvisionedOnDevice();
3260 }
3261 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3262 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3263 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3264 }
3265 default: {
3266 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3267 + capability + "', which does not require provisioning.");
3268 }
3269 }
3270
3271 } finally {
3272 Binder.restoreCallingIdentity(identity);
3273 }
3274 }
3275
3276 @Override
3277 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3278 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3279 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3280 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3281 }
3282 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3283 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3284 return (provisionedBits & capability) > 0;
3285 }
3286
3287 @Override
3288 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3289 boolean isProvisioned) {
3290 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3291 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3292 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3293 }
3294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3295 "setProvisioningStatusForCapability");
3296 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3297 // If the current provisioning status for capability already matches isProvisioned,
3298 // do nothing.
3299 if (((provisionedBits & capability) > 0) == isProvisioned) {
3300 return;
3301 }
3302 if (isProvisioned) {
3303 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3304 } else {
3305 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3306 }
3307 }
3308
3309 /**
3310 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3311 * technology. The bitfield should mirror the bitfield defined by
3312 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3313 */
3314 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3315 String key = getMmTelProvisioningKey(subId, tech);
3316 // Default is no capabilities are provisioned.
3317 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3318 }
3319
3320 /**
3321 * Sets the MmTel capability provisioning bitfield (defined by
3322 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3323 * technology specified.
3324 *
3325 * Note: This is a synchronous command and should not be called on UI thread.
3326 */
3327 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3328 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3329 String key = getMmTelProvisioningKey(subId, tech);
3330 editor.putInt(key, newField);
3331 editor.commit();
3332 }
3333
3334 private static String getMmTelProvisioningKey(int subId, int tech) {
3335 // resulting key is provision_ims_mmtel_{subId}_{tech}
3336 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3337 }
3338
3339 /**
3340 * Query CarrierConfig to see if the specified capability requires provisioning for the
3341 * carrier associated with the subscription id.
3342 */
3343 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3344 int capability) {
3345 CarrierConfigManager configManager = new CarrierConfigManager(context);
3346 PersistableBundle c = configManager.getConfigForSubId(subId);
3347 boolean requireUtProvisioning = c.getBoolean(
3348 // By default, this config is true (even if there is no SIM). We also check to make
3349 // sure the subscription needs provisioning here, so we do not need to check for
3350 // the no-SIM case, where we would normally shortcut this to false.
3351 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3352 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3353 false);
3354 boolean requireVoiceVtProvisioning = c.getBoolean(
3355 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3356
3357 // First check to make sure that the capability requires provisioning.
3358 switch (capability) {
3359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3360 // intentional fallthrough
3361 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3362 if (requireVoiceVtProvisioning) {
3363 // Voice and Video requires provisioning
3364 return true;
3365 }
3366 break;
3367 }
3368 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3369 if (requireUtProvisioning) {
3370 // UT requires provisioning
3371 return true;
3372 }
3373 break;
3374 }
3375 }
3376 return false;
3377 }
3378
3379 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003380 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003381 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3382 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3383 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003384 enforceReadPrivilegedPermission("getImsProvisioningInt");
3385 final long identity = Binder.clearCallingIdentity();
3386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003388 int slotId = getSlotIndex(subId);
3389 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3390 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3391 + subId + "' for key:" + key);
3392 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3393 }
3394 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003396 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3397 + subId + "' for key:" + key);
3398 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
3402 }
3403
3404 @Override
3405 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003406 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3407 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3408 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003409 enforceReadPrivilegedPermission("getImsProvisioningString");
3410 final long identity = Binder.clearCallingIdentity();
3411 try {
3412 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 int slotId = getSlotIndex(subId);
3414 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3415 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3416 + subId + "' for key:" + key);
3417 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3418 }
3419 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003420 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003421 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3422 + subId + "' for key:" + key);
3423 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003424 } finally {
3425 Binder.restoreCallingIdentity(identity);
3426 }
3427 }
3428
3429 @Override
3430 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3433 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003434 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3435 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003436 final long identity = Binder.clearCallingIdentity();
3437 try {
3438 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003439 int slotId = getSlotIndex(subId);
3440 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3441 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3442 + subId + "' for key:" + key);
3443 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3444 }
3445 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003446 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003447 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3448 + "' for key:" + key);
3449 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
3453 }
3454
3455 @Override
3456 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3458 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3459 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3461 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003465 int slotId = getSlotIndex(subId);
3466 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3467 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3468 + subId + "' for key:" + key);
3469 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3470 }
3471 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003472 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003473 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3474 + "' for key:" + key);
3475 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003476 } finally {
3477 Binder.restoreCallingIdentity(identity);
3478 }
3479 }
3480
Brad Ebinger4c460712018-10-01 10:40:55 -07003481 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3482 int slotId = SubscriptionManager.getSlotIndex(subId);
3483 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003484 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003485 }
3486 return slotId;
3487 }
3488
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003489 private int getSlotIndex(int subId) {
3490 int slotId = SubscriptionManager.getSlotIndex(subId);
3491 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3492 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3493 }
3494 return slotId;
3495 }
3496
Wink Saville36469e72014-06-11 15:17:00 -07003497 /**
3498 * Returns the network type for a subId
3499 */
3500 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003501 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003502 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003503 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3505 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003506
Malcolm Chend965c8b2018-02-28 15:00:40 -08003507 final long identity = Binder.clearCallingIdentity();
3508 try {
3509 final Phone phone = getPhone(subId);
3510 if (phone != null) {
3511 return phone.getServiceState().getDataNetworkType();
3512 } else {
3513 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3514 }
3515 } finally {
3516 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003517 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003518 }
3519
3520 /**
3521 * Returns the data network type
3522 */
3523 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003524 public int getDataNetworkType(String callingPackage) {
3525 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003526 }
3527
3528 /**
3529 * Returns the data network type for a subId
3530 */
3531 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003532 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003533 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003534 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003535 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3536 }
3537
Malcolm Chend965c8b2018-02-28 15:00:40 -08003538 final long identity = Binder.clearCallingIdentity();
3539 try {
3540 final Phone phone = getPhone(subId);
3541 if (phone != null) {
3542 return phone.getServiceState().getDataNetworkType();
3543 } else {
3544 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3545 }
3546 } finally {
3547 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003548 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003549 }
3550
3551 /**
Wink Saville36469e72014-06-11 15:17:00 -07003552 * Returns the Voice network type for a subId
3553 */
3554 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003555 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003557 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003558 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3559 }
3560
Malcolm Chend965c8b2018-02-28 15:00:40 -08003561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 final Phone phone = getPhone(subId);
3564 if (phone != null) {
3565 return phone.getServiceState().getVoiceNetworkType();
3566 } else {
3567 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3568 }
3569 } finally {
3570 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003571 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003572 }
3573
3574 /**
3575 * @return true if a ICC card is present
3576 */
3577 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003578 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003579 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3580 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003581 }
3582
3583 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003584 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003585 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003586 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003587 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 final Phone phone = PhoneFactory.getPhone(slotIndex);
3591 if (phone != null) {
3592 return phone.getIccCard().hasIccCard();
3593 } else {
3594 return false;
3595 }
3596 } finally {
3597 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003599 }
3600
3601 /**
3602 * Return if the current radio is LTE on CDMA. This
3603 * is a tri-state return value as for a period of time
3604 * the mode may be unknown.
3605 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003606 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003607 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003608 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003609 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003610 @Override
3611 public int getLteOnCdmaMode(String callingPackage) {
3612 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003613 }
3614
Sanket Padawe356d7632015-06-22 14:03:32 -07003615 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003616 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003618 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003619 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3620 }
3621
Malcolm Chend965c8b2018-02-28 15:00:40 -08003622 final long identity = Binder.clearCallingIdentity();
3623 try {
3624 final Phone phone = getPhone(subId);
3625 if (phone == null) {
3626 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3627 } else {
3628 return phone.getLteOnCdmaMode();
3629 }
3630 } finally {
3631 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003632 }
Wink Saville36469e72014-06-11 15:17:00 -07003633 }
3634
Wink Saville36469e72014-06-11 15:17:00 -07003635 /**
3636 * {@hide}
3637 * Returns Default subId, 0 in the case of single standby.
3638 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003639 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003640 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003641 }
3642
Shishir Agrawala9f32182016-04-12 12:00:16 -07003643 private int getSlotForDefaultSubscription() {
3644 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3645 }
3646
Wink Savilleb564aae2014-10-23 10:18:09 -07003647 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003648 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003649 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003650
Pengquan Meng466e2482018-09-21 15:54:48 -07003651 private boolean isActiveSubscription(int subId) {
3652 return mSubscriptionController.isActiveSubId(subId);
3653 }
3654
Ihab Awadf2177b72013-11-25 13:33:23 -08003655 /**
3656 * @see android.telephony.TelephonyManager.WifiCallingChoices
3657 */
3658 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003659 final long identity = Binder.clearCallingIdentity();
3660 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003661 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003662 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3663 getWhenToMakeWifiCallsDefaultPreference());
3664 } finally {
3665 Binder.restoreCallingIdentity(identity);
3666 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003667 }
3668
3669 /**
3670 * @see android.telephony.TelephonyManager.WifiCallingChoices
3671 */
3672 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003676 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003677 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
3680 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003681 }
3682
Sailesh Nepald1e68152013-12-12 19:08:02 -08003683 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003684 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003685 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003686 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003687
Jordan Liu73b078d2019-02-28 12:03:40 -08003688 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3689 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3690 if (phoneId == -1) {
3691 throw new IllegalArgumentException("Given slot index: " + slotIndex
3692 + " does not correspond to an active phone");
3693 }
3694 return PhoneFactory.getPhone(phoneId);
3695 }
3696
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003698 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3699 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3701 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003702 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003703 if (DBG) {
3704 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3705 }
3706 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3707 p2);
3708 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709
Jordan Liu73b078d2019-02-28 12:03:40 -08003710
3711 @Override
3712 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3713 int slotIndex, String callingPackage, String aid, int p2) {
3714 enforceModifyPermission();
3715 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3716 if (DBG) {
3717 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3718 }
3719 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3720 callingPackage, aid, p2);
3721 }
3722
3723 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3724 String callingPackage, String aid, int p2) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
3727 if (TextUtils.equals(ISDR_AID, aid)) {
3728 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003729 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3730 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003731 if (bestComponent == null
3732 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3733 loge("The calling package is not allowed to access ISD-R.");
3734 throw new SecurityException(
3735 "The calling package is not allowed to access ISD-R.");
3736 }
Derek Tan740e1672017-06-27 14:56:27 -07003737 }
Derek Tan740e1672017-06-27 14:56:27 -07003738
Malcolm Chend965c8b2018-02-28 15:00:40 -08003739 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu73b078d2019-02-28 12:03:40 -08003740 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3741 null /* workSource */);
3742 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003743 return response;
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003747 }
3748
3749 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003750 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3752 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003753 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3754 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3755 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003756
Jordan Liu73b078d2019-02-28 12:03:40 -08003757 @Override
3758 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3759 enforceModifyPermission();
3760 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3761 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3762 channel);
3763 }
3764
3765 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003766 final long identity = Binder.clearCallingIdentity();
3767 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 if (channel < 0) {
3769 return false;
3770 }
Jordan Liu73b078d2019-02-28 12:03:40 -08003771 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3772 null /* workSource */);
3773 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003774 return success;
3775 } finally {
3776 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003777 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003778 }
3779
3780 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003781 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003782 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3784 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu73b078d2019-02-28 12:03:40 -08003785 if (DBG) {
3786 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3787 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3788 + p3 + " data=" + data);
3789 }
3790 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3791 command, p1, p2, p3, data);
3792 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003793
Jordan Liu73b078d2019-02-28 12:03:40 -08003794 @Override
3795 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3796 int command, int p1, int p2, int p3, String data) {
3797 enforceModifyPermission();
3798 if (DBG) {
3799 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3800 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3801 + p3 + " data=" + data);
3802 }
3803 return iccTransmitApduLogicalChannelWithPermission(
3804 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3805 data);
3806 }
3807
3808 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3809 int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003810 final long identity = Binder.clearCallingIdentity();
3811 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003812 if (channel < 0) {
3813 return "";
3814 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003815
Malcolm Chend965c8b2018-02-28 15:00:40 -08003816 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003817 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3818 null /* workSource */);
3819 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003820
Malcolm Chend965c8b2018-02-28 15:00:40 -08003821 // Append the returned status code to the end of the response payload.
3822 String s = Integer.toHexString(
3823 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3824 if (response.payload != null) {
3825 s = IccUtils.bytesToHexString(response.payload) + s;
3826 }
3827 return s;
3828 } finally {
3829 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003830 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003831 }
Jake Hambye994d462014-02-03 13:10:13 -08003832
Evan Charltonc66da362014-05-16 14:06:40 -07003833 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003834 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3835 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3837 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003838 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu73b078d2019-02-28 12:03:40 -08003839 if (DBG) {
3840 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3841 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3842 }
3843 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3844 cla, command, p1, p2, p3, data);
3845 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003846
Jordan Liu73b078d2019-02-28 12:03:40 -08003847 @Override
3848 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3849 int command, int p1, int p2, int p3, String data) {
3850 enforceModifyPermission();
3851 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3852 if (DBG) {
3853 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3854 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3855 + " data=" + data);
3856 }
3857
3858 return iccTransmitApduBasicChannelWithPermission(
3859 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3860 p2, p3, data);
3861 }
3862
3863 // open APDU basic channel assuming the caller has sufficient permissions
3864 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3865 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3869 && TextUtils.equals(ISDR_AID, data)) {
3870 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003871 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3872 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003873 if (bestComponent == null
3874 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3875 loge("The calling package is not allowed to select ISD-R.");
3876 throw new SecurityException(
3877 "The calling package is not allowed to select ISD-R.");
3878 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003879 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003880
Malcolm Chend965c8b2018-02-28 15:00:40 -08003881 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu73b078d2019-02-28 12:03:40 -08003882 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3883 null /* workSource */);
3884 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003885
Malcolm Chend965c8b2018-02-28 15:00:40 -08003886 // Append the returned status code to the end of the response payload.
3887 String s = Integer.toHexString(
3888 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3889 if (response.payload != null) {
3890 s = IccUtils.bytesToHexString(response.payload) + s;
3891 }
3892 return s;
3893 } finally {
3894 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003895 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003896 }
3897
3898 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003899 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003900 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3902 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003903
Malcolm Chend965c8b2018-02-28 15:00:40 -08003904 final long identity = Binder.clearCallingIdentity();
3905 try {
3906 if (DBG) {
3907 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3908 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3909 }
3910
3911 IccIoResult response =
3912 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3913 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3914 subId);
3915
3916 if (DBG) {
3917 log("Exchange SIM_IO [R]" + response);
3918 }
3919
3920 byte[] result = null;
3921 int length = 2;
3922 if (response.payload != null) {
3923 length = 2 + response.payload.length;
3924 result = new byte[length];
3925 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3926 } else {
3927 result = new byte[length];
3928 }
3929
3930 result[length - 1] = (byte) response.sw2;
3931 result[length - 2] = (byte) response.sw1;
3932 return result;
3933 } finally {
3934 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003935 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003936 }
3937
Nathan Haroldb3014052017-01-25 15:57:32 -08003938 /**
3939 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3940 * on a particular subscription
3941 */
sqianb6e41952018-03-12 14:54:01 -07003942 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3943 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3944 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3945 return null;
3946 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003947
3948 final long identity = Binder.clearCallingIdentity();
3949 try {
3950 if (appType != TelephonyManager.APPTYPE_USIM
3951 && appType != TelephonyManager.APPTYPE_SIM) {
3952 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3953 return null;
3954 }
3955 Object response = sendRequest(
3956 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3957 if (response instanceof String[]) {
3958 return (String[]) response;
3959 }
3960 // Response is an Exception of some kind,
3961 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003962 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003963 } finally {
3964 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003965 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003966 }
3967
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003968 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003969 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3971 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003972
Malcolm Chend965c8b2018-02-28 15:00:40 -08003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3976 if (response.payload == null) {
3977 return "";
3978 }
Evan Charltonc66da362014-05-16 14:06:40 -07003979
Malcolm Chend965c8b2018-02-28 15:00:40 -08003980 // Append the returned status code to the end of the response payload.
3981 String s = Integer.toHexString(
3982 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3983 s = IccUtils.bytesToHexString(response.payload) + s;
3984 return s;
3985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
Evan Charltonc66da362014-05-16 14:06:40 -07003988 }
3989
Jake Hambye994d462014-02-03 13:10:13 -08003990 /**
3991 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3992 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3993 *
3994 * @param itemID the ID of the item to read
3995 * @return the NV item as a String, or null on error.
3996 */
3997 @Override
3998 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003999 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004000 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4001 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004002
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07004006 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004007 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4008 return value;
4009 } finally {
4010 Binder.restoreCallingIdentity(identity);
4011 }
Jake Hambye994d462014-02-03 13:10:13 -08004012 }
4013
4014 /**
4015 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4016 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4017 *
4018 * @param itemID the ID of the item to read
4019 * @param itemValue the value to write, as a String
4020 * @return true on success; false on any failure
4021 */
4022 @Override
4023 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07004024 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004027
4028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4031 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07004032 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004033 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4034 return success;
4035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
Jake Hambye994d462014-02-03 13:10:13 -08004038 }
4039
4040 /**
4041 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4042 * Used for device configuration by some CDMA operators.
4043 *
4044 * @param preferredRoamingList byte array containing the new PRL
4045 * @return true on success; false on any failure
4046 */
4047 @Override
4048 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004049 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4050 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004051
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4055 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4056 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4057 return success;
4058 } finally {
4059 Binder.restoreCallingIdentity(identity);
4060 }
Jake Hambye994d462014-02-03 13:10:13 -08004061 }
4062
4063 /**
chen xu1cc0abe2018-10-26 17:39:23 -07004064 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004065 * Used for device configuration by some CDMA operators.
4066 *
chen xu1cc0abe2018-10-26 17:39:23 -07004067 * @param slotIndex - device slot.
4068 *
Jake Hambye994d462014-02-03 13:10:13 -08004069 * @return true on success; false on any failure
4070 */
4071 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07004072 public boolean resetModemConfig(int slotIndex) {
4073 Phone phone = PhoneFactory.getPhone(slotIndex);
4074 if (phone != null) {
4075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4076 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004077
chen xu1cc0abe2018-10-26 17:39:23 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4081 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4082 return success;
4083 } finally {
4084 Binder.restoreCallingIdentity(identity);
4085 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004086 }
chen xu1cc0abe2018-10-26 17:39:23 -07004087 return false;
4088 }
4089
4090 /**
4091 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4092 *
4093 * @param slotIndex - device slot.
4094 *
4095 * @return true on success; false on any failure
4096 */
4097 @Override
4098 public boolean rebootModem(int slotIndex) {
4099 Phone phone = PhoneFactory.getPhone(slotIndex);
4100 if (phone != null) {
4101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4102 mApp, phone.getSubId(), "rebootModem");
4103
4104 final long identity = Binder.clearCallingIdentity();
4105 try {
4106 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4107 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4108 return success;
4109 } finally {
4110 Binder.restoreCallingIdentity(identity);
4111 }
4112 }
4113 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004114 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004115
Svet Ganovb320e182015-04-16 12:30:10 -07004116 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004117 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004119 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004120 return new String[0];
4121 }
4122
Malcolm Chend965c8b2018-02-28 15:00:40 -08004123 final long identity = Binder.clearCallingIdentity();
4124 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004125 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
Wink Saville36469e72014-06-11 15:17:00 -07004129 }
4130
Brad Ebinger51f743a2017-01-23 13:50:20 -08004131 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004132 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4133 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004134 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004135 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004136 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004137
4138 final long identity = Binder.clearCallingIdentity();
4139 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004140 ImsResolver resolver = PhoneFactory.getImsResolver();
4141 if (resolver == null) {
4142 // may happen if the device does not support IMS.
4143 return;
4144 }
4145 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004146 } finally {
4147 Binder.restoreCallingIdentity(identity);
4148 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004149 }
4150
4151 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004152 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4153 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004154 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004155 public void disableIms(int slotId) {
4156 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004157
4158 final long identity = Binder.clearCallingIdentity();
4159 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004160 ImsResolver resolver = PhoneFactory.getImsResolver();
4161 if (resolver == null) {
4162 // may happen if the device does not support IMS.
4163 return;
4164 }
4165 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004166 } finally {
4167 Binder.restoreCallingIdentity(identity);
4168 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004169 }
4170
4171 /**
4172 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4173 * feature or {@link null} if the service is not available. If the feature is available, the
4174 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4175 */
4176 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004177 IImsServiceFeatureCallback callback) {
4178 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004179
4180 final long identity = Binder.clearCallingIdentity();
4181 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004182 ImsResolver resolver = PhoneFactory.getImsResolver();
4183 if (resolver == null) {
4184 // may happen if the device does not support IMS.
4185 return null;
4186 }
4187 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004188 } finally {
4189 Binder.restoreCallingIdentity(identity);
4190 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004191 }
4192
4193 /**
4194 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4195 * feature during emergency calling or {@link null} if the service is not available. If the
4196 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4197 * listener for feature updates.
4198 */
4199 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4200 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004201
4202 final long identity = Binder.clearCallingIdentity();
4203 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004204 ImsResolver resolver = PhoneFactory.getImsResolver();
4205 if (resolver == null) {
4206 // may happen if the device does not support IMS.
4207 return null;
4208 }
4209 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004213 }
4214
Brad Ebinger5f64b052017-12-14 14:26:15 -08004215 /**
4216 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004217 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004218 */
4219 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4220 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004221
4222 final long identity = Binder.clearCallingIdentity();
4223 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004224 ImsResolver resolver = PhoneFactory.getImsResolver();
4225 if (resolver == null) {
4226 // may happen if the device does not support IMS.
4227 return null;
4228 }
4229 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004230 } finally {
4231 Binder.restoreCallingIdentity(identity);
4232 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004233 }
4234
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004235 /**
4236 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004237 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004238 */
4239 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4240 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004241
4242 final long identity = Binder.clearCallingIdentity();
4243 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004244 ImsResolver resolver = PhoneFactory.getImsResolver();
4245 if (resolver == null) {
4246 // may happen if the device does not support IMS.
4247 return null;
4248 }
4249 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004250 } finally {
4251 Binder.restoreCallingIdentity(identity);
4252 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004253 }
4254
Brad Ebinger884c07b2018-02-15 16:17:40 -08004255 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004256 * Sets the ImsService Package Name that Telephony will bind to.
4257 *
4258 * @param slotId the slot ID that the ImsService should bind for.
4259 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4260 * ImsService is the device default ImsService.
4261 * @param packageName The package name of the application that contains the ImsService to bind
4262 * to.
4263 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4264 * @hide
4265 */
4266 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004267 int[] subIds = SubscriptionManager.getSubId(slotId);
4268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4269 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4270 "setImsService");
4271
Malcolm Chend965c8b2018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004274 ImsResolver resolver = PhoneFactory.getImsResolver();
4275 if (resolver == null) {
4276 // may happen if the device does not support IMS.
4277 return false;
4278 }
4279 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4280 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004281 } finally {
4282 Binder.restoreCallingIdentity(identity);
4283 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004284 }
4285
4286 /**
4287 * Return the ImsService configuration.
4288 *
4289 * @param slotId The slot that the ImsService is associated with.
4290 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4291 * the device default.
4292 * @return the package name of the ImsService configuration.
4293 */
4294 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004295 int[] subIds = SubscriptionManager.getSubId(slotId);
4296 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4297 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4298 "getImsService");
4299
Malcolm Chend965c8b2018-02-28 15:00:40 -08004300 final long identity = Binder.clearCallingIdentity();
4301 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004302 ImsResolver resolver = PhoneFactory.getImsResolver();
4303 if (resolver == null) {
4304 // may happen if the device does not support IMS.
4305 return "";
4306 }
4307 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004308 } finally {
4309 Binder.restoreCallingIdentity(identity);
4310 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004311 }
4312
Wink Saville36469e72014-06-11 15:17:00 -07004313 public void setImsRegistrationState(boolean registered) {
4314 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004318 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319 } finally {
4320 Binder.restoreCallingIdentity(identity);
4321 }
Wink Saville36469e72014-06-11 15:17:00 -07004322 }
4323
4324 /**
Stuart Scott54788802015-03-30 13:18:01 -07004325 * Set the network selection mode to automatic.
4326 *
4327 */
4328 @Override
4329 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004330 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4331 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004332
Pengquan Meng466e2482018-09-21 15:54:48 -07004333 if (!isActiveSubscription(subId)) {
4334 return;
4335 }
4336
Malcolm Chend965c8b2018-02-28 15:00:40 -08004337 final long identity = Binder.clearCallingIdentity();
4338 try {
4339 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4340 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
4343 }
Stuart Scott54788802015-03-30 13:18:01 -07004344 }
4345
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004346 /**
4347 * Ask the radio to connect to the input network and change selection mode to manual.
4348 *
4349 * @param subId the id of the subscription.
4350 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4351 * the operator to attach to.
4352 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4353 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4354 * normal network selection next time.
4355 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004356 */
4357 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004358 public boolean setNetworkSelectionModeManual(
4359 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4361 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004362
4363 if (!isActiveSubscription(subId)) {
4364 return false;
4365 }
4366
Malcolm Chend965c8b2018-02-28 15:00:40 -08004367 final long identity = Binder.clearCallingIdentity();
4368 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004369 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004370 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004371 if (DBG) {
4372 log("setNetworkSelectionModeManual: subId: " + subId
4373 + " operator: " + operatorInfo);
4374 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004375 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4376 } finally {
4377 Binder.restoreCallingIdentity(identity);
4378 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004379 }
4380
4381 /**
4382 * Scans for available networks.
4383 */
4384 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004385 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4387 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004388 LocationAccessPolicy.LocationPermissionResult locationResult =
4389 LocationAccessPolicy.checkLocationPermission(mApp,
4390 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4391 .setCallingPackage(callingPackage)
4392 .setCallingPid(Binder.getCallingPid())
4393 .setCallingUid(Binder.getCallingUid())
4394 .setMethod("getCellNetworkScanResults")
4395 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4396 .build());
4397 switch (locationResult) {
4398 case DENIED_HARD:
4399 throw new SecurityException("Not allowed to access scan results -- location");
4400 case DENIED_SOFT:
4401 return null;
4402 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004403
Pengquan Meng0c05b502018-09-06 09:59:22 -07004404 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004405 try {
4406 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004407 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004408 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004409 } finally {
4410 Binder.restoreCallingIdentity(identity);
4411 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004412 }
4413
4414 /**
yinxub1bed742017-04-17 11:45:04 -07004415 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004416 *
yinxub1bed742017-04-17 11:45:04 -07004417 * @param subId id of the subscription
4418 * @param request contains the radio access networks with bands/channels to scan
4419 * @param messenger callback messenger for scan results or errors
4420 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004421 * @return the id of the requested scan which can be used to stop the scan.
4422 */
4423 @Override
4424 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004425 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004428 LocationAccessPolicy.LocationPermissionResult locationResult =
4429 LocationAccessPolicy.checkLocationPermission(mApp,
4430 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4431 .setCallingPackage(callingPackage)
4432 .setCallingPid(Binder.getCallingPid())
4433 .setCallingUid(Binder.getCallingUid())
4434 .setMethod("requestNetworkScan")
4435 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4436 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004437 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
4438 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request);
4439 if (e != null) {
4440 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4441 throw e;
4442 } else {
Hall Liu46dd96a2019-04-03 12:50:44 -07004443 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004444 return TelephonyScanManager.INVALID_SCAN_ID;
4445 }
4446 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004447 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004448 return mNetworkScanRequestTracker.startNetworkScan(
4449 request, messenger, binder, getPhone(subId),
4450 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004451 }
4452
Hall Liub2ac8ef2019-02-28 15:56:23 -08004453 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
4454 NetworkScanRequest request) {
4455 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4456 != PERMISSION_GRANTED) {
4457 return new SecurityException("permission.NETWORK_SCAN is needed for network scans"
4458 + " without location access.");
4459 }
4460
4461 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4462 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
4463 if (ras.getBands() != null && ras.getBands().length > 0) {
4464 return new SecurityException("Specific bands must not be"
4465 + " scanned without location access.");
4466 }
4467 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4468 return new SecurityException("Specific channels must not be"
4469 + " scanned without location access.");
4470 }
4471 }
4472 }
4473
4474 List<String> allowedMccMncs =
4475 NetworkScanRequestTracker.getAllowedMccMncsForLocationRestrictedScan(mApp);
4476 for (String mccmnc : request.getPlmns()) {
4477 if (!allowedMccMncs.contains(mccmnc)) {
4478 return new SecurityException("Requested mccmnc " + mccmnc + " is not known to the"
4479 + " device and cannot be scanned for without location access.");
4480 }
4481 }
4482
4483 return null;
4484 }
4485
yinxu504e1392017-04-12 16:03:22 -07004486 /**
4487 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004488 *
4489 * @param subId id of the subscription
4490 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004491 */
4492 @Override
4493 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4495 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004496
4497 final long identity = Binder.clearCallingIdentity();
4498 try {
4499 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4500 } finally {
4501 Binder.restoreCallingIdentity(identity);
4502 }
yinxu504e1392017-04-12 16:03:22 -07004503 }
4504
4505 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004506 * Get the calculated preferred network type.
4507 * Used for debugging incorrect network type.
4508 *
4509 * @return the preferred network type, defined in RILConstants.java.
4510 */
4511 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004512 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004513 final Phone defaultPhone = getDefaultPhone();
4514 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4515 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004516 return RILConstants.PREFERRED_NETWORK_MODE;
4517 }
4518
Malcolm Chend965c8b2018-02-28 15:00:40 -08004519 final long identity = Binder.clearCallingIdentity();
4520 try {
4521 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004522 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004523 } finally {
4524 Binder.restoreCallingIdentity(identity);
4525 }
Junda Liu84d15a22014-07-02 11:21:04 -07004526 }
4527
4528 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004529 * Get the preferred network type.
4530 * Used for device configuration by some CDMA operators.
4531 *
4532 * @return the preferred network type, defined in RILConstants.java.
4533 */
4534 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004535 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004536 TelephonyPermissions
4537 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4538 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004539
4540 final long identity = Binder.clearCallingIdentity();
4541 try {
4542 if (DBG) log("getPreferredNetworkType");
4543 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4544 int networkType = (result != null ? result[0] : -1);
4545 if (DBG) log("getPreferredNetworkType: " + networkType);
4546 return networkType;
4547 } finally {
4548 Binder.restoreCallingIdentity(identity);
4549 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004550 }
4551
4552 /**
4553 * Set the preferred network type.
4554 * Used for device configuration by some CDMA operators.
4555 *
4556 * @param networkType the preferred network type, defined in RILConstants.java.
4557 * @return true on success; false on any failure.
4558 */
4559 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004560 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4562 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004563
4564 final long identity = Binder.clearCallingIdentity();
4565 try {
4566 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4567 Boolean success = (Boolean) sendRequest(
4568 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4569 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4570 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004571 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004572 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4573 }
4574 return success;
4575 } finally {
4576 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004577 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004578 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004579
4580 /**
Miaoa84611c2019-03-15 09:21:10 +08004581 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004582 *
Miaoa84611c2019-03-15 09:21:10 +08004583 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004584 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004585 * @hide
4586 */
4587 @Override
Miaoa84611c2019-03-15 09:21:10 +08004588 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004589 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004591 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004592 try {
Miaoa84611c2019-03-15 09:21:10 +08004593 if (phone != null) {
4594 return phone.hasMatchedTetherApnSetting();
4595 } else {
4596 return false;
4597 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004600 }
Junda Liu475951f2014-11-07 16:45:03 -08004601 }
4602
4603 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004604 * Set mobile data enabled
4605 * Used by the user through settings etc to turn on/off mobile data
4606 *
4607 * @param enable {@code true} turn turn data on, else {@code false}
4608 */
4609 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004610 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4612 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004613
4614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 int phoneId = mSubscriptionController.getPhoneId(subId);
4617 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4618 Phone phone = PhoneFactory.getPhone(phoneId);
4619 if (phone != null) {
4620 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004621 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004622 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004623 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004624 }
4625 } finally {
4626 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004627 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004628 }
4629
4630 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004631 * Get the user enabled state of Mobile Data.
4632 *
4633 * TODO: remove and use isUserDataEnabled.
4634 * This can't be removed now because some vendor codes
4635 * calls through ITelephony directly while they should
4636 * use TelephonyManager.
4637 *
4638 * @return true on enabled
4639 */
4640 @Override
4641 public boolean getDataEnabled(int subId) {
4642 return isUserDataEnabled(subId);
4643 }
4644
4645 /**
4646 * Get whether mobile data is enabled per user setting.
4647 *
4648 * There are other factors deciding whether mobile data is actually enabled, but they are
4649 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004650 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004651 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004652 *
4653 * @return {@code true} if data is enabled else {@code false}
4654 */
4655 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004656 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004657 try {
4658 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4659 null);
4660 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4662 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004663 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004664
4665 final long identity = Binder.clearCallingIdentity();
4666 try {
4667 int phoneId = mSubscriptionController.getPhoneId(subId);
4668 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4669 Phone phone = PhoneFactory.getPhone(phoneId);
4670 if (phone != null) {
4671 boolean retVal = phone.isUserDataEnabled();
4672 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4673 return retVal;
4674 } else {
4675 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4676 return false;
4677 }
4678 } finally {
4679 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004680 }
4681 }
4682
4683 /**
4684 * Get whether mobile data is enabled.
4685 *
4686 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4687 * whether mobile data is actually enabled.
4688 *
4689 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4690 *
4691 * @return {@code true} if data is enabled else {@code false}
4692 */
4693 @Override
4694 public boolean isDataEnabled(int subId) {
4695 try {
4696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4697 null);
4698 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4700 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004701 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 int phoneId = mSubscriptionController.getPhoneId(subId);
4706 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4707 Phone phone = PhoneFactory.getPhone(phoneId);
4708 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004709 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004710 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4711 return retVal;
4712 } else {
4713 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4714 return false;
4715 }
4716 } finally {
4717 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004718 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004719 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004720
4721 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004722 public int getCarrierPrivilegeStatus(int subId) {
4723 final Phone phone = getPhone(subId);
4724 if (phone == null) {
4725 loge("getCarrierPrivilegeStatus: Invalid subId");
4726 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4727 }
4728 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004729 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004730 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004731 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4732 }
4733 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004734 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004735 }
Junda Liu29340342014-07-10 15:23:27 -07004736
4737 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004738 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4739 final Phone phone = getPhone(subId);
4740 if (phone == null) {
4741 loge("getCarrierPrivilegeStatus: Invalid subId");
4742 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4743 }
4744 UiccProfile profile =
4745 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4746 if (profile == null) {
4747 loge("getCarrierPrivilegeStatus: No UICC");
4748 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4749 }
4750 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4751 }
4752
4753 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004754 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004755 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004756 if (TextUtils.isEmpty(pkgName))
4757 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004758 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004759 if (card == null) {
4760 loge("checkCarrierPrivilegesForPackage: No UICC");
4761 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4762 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004763 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4764 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004765 }
4766
4767 @Override
4768 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004769 if (TextUtils.isEmpty(pkgName))
4770 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004771 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4772 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4773 UiccCard card = UiccController.getInstance().getUiccCard(i);
4774 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004775 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004776 continue;
4777 }
4778
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004779 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004780 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4781 break;
4782 }
4783 }
4784
4785 return result;
Junda Liu29340342014-07-10 15:23:27 -07004786 }
Derek Tan89e89d42014-07-08 17:00:10 -07004787
4788 @Override
Junda Liue64de782015-04-16 17:19:16 -07004789 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4790 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4791 loge("phoneId " + phoneId + " is not valid.");
4792 return null;
4793 }
4794 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004795 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004796 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004797 return null ;
4798 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004799 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004800 }
4801
Amith Yamasani6e118872016-02-19 12:53:51 -08004802 @Override
4803 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004804 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004805 List<String> privilegedPackages = new ArrayList<>();
4806 List<PackageInfo> packages = null;
4807 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4808 UiccCard card = UiccController.getInstance().getUiccCard(i);
4809 if (card == null) {
4810 // No UICC in that slot.
4811 continue;
4812 }
4813 if (card.hasCarrierPrivilegeRules()) {
4814 if (packages == null) {
4815 // Only check packages in user 0 for now
4816 packages = pm.getInstalledPackagesAsUser(
4817 PackageManager.MATCH_DISABLED_COMPONENTS
4818 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4819 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4820 }
4821 for (int p = packages.size() - 1; p >= 0; p--) {
4822 PackageInfo pkgInfo = packages.get(p);
4823 if (pkgInfo != null && pkgInfo.packageName != null
4824 && card.getCarrierPrivilegeStatus(pkgInfo)
4825 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4826 privilegedPackages.add(pkgInfo.packageName);
4827 }
4828 }
4829 }
4830 }
4831 return privilegedPackages;
4832 }
4833
Wink Savilleb564aae2014-10-23 10:18:09 -07004834 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004835 final Phone phone = getPhone(subId);
4836 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004837 if (card == null) {
4838 loge("getIccId: No UICC");
4839 return null;
4840 }
4841 String iccId = card.getIccId();
4842 if (TextUtils.isEmpty(iccId)) {
4843 loge("getIccId: ICC ID is null or empty.");
4844 return null;
4845 }
4846 return iccId;
4847 }
4848
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004849 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004850 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4851 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4853 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004854
Malcolm Chend965c8b2018-02-28 15:00:40 -08004855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 final String iccId = getIccId(subId);
4858 final Phone phone = getPhone(subId);
4859 if (phone == null) {
4860 return false;
4861 }
4862 final String subscriberId = phone.getSubscriberId();
4863
4864 if (DBG_MERGE) {
4865 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4866 + subscriberId + " to " + number);
4867 }
4868
4869 if (TextUtils.isEmpty(iccId)) {
4870 return false;
4871 }
4872
4873 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4874
4875 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4876 if (alphaTag == null) {
4877 editor.remove(alphaTagPrefKey);
4878 } else {
4879 editor.putString(alphaTagPrefKey, alphaTag);
4880 }
4881
4882 // Record both the line number and IMSI for this ICCID, since we need to
4883 // track all merged IMSIs based on line number
4884 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4885 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4886 if (number == null) {
4887 editor.remove(numberPrefKey);
4888 editor.remove(subscriberPrefKey);
4889 } else {
4890 editor.putString(numberPrefKey, number);
4891 editor.putString(subscriberPrefKey, subscriberId);
4892 }
4893
4894 editor.commit();
4895 return true;
4896 } finally {
4897 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004898 }
Derek Tan7226c842014-07-02 17:42:23 -07004899 }
4900
4901 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004902 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004903 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004904 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004905 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004906 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004907 return null;
4908 }
Derek Tan97ebb422014-09-05 16:55:38 -07004909
Malcolm Chend965c8b2018-02-28 15:00:40 -08004910 final long identity = Binder.clearCallingIdentity();
4911 try {
4912 String iccId = getIccId(subId);
4913 if (iccId != null) {
4914 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4915 if (DBG_MERGE) {
4916 log("getLine1NumberForDisplay returning "
4917 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4918 }
4919 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004920 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004921 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4922 return null;
4923 } finally {
4924 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004925 }
Derek Tan7226c842014-07-02 17:42:23 -07004926 }
4927
4928 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004929 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004931 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004932 return null;
4933 }
Derek Tan97ebb422014-09-05 16:55:38 -07004934
Malcolm Chend965c8b2018-02-28 15:00:40 -08004935 final long identity = Binder.clearCallingIdentity();
4936 try {
4937 String iccId = getIccId(subId);
4938 if (iccId != null) {
4939 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4940 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4941 }
4942 return null;
4943 } finally {
4944 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004945 }
Derek Tan7226c842014-07-02 17:42:23 -07004946 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004947
4948 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004949 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004950 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4951 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004953 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4954 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004955 return null;
4956 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004957
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004958 final long identity = Binder.clearCallingIdentity();
4959 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004960 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004961 final TelephonyManager tele = TelephonyManager.from(context);
4962 final SubscriptionManager sub = SubscriptionManager.from(context);
4963
4964 // Figure out what subscribers are currently active
4965 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4966 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4967 // the process, where TelephonyManager was instantiated.
4968 // Otherwise AppOps check will fail.
4969
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004970 final int[] subIds = sub.getActiveSubscriptionIdList();
4971 for (int subId : subIds) {
4972 activeSubscriberIds.add(tele.getSubscriberId(subId));
4973 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004974
4975 // First pass, find a number override for an active subscriber
4976 String mergeNumber = null;
4977 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4978 for (String key : prefs.keySet()) {
4979 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4980 final String subscriberId = (String) prefs.get(key);
4981 if (activeSubscriberIds.contains(subscriberId)) {
4982 final String iccId = key.substring(
4983 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4984 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4985 mergeNumber = (String) prefs.get(numberKey);
4986 if (DBG_MERGE) {
4987 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4988 + " for active subscriber " + subscriberId);
4989 }
4990 if (!TextUtils.isEmpty(mergeNumber)) {
4991 break;
4992 }
4993 }
4994 }
4995 }
4996
4997 // Shortcut when no active merged subscribers
4998 if (TextUtils.isEmpty(mergeNumber)) {
4999 return null;
5000 }
5001
5002 // Second pass, find all subscribers under that line override
5003 final ArraySet<String> result = new ArraySet<>();
5004 for (String key : prefs.keySet()) {
5005 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5006 final String number = (String) prefs.get(key);
5007 if (mergeNumber.equals(number)) {
5008 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5009 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5010 final String subscriberId = (String) prefs.get(subscriberKey);
5011 if (!TextUtils.isEmpty(subscriberId)) {
5012 result.add(subscriberId);
5013 }
5014 }
5015 }
5016 }
5017
5018 final String[] resultArray = result.toArray(new String[result.size()]);
5019 Arrays.sort(resultArray);
5020 if (DBG_MERGE) {
5021 Slog.d(LOG_TAG,
5022 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5023 }
5024 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005025 } finally {
5026 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005027 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005028 }
5029
5030 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005031 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005032 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5033 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 final Phone phone = getPhone(subId);
5038 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005042 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005043
5044 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005045 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005046 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5047 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005048 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005049
5050 final long identity = Binder.clearCallingIdentity();
5051 try {
5052 final Phone phone = getPhone(subId);
5053 if (phone == null) {
5054 return false;
5055 }
5056 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5057 cdmaNonRoamingList);
5058 } finally {
5059 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005060 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005061 }
5062
5063 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005064 @Deprecated
5065 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5066 enforceModifyPermission();
5067
5068 int returnValue = 0;
5069 try {
vagdevie435a3e2018-08-15 16:01:53 -07005070 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005071 if(result.exception == null) {
5072 if (result.result != null) {
5073 byte[] responseData = (byte[])(result.result);
5074 if(responseData.length > oemResp.length) {
5075 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5076 responseData.length + "bytes. Buffer Size is " +
5077 oemResp.length + "bytes.");
5078 }
5079 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5080 returnValue = responseData.length;
5081 }
5082 } else {
5083 CommandException ex = (CommandException) result.exception;
5084 returnValue = ex.getCommandError().ordinal();
5085 if(returnValue > 0) returnValue *= -1;
5086 }
5087 } catch (RuntimeException e) {
5088 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5089 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5090 if(returnValue > 0) returnValue *= -1;
5091 }
5092
5093 return returnValue;
5094 }
5095
5096 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005097 public void setRadioCapability(RadioAccessFamily[] rafs) {
5098 try {
5099 ProxyController.getInstance().setRadioCapability(rafs);
5100 } catch (RuntimeException e) {
5101 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5102 }
5103 }
5104
5105 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005106 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005107 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07005108 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005109 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07005110 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005111 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005112 final long identity = Binder.clearCallingIdentity();
5113 try {
chen xufeeed752018-10-26 14:17:57 -07005114 TelephonyPermissions
5115 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5116 mApp, phone.getSubId(), "getRadioAccessFamily");
5117 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005118 } finally {
5119 Binder.restoreCallingIdentity(identity);
5120 }
chen xufeeed752018-10-26 14:17:57 -07005121 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005122 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005123
5124 @Override
5125 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005126 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005127 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005131 ImsManager.getInstance(defaultPhone.getContext(),
5132 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005133 } finally {
5134 Binder.restoreCallingIdentity(identity);
5135 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005136 }
5137
5138 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005139 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005140 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005142 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005143 return false;
5144 }
Svet Ganovb320e182015-04-16 12:30:10 -07005145
Malcolm Chend965c8b2018-02-28 15:00:40 -08005146 final long identity = Binder.clearCallingIdentity();
5147 try {
5148 // Check the user preference and the system-level IMS setting. Even if the user has
5149 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5150 // In the long run, we may instead need to check if there exists a connection service
5151 // which can support video calling.
5152 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005153 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005154 return imsManager.isVtEnabledByPlatform()
5155 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5156 && imsManager.isVtEnabledByUser();
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005160 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005161
Andrew Leea1239f22015-03-02 17:44:07 -08005162 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005163 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5165 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5166 return false;
5167 }
5168
5169 final long identity = Binder.clearCallingIdentity();
5170 try {
5171 CarrierConfigManager configManager =
5172 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005173 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005174 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5175 } finally {
5176 Binder.restoreCallingIdentity(identity);
5177 }
Andrew Leea1239f22015-03-02 17:44:07 -08005178 }
5179
5180 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005181 public boolean isWorldPhone(int subId, String callingPackage) {
5182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5183 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5184 return false;
5185 }
5186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 CarrierConfigManager configManager =
5190 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005191 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005192 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5193 } finally {
5194 Binder.restoreCallingIdentity(identity);
5195 }
Andrew Leea1239f22015-03-02 17:44:07 -08005196 }
5197
Andrew Lee9431b832015-03-09 18:46:45 -07005198 @Override
5199 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005200 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005201 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005202 }
5203
5204 @Override
5205 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005206 final long identity = Binder.clearCallingIdentity();
5207 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005208 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005209 } finally {
5210 Binder.restoreCallingIdentity(identity);
5211 }
Andrew Lee9431b832015-03-09 18:46:45 -07005212 }
5213
Hall Liuf6668912018-10-31 17:05:23 -07005214 /**
5215 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5216 * support for the feature and device firmware support.
5217 *
5218 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5219 */
5220 @Override
5221 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005223 final Phone phone = getPhone(subscriptionId);
5224 if (phone == null) {
5225 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5226 return false;
5227 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005228 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005229 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005230 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5231 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005232 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005233 return isCarrierSupported && isDeviceSupported;
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Hall Liu98187582018-01-22 19:15:32 -08005237 }
5238
Hall Liuf6668912018-10-31 17:05:23 -07005239 /**
5240 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5241 * both also support RTT.
5242 */
5243 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Hall Liuf6668912018-10-31 17:05:23 -07005246 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005247 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005251 }
5252
Sanket Padawe7310cc72015-01-14 09:53:20 -08005253 /**
5254 * Returns the unique device ID of phone, for example, the IMEI for
5255 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5256 *
5257 * <p>Requires Permission:
5258 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5259 */
5260 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005261 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005262 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005263 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005264 return null;
5265 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005266 int subId = phone.getSubId();
5267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5268 mApp, subId, callingPackage, "getDeviceId")) {
5269 return null;
5270 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 return phone.getDeviceId();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005278 }
5279
Ping Sunc67b7c22016-03-02 19:16:45 +08005280 /**
5281 * {@hide}
5282 * Returns the IMS Registration Status on a particular subid
5283 *
5284 * @param subId
5285 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005286 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005287 Phone phone = getPhone(subId);
5288 if (phone != null) {
5289 return phone.isImsRegistered();
5290 } else {
5291 return false;
5292 }
5293 }
5294
Santos Cordon7a1885b2015-02-03 11:15:19 -08005295 @Override
5296 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5300 } finally {
5301 Binder.restoreCallingIdentity(identity);
5302 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005303 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005304
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005305 /**
5306 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005307 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005308 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005309 final long identity = Binder.clearCallingIdentity();
5310 try {
5311 Phone phone = getPhone(subId);
5312 if (phone != null) {
5313 return phone.isWifiCallingEnabled();
5314 } else {
5315 return false;
5316 }
5317 } finally {
5318 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005319 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005320 }
5321
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005322 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005323 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005324 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005325 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005326 final long identity = Binder.clearCallingIdentity();
5327 try {
5328 Phone phone = getPhone(subId);
5329 if (phone != null) {
5330 return phone.isVideoEnabled();
5331 } else {
5332 return false;
5333 }
5334 } finally {
5335 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005336 }
5337 }
5338
5339 /**
5340 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5341 * defined in {@link ImsRegistrationImplBase}.
5342 */
5343 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005344 final long identity = Binder.clearCallingIdentity();
5345 try {
5346 Phone phone = getPhone(subId);
5347 if (phone != null) {
5348 return phone.getImsRegistrationTech();
5349 } else {
5350 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5351 }
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005354 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005355 }
5356
Stuart Scott8eef64f2015-04-08 15:13:54 -07005357 @Override
5358 public void factoryReset(int subId) {
5359 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005360 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5361 return;
5362 }
5363
Svet Ganovcc087f82015-05-12 20:35:54 -07005364 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005365
Svet Ganovcc087f82015-05-12 20:35:54 -07005366 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005367 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5368 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005369 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005370 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005371 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005372 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5373 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005374 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005375 // There has been issues when Sms raw table somehow stores orphan
5376 // fragments. They lead to garbled message when new fragments come
5377 // in and combined with those stale ones. In case this happens again,
5378 // user can reset all network settings which will clean up this table.
5379 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005380 } finally {
5381 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005382 }
5383 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005384
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005385 private void cleanUpSmsRawTable(Context context) {
5386 ContentResolver resolver = context.getContentResolver();
5387 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5388 resolver.delete(uri, null, null);
5389 }
5390
Narayan Kamath1c496c22015-04-16 14:40:19 +01005391 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005392 public String getSimLocaleForSubscriber(int subId) {
5393 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5394 final Phone phone = getPhone(subId);
5395 if (phone == null) {
5396 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005397 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005398 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005399 final long identity = Binder.clearCallingIdentity();
5400 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005401 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5402 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005403 // Try and fetch the locale from the carrier properties or from the SIM language
5404 // preferences (EF-PL and EF-LI)...
5405 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005406 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005407 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5408 if (localeFromDefaultSim != null) {
5409 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5410 if (DBG) log("Using locale from subId: " + subId + " locale: "
5411 + localeFromDefaultSim);
5412 return localeFromDefaultSim.toLanguageTag();
5413 } else {
5414 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005415 }
5416 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005417
Malcolm Chend965c8b2018-02-28 15:00:40 -08005418 // The SIM language preferences only store a language (e.g. fr = French), not an
5419 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5420 // the SIM and carrier preferences does not include a country we add the country
5421 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005422 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005423 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005424 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005425 return mccLocale.toLanguageTag();
5426 }
5427
5428 if (DBG) log("No locale found - returning null");
5429 return null;
5430 } finally {
5431 Binder.restoreCallingIdentity(identity);
5432 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005433 }
5434
5435 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005436 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005437 }
5438
Malcolm Chend965c8b2018-02-28 15:00:40 -08005439 /**
5440 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5441 */
5442 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005443 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005444 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005445
Chenjie Yu1ba97252018-01-11 18:16:20 -08005446 private final ModemActivityInfo mLastModemActivityInfo =
5447 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5448
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005449 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005450 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5451 * representing the state of the modem.
5452 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005453 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5454 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005455 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005456 */
5457 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005458 public void requestModemActivityInfo(ResultReceiver result) {
5459 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005460 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 ModemActivityInfo ret = null;
5465 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005466 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5467 CMD_GET_MODEM_ACTIVITY_INFO,
5468 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005469 if (isModemActivityInfoValid(info)) {
5470 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5471 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5472 mergedTxTimeMs[i] =
5473 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5474 }
5475 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5476 mLastModemActivityInfo.setSleepTimeMillis(
5477 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5478 mLastModemActivityInfo.setIdleTimeMillis(
5479 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5480 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5481 mLastModemActivityInfo.setRxTimeMillis(
5482 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5483 mLastModemActivityInfo.setEnergyUsed(
5484 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005485 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5487 mLastModemActivityInfo.getSleepTimeMillis(),
5488 mLastModemActivityInfo.getIdleTimeMillis(),
5489 mLastModemActivityInfo.getTxTimeMillis(),
5490 mLastModemActivityInfo.getRxTimeMillis(),
5491 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005492 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005493 Bundle bundle = new Bundle();
5494 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5495 result.send(0, bundle);
5496 } finally {
5497 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005498 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005499 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005500
Siddharth Rayf5d29552018-06-17 15:02:38 -07005501 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5502 // less than total activity duration.
5503 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5504 if (info == null) {
5505 return false;
5506 }
5507 int activityDurationMs =
5508 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5509 int totalTxTimeMs = 0;
5510 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5511 totalTxTimeMs += info.getTxTimeMillis()[i];
5512 }
5513 return (info.isValid()
5514 && (info.getSleepTimeMillis() <= activityDurationMs)
5515 && (info.getIdleTimeMillis() <= activityDurationMs)
5516 && (info.getRxTimeMillis() <= activityDurationMs)
5517 && (totalTxTimeMs <= activityDurationMs));
5518 }
5519
Jack Yu85bd38a2015-11-09 11:34:32 -08005520 /**
5521 * {@hide}
5522 * Returns the service state information on specified subscription.
5523 */
5524 @Override
5525 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005526 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005527 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005528 return null;
5529 }
5530
Hall Liuf19c44f2018-11-27 14:38:17 -08005531 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5532 LocationAccessPolicy.checkLocationPermission(mApp,
5533 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5534 .setCallingPackage(callingPackage)
5535 .setCallingPid(Binder.getCallingPid())
5536 .setCallingUid(Binder.getCallingUid())
5537 .setMethod("getServiceStateForSubscriber")
5538 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5539 .build());
5540
5541 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5542 LocationAccessPolicy.checkLocationPermission(mApp,
5543 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5544 .setCallingPackage(callingPackage)
5545 .setCallingPid(Binder.getCallingPid())
5546 .setCallingUid(Binder.getCallingUid())
5547 .setMethod("getServiceStateForSubscriber")
5548 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5549 .build());
5550 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5551 boolean hasFinePermission =
5552 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5553 boolean hasCoarsePermission =
5554 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5555
Malcolm Chend965c8b2018-02-28 15:00:40 -08005556 final long identity = Binder.clearCallingIdentity();
5557 try {
5558 final Phone phone = getPhone(subId);
5559 if (phone == null) {
5560 return null;
5561 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005562
Hall Liuf19c44f2018-11-27 14:38:17 -08005563 ServiceState ss = phone.getServiceState();
5564
5565 // Scrub out the location info in ServiceState depending on what level of access
5566 // the caller has.
5567 if (hasFinePermission) return ss;
5568 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5569 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005573 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005574
5575 /**
5576 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5577 *
5578 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5579 * voicemail ringtone.
5580 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5581 * PhoneAccount.
5582 */
5583 @Override
5584 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005585 final long identity = Binder.clearCallingIdentity();
5586 try {
5587 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5588 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005589 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005590 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005591
Malcolm Chend965c8b2018-02-28 15:00:40 -08005592 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5593 } finally {
5594 Binder.restoreCallingIdentity(identity);
5595 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005596 }
5597
5598 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005599 * Sets the per-account voicemail ringtone.
5600 *
5601 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5602 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5603 *
5604 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5605 * voicemail ringtone.
5606 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5607 * PhoneAccount.
5608 */
5609 @Override
5610 public void setVoicemailRingtoneUri(String callingPackage,
5611 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005612 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5614 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005615 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5617 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5618 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005619 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005620
5621 final long identity = Binder.clearCallingIdentity();
5622 try {
5623 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5624 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005625 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005626 }
5627 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005630 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005631 }
5632
5633 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005634 * Returns whether vibration is set for voicemail notification in Phone settings.
5635 *
5636 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5637 * voicemail vibration setting.
5638 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5639 */
5640 @Override
5641 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5645 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005646 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005647 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005648
Malcolm Chend965c8b2018-02-28 15:00:40 -08005649 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5650 } finally {
5651 Binder.restoreCallingIdentity(identity);
5652 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005653 }
5654
Youhan Wange64578a2016-05-02 15:32:42 -07005655 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005656 * Sets the per-account voicemail vibration.
5657 *
5658 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5659 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5660 *
5661 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5662 * voicemail vibration setting.
5663 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5664 * specific PhoneAccount.
5665 */
5666 @Override
5667 public void setVoicemailVibrationEnabled(String callingPackage,
5668 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005669 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005670 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5671 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005672 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005673 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5674 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5675 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005676 }
5677
Malcolm Chend965c8b2018-02-28 15:00:40 -08005678 final long identity = Binder.clearCallingIdentity();
5679 try {
5680 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5681 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005682 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005683 }
5684 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5685 } finally {
5686 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005687 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005688 }
5689
5690 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005691 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5692 *
5693 * @throws SecurityException if the caller does not have the required permission
5694 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005695 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005696 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005697 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005698 }
5699
5700 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005701 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5702 * permission.
5703 *
5704 * @throws SecurityException if the caller does not have the required permission
5705 */
5706 private void enforceSendSmsPermission() {
5707 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5708 }
5709
5710 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005711 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005712 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005713 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005714 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005715 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005719 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005720 if (componentName == null) {
5721 throw new SecurityException(
5722 "Caller not current active visual voicemail package[null]");
5723 }
5724 String vvmPackage = componentName.getPackageName();
5725 if (!callingPackage.equals(vvmPackage)) {
5726 throw new SecurityException("Caller not current active visual voicemail package["
5727 + vvmPackage + "]");
5728 }
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005731 }
5732 }
5733
5734 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005735 * Return the application ID for the app type.
5736 *
5737 * @param subId the subscription ID that this request applies to.
5738 * @param appType the uicc app type.
5739 * @return Application ID for specificied app type, or null if no uicc.
5740 */
5741 @Override
5742 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005743 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005744 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005745
5746 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005747 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005748 if (phone == null) {
5749 return null;
5750 }
5751 String aid = null;
5752 try {
5753 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5754 .getApplicationByType(appType).getAid();
5755 } catch (Exception e) {
5756 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5757 }
5758 return aid;
5759 } finally {
5760 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005761 }
Youhan Wange64578a2016-05-02 15:32:42 -07005762 }
5763
Youhan Wang4001d252016-05-11 10:29:41 -07005764 /**
5765 * Return the Electronic Serial Number.
5766 *
5767 * @param subId the subscription ID that this request applies to.
5768 * @return ESN or null if error.
5769 */
5770 @Override
5771 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005772 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005773 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005776 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005777 if (phone == null) {
5778 return null;
5779 }
5780 String esn = null;
5781 try {
5782 esn = phone.getEsn();
5783 } catch (Exception e) {
5784 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5785 }
5786 return esn;
5787 } finally {
5788 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005789 }
Youhan Wang4001d252016-05-11 10:29:41 -07005790 }
5791
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005792 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005793 * Return the Preferred Roaming List Version.
5794 *
5795 * @param subId the subscription ID that this request applies to.
5796 * @return PRLVersion or null if error.
5797 */
5798 @Override
5799 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005800 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005801 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005802
5803 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005804 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005805 if (phone == null) {
5806 return null;
5807 }
5808 String cdmaPrlVersion = null;
5809 try {
5810 cdmaPrlVersion = phone.getCdmaPrlVersion();
5811 } catch (Exception e) {
5812 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5813 }
5814 return cdmaPrlVersion;
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005817 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005818 }
5819
5820 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005821 * Get snapshot of Telephony histograms
5822 * @return List of Telephony histograms
5823 * @hide
5824 */
5825 @Override
5826 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5828 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005829
5830 final long identity = Binder.clearCallingIdentity();
5831 try {
5832 return RIL.getTelephonyRILTimingHistograms();
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005836 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005837
5838 /**
5839 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005840 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5841 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005842 * Require system privileges. In the future we may add this to carrier APIs.
5843 *
Michele Berionne0963c862018-11-27 18:57:59 -08005844 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005845 */
5846 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005847 @TelephonyManager.SetCarrierRestrictionResult
5848 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005849 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005850 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005851
Michele Berionne0963c862018-11-27 18:57:59 -08005852 if (carrierRestrictionRules == null) {
5853 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005854 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005855
Malcolm Chend965c8b2018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005858 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005859 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005863 }
5864
5865 /**
5866 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005867 * Get the allowed carrier list and the excluded carrier list, including the priority between
5868 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005869 * Require system privileges. In the future we may add this to carrier APIs.
5870 *
Michele Berionne0963c862018-11-27 18:57:59 -08005871 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005872 */
5873 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005874 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005875 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005876 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005877
5878 final long identity = Binder.clearCallingIdentity();
5879 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005880 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5881 if (response instanceof CarrierRestrictionRules) {
5882 return (CarrierRestrictionRules) response;
5883 }
5884 // Response is an Exception of some kind,
5885 // which is signalled to the user as a NULL retval
5886 return null;
5887 } catch (Exception e) {
5888 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5889 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005893 }
5894
fionaxu59545b42016-05-25 15:53:37 -07005895 /**
5896 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5897 * @param subId the subscription ID that this action applies to.
5898 * @param enabled control enable or disable metered apns.
5899 * {@hide}
5900 */
5901 @Override
5902 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5903 enforceModifyPermission();
5904 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005905
5906 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005907 if (phone == null) {
5908 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5909 return;
5910 }
5911 try {
5912 phone.carrierActionSetMeteredApnsEnabled(enabled);
5913 } catch (Exception e) {
5914 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005915 } finally {
5916 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005917 }
5918 }
5919
5920 /**
5921 * Action set from carrier signalling broadcast receivers to enable/disable radio
5922 * @param subId the subscription ID that this action applies to.
5923 * @param enabled control enable or disable radio.
5924 * {@hide}
5925 */
5926 @Override
5927 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5928 enforceModifyPermission();
5929 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005930
5931 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005932 if (phone == null) {
5933 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5934 return;
5935 }
5936 try {
5937 phone.carrierActionSetRadioEnabled(enabled);
5938 } catch (Exception e) {
5939 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005940 } finally {
5941 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005942 }
5943 }
5944
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005945 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005946 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5947 * network status based on which carrier apps could apply actions accordingly,
5948 * enable/disable default url handler for example.
5949 *
5950 * @param subId the subscription ID that this action applies to.
5951 * @param report control start/stop reporting the default network status.
5952 * {@hide}
5953 */
5954 @Override
5955 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5956 enforceModifyPermission();
5957 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005958
5959 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005960 if (phone == null) {
5961 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5962 return;
5963 }
5964 try {
5965 phone.carrierActionReportDefaultNetworkStatus(report);
5966 } catch (Exception e) {
5967 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005970 }
5971 }
5972
5973 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005974 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5975 * bug report is being generated.
5976 */
5977 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005978 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005979 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5980 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005981 writer.println("Permission Denial: can't dump Phone from pid="
5982 + Binder.getCallingPid()
5983 + ", uid=" + Binder.getCallingUid()
5984 + "without permission "
5985 + android.Manifest.permission.DUMP);
5986 return;
5987 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005988 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005989 }
Jack Yueb89b242016-06-22 13:27:47 -07005990
Brad Ebingerdac2f002018-04-03 15:17:52 -07005991 @Override
5992 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5993 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5994 throws RemoteException {
5995 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5996 }
5997
Jack Yueb89b242016-06-22 13:27:47 -07005998 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005999 * Get aggregated video call data usage since boot.
6000 *
6001 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6002 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006003 * {@hide}
6004 */
6005 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006006 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006007 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6008 null);
6009
Malcolm Chend965c8b2018-02-28 15:00:40 -08006010 final long identity = Binder.clearCallingIdentity();
6011 try {
6012 // NetworkStatsService keeps tracking the active network interface and identity. It
6013 // records the delta with the corresponding network identity.
6014 // We just return the total video call data usage snapshot since boot.
6015 Phone phone = getPhone(subId);
6016 if (phone != null) {
6017 return phone.getVtDataUsage(perUidStats);
6018 }
6019 return null;
6020 } finally {
6021 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006022 }
Jack Yueb89b242016-06-22 13:27:47 -07006023 }
Jack Yu75ab2952016-07-08 14:29:33 -07006024
6025 /**
6026 * Policy control of data connection. Usually used when data limit is passed.
6027 * @param enabled True if enabling the data, otherwise disabling.
6028 * @param subId Subscription index
6029 * {@hide}
6030 */
6031 @Override
6032 public void setPolicyDataEnabled(boolean enabled, int subId) {
6033 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006034
6035 final long identity = Binder.clearCallingIdentity();
6036 try {
6037 Phone phone = getPhone(subId);
6038 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08006039 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006040 }
6041 } finally {
6042 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006043 }
6044 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006045
6046 /**
6047 * Get Client request stats
6048 * @return List of Client Request Stats
6049 * @hide
6050 */
6051 @Override
6052 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006053 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006054 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006055 return null;
6056 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006057 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006058
Malcolm Chend965c8b2018-02-28 15:00:40 -08006059 final long identity = Binder.clearCallingIdentity();
6060 try {
6061 if (phone != null) {
6062 return phone.getClientRequestStats();
6063 }
6064
6065 return null;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
6068 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006069 }
6070
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006071 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006072 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006073 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006074 }
Jack Yueb4124c2017-02-16 15:32:43 -08006075
6076 /**
Grace Chen70990072017-03-24 17:21:30 -07006077 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006078 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006079 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006080 * @param state State of SIM (power down, power up, pass through)
6081 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6082 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6083 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006084 *
6085 **/
6086 @Override
Grace Chen70990072017-03-24 17:21:30 -07006087 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006088 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006089 Phone phone = PhoneFactory.getPhone(slotIndex);
6090
vagdevie435a3e2018-08-15 16:01:53 -07006091 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6092
Malcolm Chend965c8b2018-02-28 15:00:40 -08006093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07006096 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006097 }
6098 } finally {
6099 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006100 }
6101 }
Shuo Qiandd210312017-04-12 22:11:33 +00006102
Tyler Gunn65d45c22017-06-05 11:22:26 -07006103 private boolean isUssdApiAllowed(int subId) {
6104 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006105 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006106 if (configManager == null) {
6107 return false;
6108 }
6109 PersistableBundle pb = configManager.getConfigForSubId(subId);
6110 if (pb == null) {
6111 return false;
6112 }
6113 return pb.getBoolean(
6114 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6115 }
6116
Shuo Qiandd210312017-04-12 22:11:33 +00006117 /**
6118 * Check if phone is in emergency callback mode
6119 * @return true if phone is in emergency callback mode
6120 * @param subId sub id
6121 */
goneil9c5f4872017-12-05 14:07:56 -08006122 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006123 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006124 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006125 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08006126
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 if (phone != null) {
6130 return phone.isInEcm();
6131 } else {
6132 return false;
6133 }
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006136 }
6137 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006138
6139 /**
6140 * Get the current signal strength information for the given subscription.
6141 * Because this information is not updated when the device is in a low power state
6142 * it should not be relied-upon to be current.
6143 * @param subId Subscription index
6144 * @return the most recent cached signal strength info from the modem
6145 */
6146 @Override
6147 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08006148 final long identity = Binder.clearCallingIdentity();
6149 try {
6150 Phone p = getPhone(subId);
6151 if (p == null) {
6152 return null;
6153 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006154
Malcolm Chend965c8b2018-02-28 15:00:40 -08006155 return p.getSignalStrength();
6156 } finally {
6157 Binder.restoreCallingIdentity(identity);
6158 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006159 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006160
Pengquan Meng9140aec2018-08-22 14:49:57 -07006161 /**
chen xu907e5a22018-10-11 13:21:04 -07006162 * Get the current modem radio state for the given slot.
6163 * @param slotIndex slot index.
6164 * @param callingPackage the name of the package making the call.
6165 * @return the current radio power state from the modem
6166 */
6167 @Override
6168 public int getRadioPowerState(int slotIndex, String callingPackage) {
6169 Phone phone = PhoneFactory.getPhone(slotIndex);
6170 if (phone != null) {
6171 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6172 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6173 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6174 }
6175
6176 final long identity = Binder.clearCallingIdentity();
6177 try {
6178 return phone.getRadioPowerState();
6179 } finally {
6180 Binder.restoreCallingIdentity(identity);
6181 }
6182 }
6183 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6184 }
6185
6186 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006187 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6188 *
6189 * <p>Requires one of the following permissions:
6190 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6191 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6192 * privileges.
6193 *
6194 * @param subId subscription id
6195 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6196 * {@code false}.
6197 */
6198 @Override
6199 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006200 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6201 null /* message */);
6202
Pengquan Meng0c05b502018-09-06 09:59:22 -07006203 boolean isEnabled = false;
6204 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006205 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006206 Phone phone = getPhone(subId);
6207 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006208 } catch (Exception e) {
6209 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6210 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006211 } finally {
6212 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006213 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006214 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006215 }
6216
6217
6218 /**
6219 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6220 *
6221 * <p> Requires permission:
6222 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6223 * privileges.
6224 *
6225 * @param subId subscription id
6226 * @param isEnabled {@code true} means enable, {@code false} means disable.
6227 */
6228 @Override
6229 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006230 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6231 mApp, subId, "setDataRoamingEnabled");
6232
Pengquan Meng0c05b502018-09-06 09:59:22 -07006233 final long identity = Binder.clearCallingIdentity();
6234 try {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006235 Phone phone = getPhone(subId);
6236 if (phone != null) {
6237 phone.setDataRoamingEnabled(isEnabled);
6238 }
6239 } finally {
6240 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006241 }
6242 }
6243
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006244 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006245 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006246 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6247 mApp, subId, "isManualNetworkSelectionAllowed");
6248
Pengquan Meng312de0c2018-10-03 12:19:13 -07006249 boolean isAllowed = true;
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
Pengquan Meng312de0c2018-10-03 12:19:13 -07006252 Phone phone = getPhone(subId);
6253 if (phone != null) {
6254 isAllowed = phone.isCspPlmnEnabled();
6255 }
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
6258 }
6259 return isAllowed;
6260 }
6261
6262 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006263 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006264 try {
6265 enforceReadPrivilegedPermission("getUiccCardsInfo");
6266 } catch (SecurityException e) {
6267 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6268 // has carrier privileges on an active UICC
6269 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6270 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6271 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6272 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006273 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006277 UiccController uiccController = UiccController.getInstance();
6278 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6279
6280 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6281 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6282 // Remove private info if the caller doesn't have access
6283 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6284 for (UiccCardInfo cardInfo : cardInfos) {
6285 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6286 UiccProfile profile = card.getUiccProfile();
6287 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6288 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6289 filteredInfos.add(cardInfo.getUnprivileged());
6290 } else {
6291 filteredInfos.add(cardInfo);
6292 }
6293 }
6294 return filteredInfos;
6295 }
6296 return cardInfos;
6297 } catch (PackageManager.NameNotFoundException e) {
6298 // This should not happen since we pass the package info in from TelephonyManager
6299 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006300 } finally {
6301 Binder.restoreCallingIdentity(identity);
6302 }
6303 }
6304
6305 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006306 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006307 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006308
Malcolm Chend965c8b2018-02-28 15:00:40 -08006309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6312 if (slots == null) {
6313 Rlog.i(LOG_TAG, "slots is null.");
6314 return null;
6315 }
6316
6317 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6318 for (int i = 0; i < slots.length; i++) {
6319 UiccSlot slot = slots[i];
6320 if (slot == null) {
6321 continue;
6322 }
6323
6324 String cardId;
6325 UiccCard card = slot.getUiccCard();
6326 if (card != null) {
6327 cardId = card.getCardId();
6328 } else {
6329 cardId = slot.getIccId();
6330 }
6331
6332 int cardState = 0;
6333 switch (slot.getCardState()) {
6334 case CARDSTATE_ABSENT:
6335 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6336 break;
6337 case CARDSTATE_PRESENT:
6338 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6339 break;
6340 case CARDSTATE_ERROR:
6341 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6342 break;
6343 case CARDSTATE_RESTRICTED:
6344 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6345 break;
6346 default:
6347 break;
6348
6349 }
6350
6351 infos[i] = new UiccSlotInfo(
6352 slot.isActive(),
6353 slot.isEuicc(),
6354 cardId,
6355 cardState,
6356 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006357 slot.isExtendedApduSupported(),
6358 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006359 }
6360 return infos;
6361 } finally {
6362 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006363 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006364 }
6365
6366 @Override
6367 public boolean switchSlots(int[] physicalSlots) {
6368 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6373 } finally {
6374 Binder.restoreCallingIdentity(identity);
6375 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006376 }
Jack Yu4c988042018-02-27 15:30:01 -08006377
6378 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006379 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 return UiccController.getInstance().getCardIdForDefaultEuicc();
6383 } finally {
6384 Binder.restoreCallingIdentity(identity);
6385 }
6386 }
6387
6388 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006389 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6390 enforceModifyPermission();
6391 final Phone phone = getPhone(subId);
6392 if (phone == null) {
6393 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6394 return;
6395 }
6396
Malcolm Chend965c8b2018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
6398 try {
6399 phone.setRadioIndicationUpdateMode(filters, mode);
6400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
Jack Yu4c988042018-02-27 15:30:01 -08006403 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006404
6405 /**
goneil47ffb6e2018-04-06 15:40:58 -07006406 * A test API to reload the UICC profile.
6407 *
6408 * <p>Requires that the calling app has permission
6409 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6410 * @hide
6411 */
6412 @Override
6413 public void refreshUiccProfile(int subId) {
6414 enforceModifyPermission();
6415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 Phone phone = getPhone(subId);
6419 if (phone == null) {
6420 return;
6421 }
6422 UiccCard uiccCard = phone.getUiccCard();
6423 if (uiccCard == null) {
6424 return;
6425 }
6426 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6427 if (uiccProfile == null) {
6428 return;
6429 }
6430 uiccProfile.refresh();
6431 } finally {
6432 Binder.restoreCallingIdentity(identity);
6433 }
6434 }
6435
6436 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006437 * Returns false if the mobile data is disabled by default, otherwise return true.
6438 */
6439 private boolean getDefaultDataEnabled() {
6440 return "true".equalsIgnoreCase(
6441 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6442 }
6443
6444 /**
6445 * Returns true if the data roaming is enabled by default, i.e the system property
6446 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6447 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6448 */
6449 private boolean getDefaultDataRoamingEnabled(int subId) {
6450 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006451 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006452 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6453 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6454 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6455 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6456 return isDataRoamingEnabled;
6457 }
6458
6459 /**
6460 * Returns the default network type for the given {@code subId}, if the default network type is
6461 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6462 */
6463 private int getDefaultNetworkType(int subId) {
6464 return Integer.parseInt(
6465 TelephonyManager.getTelephonyProperty(
6466 mSubscriptionController.getPhoneId(subId),
6467 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6468 String.valueOf(Phone.PREFERRED_NT_MODE)));
6469 }
fionaxua13278b2018-03-21 00:08:13 -07006470
6471 @Override
6472 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6473 gid1, String gid2, String plmn, String spn) {
6474 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
6478 final Phone phone = getPhone(subId);
6479 if (phone == null) {
6480 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6481 return;
6482 }
6483 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6484 } finally {
6485 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006486 }
fionaxua13278b2018-03-21 00:08:13 -07006487 }
6488
6489 @Override
6490 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006491 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006492
6493 final long identity = Binder.clearCallingIdentity();
6494 try {
6495 final Phone phone = getPhone(subId);
6496 if (phone == null) {
6497 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6498 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6499 }
6500 return phone.getCarrierIdListVersion();
6501 } finally {
6502 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006503 }
fionaxua13278b2018-03-21 00:08:13 -07006504 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006505
6506 @Override
6507 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6509 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6510 return -1;
6511 }
6512
6513 final long identity = Binder.clearCallingIdentity();
6514 try {
6515 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
6519 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006520
6521 @Override
6522 public int getCdmaRoamingMode(int subId) {
6523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6524 mApp, subId, "getCdmaRoamingMode");
6525
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6529 } finally {
6530 Binder.restoreCallingIdentity(identity);
6531 }
6532 }
6533
6534 @Override
6535 public boolean setCdmaRoamingMode(int subId, int mode) {
6536 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6537 mApp, subId, "setCdmaRoamingMode");
6538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
6545 }
6546
6547 @Override
6548 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6550 mApp, subId, "setCdmaSubscriptionMode");
6551
6552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6555 } finally {
6556 Binder.restoreCallingIdentity(identity);
6557 }
6558 }
chen xu7ee67862018-10-30 22:27:10 -07006559
sqian2fff4a32018-11-05 14:18:37 -08006560 private void ensureUserRunning(int userId) {
6561 if (!mUserManager.isUserRunning(userId)) {
6562 throw new IllegalStateException("User " + userId + " does not exist or not running");
6563 }
6564 }
6565
6566 /**
6567 * Returns a list of SMS apps on a given user.
6568 *
6569 * Only the shell user (UID 2000 or 0) can call it.
6570 * Target user must be running.
6571 */
6572 @Override
6573 public String[] getSmsApps(int userId) {
6574 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6575 ensureUserRunning(userId);
6576
6577 final Collection<SmsApplicationData> apps =
6578 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6579
6580 String[] ret = new String[apps.size()];
6581 int i = 0;
6582 for (SmsApplicationData app : apps) {
6583 ret[i++] = app.mPackageName;
6584 }
6585 return ret;
6586 }
6587
6588 /**
6589 * Returns the default SMS app package name on a given user.
6590 *
6591 * Only the shell user (UID 2000 or 0) can call it.
6592 * Target user must be running.
6593 */
6594 @Override
6595 public String getDefaultSmsApp(int userId) {
6596 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6597 ensureUserRunning(userId);
6598
6599 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6600 /* updateIfNeeded= */ true, userId);
6601 return cn == null ? null : cn.getPackageName();
6602 }
6603
6604 /**
6605 * Set a package as the default SMS app on a given user.
6606 *
6607 * Only the shell user (UID 2000 or 0) can call it.
6608 * Target user must be running.
6609 */
6610 @Override
6611 public void setDefaultSmsApp(int userId, String packageName) {
6612 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6613 ensureUserRunning(userId);
6614
6615 boolean found = false;
6616 for (String pkg : getSmsApps(userId)) {
6617 if (TextUtils.equals(packageName, pkg)) {
6618 found = true;
6619 break;
6620 }
6621 }
6622 if (!found) {
6623 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6624 }
6625
6626 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6627 }
6628
chen xu7ee67862018-10-30 22:27:10 -07006629 @Override
sqian65eefe12019-02-22 15:55:18 -08006630 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqian04b86072018-11-07 14:02:21 -08006631 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian65eefe12019-02-22 15:55:18 -08006633 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian03bca152018-12-05 18:48:28 -08006634 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6635 }
6636 final long identity = Binder.clearCallingIdentity();
6637 try {
sqian991b35e2018-12-12 16:48:18 -08006638 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6639 for (Phone phone: PhoneFactory.getPhones()) {
6640 if (phone.getEmergencyNumberTracker() != null
6641 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6642 emergencyNumberListInternal.put(
6643 phone.getSubId(),
6644 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6645 }
sqian03bca152018-12-05 18:48:28 -08006646 }
sqian991b35e2018-12-12 16:48:18 -08006647 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006648 } finally {
6649 Binder.restoreCallingIdentity(identity);
6650 }
sqian04b86072018-11-07 14:02:21 -08006651 }
6652
6653 @Override
sqian65eefe12019-02-22 15:55:18 -08006654 public boolean isEmergencyNumber(String number, boolean exactMatch) {
sqian03bca152018-12-05 18:48:28 -08006655 final Phone defaultPhone = getDefaultPhone();
6656 if (!exactMatch) {
6657 TelephonyPermissions
6658 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian65eefe12019-02-22 15:55:18 -08006659 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian03bca152018-12-05 18:48:28 -08006660 }
6661 final long identity = Binder.clearCallingIdentity();
6662 try {
sqian991b35e2018-12-12 16:48:18 -08006663 for (Phone phone: PhoneFactory.getPhones()) {
6664 if (phone.getEmergencyNumberTracker() != null
6665 && phone.getEmergencyNumberTracker() != null) {
6666 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6667 number, exactMatch)) {
6668 return true;
sqian03bca152018-12-05 18:48:28 -08006669 }
6670 }
sqian03bca152018-12-05 18:48:28 -08006671 }
6672 return false;
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 }
6677
sqian9d4df8b2019-01-15 18:32:07 -08006678 /**
6679 * Update emergency number list for test mode.
6680 */
6681 @Override
6682 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6683 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6684 "updateEmergencyNumberListTestMode");
6685
6686 final long identity = Binder.clearCallingIdentity();
6687 try {
6688 for (Phone phone: PhoneFactory.getPhones()) {
6689 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6690 if (tracker != null) {
6691 tracker.executeEmergencyNumberTestModeCommand(action, num);
6692 }
6693 }
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
6696 }
6697 }
6698
6699 /**
6700 * Get the full emergency number list for test mode.
6701 */
6702 @Override
6703 public List<String> getEmergencyNumberListTestMode() {
6704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6705 "getEmergencyNumberListTestMode");
6706
6707 final long identity = Binder.clearCallingIdentity();
6708 try {
6709 Set<String> emergencyNumbers = new HashSet<>();
6710 for (Phone phone: PhoneFactory.getPhones()) {
6711 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6712 if (tracker != null) {
6713 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6714 emergencyNumbers.add(num.getNumber());
6715 }
6716 }
6717 }
6718 return new ArrayList<>(emergencyNumbers);
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
6721 }
6722 }
6723
sqian04b86072018-11-07 14:02:21 -08006724 @Override
chen xu7ee67862018-10-30 22:27:10 -07006725 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6726 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6727 Phone phone = getPhone(subId);
6728 if (phone == null) {
6729 return null;
6730 }
6731 final long identity = Binder.clearCallingIdentity();
6732 try {
6733 UiccProfile profile = UiccController.getInstance()
6734 .getUiccProfileForPhone(phone.getPhoneId());
6735 if (profile != null) {
6736 return profile.getCertsFromCarrierPrivilegeAccessRules();
6737 }
6738 } finally {
6739 Binder.restoreCallingIdentity(identity);
6740 }
6741 return null;
6742 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006743
6744 /**
6745 * Enable or disable a modem stack.
6746 */
6747 @Override
6748 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6749 enforceModifyPermission();
6750
6751 final long identity = Binder.clearCallingIdentity();
6752 try {
6753 Phone phone = PhoneFactory.getPhone(slotIndex);
6754 if (phone == null) {
6755 return false;
6756 } else {
6757 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6758 }
6759 } finally {
6760 Binder.restoreCallingIdentity(identity);
6761 }
6762 }
Micheled3107c52018-12-21 15:00:11 -08006763
6764 @Override
Michele2fb0f222019-03-19 14:58:42 -07006765 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Micheled3107c52018-12-21 15:00:11 -08006766 enforceModifyPermission();
6767
6768 final long identity = Binder.clearCallingIdentity();
6769 try {
6770 mTelephonySharedPreferences.edit()
Michele2fb0f222019-03-19 14:58:42 -07006771 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Micheled3107c52018-12-21 15:00:11 -08006772 .commit();
6773 } finally {
6774 Binder.restoreCallingIdentity(identity);
6775 }
6776 }
6777
6778 @Override
Michele2fb0f222019-03-19 14:58:42 -07006779 @TelephonyManager.IsMultiSimSupportedResult
6780 public int isMultiSimSupported(String callingPackage) {
Michelebcb01bc2019-02-04 11:36:23 -08006781 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele2fb0f222019-03-19 14:58:42 -07006782 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6783 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michelebcb01bc2019-02-04 11:36:23 -08006784 }
Micheled3107c52018-12-21 15:00:11 -08006785
6786 final long identity = Binder.clearCallingIdentity();
6787 try {
Michele2fb0f222019-03-19 14:58:42 -07006788 return isMultiSimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006789 } finally {
6790 Binder.restoreCallingIdentity(identity);
6791 }
6792 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006793
Michele2fb0f222019-03-19 14:58:42 -07006794 @TelephonyManager.IsMultiSimSupportedResult
6795 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006796 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6797 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6798 if (numPhysicalSlots < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006799 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6800 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006801 }
6802 // Check if the hardware supports multisim functionality. If usage of multisim is not
6803 // supported by the modem, indicate that it is restricted.
6804 PhoneCapability staticCapability =
6805 mPhoneConfigurationManager.getStaticPhoneCapability();
6806 if (staticCapability == null) {
Michele2fb0f222019-03-19 14:58:42 -07006807 loge("isMultiSimSupportedInternal: no static configuration available");
6808 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006809 }
6810 if (staticCapability.logicalModemList.size() < 2) {
Michele2fb0f222019-03-19 14:58:42 -07006811 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
6812 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006813 }
6814 // Check if support of multiple SIMs is restricted by carrier
6815 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele2fb0f222019-03-19 14:58:42 -07006816 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08006817 }
6818
Michele2fb0f222019-03-19 14:58:42 -07006819 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08006820 }
6821
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006822 /**
6823 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006824 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6825 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6826 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006827 * @param numOfSims number of active sims we want to switch to
6828 */
6829 @Override
6830 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006831 if (numOfSims == 1) {
6832 enforceModifyPermission();
6833 } else {
6834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6835 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6836 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006837 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006838
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006839 try {
Michele30b57b22019-03-01 12:01:14 -08006840 //only proceed if multi-sim is not restricted
Michele2fb0f222019-03-19 14:58:42 -07006841 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08006842 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6843 return;
6844 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006845 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848 }
6849 }
6850
6851 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006852 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006853 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006854 */
6855 @Override
6856 public boolean isRebootRequiredForModemConfigChange() {
6857 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6858 final long identity = Binder.clearCallingIdentity();
6859 try {
6860 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
6864 }
6865
Pengquan Meng92d253b2019-02-06 11:12:53 -08006866 private void updateModemStateMetrics() {
6867 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6868 // TODO: check the state for each modem if the api is ready.
6869 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6870 }
6871
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006872 @Override
6873 public int[] getSlotsMapping() {
6874 enforceReadPrivilegedPermission("getSlotsMapping");
6875
6876 final long identity = Binder.clearCallingIdentity();
6877 try {
6878 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6879 // All logical slots should have a mapping to a physical slot.
6880 int[] logicalSlotsMapping = new int[phoneCount];
6881 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6882 for (int i = 0; i < slotInfos.length; i++) {
6883 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6884 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6885 }
6886 }
6887 return logicalSlotsMapping;
6888 } finally {
6889 Binder.restoreCallingIdentity(identity);
6890 }
6891 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006892
6893 /**
6894 * Get the IRadio HAL Version
6895 */
6896 @Override
6897 public int getRadioHalVersion() {
6898 Phone phone = getDefaultPhone();
6899 if (phone == null) return -1;
6900 HalVersion hv = phone.getHalVersion();
6901 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6902 return hv.major * 100 + hv.minor;
6903 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006904}