blob: 74f4dee2911dcee5b4189aa4659ffbdc2c477055 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Ta-wei Yen87c49842016-05-13 21:19:52 -070021import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
22
Ta-wei Yen30a69c82016-12-27 14:52:32 -080023import android.Manifest.permission;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070024import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070026import android.content.ComponentName;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.content.Context;
28import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070029import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070030import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070031import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080032import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070033import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070034import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070035import android.net.Uri;
36import android.os.AsyncResult;
37import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080038import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070039import android.os.Bundle;
40import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070041import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Looper;
43import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.Messenger;
Tyler Gunn65d45c22017-06-05 11:22:26 -070045import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080046import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070047import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048import android.os.ServiceManager;
Brad Ebingerdac2f002018-04-03 15:17:52 -070049import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070050import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070052import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070053import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070054import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080055import android.provider.Settings;
Santos Cordon7a1885b2015-02-03 11:15:19 -080056import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080057import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070058import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070059import android.telephony.CarrierConfigManager;
Michele Berionne0963c862018-11-27 18:57:59 -080060import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070061import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070062import android.telephony.CellInfoGsm;
63import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070064import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070065import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070066import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070067import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080068import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070069import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080070import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070071import android.telephony.NetworkScanRequest;
Michelebcb01bc2019-02-04 11:36:23 -080072import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080073import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070074import android.telephony.RadioAccessFamily;
Tyler Gunn65d45c22017-06-05 11:22:26 -070075import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080077import android.telephony.SignalStrength;
Jack Yu84291ec2017-05-26 16:07:50 -070078import android.telephony.SmsManager;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080079import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080080import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070081import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070082import android.telephony.TelephonyManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080083import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000084import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070085import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070086import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070087import android.telephony.cdma.CdmaCellLocation;
Jack Yu311536f2018-11-26 11:20:48 -080088import android.telephony.data.ApnSetting;
calvinpaneed9ae82018-11-01 19:43:06 +080089import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070090import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080091import android.telephony.ims.ProvisioningManager;
Brad Ebinger4c460712018-10-01 10:40:55 -070092import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080093import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -070094import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -080095import android.telephony.ims.aidl.IImsMmTelFeature;
96import android.telephony.ims.aidl.IImsRcsFeature;
97import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger4c460712018-10-01 10:40:55 -070098import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.feature.MmTelFeature;
100import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800101import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700102import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800103import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700104import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800105import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800106import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800107
Brad Ebinger4c460712018-10-01 10:40:55 -0700108import com.android.ims.ImsException;
Andrew Lee312e8172014-10-23 17:01:36 -0700109import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800110import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700111import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700112import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700113import com.android.internal.telephony.CarrierInfoManager;
chen xu02581692018-11-11 19:03:44 -0800114import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700115import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700116import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800118import com.android.internal.telephony.HalVersion;
Hall Liud892bec2018-11-30 14:51:45 -0800119import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800121import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700122import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100123import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700124import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700125import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import com.android.internal.telephony.Phone;
Malcolm Chenf144d942018-08-14 16:00:53 -0700127import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800128import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700129import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700130import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700131import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700132import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700133import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.ServiceStateTracker;
sqian2fff4a32018-11-05 14:18:37 -0800135import com.android.internal.telephony.SmsApplication;
136import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800137import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800138import com.android.internal.telephony.TelephonyPermissions;
sqian9d4df8b2019-01-15 18:32:07 -0800139import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700140import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebingereb160e22019-01-23 15:06:19 -0800141import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng92d253b2019-02-06 11:12:53 -0800142import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700143import com.android.internal.telephony.uicc.IccIoResult;
144import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800145import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700146import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800147import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700148import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800149import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000150import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700151import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800152import com.android.internal.util.HexDump;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700153import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800154import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700155import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700156import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800157
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700158import java.io.FileDescriptor;
159import java.io.PrintWriter;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800160import java.nio.charset.StandardCharsets;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700161import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800162import java.util.Arrays;
sqian2fff4a32018-11-05 14:18:37 -0800163import java.util.Collection;
sqian03bca152018-12-05 18:48:28 -0800164import java.util.HashMap;
sqian9d4df8b2019-01-15 18:32:07 -0800165import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800166import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100167import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800168import java.util.Map;
sqian9d4df8b2019-01-15 18:32:07 -0800169import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700170
171/**
172 * Implementation of the ITelephony interface.
173 */
Santos Cordon117fee72014-05-16 17:56:12 -0700174public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700175 private static final String LOG_TAG = "PhoneInterfaceManager";
176 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
177 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700179
180 // Message codes used with mMainThreadHandler
181 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700182 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
183 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700184 private static final int CMD_OPEN_CHANNEL = 9;
185 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
186 private static final int CMD_CLOSE_CHANNEL = 11;
187 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800188 private static final int CMD_NV_READ_ITEM = 13;
189 private static final int EVENT_NV_READ_ITEM_DONE = 14;
190 private static final int CMD_NV_WRITE_ITEM = 15;
191 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
192 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
193 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu1cc0abe2018-10-26 17:39:23 -0700194 private static final int CMD_RESET_MODEM_CONFIG = 19;
195 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800196 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
197 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
198 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
199 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800200 private static final int CMD_SEND_ENVELOPE = 25;
201 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000202 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
203 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700204 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
205 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
206 private static final int CMD_EXCHANGE_SIM_IO = 31;
207 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800208 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
209 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700210 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
211 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700212 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
213 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700214 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
215 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
216 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
217 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700218 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
219 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
220 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
221 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700222 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800223 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
224 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000225 private static final int CMD_SWITCH_SLOTS = 50;
226 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700227 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
228 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
229 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
230 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
231 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
232 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
233 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
234 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700235 private static final int CMD_GET_ALL_CELL_INFO = 60;
236 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
237 private static final int CMD_GET_CELL_LOCATION = 62;
238 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu1cc0abe2018-10-26 17:39:23 -0700239 private static final int CMD_MODEM_REBOOT = 64;
240 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700241 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
242 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen509b5b72019-01-15 20:22:16 -0800243 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
244 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700245
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800246 // Parameters of select command.
247 private static final int SELECT_COMMAND = 0xA4;
248 private static final int SELECT_P1 = 0x04;
249 private static final int SELECT_P2 = 0;
250 private static final int SELECT_P3 = 0x10;
251
Pengquan Meng85728fb2018-03-12 16:31:21 -0700252 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
253 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
254 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
255
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700256 /** The singleton instance. */
257 private static PhoneInterfaceManager sInstance;
258
Wink Saville3ab207e2014-11-20 13:07:20 -0800259 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800260 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700261 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800262 private AppOpsManager mAppOps;
263 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800264 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800265 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chenf144d942018-08-14 16:00:53 -0700266 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267
Derek Tan97ebb422014-09-05 16:55:38 -0700268 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
269 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800270 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800271 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700272
Micheled3107c52018-12-21 15:00:11 -0800273 // String to store multi SIM allowed
274 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
275
Derek Tan740e1672017-06-27 14:56:27 -0700276 // The AID of ISD-R.
277 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
278
yinxub1bed742017-04-17 11:45:04 -0700279 private NetworkScanRequestTracker mNetworkScanRequestTracker;
280
David Kelly5e06a7f2018-03-12 14:10:59 +0000281 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
282 private static final int MANUFACTURER_CODE_LENGTH = 8;
283
Derek Tan89e89d42014-07-08 17:00:10 -0700284 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700285 * A request object to use for transmitting data to an ICC.
286 */
287 private static final class IccAPDUArgument {
288 public int channel, cla, command, p1, p2, p3;
289 public String data;
290
291 public IccAPDUArgument(int channel, int cla, int command,
292 int p1, int p2, int p3, String data) {
293 this.channel = channel;
294 this.cla = cla;
295 this.command = command;
296 this.p1 = p1;
297 this.p2 = p2;
298 this.p3 = p3;
299 this.data = data;
300 }
301 }
302
303 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700304 * A request object to use for transmitting data to an ICC.
305 */
306 private static final class ManualNetworkSelectionArgument {
307 public OperatorInfo operatorInfo;
308 public boolean persistSelection;
309
310 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
311 this.operatorInfo = operatorInfo;
312 this.persistSelection = persistSelection;
313 }
314 }
315
316 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700317 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
318 * request after sending. The main thread will notify the request when it is complete.
319 */
320 private static final class MainThreadRequest {
321 /** The argument to use for the request */
322 public Object argument;
323 /** The result of the request that is run on the main thread */
324 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800325 // The subscriber id that this request applies to. Defaults to
326 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
327 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700328
Nathan Harold92bed182018-10-12 18:16:49 -0700329 // In cases where subId is unavailable, the caller needs to specify the phone.
330 public Phone phone;
331
vagdevie435a3e2018-08-15 16:01:53 -0700332 public WorkSource workSource;
333
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334 public MainThreadRequest(Object argument) {
335 this.argument = argument;
336 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800337
Nathan Harold92bed182018-10-12 18:16:49 -0700338 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
339 this.argument = argument;
340 if (phone != null) {
341 this.phone = phone;
342 }
343 this.workSource = workSource;
344 }
345
vagdevie435a3e2018-08-15 16:01:53 -0700346 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800347 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800348 if (subId != null) {
349 this.subId = subId;
350 }
vagdevie435a3e2018-08-15 16:01:53 -0700351 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800352 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353 }
354
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800355 private static final class IncomingThirdPartyCallArgs {
356 public final ComponentName component;
357 public final String callId;
358 public final String callerDisplayName;
359
360 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
361 String callerDisplayName) {
362 this.component = component;
363 this.callId = callId;
364 this.callerDisplayName = callerDisplayName;
365 }
366 }
367
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700368 /**
369 * A handler that processes messages on the main thread in the phone process. Since many
370 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
371 * inbound binder threads to the main thread in the phone process. The Binder thread
372 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
373 * on, which will be notified when the operation completes and will contain the result of the
374 * request.
375 *
376 * <p>If a MainThreadRequest object is provided in the msg.obj field,
377 * note that request.result must be set to something non-null for the calling thread to
378 * unblock.
379 */
380 private final class MainThreadHandler extends Handler {
381 @Override
382 public void handleMessage(Message msg) {
383 MainThreadRequest request;
384 Message onCompleted;
385 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800386 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700387 IccAPDUArgument iccArgument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800388 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700389
390 switch (msg.what) {
Pengquan Meng0c05b502018-09-06 09:59:22 -0700391 case CMD_HANDLE_USSD_REQUEST: {
392 request = (MainThreadRequest) msg.obj;
393 final Phone phone = getPhoneFromRequest(request);
394 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
395 String ussdRequest = ussdObject.first;
396 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700397
Pengquan Meng0c05b502018-09-06 09:59:22 -0700398 if (!isUssdApiAllowed(request.subId)) {
399 // Carrier does not support use of this API, return failure.
400 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
401 UssdResponse response = new UssdResponse(ussdRequest, null);
402 Bundle returnData = new Bundle();
403 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
404 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700405
Pengquan Meng0c05b502018-09-06 09:59:22 -0700406 request.result = true;
407 notifyRequester(request);
408 return;
409 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700410
Pengquan Meng0c05b502018-09-06 09:59:22 -0700411 try {
412 request.result = phone != null
413 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
414 } catch (CallStateException cse) {
415 request.result = false;
416 }
417 // Wake up the requesting thread
418 notifyRequester(request);
419 break;
pkanwar32d516d2016-10-14 19:37:38 -0700420 }
421
Yorke Lee716f67e2015-06-17 15:39:16 -0700422 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700423 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700424 final Phone phone = getPhoneFromRequest(request);
425 request.result = phone != null ?
426 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
427 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700428 // Wake up the requesting thread
Pengquan Meng0c05b502018-09-06 09:59:22 -0700429 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700430 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700431 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700432
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700433 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700434 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800436 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700437 if (uiccCard == null) {
438 loge("iccTransmitApduLogicalChannel: No UICC");
439 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700440 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700441 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700442 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
443 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700444 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700445 iccArgument.channel, iccArgument.cla, iccArgument.command,
446 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700447 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700448 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700449 break;
450
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700451 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700452 ar = (AsyncResult) msg.obj;
453 request = (MainThreadRequest) ar.userObj;
454 if (ar.exception == null && ar.result != null) {
455 request.result = ar.result;
456 } else {
457 request.result = new IccIoResult(0x6F, 0, (byte[])null);
458 if (ar.result == null) {
459 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800460 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800462 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 } else {
464 loge("iccTransmitApduLogicalChannel: Unknown exception");
465 }
466 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700467 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700468 break;
469
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
471 request = (MainThreadRequest) msg.obj;
472 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800473 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700474 if (uiccCard == null) {
475 loge("iccTransmitApduBasicChannel: No UICC");
476 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700477 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700478 } else {
479 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
480 request);
481 uiccCard.iccTransmitApduBasicChannel(
482 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
483 iccArgument.p3, iccArgument.data, onCompleted);
484 }
485 break;
486
487 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
488 ar = (AsyncResult) msg.obj;
489 request = (MainThreadRequest) ar.userObj;
490 if (ar.exception == null && ar.result != null) {
491 request.result = ar.result;
492 } else {
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
494 if (ar.result == null) {
495 loge("iccTransmitApduBasicChannel: Empty response");
496 } else if (ar.exception instanceof CommandException) {
497 loge("iccTransmitApduBasicChannel: CommandException: " +
498 ar.exception);
499 } else {
500 loge("iccTransmitApduBasicChannel: Unknown exception");
501 }
502 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700503 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700504 break;
505
506 case CMD_EXCHANGE_SIM_IO:
507 request = (MainThreadRequest) msg.obj;
508 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800509 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700510 if (uiccCard == null) {
511 loge("iccExchangeSimIO: No UICC");
512 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700513 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 } else {
515 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
516 request);
517 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
518 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
519 iccArgument.data, onCompleted);
520 }
521 break;
522
523 case EVENT_EXCHANGE_SIM_IO_DONE:
524 ar = (AsyncResult) msg.obj;
525 request = (MainThreadRequest) ar.userObj;
526 if (ar.exception == null && ar.result != null) {
527 request.result = ar.result;
528 } else {
529 request.result = new IccIoResult(0x6f, 0, (byte[])null);
530 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 break;
533
Derek Tan4d5e5c12014-02-04 11:54:58 -0800534 case CMD_SEND_ENVELOPE:
535 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800536 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 if (uiccCard == null) {
538 loge("sendEnvelopeWithStatus: No UICC");
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700540 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 } else {
542 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
543 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
544 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800545 break;
546
547 case EVENT_SEND_ENVELOPE_DONE:
548 ar = (AsyncResult) msg.obj;
549 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700550 if (ar.exception == null && ar.result != null) {
551 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800552 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
554 if (ar.result == null) {
555 loge("sendEnvelopeWithStatus: Empty response");
556 } else if (ar.exception instanceof CommandException) {
557 loge("sendEnvelopeWithStatus: CommandException: " +
558 ar.exception);
559 } else {
560 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
561 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800562 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700563 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800564 break;
565
Shishir Agrawal566b7612013-10-28 14:41:00 -0700566 case CMD_OPEN_CHANNEL:
567 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800568 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800569 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700570 if (uiccCard == null) {
571 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800572 request.result = new IccOpenLogicalChannelResponse(-1,
573 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700574 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700575 } else {
576 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800577 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
578 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 break;
581
582 case EVENT_OPEN_CHANNEL_DONE:
583 ar = (AsyncResult) msg.obj;
584 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700587 int[] result = (int[]) ar.result;
588 int channelId = result[0];
589 byte[] selectResponse = null;
590 if (result.length > 1) {
591 selectResponse = new byte[result.length - 1];
592 for (int i = 1; i < result.length; ++i) {
593 selectResponse[i - 1] = (byte) result[i];
594 }
595 }
596 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700597 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700598 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700599 if (ar.result == null) {
600 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700601 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 if (ar.exception != null) {
603 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
604 }
605
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700606 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700607 if (ar.exception instanceof CommandException) {
608 CommandException.Error error =
609 ((CommandException) (ar.exception)).getCommandError();
610 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700612 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700613 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(
617 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700619 request.result = openChannelResp;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700620 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 break;
622
623 case CMD_CLOSE_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900628 request.result = false;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700629 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 } else {
631 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
632 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800637 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
638 break;
639
640 case CMD_NV_READ_ITEM:
641 request = (MainThreadRequest) msg.obj;
642 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800643 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
644 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800645 break;
646
647 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 ar = (AsyncResult) msg.obj;
649 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800650 if (ar.exception == null && ar.result != null) {
651 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800653 request.result = "";
654 if (ar.result == null) {
655 loge("nvReadItem: Empty response");
656 } else if (ar.exception instanceof CommandException) {
657 loge("nvReadItem: CommandException: " +
658 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800660 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 }
662 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700663 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700664 break;
665
Jake Hambye994d462014-02-03 13:10:13 -0800666 case CMD_NV_WRITE_ITEM:
667 request = (MainThreadRequest) msg.obj;
668 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
669 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800670 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdevie435a3e2018-08-15 16:01:53 -0700671 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800672 break;
673
674 case EVENT_NV_WRITE_ITEM_DONE:
675 handleNullReturnEvent(msg, "nvWriteItem");
676 break;
677
678 case CMD_NV_WRITE_CDMA_PRL:
679 request = (MainThreadRequest) msg.obj;
680 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800681 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800682 break;
683
684 case EVENT_NV_WRITE_CDMA_PRL_DONE:
685 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
686 break;
687
chen xu1cc0abe2018-10-26 17:39:23 -0700688 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800689 request = (MainThreadRequest) msg.obj;
chen xu1cc0abe2018-10-26 17:39:23 -0700690 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800691 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
chen xu1cc0abe2018-10-26 17:39:23 -0700694 case EVENT_RESET_MODEM_CONFIG_DONE:
695 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
Jake Hamby7c27be32014-03-03 13:25:59 -0800698 case CMD_GET_PREFERRED_NETWORK_TYPE:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700701 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800702 break;
703
704 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
707 if (ar.exception == null && ar.result != null) {
708 request.result = ar.result; // Integer
709 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800710 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800711 if (ar.result == null) {
712 loge("getPreferredNetworkType: Empty response");
713 } else if (ar.exception instanceof CommandException) {
714 loge("getPreferredNetworkType: CommandException: " +
715 ar.exception);
716 } else {
717 loge("getPreferredNetworkType: Unknown exception");
718 }
719 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700720 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800721 break;
722
723 case CMD_SET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
726 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700727 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800728 break;
729
730 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
731 handleNullReturnEvent(msg, "setPreferredNetworkType");
732 break;
733
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000734 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
735 request = (MainThreadRequest)msg.obj;
736 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800737 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000738 break;
739
740 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
741 ar = (AsyncResult)msg.obj;
742 request = (MainThreadRequest)ar.userObj;
743 request.result = ar;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700744 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000745 break;
746
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800747 case CMD_SET_VOICEMAIL_NUMBER:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
750 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800751 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
752 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800753 break;
754
755 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
756 handleNullReturnEvent(msg, "setVoicemailNumber");
757 break;
758
Stuart Scott54788802015-03-30 13:18:01 -0700759 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
762 request);
763 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
764 break;
765
766 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
767 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
768 break;
769
Shishir Agrawal302c8692015-06-19 13:49:39 -0700770 case CMD_PERFORM_NETWORK_SCAN:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
773 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
774 break;
775
776 case EVENT_PERFORM_NETWORK_SCAN_DONE:
777 ar = (AsyncResult) msg.obj;
778 request = (MainThreadRequest) ar.userObj;
779 CellNetworkScanResult cellScanResult;
780 if (ar.exception == null && ar.result != null) {
781 cellScanResult = new CellNetworkScanResult(
782 CellNetworkScanResult.STATUS_SUCCESS,
783 (List<OperatorInfo>) ar.result);
784 } else {
785 if (ar.result == null) {
786 loge("getCellNetworkScanResults: Empty response");
787 }
788 if (ar.exception != null) {
789 loge("getCellNetworkScanResults: Exception: " + ar.exception);
790 }
791 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
792 if (ar.exception instanceof CommandException) {
793 CommandException.Error error =
794 ((CommandException) (ar.exception)).getCommandError();
795 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
796 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
797 } else if (error == CommandException.Error.GENERIC_FAILURE) {
798 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
799 }
800 }
801 cellScanResult = new CellNetworkScanResult(errorCode, null);
802 }
803 request.result = cellScanResult;
Pengquan Meng0c05b502018-09-06 09:59:22 -0700804 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700805 break;
806
807 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
808 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700809 ManualNetworkSelectionArgument selArg =
810 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700811 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
812 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700813 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
814 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700815 break;
816
817 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Mengdd9ac822018-09-20 15:25:35 -0700818 ar = (AsyncResult) msg.obj;
819 request = (MainThreadRequest) ar.userObj;
820 if (ar.exception == null) {
821 request.result = true;
822 } else {
823 request.result = false;
824 loge("setNetworkSelectionModeManual " + ar.exception);
825 }
826 notifyRequester(request);
827 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700828 break;
829
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700830 case CMD_GET_MODEM_ACTIVITY_INFO:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800833 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700834 break;
835
836 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null && ar.result != null) {
840 request.result = ar.result;
841 } else {
842 if (ar.result == null) {
843 loge("queryModemActivityInfo: Empty response");
844 } else if (ar.exception instanceof CommandException) {
845 loge("queryModemActivityInfo: CommandException: " +
846 ar.exception);
847 } else {
848 loge("queryModemActivityInfo: Unknown exception");
849 }
850 }
Amit Mahajand4766222016-01-28 15:28:28 -0800851 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
852 if (request.result == null) {
853 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
854 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700855 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 break;
857
Meng Wang1a7c35a2016-05-05 20:56:15 -0700858 case CMD_SET_ALLOWED_CARRIERS:
859 request = (MainThreadRequest) msg.obj;
Michele Berionne0963c862018-11-27 18:57:59 -0800860 CarrierRestrictionRules argument =
861 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700862 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne0963c862018-11-27 18:57:59 -0800863 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700864 break;
865
866 case EVENT_SET_ALLOWED_CARRIERS_DONE:
867 ar = (AsyncResult) msg.obj;
868 request = (MainThreadRequest) ar.userObj;
869 if (ar.exception == null && ar.result != null) {
870 request.result = ar.result;
871 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800872 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
873 if (ar.exception instanceof CommandException) {
874 loge("setAllowedCarriers: CommandException: " + ar.exception);
875 CommandException.Error error =
876 ((CommandException) (ar.exception)).getCommandError();
877 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 request.result =
879 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
880 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700881 } else {
882 loge("setAllowedCarriers: Unknown exception");
883 }
884 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700885 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 break;
887
888 case CMD_GET_ALLOWED_CARRIERS:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -0800891 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700892 break;
893
894 case EVENT_GET_ALLOWED_CARRIERS_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null && ar.result != null) {
898 request.result = ar.result;
899 } else {
Michele Berionne0963c862018-11-27 18:57:59 -0800900 request.result = new IllegalStateException(
901 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700902 if (ar.result == null) {
903 loge("getAllowedCarriers: Empty response");
904 } else if (ar.exception instanceof CommandException) {
905 loge("getAllowedCarriers: CommandException: " +
906 ar.exception);
907 } else {
908 loge("getAllowedCarriers: Unknown exception");
909 }
910 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700911 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700912 break;
913
Nathan Haroldb3014052017-01-25 15:57:32 -0800914 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
915 ar = (AsyncResult) msg.obj;
916 request = (MainThreadRequest) ar.userObj;
917 if (ar.exception == null && ar.result != null) {
918 request.result = ar.result;
919 } else {
920 request.result = new IllegalArgumentException(
921 "Failed to retrieve Forbidden Plmns");
922 if (ar.result == null) {
923 loge("getForbiddenPlmns: Empty response");
924 } else {
925 loge("getForbiddenPlmns: Unknown exception");
926 }
927 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700928 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800929 break;
930
931 case CMD_GET_FORBIDDEN_PLMNS:
932 request = (MainThreadRequest) msg.obj;
933 uiccCard = getUiccCardFromRequest(request);
934 if (uiccCard == null) {
935 loge("getForbiddenPlmns() UiccCard is null");
936 request.result = new IllegalArgumentException(
937 "getForbiddenPlmns() UiccCard is null");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700938 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800939 break;
940 }
941 Integer appType = (Integer) request.argument;
942 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
943 if (uiccApp == null) {
944 loge("getForbiddenPlmns() no app with specified type -- "
945 + appType);
946 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Meng0c05b502018-09-06 09:59:22 -0700947 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800948 break;
949 } else {
950 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
951 + " specified type -- " + appType);
952 }
953 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
954 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
955 onCompleted);
956 break;
957
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000958 case CMD_SWITCH_SLOTS:
959 request = (MainThreadRequest) msg.obj;
960 int[] physicalSlots = (int[]) request.argument;
961 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
962 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
963 break;
964
965 case EVENT_SWITCH_SLOTS_DONE:
966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
968 request.result = (ar.exception == null);
Pengquan Meng0c05b502018-09-06 09:59:22 -0700969 notifyRequester(request);
970 break;
971 case CMD_GET_NETWORK_SELECTION_MODE:
972 request = (MainThreadRequest) msg.obj;
973 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
974 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
975 break;
976
977 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
978 ar = (AsyncResult) msg.obj;
979 request = (MainThreadRequest) ar.userObj;
980 if (ar.exception != null) {
981 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
982 } else {
983 int mode = ((int[]) ar.result)[0];
984 if (mode == 0) {
985 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
986 } else {
987 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
988 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000989 }
Pengquan Meng0c05b502018-09-06 09:59:22 -0700990 notifyRequester(request);
991 break;
992 case CMD_GET_CDMA_ROAMING_MODE:
993 request = (MainThreadRequest) msg.obj;
994 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
995 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
996 break;
997 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
998 ar = (AsyncResult) msg.obj;
999 request = (MainThreadRequest) ar.userObj;
1000 if (ar.exception != null) {
1001 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1002 } else {
1003 request.result = ((int[]) ar.result)[0];
1004 }
1005 notifyRequester(request);
1006 break;
1007 case CMD_SET_CDMA_ROAMING_MODE:
1008 request = (MainThreadRequest) msg.obj;
1009 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1010 int mode = (int) request.argument;
1011 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1012 break;
1013 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 request.result = ar.exception == null;
1017 notifyRequester(request);
1018 break;
1019 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1022 int subscriptionMode = (int) request.argument;
1023 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1024 break;
1025 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1026 ar = (AsyncResult) msg.obj;
1027 request = (MainThreadRequest) ar.userObj;
1028 request.result = ar.exception == null;
1029 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001030 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001031 case CMD_GET_ALL_CELL_INFO:
1032 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001033 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001034 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001035 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001036 case EVENT_GET_ALL_CELL_INFO_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001039 // If a timeout occurs, the response will be null
1040 request.result = (ar.exception == null && ar.result != null)
1041 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001042 synchronized (request) {
1043 request.notifyAll();
1044 }
1045 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001046 case CMD_REQUEST_CELL_INFO_UPDATE:
1047 request = (MainThreadRequest) msg.obj;
1048 request.phone.requestCellInfoUpdate(request.workSource,
1049 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1050 break;
1051 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1052 ar = (AsyncResult) msg.obj;
1053 request = (MainThreadRequest) ar.userObj;
1054 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1055 try {
1056 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001057 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001058 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1059 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001060 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001061 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001062 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001063 } else {
1064 // use the result as returned
1065 cb.onCellInfo((List<CellInfo>) ar.result);
1066 }
1067 } catch (RemoteException re) {
1068 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1069 }
1070 break;
1071 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001072 request = (MainThreadRequest) msg.obj;
1073 WorkSource ws = (WorkSource) request.argument;
1074 Phone phone = getPhoneFromRequest(request);
1075 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1076 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001078 ar = (AsyncResult) msg.obj;
1079 request = (MainThreadRequest) ar.userObj;
1080 if (ar.exception == null) {
1081 request.result = ar.result;
1082 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001083 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001084 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1085 ? new CdmaCellLocation() : new GsmCellLocation();
1086 }
1087
1088 synchronized (request) {
1089 request.notifyAll();
1090 }
1091 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001092 case CMD_MODEM_REBOOT:
1093 request = (MainThreadRequest) msg.obj;
1094 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001095 defaultPhone.rebootModem(onCompleted);
chen xu1cc0abe2018-10-26 17:39:23 -07001096 break;
chen xu1cc0abe2018-10-26 17:39:23 -07001097 case EVENT_CMD_MODEM_REBOOT_DONE:
1098 handleNullReturnEvent(msg, "rebootModem");
1099 break;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001100 case CMD_REQUEST_ENABLE_MODEM:
1101 request = (MainThreadRequest) msg.obj;
1102 boolean enable = (boolean) request.argument;
1103 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001104 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen509b5b72019-01-15 20:22:16 -08001105 PhoneConfigurationManager.getInstance()
1106 .enablePhone(request.phone, enable, onCompleted);
1107 break;
1108 case EVENT_ENABLE_MODEM_DONE:
1109 ar = (AsyncResult) msg.obj;
1110 request = (MainThreadRequest) ar.userObj;
1111 request.result = (ar.exception == null);
Nazanin Bakhshi9b379572019-03-01 17:27:47 -08001112 //update the cache as modem status has changed
1113 mPhoneConfigurationManager.addToPhoneStatusCache(
1114 request.phone.getPhoneId(), msg.arg1 == 1);
Pengquan Meng92d253b2019-02-06 11:12:53 -08001115 updateModemStateMetrics();
Malcolm Chen509b5b72019-01-15 20:22:16 -08001116 notifyRequester(request);
1117 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001118 default:
1119 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1120 break;
1121 }
1122 }
Jake Hambye994d462014-02-03 13:10:13 -08001123
Pengquan Meng0c05b502018-09-06 09:59:22 -07001124 private void notifyRequester(MainThreadRequest request) {
1125 synchronized (request) {
1126 request.notifyAll();
1127 }
1128 }
1129
Jake Hambye994d462014-02-03 13:10:13 -08001130 private void handleNullReturnEvent(Message msg, String command) {
1131 AsyncResult ar = (AsyncResult) msg.obj;
1132 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1133 if (ar.exception == null) {
1134 request.result = true;
1135 } else {
1136 request.result = false;
1137 if (ar.exception instanceof CommandException) {
1138 loge(command + ": CommandException: " + ar.exception);
1139 } else {
1140 loge(command + ": Unknown exception");
1141 }
1142 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07001143 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001144 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001145 }
1146
1147 /**
1148 * Posts the specified command to be executed on the main thread,
1149 * waits for the request to complete, and returns the result.
1150 * @see #sendRequestAsync
1151 */
1152 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001153 return sendRequest(
1154 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001155 }
1156
1157 /**
1158 * Posts the specified command to be executed on the main thread,
1159 * waits for the request to complete, and returns the result.
1160 * @see #sendRequestAsync
1161 */
1162 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1163 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001164 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001165 }
1166
1167 /**
1168 * Posts the specified command to be executed on the main thread,
1169 * waits for the request to complete, and returns the result.
1170 * @see #sendRequestAsync
1171 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001172 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001173 return sendRequest(command, argument, subId, null, null);
vagdevie435a3e2018-08-15 16:01:53 -07001174 }
1175
1176 /**
1177 * Posts the specified command to be executed on the main thread,
1178 * waits for the request to complete, and returns the result.
1179 * @see #sendRequestAsync
1180 */
Nathan Harold92bed182018-10-12 18:16:49 -07001181 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1182 return sendRequest(command, argument, subId, null, workSource);
1183 }
1184
1185 /**
1186 * Posts the specified command to be executed on the main thread,
1187 * waits for the request to complete, and returns the result.
1188 * @see #sendRequestAsync
1189 */
1190 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1191 return sendRequest(
1192 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1193 }
1194
1195 /**
1196 * Posts the specified command to be executed on the main thread,
1197 * waits for the request to complete, and returns the result.
1198 * @see #sendRequestAsync
1199 */
1200 private Object sendRequest(
1201 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001202 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1203 throw new RuntimeException("This method will deadlock if called from the main thread.");
1204 }
1205
Nathan Harold92bed182018-10-12 18:16:49 -07001206 MainThreadRequest request = null;
1207 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1208 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1209 } else if (phone != null) {
1210 request = new MainThreadRequest(argument, phone, workSource);
1211 } else {
1212 request = new MainThreadRequest(argument, subId, workSource);
1213 }
1214
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001215 Message msg = mMainThreadHandler.obtainMessage(command, request);
1216 msg.sendToTarget();
1217
1218 // Wait for the request to complete
1219 synchronized (request) {
1220 while (request.result == null) {
1221 try {
1222 request.wait();
1223 } catch (InterruptedException e) {
1224 // Do nothing, go back and wait until the request is complete
1225 }
1226 }
1227 }
1228 return request.result;
1229 }
1230
1231 /**
1232 * Asynchronous ("fire and forget") version of sendRequest():
1233 * Posts the specified command to be executed on the main thread, and
1234 * returns immediately.
1235 * @see #sendRequest
1236 */
1237 private void sendRequestAsync(int command) {
1238 mMainThreadHandler.sendEmptyMessage(command);
1239 }
1240
1241 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001242 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001244 */
1245 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001246 sendRequestAsync(command, argument, null, null);
1247 }
1248
1249 /**
1250 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1251 * @see {@link #sendRequest(int,Object)}
1252 */
1253 private void sendRequestAsync(
1254 int command, Object argument, Phone phone, WorkSource workSource) {
1255 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001256 Message msg = mMainThreadHandler.obtainMessage(command, request);
1257 msg.sendToTarget();
1258 }
1259
1260 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001261 * Initialize the singleton PhoneInterfaceManager instance.
1262 * This is only done once, at startup, from PhoneApp.onCreate().
1263 */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001264 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001265 synchronized (PhoneInterfaceManager.class) {
1266 if (sInstance == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001267 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001268 } else {
1269 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1270 }
1271 return sInstance;
1272 }
1273 }
1274
1275 /** Private constructor; @see init() */
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001276 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001277 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001278 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001279 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001280 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1281 mMainThreadHandler = new MainThreadHandler();
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001282 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001283 mTelephonySharedPreferences =
1284 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001285 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chenf144d942018-08-14 16:00:53 -07001286 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001287
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001288 publish();
1289 }
1290
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001291 private Phone getDefaultPhone() {
1292 Phone thePhone = getPhone(getDefaultSubscription());
1293 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1294 }
1295
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001296 private void publish() {
1297 if (DBG) log("publish: " + this);
1298
1299 ServiceManager.addService("phone", this);
1300 }
1301
Stuart Scott584921c2015-01-15 17:10:34 -08001302 private Phone getPhoneFromRequest(MainThreadRequest request) {
Sanket Padawe56e75a32016-02-08 12:18:19 -08001303 return (request.subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001304 ? getDefaultPhone() : getPhone(request.subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001305 }
1306
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001307 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1308 Phone phone = getPhoneFromRequest(request);
1309 return phone == null ? null :
1310 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1311 }
1312
Wink Saville36469e72014-06-11 15:17:00 -07001313 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001314 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001315 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001317
1318 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001319 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001320 }
1321
Wink Savilleb564aae2014-10-23 10:18:09 -07001322 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001323 if (DBG) log("dial: " + number);
1324 // No permission check needed here: This is just a wrapper around the
1325 // ACTION_DIAL intent, which is available to any app since it puts up
1326 // the UI before it does anything.
1327
Malcolm Chend965c8b2018-02-28 15:00:40 -08001328 final long identity = Binder.clearCallingIdentity();
1329 try {
1330 String url = createTelUrl(number);
1331 if (url == null) {
1332 return;
1333 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001334
Malcolm Chend965c8b2018-02-28 15:00:40 -08001335 // PENDING: should we just silently fail if phone is offhook or ringing?
1336 PhoneConstants.State state = mCM.getState(subId);
1337 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1338 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1339 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1340 mApp.startActivity(intent);
1341 }
1342 } finally {
1343 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 }
1345 }
1346
1347 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001348 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001349 }
1350
Wink Savilleb564aae2014-10-23 10:18:09 -07001351 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001352 if (DBG) log("call: " + number);
1353
1354 // This is just a wrapper around the ACTION_CALL intent, but we still
1355 // need to do a permission check since we're calling startActivity()
1356 // from the context of the phone app.
1357 enforceCallPermission();
1358
1359 if (mAppOps.noteOp(AppOpsManager.OP_CALL_PHONE, Binder.getCallingUid(), callingPackage)
1360 != AppOpsManager.MODE_ALLOWED) {
1361 return;
1362 }
1363
Malcolm Chend965c8b2018-02-28 15:00:40 -08001364 final long identity = Binder.clearCallingIdentity();
1365 try {
1366 String url = createTelUrl(number);
1367 if (url == null) {
1368 return;
1369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001370
Malcolm Chend965c8b2018-02-28 15:00:40 -08001371 boolean isValid = false;
1372 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1373 if (slist != null) {
1374 for (SubscriptionInfo subInfoRecord : slist) {
1375 if (subInfoRecord.getSubscriptionId() == subId) {
1376 isValid = true;
1377 break;
1378 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001379 }
Wink Saville08874612014-08-31 19:19:58 -07001380 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001381 if (!isValid) {
1382 return;
1383 }
Wink Saville08874612014-08-31 19:19:58 -07001384
Malcolm Chend965c8b2018-02-28 15:00:40 -08001385 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1386 intent.putExtra(SUBSCRIPTION_KEY, subId);
1387 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1388 mApp.startActivity(intent);
1389 } finally {
1390 Binder.restoreCallingIdentity(identity);
1391 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001392 }
1393
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001395 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001396 }
1397
Wink Savilleb564aae2014-10-23 10:18:09 -07001398 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001399 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001400 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1401 }
1402
1403 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001408 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001409 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1410 }
1411
1412 /** {@hide} */
1413 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001414 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001415 }
1416
Wink Savilleb564aae2014-10-23 10:18:09 -07001417 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001418 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001419
1420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1423 checkSimPin.start();
1424 return checkSimPin.unlockSim(null, pin);
1425 } finally {
1426 Binder.restoreCallingIdentity(identity);
1427 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001428 }
1429
Wink Saville9de0f752013-10-22 19:04:03 -07001430 /** {@hide} */
1431 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001432 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001433 }
1434
Wink Savilleb564aae2014-10-23 10:18:09 -07001435 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001436 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001437
1438 final long identity = Binder.clearCallingIdentity();
1439 try {
1440 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1441 checkSimPuk.start();
1442 return checkSimPuk.unlockSim(puk, pin);
1443 } finally {
1444 Binder.restoreCallingIdentity(identity);
1445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001446 }
1447
1448 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001449 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 * a synchronous one.
1451 */
1452 private static class UnlockSim extends Thread {
1453
1454 private final IccCard mSimCard;
1455
1456 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001457 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1458 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459
1460 // For replies from SimCard interface
1461 private Handler mHandler;
1462
1463 // For async handler to identify request type
1464 private static final int SUPPLY_PIN_COMPLETE = 100;
1465
1466 public UnlockSim(IccCard simCard) {
1467 mSimCard = simCard;
1468 }
1469
1470 @Override
1471 public void run() {
1472 Looper.prepare();
1473 synchronized (UnlockSim.this) {
1474 mHandler = new Handler() {
1475 @Override
1476 public void handleMessage(Message msg) {
1477 AsyncResult ar = (AsyncResult) msg.obj;
1478 switch (msg.what) {
1479 case SUPPLY_PIN_COMPLETE:
1480 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1481 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001482 mRetryCount = msg.arg1;
1483 if (ar.exception != null) {
1484 if (ar.exception instanceof CommandException &&
1485 ((CommandException)(ar.exception)).getCommandError()
1486 == CommandException.Error.PASSWORD_INCORRECT) {
1487 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1488 } else {
1489 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1490 }
1491 } else {
1492 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1493 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001494 mDone = true;
1495 UnlockSim.this.notifyAll();
1496 }
1497 break;
1498 }
1499 }
1500 };
1501 UnlockSim.this.notifyAll();
1502 }
1503 Looper.loop();
1504 }
1505
1506 /*
1507 * Use PIN or PUK to unlock SIM card
1508 *
1509 * If PUK is null, unlock SIM card with PIN
1510 *
1511 * If PUK is not null, unlock SIM card with PUK and set PIN code
1512 */
Wink Saville9de0f752013-10-22 19:04:03 -07001513 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001514
1515 while (mHandler == null) {
1516 try {
1517 wait();
1518 } catch (InterruptedException e) {
1519 Thread.currentThread().interrupt();
1520 }
1521 }
1522 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1523
1524 if (puk == null) {
1525 mSimCard.supplyPin(pin, callback);
1526 } else {
1527 mSimCard.supplyPuk(puk, pin, callback);
1528 }
1529
1530 while (!mDone) {
1531 try {
1532 Log.d(LOG_TAG, "wait for done");
1533 wait();
1534 } catch (InterruptedException e) {
1535 // Restore the interrupted status
1536 Thread.currentThread().interrupt();
1537 }
1538 }
1539 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001540 int[] resultArray = new int[2];
1541 resultArray[0] = mResult;
1542 resultArray[1] = mRetryCount;
1543 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 }
1545 }
1546
1547 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001548 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001549
1550 }
1551
Wink Savilleb564aae2014-10-23 10:18:09 -07001552 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001553 // No permission check needed here: this call is harmless, and it's
1554 // needed for the ServiceState.requestStateUpdate() call (which is
1555 // already intentionally exposed to 3rd parties.)
Malcolm Chend965c8b2018-02-28 15:00:40 -08001556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final Phone phone = getPhone(subId);
1559 if (phone != null) {
1560 phone.updateServiceLocation();
1561 }
1562 } finally {
1563 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001564 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001565 }
1566
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001567 @Override
1568 public boolean isRadioOn(String callingPackage) {
1569 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001570 }
1571
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001572 @Override
1573 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001574 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001575 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001576 return false;
1577 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001578
1579 final long identity = Binder.clearCallingIdentity();
1580 try {
1581 return isRadioOnForSubscriber(subId);
1582 } finally {
1583 Binder.restoreCallingIdentity(identity);
1584 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001585 }
1586
1587 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001588 final long identity = Binder.clearCallingIdentity();
1589 try {
1590 final Phone phone = getPhone(subId);
1591 if (phone != null) {
1592 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1593 } else {
1594 return false;
1595 }
1596 } finally {
1597 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001598 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001599 }
1600
1601 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001602 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001603 }
Wink Saville36469e72014-06-11 15:17:00 -07001604
Wink Savilleb564aae2014-10-23 10:18:09 -07001605 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001607
1608 final long identity = Binder.clearCallingIdentity();
1609 try {
1610 final Phone phone = getPhone(subId);
1611 if (phone != null) {
1612 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1613 }
1614 } finally {
1615 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001616 }
Wink Saville36469e72014-06-11 15:17:00 -07001617 }
1618
1619 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001620 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001621 }
1622
Wink Savilleb564aae2014-10-23 10:18:09 -07001623 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001624 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001625
1626 final long identity = Binder.clearCallingIdentity();
1627 try {
1628 final Phone phone = getPhone(subId);
1629 if (phone == null) {
1630 return false;
1631 }
1632 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1633 toggleRadioOnOffForSubscriber(subId);
1634 }
1635 return true;
1636 } finally {
1637 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001638 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001639 }
Wink Saville36469e72014-06-11 15:17:00 -07001640
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001641 public boolean needMobileRadioShutdown() {
1642 /*
1643 * If any of the Radios are available, it will need to be
1644 * shutdown. So return true if any Radio is available.
1645 */
Malcolm Chend965c8b2018-02-28 15:00:40 -08001646 final long identity = Binder.clearCallingIdentity();
1647 try {
1648 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1649 Phone phone = PhoneFactory.getPhone(i);
1650 if (phone != null && phone.isRadioAvailable()) return true;
1651 }
1652 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1653 return false;
1654 } finally {
1655 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001656 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001657 }
1658
Malcolm Chend965c8b2018-02-28 15:00:40 -08001659 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001660 public void shutdownMobileRadios() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001661 enforceModifyPermission();
1662
1663 final long identity = Binder.clearCallingIdentity();
1664 try {
1665 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1666 logv("Shutting down Phone " + i);
1667 shutdownRadioUsingPhoneId(i);
1668 }
1669 } finally {
1670 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001671 }
1672 }
1673
1674 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001675 Phone phone = PhoneFactory.getPhone(phoneId);
1676 if (phone != null && phone.isRadioAvailable()) {
1677 phone.shutdownRadio();
1678 }
1679 }
1680
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001681 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001682 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001683
1684 final long identity = Binder.clearCallingIdentity();
1685 try {
1686 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1687 if (defaultPhone != null) {
1688 defaultPhone.setRadioPower(turnOn);
1689 return true;
1690 } else {
1691 loge("There's no default phone.");
1692 return false;
1693 }
1694 } finally {
1695 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001696 }
Wink Saville36469e72014-06-11 15:17:00 -07001697 }
1698
Wink Savilleb564aae2014-10-23 10:18:09 -07001699 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001700 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001701
1702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 final Phone phone = getPhone(subId);
1705 if (phone != null) {
1706 phone.setRadioPower(turnOn);
1707 return true;
1708 } else {
1709 return false;
1710 }
1711 } finally {
1712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 }
1715
Wink Saville36469e72014-06-11 15:17:00 -07001716 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001717 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 public boolean enableDataConnectivity() {
1719 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001720
1721 final long identity = Binder.clearCallingIdentity();
1722 try {
1723 int subId = mSubscriptionController.getDefaultDataSubId();
1724 final Phone phone = getPhone(subId);
1725 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001726 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001727 return true;
1728 } else {
1729 return false;
1730 }
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
Wink Saville36469e72014-06-11 15:17:00 -07001736 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001737 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001738 public boolean disableDataConnectivity() {
1739 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001740
1741 final long identity = Binder.clearCallingIdentity();
1742 try {
1743 int subId = mSubscriptionController.getDefaultDataSubId();
1744 final Phone phone = getPhone(subId);
1745 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08001746 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001747 return true;
1748 } else {
1749 return false;
1750 }
1751 } finally {
1752 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001753 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001754 }
1755
Sanket Padawe356d7632015-06-22 14:03:32 -07001756 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001757 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
Jack Yu311536f2018-11-26 11:20:48 -08001762 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001763 } else {
1764 return false;
1765 }
1766 } finally {
1767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 }
1770
1771 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001772 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001773 }
1774
pkanwarae03a6b2016-11-06 20:37:09 -08001775 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001776 enforceCallPermission();
1777
1778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1781 return;
1782 }
1783 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1784 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1785 } finally {
1786 Binder.restoreCallingIdentity(identity);
1787 }
pkanwar32d516d2016-10-14 19:37:38 -07001788 };
1789
Wink Savilleb564aae2014-10-23 10:18:09 -07001790 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001791 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08001792
1793 final long identity = Binder.clearCallingIdentity();
1794 try {
1795 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1796 return false;
1797 }
1798 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1799 } finally {
1800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001802 }
1803
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001804 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001805 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001806 }
1807
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001808 public int getCallStateForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001809 final long identity = Binder.clearCallingIdentity();
1810 try {
1811 Phone phone = PhoneFactory.getPhone(slotIndex);
1812 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1813 PhoneConstantConversions.convertCallState(phone.getState());
1814 } finally {
1815 Binder.restoreCallingIdentity(identity);
1816 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001817 }
1818
Sanket Padawe356d7632015-06-22 14:03:32 -07001819 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001820 public int getDataState() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1824 if (phone != null) {
1825 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1826 } else {
1827 return PhoneConstantConversions.convertDataState(
1828 PhoneConstants.DataState.DISCONNECTED);
1829 }
1830 } finally {
1831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001832 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 }
1834
Sanket Padawe356d7632015-06-22 14:03:32 -07001835 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 public int getDataActivity() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08001837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 Phone phone = getPhone(mSubscriptionController.getDefaultDataSubId());
1840 if (phone != null) {
1841 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1842 } else {
1843 return TelephonyManager.DATA_ACTIVITY_NONE;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 }
1849
1850 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001851 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001852 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001853 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001854
1855 LocationAccessPolicy.LocationPermissionResult locationResult =
1856 LocationAccessPolicy.checkLocationPermission(mApp,
1857 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1858 .setCallingPackage(callingPackage)
1859 .setCallingPid(Binder.getCallingPid())
1860 .setCallingUid(Binder.getCallingUid())
1861 .setMethod("getCellLocation")
1862 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1863 .build());
1864 switch (locationResult) {
1865 case DENIED_HARD:
1866 throw new SecurityException("Not allowed to access cell location");
1867 case DENIED_SOFT:
1868 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 }
1870
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001871 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08001872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 if (DBG_LOC) log("getCellLocation: is active user");
1875 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001876 int subId = mSubscriptionController.getDefaultDataSubId();
1877 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1878 cl.fillInNotifierBundle(data);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001879 return data;
1880 } finally {
1881 Binder.restoreCallingIdentity(identity);
1882 }
Svetoslav64fad262015-04-14 14:35:21 -07001883 }
1884
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001886 public String getNetworkCountryIsoForPhone(int phoneId) {
1887 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1888 // registered cell info, so return a NULL country instead.
1889 final long identity = Binder.clearCallingIdentity();
1890 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001891 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1892 // Get default phone in this case.
1893 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1894 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001895 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001896 // Todo: fix this when we can get the actual cellular network info when the device
1897 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001898 if (TelephonyManager.NETWORK_TYPE_IWLAN
1899 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1900 return "";
1901 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08001902 Phone phone = PhoneFactory.getPhone(phoneId);
1903 if (phone != null) {
1904 ServiceStateTracker sst = phone.getServiceStateTracker();
1905 if (sst != null) {
1906 LocaleTracker lt = sst.getLocaleTracker();
1907 if (lt != null) {
1908 return lt.getCurrentCountry();
1909 }
1910 }
1911 }
1912 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001913 } finally {
1914 Binder.restoreCallingIdentity(identity);
1915 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001916 }
1917
1918 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001920 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001921 }
1922
Sanket Padawe356d7632015-06-22 14:03:32 -07001923 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001924 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 mApp.enforceCallingOrSelfPermission(
1926 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001927
1928 final long identity = Binder.clearCallingIdentity();
1929 try {
1930 final Phone phone = getPhone(subId);
1931 if (phone != null) {
1932 phone.enableLocationUpdates();
1933 }
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 @Override
1940 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001941 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Sanket Padawe356d7632015-06-22 14:03:32 -07001944 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001945 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 mApp.enforceCallingOrSelfPermission(
1947 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chend965c8b2018-02-28 15:00:40 -08001948
1949 final long identity = Binder.clearCallingIdentity();
1950 try {
1951 final Phone phone = getPhone(subId);
1952 if (phone != null) {
1953 phone.disableLocationUpdates();
1954 }
1955 } finally {
1956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001957 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 }
1959
Nathan Harold31d7ff32018-10-15 20:20:30 -07001960 /**
1961 * Returns the target SDK version number for a given package name.
1962 *
1963 * @return target SDK if the package is found or INT_MAX.
1964 */
1965 private int getTargetSdk(String packageName) {
1966 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08001967 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(
1968 packageName, 0);
Nathan Harold31d7ff32018-10-15 20:20:30 -07001969 if (ai != null) return ai.targetSdkVersion;
1970 } catch (PackageManager.NameNotFoundException unexpected) {
1971 }
1972 return Integer.MAX_VALUE;
1973 }
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 @Override
1976 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07001977 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
1978 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07001979 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
1980 throw new SecurityException(
1981 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
1982 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07001983
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 if (mAppOps.noteOp(AppOpsManager.OP_NEIGHBORING_CELLS, Binder.getCallingUid(),
1985 callingPackage) != AppOpsManager.MODE_ALLOWED) {
1986 return null;
1987 }
Svetoslav64fad262015-04-14 14:35:21 -07001988
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07001989 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001990
Nathan Haroldf180aac2018-06-01 18:43:55 -07001991 List<CellInfo> info = getAllCellInfo(callingPackage);
1992 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001993
Nathan Haroldf180aac2018-06-01 18:43:55 -07001994 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
1995 for (CellInfo ci : info) {
1996 if (ci instanceof CellInfoGsm) {
1997 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
1998 } else if (ci instanceof CellInfoWcdma) {
1999 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002002 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002005 private List<CellInfo> getCachedCellInfo() {
2006 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2007 for (Phone phone : PhoneFactory.getPhones()) {
2008 List<CellInfo> info = phone.getAllCellInfo();
2009 if (info != null) cellInfos.addAll(info);
2010 }
2011 return cellInfos;
2012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013
2014 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002015 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002016 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002017 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002018
2019 LocationAccessPolicy.LocationPermissionResult locationResult =
2020 LocationAccessPolicy.checkLocationPermission(mApp,
2021 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2022 .setCallingPackage(callingPackage)
2023 .setCallingPid(Binder.getCallingPid())
2024 .setCallingUid(Binder.getCallingUid())
2025 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002026 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002027 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2028 .build());
2029 switch (locationResult) {
2030 case DENIED_HARD:
2031 throw new SecurityException("Not allowed to access cell info");
2032 case DENIED_SOFT:
2033 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 }
2035
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002036 final int targetSdk = getTargetSdk(callingPackage);
2037 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2038 return getCachedCellInfo();
2039 }
2040
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002041 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002043 final long identity = Binder.clearCallingIdentity();
2044 try {
2045 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2046 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002047 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002048 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002049 if (info != null) cellInfos.addAll(info);
2050 }
2051 return cellInfos;
2052 } finally {
2053 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 }
2055 }
2056
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002057 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002058 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2059 requestCellInfoUpdateInternal(
2060 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2061 }
2062
2063 @Override
2064 public void requestCellInfoUpdateWithWorkSource(
2065 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2066 enforceModifyPermission();
2067 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2068 }
2069
2070 private void requestCellInfoUpdateInternal(
2071 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002072 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002073 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002074
2075 LocationAccessPolicy.LocationPermissionResult locationResult =
2076 LocationAccessPolicy.checkLocationPermission(mApp,
2077 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2078 .setCallingPackage(callingPackage)
2079 .setCallingPid(Binder.getCallingPid())
2080 .setCallingUid(Binder.getCallingUid())
2081 .setMethod("requestCellInfoUpdate")
2082 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2083 .build());
2084 switch (locationResult) {
2085 case DENIED_HARD:
2086 throw new SecurityException("Not allowed to access cell info");
2087 case DENIED_SOFT:
2088 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002089 }
2090
2091 final Phone phone = getPhone(subId);
2092 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2093
2094 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2095 }
2096
2097 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002099 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08002101
2102 final long identity = Binder.clearCallingIdentity();
2103 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002104 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002105 } finally {
2106 Binder.restoreCallingIdentity(identity);
2107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
Shishir Agrawala9f32182016-04-12 12:00:16 -07002110 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002111 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002112 Phone phone = PhoneFactory.getPhone(slotIndex);
2113 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002114 return null;
2115 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002116 int subId = phone.getSubId();
2117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2118 mApp, subId, callingPackage, "getImeiForSlot")) {
2119 return null;
2120 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002121
2122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 return phone.getImei();
2125 } finally {
2126 Binder.restoreCallingIdentity(identity);
2127 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002128 }
2129
2130 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002131 public String getTypeAllocationCodeForSlot(int slotIndex) {
2132 Phone phone = PhoneFactory.getPhone(slotIndex);
2133 String tac = null;
2134 if (phone != null) {
2135 String imei = phone.getImei();
2136 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2137 }
2138 return tac;
2139 }
2140
2141 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002142 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002143 Phone phone = PhoneFactory.getPhone(slotIndex);
2144 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002145 return null;
2146 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002147
Jeff Davidson913390f2018-02-23 17:11:49 -08002148 int subId = phone.getSubId();
2149 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2150 mApp, subId, callingPackage, "getMeidForSlot")) {
2151 return null;
2152 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002153
2154 final long identity = Binder.clearCallingIdentity();
2155 try {
2156 return phone.getMeid();
2157 } finally {
2158 Binder.restoreCallingIdentity(identity);
2159 }
Jack Yu2af8d712017-03-15 17:14:14 -07002160 }
2161
2162 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002163 public String getManufacturerCodeForSlot(int slotIndex) {
2164 Phone phone = PhoneFactory.getPhone(slotIndex);
2165 String manufacturerCode = null;
2166 if (phone != null) {
2167 String meid = phone.getMeid();
2168 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2169 }
2170 return manufacturerCode;
2171 }
2172
2173 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002174 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002175 Phone phone = PhoneFactory.getPhone(slotIndex);
2176 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002177 return null;
2178 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002179 int subId = phone.getSubId();
2180 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2181 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2182 return null;
2183 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002184
2185 final long identity = Binder.clearCallingIdentity();
2186 try {
2187 return phone.getDeviceSvn();
2188 } finally {
2189 Binder.restoreCallingIdentity(identity);
2190 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002191 }
2192
fionaxu43304da2017-11-27 22:51:16 -08002193 @Override
2194 public int getSubscriptionCarrierId(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002195 final long identity = Binder.clearCallingIdentity();
2196 try {
2197 final Phone phone = getPhone(subId);
2198 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2199 } finally {
2200 Binder.restoreCallingIdentity(identity);
2201 }
fionaxu43304da2017-11-27 22:51:16 -08002202 }
2203
2204 @Override
2205 public String getSubscriptionCarrierName(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 final Phone phone = getPhone(subId);
2209 return phone == null ? null : phone.getCarrierName();
2210 } finally {
2211 Binder.restoreCallingIdentity(identity);
2212 }
fionaxu43304da2017-11-27 22:51:16 -08002213 }
2214
calvinpaneed9ae82018-11-01 19:43:06 +08002215 @Override
chen xua31f22b2019-03-06 15:28:50 -08002216 public int getSubscriptionSpecificCarrierId(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002217 final long identity = Binder.clearCallingIdentity();
2218 try {
2219 final Phone phone = getPhone(subId);
2220 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xua31f22b2019-03-06 15:28:50 -08002221 : phone.getSpecificCarrierId();
chen xuc93cc282018-11-04 17:17:00 -08002222 } finally {
2223 Binder.restoreCallingIdentity(identity);
2224 }
2225 }
2226
2227 @Override
chen xua31f22b2019-03-06 15:28:50 -08002228 public String getSubscriptionSpecificCarrierName(int subId) {
chen xuc93cc282018-11-04 17:17:00 -08002229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 final Phone phone = getPhone(subId);
chen xua31f22b2019-03-06 15:28:50 -08002232 return phone == null ? null : phone.getSpecificCarrierName();
chen xuc93cc282018-11-04 17:17:00 -08002233 } finally {
2234 Binder.restoreCallingIdentity(identity);
2235 }
2236 }
2237
chen xu02581692018-11-11 19:03:44 -08002238 @Override
chen xu4ca4e692018-12-06 22:10:03 -08002239 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2240 if (!isSubscriptionMccMnc) {
2241 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2242 }
chen xu02581692018-11-11 19:03:44 -08002243 final Phone phone = PhoneFactory.getPhone(slotIndex);
2244 if (phone == null) {
2245 return TelephonyManager.UNKNOWN_CARRIER_ID;
2246 }
2247 final long identity = Binder.clearCallingIdentity();
2248 try {
2249 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
2252 }
2253 }
2254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 //
2256 // Internal helper methods.
2257 //
2258
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002259 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002260 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2261 *
2262 * @throws SecurityException if the caller does not have the required permission
2263 */
2264 private void enforceModifyPermission() {
2265 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2266 }
2267
2268 /**
2269 * Make sure the caller has the CALL_PHONE permission.
2270 *
2271 * @throws SecurityException if the caller does not have the required permission
2272 */
2273 private void enforceCallPermission() {
2274 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2275 }
2276
Stuart Scott8eef64f2015-04-08 15:13:54 -07002277 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002278 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002279 "ConnectivityService");
2280 }
2281
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 private String createTelUrl(String number) {
2283 if (TextUtils.isEmpty(number)) {
2284 return null;
2285 }
2286
Jake Hambye994d462014-02-03 13:10:13 -08002287 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 }
2289
Ihab Awadf9e92732013-12-05 18:02:52 -08002290 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2292 }
2293
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002294 private static void logv(String msg) {
2295 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2296 }
2297
Ihab Awadf9e92732013-12-05 18:02:52 -08002298 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2300 }
2301
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002304 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002308 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002309 final long identity = Binder.clearCallingIdentity();
2310 try {
2311 final Phone phone = PhoneFactory.getPhone(slotIndex);
2312 if (phone == null) {
2313 return PhoneConstants.PHONE_TYPE_NONE;
2314 } else {
2315 return phone.getPhoneType();
2316 }
2317 } finally {
2318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002319 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002320 }
2321
2322 /**
2323 * Returns the CDMA ERI icon index to display
2324 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 @Override
2326 public int getCdmaEriIconIndex(String callingPackage) {
2327 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002328 }
2329
Sanket Padawe356d7632015-06-22 14:03:32 -07002330 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002331 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002333 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 return -1;
2335 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002336
2337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 if (phone != null) {
2341 return phone.getCdmaEriIconIndex();
2342 } else {
2343 return -1;
2344 }
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349
2350 /**
2351 * Returns the CDMA ERI icon mode,
2352 * 0 - ON
2353 * 1 - FLASHING
2354 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002355 @Override
2356 public int getCdmaEriIconMode(String callingPackage) {
2357 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002358 }
2359
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002361 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002363 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002364 return -1;
2365 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002366
2367 final long identity = Binder.clearCallingIdentity();
2368 try {
2369 final Phone phone = getPhone(subId);
2370 if (phone != null) {
2371 return phone.getCdmaEriIconMode();
2372 } else {
2373 return -1;
2374 }
2375 } finally {
2376 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379
2380 /**
2381 * Returns the CDMA ERI text,
2382 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002383 @Override
2384 public String getCdmaEriText(String callingPackage) {
2385 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002386 }
2387
Sanket Padawe356d7632015-06-22 14:03:32 -07002388 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002389 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002391 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002392 return null;
2393 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002394
2395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 final Phone phone = getPhone(subId);
2398 if (phone != null) {
2399 return phone.getCdmaEriText();
2400 } else {
2401 return null;
2402 }
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002405 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002406 }
2407
2408 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002409 * Returns the CDMA MDN.
2410 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002411 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002412 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002413 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2414 mApp, subId, "getCdmaMdn");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002415
2416 final long identity = Binder.clearCallingIdentity();
2417 try {
2418 final Phone phone = getPhone(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002419 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002420 return phone.getLine1Number();
2421 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002422 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002423 return null;
2424 }
2425 } finally {
2426 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002427 }
2428 }
2429
2430 /**
2431 * Returns the CDMA MIN.
2432 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002433 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002434 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2436 mApp, subId, "getCdmaMin");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002437
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 final Phone phone = getPhone(subId);
2441 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2442 return phone.getCdmaMin();
2443 } else {
2444 return null;
2445 }
2446 } finally {
2447 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002448 }
2449 }
2450
Hall Liud892bec2018-11-30 14:51:45 -08002451 @Override
2452 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2453 INumberVerificationCallback callback, String callingPackage) {
2454 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2455 != PERMISSION_GRANTED) {
2456 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2457 }
2458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2459
2460 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2461 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2462 throw new SecurityException("Calling package must be configured in the device config");
2463 }
2464
2465 if (range == null) {
2466 throw new NullPointerException("Range must be non-null");
2467 }
2468
2469 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002470 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002471
2472 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2473 }
2474
Junda Liuca05d5d2014-08-14 22:36:34 -07002475 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002476 * Returns true if CDMA provisioning needs to run.
2477 */
2478 public boolean needsOtaServiceProvisioning() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002479 final long identity = Binder.clearCallingIdentity();
2480 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002481 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chend965c8b2018-02-28 15:00:40 -08002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002488 * Sets the voice mail number of a given subId.
2489 */
2490 @Override
2491 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002492 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2497 new Pair<String, String>(alphaTag, number), new Integer(subId));
2498 return success;
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
2501 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002502 }
2503
Ta-wei Yen87c49842016-05-13 21:19:52 -07002504 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002505 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2506 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002507 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002508 if (!TextUtils.equals(callingPackage, systemDialer)) {
2509 throw new SecurityException("caller must be system dialer");
2510 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2515 if (phoneAccountHandle == null) {
2516 return null;
2517 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002518 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002519 } finally {
2520 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002521 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002522 }
2523
2524 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002525 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002527 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002529 return null;
2530 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002531
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002532 final long identity = Binder.clearCallingIdentity();
2533 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002534 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002535 } finally {
2536 Binder.restoreCallingIdentity(identity);
2537 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002538 }
2539
2540 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002541 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2542 VisualVoicemailSmsFilterSettings settings) {
2543 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002548 mApp, callingPackage, subId, settings);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002552 }
2553
2554 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002555 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2556 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002561 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002562 } finally {
2563 Binder.restoreCallingIdentity(identity);
2564 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002565 }
2566
2567 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002568 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2569 String callingPackage, int subId) {
2570 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002571
2572 final long identity = Binder.clearCallingIdentity();
2573 try {
2574 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002575 mApp, callingPackage, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002576 } finally {
2577 Binder.restoreCallingIdentity(identity);
2578 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002579 }
2580
2581 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002582 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002583 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002584
2585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002588 mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002592 }
2593
2594 @Override
2595 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2596 String number, int port, String text, PendingIntent sentIntent) {
2597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002598 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002599 enforceSendSmsPermission();
2600 // Make the calls as the phone process.
2601 final long identity = Binder.clearCallingIdentity();
2602 try {
2603 SmsManager smsManager = SmsManager.getSmsManagerForSubscriptionId(subId);
2604 if (port == 0) {
2605 smsManager.sendTextMessageWithSelfPermissions(number, null, text,
2606 sentIntent, null, false);
2607 } else {
2608 byte[] data = text.getBytes(StandardCharsets.UTF_8);
2609 smsManager.sendDataMessageWithSelfPermissions(number, null,
2610 (short) port, data, sentIntent, null);
2611 }
2612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002615 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002616 /**
fionaxu0152e512016-11-14 13:36:14 -08002617 * Sets the voice activation state of a given subId.
2618 */
2619 @Override
2620 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2622 mApp, subId, "setVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002623
2624 final long identity = Binder.clearCallingIdentity();
2625 try {
2626 final Phone phone = getPhone(subId);
2627 if (phone != null) {
2628 phone.setVoiceActivationState(activationState);
2629 } else {
2630 loge("setVoiceActivationState fails with invalid subId: " + subId);
2631 }
2632 } finally {
2633 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002634 }
2635 }
2636
2637 /**
2638 * Sets the data activation state of a given subId.
2639 */
2640 @Override
2641 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002642 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2643 mApp, subId, "setDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 final Phone phone = getPhone(subId);
2648 if (phone != null) {
2649 phone.setDataActivationState(activationState);
2650 } else {
2651 loge("setVoiceActivationState fails with invalid subId: " + subId);
2652 }
2653 } finally {
2654 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002655 }
2656 }
2657
2658 /**
2659 * Returns the voice activation state of a given subId.
2660 */
2661 @Override
2662 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002663 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002664
fionaxu0152e512016-11-14 13:36:14 -08002665 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 if (phone != null) {
2669 return phone.getVoiceActivationState();
2670 } else {
2671 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2672 }
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002675 }
2676 }
2677
2678 /**
2679 * Returns the data activation state of a given subId.
2680 */
2681 @Override
2682 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002683 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chend965c8b2018-02-28 15:00:40 -08002684
fionaxu0152e512016-11-14 13:36:14 -08002685 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 if (phone != null) {
2689 return phone.getDataActivationState();
2690 } else {
2691 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2692 }
2693 } finally {
2694 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002695 }
2696 }
2697
2698 /**
Wink Saville36469e72014-06-11 15:17:00 -07002699 * Returns the unread count of voicemails for a subId
2700 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002701 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002702 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2704 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2705 return 0;
2706 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 final Phone phone = getPhone(subId);
2710 if (phone != null) {
2711 return phone.getVoiceMessageCount();
2712 } else {
2713 return 0;
2714 }
2715 } finally {
2716 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002717 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002718 }
2719
2720 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002721 * returns true, if the device is in a state where both voice and data
2722 * are supported simultaneously. This can change based on location or network condition.
2723 */
2724 @Override
2725 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 final Phone phone = getPhone(subId);
2729 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002733 }
2734
2735 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002736 * Send the dialer code if called from the current default dialer or the caller has
2737 * carrier privilege.
2738 * @param inputCode The dialer code to send
2739 */
2740 @Override
2741 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002742 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002743 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002744 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2745 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002746 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002747 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2748 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002749 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08002750
2751 final long identity = Binder.clearCallingIdentity();
2752 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002753 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chend965c8b2018-02-28 15:00:40 -08002754 } finally {
2755 Binder.restoreCallingIdentity(identity);
2756 }
fionaxu235cc5e2017-03-06 22:25:57 -08002757 }
2758
2759 /**
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002760 * Returns the data network type.
2761 * Legacy call, permission-free.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 *
2763 * @Deprecated to be removed Q3 2013 use {@link #getDataNetworkType}.
2764 */
2765 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002766 public int getNetworkType() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(getDefaultSubscription());
2770 if (phone != null) {
2771 return phone.getServiceState().getDataNetworkType();
2772 } else {
2773 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07002777 }
Wink Saville36469e72014-06-11 15:17:00 -07002778 }
2779
Pengquan Meng0c05b502018-09-06 09:59:22 -07002780 @Override
2781 public int getNetworkSelectionMode(int subId) {
Pengquan Meng466e2482018-09-21 15:54:48 -07002782 if (!isActiveSubscription(subId)) {
2783 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2784 }
2785
Pengquan Meng0c05b502018-09-06 09:59:22 -07002786 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2787 }
2788
Brad Ebinger4c460712018-10-01 10:40:55 -07002789 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002790 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2791 throws RemoteException {
2792 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002793 final long token = Binder.clearCallingIdentity();
2794 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002795 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002796 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002797 .addRegistrationCallbackForSubscription(c, subId);
2798 } finally {
2799 Binder.restoreCallingIdentity(token);
2800 }
2801 }
2802
2803 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002804 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2805 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2808 }
2809 Binder.withCleanCallingIdentity(() -> {
2810 try {
2811 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002812 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002813 .removeRegistrationCallbackForSubscription(c, subId);
2814 } catch (IllegalArgumentException e) {
2815 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2816 + "is inactive, ignoring unregister.");
2817 // If the subscription is no longer active, just return, since the callback
2818 // will already have been removed internally.
2819 }
2820 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002821 }
2822
2823 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002824 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2825 throws RemoteException {
2826 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger4c460712018-10-01 10:40:55 -07002827 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2828 final long token = Binder.clearCallingIdentity();
2829 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002830 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4c460712018-10-01 10:40:55 -07002831 .addCapabilitiesCallbackForSubscription(c, subId);
2832 } finally {
2833 Binder.restoreCallingIdentity(token);
2834 }
2835 }
2836
2837 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002838 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2839 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002840
2841 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2842 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2843 }
2844 Binder.withCleanCallingIdentity(() -> {
2845 try {
2846 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002847 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002848 .removeCapabilitiesCallbackForSubscription(c, subId);
2849 } catch (IllegalArgumentException e) {
2850 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2851 + "is inactive, ignoring unregister.");
2852 // If the subscription is no longer active, just return, since the callback
2853 // will already have been removed internally.
2854 }
2855 });
Brad Ebinger4c460712018-10-01 10:40:55 -07002856 }
2857
2858 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002859 public boolean isCapable(int subId, int capability, int regTech) {
2860 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002861 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2862 final long token = Binder.clearCallingIdentity();
2863 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002864 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002865 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
2866 } catch (ImsException e) {
2867 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2868 return false;
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002869 } catch (IllegalArgumentException e) {
2870 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2871 return false;
Brad Ebinger4c460712018-10-01 10:40:55 -07002872 } finally {
2873 Binder.restoreCallingIdentity(token);
2874 }
2875 }
2876
2877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002878 public boolean isAvailable(int subId, int capability, int regTech) {
2879 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger4c460712018-10-01 10:40:55 -07002880 final long token = Binder.clearCallingIdentity();
2881 try {
2882 Phone phone = getPhone(subId);
2883 if (phone == null) return false;
2884 return phone.isImsCapabilityAvailable(capability, regTech);
2885 } finally {
2886 Binder.restoreCallingIdentity(token);
2887 }
2888 }
2889
2890 @Override
2891 public boolean isAdvancedCallingSettingEnabled(int subId) {
2892 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2893 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2894 final long token = Binder.clearCallingIdentity();
2895 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002896 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002897 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
2898 } finally {
2899 Binder.restoreCallingIdentity(token);
2900 }
2901 }
2902
2903 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002904 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002906 "setAdvancedCallingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002907 final long identity = Binder.clearCallingIdentity();
2908 try {
2909 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002910 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002911 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
2914 }
2915 }
2916
2917 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002918 public boolean isVtSettingEnabled(int subId) {
2919 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002920 final long identity = Binder.clearCallingIdentity();
2921 try {
2922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002923 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002924 getSlotIndexOrException(subId)).isVtEnabledByUser();
2925 } finally {
2926 Binder.restoreCallingIdentity(identity);
2927 }
2928 }
2929
2930 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002931 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002933 "setVtSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002934 final long identity = Binder.clearCallingIdentity();
2935 try {
2936 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002937 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002938 } finally {
2939 Binder.restoreCallingIdentity(identity);
2940 }
2941 }
2942
2943 @Override
2944 public boolean isVoWiFiSettingEnabled(int subId) {
2945 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
2946 final long identity = Binder.clearCallingIdentity();
2947 try {
2948 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002949 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002950 getSlotIndexOrException(subId)).isWfcEnabledByUser();
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
2954 }
2955
2956 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002957 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002958 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002959 "setVoWiFiSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002960 final long identity = Binder.clearCallingIdentity();
2961 try {
2962 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002963 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger4c460712018-10-01 10:40:55 -07002964 } finally {
2965 Binder.restoreCallingIdentity(identity);
2966 }
2967 }
2968
2969 @Override
2970 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
2971 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
2972 final long identity = Binder.clearCallingIdentity();
2973 try {
2974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002975 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002976 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
2977 } finally {
2978 Binder.restoreCallingIdentity(identity);
2979 }
2980 }
2981
2982 @Override
Brad Ebinger0de268e2019-02-21 14:49:10 -08002983 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger4c460712018-10-01 10:40:55 -07002984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger0de268e2019-02-21 14:49:10 -08002985 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger4c460712018-10-01 10:40:55 -07002986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08002989 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07002990 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
2991 } finally {
2992 Binder.restoreCallingIdentity(identity);
2993 }
2994 }
2995
2996 @Override
2997 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
2998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
2999 "setVoWiFiNonPersistent");
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger43e66f12019-01-15 12:40:04 -08003003 boolean isRoaming = TelephonyManager.from(
3004 getPhone(subId).getContext()).isNetworkRoaming(subId);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003005 ImsManager.getInstance(mApp,
Brad Ebinger43e66f12019-01-15 12:40:04 -08003006 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode, isRoaming);
Brad Ebinger4c460712018-10-01 10:40:55 -07003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
3009 }
3010 }
3011
3012 @Override
3013 public int getVoWiFiModeSetting(int subId) {
3014 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003018 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003019 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
3020 } finally {
3021 Binder.restoreCallingIdentity(identity);
3022 }
3023 }
3024
3025 @Override
3026 public void setVoWiFiModeSetting(int subId, int mode) {
3027 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3028 "setVoWiFiModeSetting");
3029 final long identity = Binder.clearCallingIdentity();
3030 try {
3031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003032 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003033 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
3034 } finally {
3035 Binder.restoreCallingIdentity(identity);
3036 }
3037 }
3038
3039 @Override
3040 public int getVoWiFiRoamingModeSetting(int subId) {
3041 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003045 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003046 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
3047 } finally {
3048 Binder.restoreCallingIdentity(identity);
3049 }
3050 }
3051
3052 @Override
3053 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3054 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3055 "setVoWiFiRoamingModeSetting");
3056 final long identity = Binder.clearCallingIdentity();
3057 try {
3058 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003059 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003060 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
3061 } finally {
3062 Binder.restoreCallingIdentity(identity);
3063 }
3064 }
3065
3066 @Override
3067 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3068 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3069 "setRttCapabilityEnabled");
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 ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003074 getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
3078 }
3079
3080 @Override
3081 public boolean isTtyOverVolteEnabled(int subId) {
3082 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003086 return ImsManager.getInstance(mApp,
Brad Ebinger4c460712018-10-01 10:40:55 -07003087 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
3088 } finally {
3089 Binder.restoreCallingIdentity(identity);
3090 }
3091 }
3092
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003093 @Override
3094 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3095 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3096 final long identity = Binder.clearCallingIdentity();
3097 try {
3098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003099 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003100 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3108 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3109 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003110 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3111 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3112 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003113 try {
3114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003115 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003116 .removeProvisioningCallbackForSubscription(callback, subId);
3117 } catch (IllegalArgumentException e) {
3118 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3119 + "is inactive, ignoring unregister.");
3120 // If the subscription is no longer active, just return, since the callback will already
3121 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003122 } finally {
3123 Binder.restoreCallingIdentity(identity);
3124 }
3125 }
3126
3127 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003128 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3129 boolean isProvisioned) {
3130 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3131 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3132 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3133 }
3134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3135 "setProvisioningStatusForCapability");
3136 final long identity = Binder.clearCallingIdentity();
3137 try {
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3139 Phone phone = getPhone(subId);
3140 if (phone == null) {
3141 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3142 + subId);
3143 return;
3144 }
3145 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3146 return;
3147 }
3148
3149 // this capability requires provisioning, route to the correct API.
3150 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3151 switch (capability) {
3152 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3153 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3154 ims.setVolteProvisioned(isProvisioned);
3155 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3156 ims.setWfcProvisioned(isProvisioned);
3157 }
3158 break;
3159 }
3160 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3161 // There is currently no difference in VT provisioning type.
3162 ims.setVtProvisioned(isProvisioned);
3163 break;
3164 }
3165 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3166 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3167 // change the capability of the feature instead if needed.
3168 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3169 == isProvisioned) {
3170 // No change in provisioning.
3171 return;
3172 }
3173 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3174 try {
3175 ims.changeMmTelCapability(capability, tech, isProvisioned);
3176 } catch (ImsException e) {
3177 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3178 + ", Exception" + e.getMessage());
3179 }
3180 break;
3181 }
3182 default: {
3183 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3184 + capability + "', which does not require provisioning.");
3185 }
3186 }
3187
3188 } finally {
3189 Binder.restoreCallingIdentity(identity);
3190 }
3191 }
3192
3193 @Override
3194 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3195 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3196 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3197 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3198 }
3199 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3200 final long identity = Binder.clearCallingIdentity();
3201 try {
3202 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3203 Phone phone = getPhone(subId);
3204 if (phone == null) {
3205 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3206 + subId);
3207 // We will fail with "true" as the provisioning status because this is the default
3208 // if we do not require provisioning.
3209 return true;
3210 }
3211
3212 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3213 return true;
3214 }
3215
3216 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3217 switch (capability) {
3218 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3219 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3220 return ims.isVolteProvisionedOnDevice();
3221 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3222 return ims.isWfcProvisionedOnDevice();
3223 }
3224 // This should never happen, since we are checking tech above to make sure it
3225 // is either LTE or IWLAN.
3226 throw new IllegalArgumentException("Invalid radio technology for voice "
3227 + "capability.");
3228 }
3229 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3230 // There is currently no difference in VT provisioning type.
3231 return ims.isVtProvisionedOnDevice();
3232 }
3233 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3234 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3235 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3236 }
3237 default: {
3238 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3239 + capability + "', which does not require provisioning.");
3240 }
3241 }
3242
3243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
3248 @Override
3249 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3250 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3251 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3252 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3253 }
3254 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3255 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3256 return (provisionedBits & capability) > 0;
3257 }
3258
3259 @Override
3260 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3261 boolean isProvisioned) {
3262 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3263 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3264 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3265 }
3266 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3267 "setProvisioningStatusForCapability");
3268 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3269 // If the current provisioning status for capability already matches isProvisioned,
3270 // do nothing.
3271 if (((provisionedBits & capability) > 0) == isProvisioned) {
3272 return;
3273 }
3274 if (isProvisioned) {
3275 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3276 } else {
3277 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3278 }
3279 }
3280
3281 /**
3282 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3283 * technology. The bitfield should mirror the bitfield defined by
3284 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3285 */
3286 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3287 String key = getMmTelProvisioningKey(subId, tech);
3288 // Default is no capabilities are provisioned.
3289 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3290 }
3291
3292 /**
3293 * Sets the MmTel capability provisioning bitfield (defined by
3294 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3295 * technology specified.
3296 *
3297 * Note: This is a synchronous command and should not be called on UI thread.
3298 */
3299 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3300 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3301 String key = getMmTelProvisioningKey(subId, tech);
3302 editor.putInt(key, newField);
3303 editor.commit();
3304 }
3305
3306 private static String getMmTelProvisioningKey(int subId, int tech) {
3307 // resulting key is provision_ims_mmtel_{subId}_{tech}
3308 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3309 }
3310
3311 /**
3312 * Query CarrierConfig to see if the specified capability requires provisioning for the
3313 * carrier associated with the subscription id.
3314 */
3315 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3316 int capability) {
3317 CarrierConfigManager configManager = new CarrierConfigManager(context);
3318 PersistableBundle c = configManager.getConfigForSubId(subId);
3319 boolean requireUtProvisioning = c.getBoolean(
3320 // By default, this config is true (even if there is no SIM). We also check to make
3321 // sure the subscription needs provisioning here, so we do not need to check for
3322 // the no-SIM case, where we would normally shortcut this to false.
3323 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, true)
3324 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3325 false);
3326 boolean requireVoiceVtProvisioning = c.getBoolean(
3327 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3328
3329 // First check to make sure that the capability requires provisioning.
3330 switch (capability) {
3331 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3332 // intentional fallthrough
3333 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3334 if (requireVoiceVtProvisioning) {
3335 // Voice and Video requires provisioning
3336 return true;
3337 }
3338 break;
3339 }
3340 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3341 if (requireUtProvisioning) {
3342 // UT requires provisioning
3343 return true;
3344 }
3345 break;
3346 }
3347 }
3348 return false;
3349 }
3350
3351 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003352 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003353 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3354 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3355 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003356 enforceReadPrivilegedPermission("getImsProvisioningInt");
3357 final long identity = Binder.clearCallingIdentity();
3358 try {
3359 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003360 int slotId = getSlotIndex(subId);
3361 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3362 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3363 + subId + "' for key:" + key);
3364 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3365 }
3366 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003367 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003368 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3369 + subId + "' for key:" + key);
3370 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003371 } finally {
3372 Binder.restoreCallingIdentity(identity);
3373 }
3374 }
3375
3376 @Override
3377 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003378 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3379 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3380 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003381 enforceReadPrivilegedPermission("getImsProvisioningString");
3382 final long identity = Binder.clearCallingIdentity();
3383 try {
3384 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003385 int slotId = getSlotIndex(subId);
3386 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3387 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3388 + subId + "' for key:" + key);
3389 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3390 }
3391 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003392 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003393 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3394 + subId + "' for key:" + key);
3395 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003396 } finally {
3397 Binder.restoreCallingIdentity(identity);
3398 }
3399 }
3400
3401 @Override
3402 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003403 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3404 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3405 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3407 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003411 int slotId = getSlotIndex(subId);
3412 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3413 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3414 + subId + "' for key:" + key);
3415 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3416 }
3417 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003418 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003419 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3420 + "' for key:" + key);
3421 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
3425 }
3426
3427 @Override
3428 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003429 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3430 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3431 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003432 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3433 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003434 final long identity = Binder.clearCallingIdentity();
3435 try {
3436 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003437 int slotId = getSlotIndex(subId);
3438 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3439 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3440 + subId + "' for key:" + key);
3441 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3442 }
3443 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003444 } catch (ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003445 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3446 + "' for key:" + key);
3447 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003448 } finally {
3449 Binder.restoreCallingIdentity(identity);
3450 }
3451 }
3452
Brad Ebinger4c460712018-10-01 10:40:55 -07003453 private int getSlotIndexOrException(int subId) throws IllegalArgumentException {
3454 int slotId = SubscriptionManager.getSlotIndex(subId);
3455 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003456 throw new IllegalArgumentException("Invalid Subscription Id, subId=" + subId);
Brad Ebinger4c460712018-10-01 10:40:55 -07003457 }
3458 return slotId;
3459 }
3460
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003461 private int getSlotIndex(int subId) {
3462 int slotId = SubscriptionManager.getSlotIndex(subId);
3463 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3464 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3465 }
3466 return slotId;
3467 }
3468
Wink Saville36469e72014-06-11 15:17:00 -07003469 /**
3470 * Returns the network type for a subId
3471 */
3472 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003473 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003474 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003475 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003476 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3477 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003478
Malcolm Chend965c8b2018-02-28 15:00:40 -08003479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 final Phone phone = getPhone(subId);
3482 if (phone != null) {
3483 return phone.getServiceState().getDataNetworkType();
3484 } else {
3485 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3486 }
3487 } finally {
3488 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003489 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003490 }
3491
3492 /**
3493 * Returns the data network type
3494 */
3495 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003496 public int getDataNetworkType(String callingPackage) {
3497 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003498 }
3499
3500 /**
3501 * Returns the data network type for a subId
3502 */
3503 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003504 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003505 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003506 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003507 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3508 }
3509
Malcolm Chend965c8b2018-02-28 15:00:40 -08003510 final long identity = Binder.clearCallingIdentity();
3511 try {
3512 final Phone phone = getPhone(subId);
3513 if (phone != null) {
3514 return phone.getServiceState().getDataNetworkType();
3515 } else {
3516 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3517 }
3518 } finally {
3519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003521 }
3522
3523 /**
Wink Saville36469e72014-06-11 15:17:00 -07003524 * Returns the Voice network type for a subId
3525 */
3526 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003527 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003528 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003529 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003530 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3531 }
3532
Malcolm Chend965c8b2018-02-28 15:00:40 -08003533 final long identity = Binder.clearCallingIdentity();
3534 try {
3535 final Phone phone = getPhone(subId);
3536 if (phone != null) {
3537 return phone.getServiceState().getVoiceNetworkType();
3538 } else {
3539 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3540 }
3541 } finally {
3542 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003543 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003544 }
3545
3546 /**
3547 * @return true if a ICC card is present
3548 */
3549 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003550 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003551 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3552 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003553 }
3554
3555 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003556 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003557 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003558 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003559 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003560 final long identity = Binder.clearCallingIdentity();
3561 try {
3562 final Phone phone = PhoneFactory.getPhone(slotIndex);
3563 if (phone != null) {
3564 return phone.getIccCard().hasIccCard();
3565 } else {
3566 return false;
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003570 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003571 }
3572
3573 /**
3574 * Return if the current radio is LTE on CDMA. This
3575 * is a tri-state return value as for a period of time
3576 * the mode may be unknown.
3577 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003578 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003579 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003580 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003581 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003582 @Override
3583 public int getLteOnCdmaMode(String callingPackage) {
3584 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003585 }
3586
Sanket Padawe356d7632015-06-22 14:03:32 -07003587 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003588 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003589 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003590 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003591 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3592 }
3593
Malcolm Chend965c8b2018-02-28 15:00:40 -08003594 final long identity = Binder.clearCallingIdentity();
3595 try {
3596 final Phone phone = getPhone(subId);
3597 if (phone == null) {
3598 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3599 } else {
3600 return phone.getLteOnCdmaMode();
3601 }
3602 } finally {
3603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003604 }
Wink Saville36469e72014-06-11 15:17:00 -07003605 }
3606
Wink Saville36469e72014-06-11 15:17:00 -07003607 /**
3608 * {@hide}
3609 * Returns Default subId, 0 in the case of single standby.
3610 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003611 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003612 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003613 }
3614
Shishir Agrawala9f32182016-04-12 12:00:16 -07003615 private int getSlotForDefaultSubscription() {
3616 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3617 }
3618
Wink Savilleb564aae2014-10-23 10:18:09 -07003619 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003620 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003621 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003622
Pengquan Meng466e2482018-09-21 15:54:48 -07003623 private boolean isActiveSubscription(int subId) {
3624 return mSubscriptionController.isActiveSubId(subId);
3625 }
3626
Ihab Awadf2177b72013-11-25 13:33:23 -08003627 /**
3628 * @see android.telephony.TelephonyManager.WifiCallingChoices
3629 */
3630 public int getWhenToMakeWifiCalls() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003631 final long identity = Binder.clearCallingIdentity();
3632 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003633 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003634 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3635 getWhenToMakeWifiCallsDefaultPreference());
3636 } finally {
3637 Binder.restoreCallingIdentity(identity);
3638 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003639 }
3640
3641 /**
3642 * @see android.telephony.TelephonyManager.WifiCallingChoices
3643 */
3644 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08003645 final long identity = Binder.clearCallingIdentity();
3646 try {
3647 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003648 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08003649 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003653 }
3654
Sailesh Nepald1e68152013-12-12 19:08:02 -08003655 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003656 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003657 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003658 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003659
Shishir Agrawal566b7612013-10-28 14:41:00 -07003660 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003661 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3662 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3664 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003665 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003666
Malcolm Chend965c8b2018-02-28 15:00:40 -08003667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 if (TextUtils.equals(ISDR_AID, aid)) {
3670 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003671 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3672 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003673 if (bestComponent == null
3674 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3675 loge("The calling package is not allowed to access ISD-R.");
3676 throw new SecurityException(
3677 "The calling package is not allowed to access ISD-R.");
3678 }
Derek Tan740e1672017-06-27 14:56:27 -07003679 }
Derek Tan740e1672017-06-27 14:56:27 -07003680
Malcolm Chend965c8b2018-02-28 15:00:40 -08003681 if (DBG) {
3682 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3683 }
3684 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
3685 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), subId);
3686 if (DBG) log("iccOpenLogicalChannel: " + response);
3687 return response;
3688 } finally {
3689 Binder.restoreCallingIdentity(identity);
3690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003691 }
3692
3693 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003694 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3696 mApp, subId, "iccCloseLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003697
Malcolm Chend965c8b2018-02-28 15:00:40 -08003698 final long identity = Binder.clearCallingIdentity();
3699 try {
3700 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3701 if (channel < 0) {
3702 return false;
3703 }
3704 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, subId);
3705 if (DBG) log("iccCloseLogicalChannel: " + success);
3706 return success;
3707 } finally {
3708 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003709 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003710 }
3711
3712 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003713 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003714 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003715 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3716 mApp, subId, "iccTransmitApduLogicalChannel");
Shishir Agrawal566b7612013-10-28 14:41:00 -07003717
Malcolm Chend965c8b2018-02-28 15:00:40 -08003718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 if (DBG) {
3721 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3722 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3723 + p3 + " data=" + data);
3724 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003725
Malcolm Chend965c8b2018-02-28 15:00:40 -08003726 if (channel < 0) {
3727 return "";
3728 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003729
Malcolm Chend965c8b2018-02-28 15:00:40 -08003730 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
3731 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), subId);
3732 if (DBG) log("iccTransmitApduLogicalChannel: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003733
Malcolm Chend965c8b2018-02-28 15:00:40 -08003734 // Append the returned status code to the end of the response payload.
3735 String s = Integer.toHexString(
3736 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3737 if (response.payload != null) {
3738 s = IccUtils.bytesToHexString(response.payload) + s;
3739 }
3740 return s;
3741 } finally {
3742 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003743 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003744 }
Jake Hambye994d462014-02-03 13:10:13 -08003745
Evan Charltonc66da362014-05-16 14:06:40 -07003746 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003747 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3748 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003749 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3750 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003752
Malcolm Chend965c8b2018-02-28 15:00:40 -08003753 final long identity = Binder.clearCallingIdentity();
3754 try {
3755 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3756 && TextUtils.equals(ISDR_AID, data)) {
3757 // Only allows LPA to select ISD-R.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08003758 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3759 .getContext().getPackageManager());
Malcolm Chend965c8b2018-02-28 15:00:40 -08003760 if (bestComponent == null
3761 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3762 loge("The calling package is not allowed to select ISD-R.");
3763 throw new SecurityException(
3764 "The calling package is not allowed to select ISD-R.");
3765 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003766 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003767
Malcolm Chend965c8b2018-02-28 15:00:40 -08003768 if (DBG) {
3769 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3770 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3771 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003772
Malcolm Chend965c8b2018-02-28 15:00:40 -08003773 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
3774 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), subId);
3775 if (DBG) log("iccTransmitApduBasicChannel: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003776
Malcolm Chend965c8b2018-02-28 15:00:40 -08003777 // Append the returned status code to the end of the response payload.
3778 String s = Integer.toHexString(
3779 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3780 if (response.payload != null) {
3781 s = IccUtils.bytesToHexString(response.payload) + s;
3782 }
3783 return s;
3784 } finally {
3785 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003786 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003787 }
3788
3789 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003790 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003791 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3793 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003794
Malcolm Chend965c8b2018-02-28 15:00:40 -08003795 final long identity = Binder.clearCallingIdentity();
3796 try {
3797 if (DBG) {
3798 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3799 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3800 }
3801
3802 IccIoResult response =
3803 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3804 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3805 subId);
3806
3807 if (DBG) {
3808 log("Exchange SIM_IO [R]" + response);
3809 }
3810
3811 byte[] result = null;
3812 int length = 2;
3813 if (response.payload != null) {
3814 length = 2 + response.payload.length;
3815 result = new byte[length];
3816 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3817 } else {
3818 result = new byte[length];
3819 }
3820
3821 result[length - 1] = (byte) response.sw2;
3822 result[length - 2] = (byte) response.sw1;
3823 return result;
3824 } finally {
3825 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003826 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003827 }
3828
Nathan Haroldb3014052017-01-25 15:57:32 -08003829 /**
3830 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
3831 * on a particular subscription
3832 */
sqianb6e41952018-03-12 14:54:01 -07003833 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
3834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
3835 mApp, subId, callingPackage, "getForbiddenPlmns")) {
3836 return null;
3837 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003838
3839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 if (appType != TelephonyManager.APPTYPE_USIM
3842 && appType != TelephonyManager.APPTYPE_SIM) {
3843 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
3844 return null;
3845 }
3846 Object response = sendRequest(
3847 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
3848 if (response instanceof String[]) {
3849 return (String[]) response;
3850 }
3851 // Response is an Exception of some kind,
3852 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08003853 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08003854 } finally {
3855 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08003856 }
Nathan Haroldb3014052017-01-25 15:57:32 -08003857 }
3858
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003859 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003860 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003861 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3862 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07003863
Malcolm Chend965c8b2018-02-28 15:00:40 -08003864 final long identity = Binder.clearCallingIdentity();
3865 try {
3866 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
3867 if (response.payload == null) {
3868 return "";
3869 }
Evan Charltonc66da362014-05-16 14:06:40 -07003870
Malcolm Chend965c8b2018-02-28 15:00:40 -08003871 // Append the returned status code to the end of the response payload.
3872 String s = Integer.toHexString(
3873 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3874 s = IccUtils.bytesToHexString(response.payload) + s;
3875 return s;
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
Evan Charltonc66da362014-05-16 14:06:40 -07003879 }
3880
Jake Hambye994d462014-02-03 13:10:13 -08003881 /**
3882 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3883 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3884 *
3885 * @param itemID the ID of the item to read
3886 * @return the NV item as a String, or null on error.
3887 */
3888 @Override
3889 public String nvReadItem(int itemID) {
vagdevie435a3e2018-08-15 16:01:53 -07003890 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3892 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003893
3894 final long identity = Binder.clearCallingIdentity();
3895 try {
3896 if (DBG) log("nvReadItem: item " + itemID);
vagdevie435a3e2018-08-15 16:01:53 -07003897 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003898 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
3899 return value;
3900 } finally {
3901 Binder.restoreCallingIdentity(identity);
3902 }
Jake Hambye994d462014-02-03 13:10:13 -08003903 }
3904
3905 /**
3906 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
3907 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
3908 *
3909 * @param itemID the ID of the item to read
3910 * @param itemValue the value to write, as a String
3911 * @return true on success; false on any failure
3912 */
3913 @Override
3914 public boolean nvWriteItem(int itemID, String itemValue) {
vagdevie435a3e2018-08-15 16:01:53 -07003915 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08003916 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3917 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003918
3919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
3922 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdevie435a3e2018-08-15 16:01:53 -07003923 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08003924 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
3925 return success;
3926 } finally {
3927 Binder.restoreCallingIdentity(identity);
3928 }
Jake Hambye994d462014-02-03 13:10:13 -08003929 }
3930
3931 /**
3932 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
3933 * Used for device configuration by some CDMA operators.
3934 *
3935 * @param preferredRoamingList byte array containing the new PRL
3936 * @return true on success; false on any failure
3937 */
3938 @Override
3939 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3941 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003942
3943 final long identity = Binder.clearCallingIdentity();
3944 try {
3945 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
3946 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
3947 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
3948 return success;
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
Jake Hambye994d462014-02-03 13:10:13 -08003952 }
3953
3954 /**
chen xu1cc0abe2018-10-26 17:39:23 -07003955 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08003956 * Used for device configuration by some CDMA operators.
3957 *
chen xu1cc0abe2018-10-26 17:39:23 -07003958 * @param slotIndex - device slot.
3959 *
Jake Hambye994d462014-02-03 13:10:13 -08003960 * @return true on success; false on any failure
3961 */
3962 @Override
chen xu1cc0abe2018-10-26 17:39:23 -07003963 public boolean resetModemConfig(int slotIndex) {
3964 Phone phone = PhoneFactory.getPhone(slotIndex);
3965 if (phone != null) {
3966 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3967 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chend965c8b2018-02-28 15:00:40 -08003968
chen xu1cc0abe2018-10-26 17:39:23 -07003969 final long identity = Binder.clearCallingIdentity();
3970 try {
3971 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
3972 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
3973 return success;
3974 } finally {
3975 Binder.restoreCallingIdentity(identity);
3976 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08003977 }
chen xu1cc0abe2018-10-26 17:39:23 -07003978 return false;
3979 }
3980
3981 /**
3982 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
3983 *
3984 * @param slotIndex - device slot.
3985 *
3986 * @return true on success; false on any failure
3987 */
3988 @Override
3989 public boolean rebootModem(int slotIndex) {
3990 Phone phone = PhoneFactory.getPhone(slotIndex);
3991 if (phone != null) {
3992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3993 mApp, phone.getSubId(), "rebootModem");
3994
3995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
3998 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
3999 return success;
4000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004005 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004006
Svet Ganovb320e182015-04-16 12:30:10 -07004007 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004008 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004010 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004011 return new String[0];
4012 }
4013
Malcolm Chend965c8b2018-02-28 15:00:40 -08004014 final long identity = Binder.clearCallingIdentity();
4015 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004016 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
Wink Saville36469e72014-06-11 15:17:00 -07004020 }
4021
Brad Ebinger51f743a2017-01-23 13:50:20 -08004022 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004023 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4024 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004025 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004026 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004027 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004028
4029 final long identity = Binder.clearCallingIdentity();
4030 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004031 ImsResolver resolver = PhoneFactory.getImsResolver();
4032 if (resolver == null) {
4033 // may happen if the device does not support IMS.
4034 return;
4035 }
4036 resolver.enableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004040 }
4041
4042 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004043 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4044 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004045 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004046 public void disableIms(int slotId) {
4047 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004048
4049 final long identity = Binder.clearCallingIdentity();
4050 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004051 ImsResolver resolver = PhoneFactory.getImsResolver();
4052 if (resolver == null) {
4053 // may happen if the device does not support IMS.
4054 return;
4055 }
4056 resolver.disableIms(slotId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004057 } finally {
4058 Binder.restoreCallingIdentity(identity);
4059 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004060 }
4061
4062 /**
4063 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4064 * feature or {@link null} if the service is not available. If the feature is available, the
4065 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4066 */
4067 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004068 IImsServiceFeatureCallback callback) {
4069 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004070
4071 final long identity = Binder.clearCallingIdentity();
4072 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004073 ImsResolver resolver = PhoneFactory.getImsResolver();
4074 if (resolver == null) {
4075 // may happen if the device does not support IMS.
4076 return null;
4077 }
4078 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004082 }
4083
4084 /**
4085 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4086 * feature during emergency calling or {@link null} if the service is not available. If the
4087 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4088 * listener for feature updates.
4089 */
4090 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4091 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004092
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004095 ImsResolver resolver = PhoneFactory.getImsResolver();
4096 if (resolver == null) {
4097 // may happen if the device does not support IMS.
4098 return null;
4099 }
4100 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004104 }
4105
Brad Ebinger5f64b052017-12-14 14:26:15 -08004106 /**
4107 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004108 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004109 */
4110 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4111 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004112
4113 final long identity = Binder.clearCallingIdentity();
4114 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004115 ImsResolver resolver = PhoneFactory.getImsResolver();
4116 if (resolver == null) {
4117 // may happen if the device does not support IMS.
4118 return null;
4119 }
4120 return resolver.getImsRegistration(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004124 }
4125
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004126 /**
4127 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebingereb160e22019-01-23 15:06:19 -08004128 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004129 */
4130 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4131 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004132
4133 final long identity = Binder.clearCallingIdentity();
4134 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004135 ImsResolver resolver = PhoneFactory.getImsResolver();
4136 if (resolver == null) {
4137 // may happen if the device does not support IMS.
4138 return null;
4139 }
4140 return resolver.getImsConfig(slotId, feature);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004144 }
4145
Brad Ebinger884c07b2018-02-15 16:17:40 -08004146 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004147 * Sets the ImsService Package Name that Telephony will bind to.
4148 *
4149 * @param slotId the slot ID that the ImsService should bind for.
4150 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4151 * ImsService is the device default ImsService.
4152 * @param packageName The package name of the application that contains the ImsService to bind
4153 * to.
4154 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4155 * @hide
4156 */
4157 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004158 int[] subIds = SubscriptionManager.getSubId(slotId);
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4160 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4161 "setImsService");
4162
Malcolm Chend965c8b2018-02-28 15:00:40 -08004163 final long identity = Binder.clearCallingIdentity();
4164 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004165 ImsResolver resolver = PhoneFactory.getImsResolver();
4166 if (resolver == null) {
4167 // may happen if the device does not support IMS.
4168 return false;
4169 }
4170 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4171 packageName);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004172 } finally {
4173 Binder.restoreCallingIdentity(identity);
4174 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004175 }
4176
4177 /**
4178 * Return the ImsService configuration.
4179 *
4180 * @param slotId The slot that the ImsService is associated with.
4181 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4182 * the device default.
4183 * @return the package name of the ImsService configuration.
4184 */
4185 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004186 int[] subIds = SubscriptionManager.getSubId(slotId);
4187 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4188 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4189 "getImsService");
4190
Malcolm Chend965c8b2018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
Brad Ebingereb160e22019-01-23 15:06:19 -08004193 ImsResolver resolver = PhoneFactory.getImsResolver();
4194 if (resolver == null) {
4195 // may happen if the device does not support IMS.
4196 return "";
4197 }
4198 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004199 } finally {
4200 Binder.restoreCallingIdentity(identity);
4201 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004202 }
4203
Wink Saville36469e72014-06-11 15:17:00 -07004204 public void setImsRegistrationState(boolean registered) {
4205 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004206
4207 final long identity = Binder.clearCallingIdentity();
4208 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004209 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
4212 }
Wink Saville36469e72014-06-11 15:17:00 -07004213 }
4214
4215 /**
Stuart Scott54788802015-03-30 13:18:01 -07004216 * Set the network selection mode to automatic.
4217 *
4218 */
4219 @Override
4220 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004221 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4222 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004223
Pengquan Meng466e2482018-09-21 15:54:48 -07004224 if (!isActiveSubscription(subId)) {
4225 return;
4226 }
4227
Malcolm Chend965c8b2018-02-28 15:00:40 -08004228 final long identity = Binder.clearCallingIdentity();
4229 try {
4230 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4231 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
Stuart Scott54788802015-03-30 13:18:01 -07004235 }
4236
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004237 /**
4238 * Ask the radio to connect to the input network and change selection mode to manual.
4239 *
4240 * @param subId the id of the subscription.
4241 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4242 * the operator to attach to.
4243 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4244 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4245 * normal network selection next time.
4246 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004247 */
4248 @Override
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004249 public boolean setNetworkSelectionModeManual(
4250 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4252 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Meng466e2482018-09-21 15:54:48 -07004253
4254 if (!isActiveSubscription(subId)) {
4255 return false;
4256 }
4257
Malcolm Chend965c8b2018-02-28 15:00:40 -08004258 final long identity = Binder.clearCallingIdentity();
4259 try {
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004260 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chend965c8b2018-02-28 15:00:40 -08004261 persistSelection);
Pengquan Menga4d9cff2018-09-20 14:57:26 -07004262 if (DBG) {
4263 log("setNetworkSelectionModeManual: subId: " + subId
4264 + " operator: " + operatorInfo);
4265 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004266 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4267 } finally {
4268 Binder.restoreCallingIdentity(identity);
4269 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004270 }
4271
4272 /**
4273 * Scans for available networks.
4274 */
4275 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004276 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004277 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4278 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004279 LocationAccessPolicy.LocationPermissionResult locationResult =
4280 LocationAccessPolicy.checkLocationPermission(mApp,
4281 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4282 .setCallingPackage(callingPackage)
4283 .setCallingPid(Binder.getCallingPid())
4284 .setCallingUid(Binder.getCallingUid())
4285 .setMethod("getCellNetworkScanResults")
4286 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4287 .build());
4288 switch (locationResult) {
4289 case DENIED_HARD:
4290 throw new SecurityException("Not allowed to access scan results -- location");
4291 case DENIED_SOFT:
4292 return null;
4293 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004294
Pengquan Meng0c05b502018-09-06 09:59:22 -07004295 long identity = Binder.clearCallingIdentity();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004296 try {
4297 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Meng0c05b502018-09-06 09:59:22 -07004298 return (CellNetworkScanResult) sendRequest(
Malcolm Chend965c8b2018-02-28 15:00:40 -08004299 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004303 }
4304
4305 /**
yinxub1bed742017-04-17 11:45:04 -07004306 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004307 *
yinxub1bed742017-04-17 11:45:04 -07004308 * @param subId id of the subscription
4309 * @param request contains the radio access networks with bands/channels to scan
4310 * @param messenger callback messenger for scan results or errors
4311 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004312 * @return the id of the requested scan which can be used to stop the scan.
4313 */
4314 @Override
4315 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004316 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004317 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4318 mApp, subId, "requestNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004319
Hall Liuf19c44f2018-11-27 14:38:17 -08004320 LocationAccessPolicy.LocationPermissionResult locationResult =
4321 LocationAccessPolicy.checkLocationPermission(mApp,
4322 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4323 .setCallingPackage(callingPackage)
4324 .setCallingPid(Binder.getCallingPid())
4325 .setCallingUid(Binder.getCallingUid())
4326 .setMethod("requestNetworkScan")
4327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4328 .build());
4329 switch (locationResult) {
4330 case DENIED_HARD:
4331 throw new SecurityException("Not allowed to request network scan -- location");
4332 case DENIED_SOFT:
4333 return -1;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004334 }
Hall Liuf19c44f2018-11-27 14:38:17 -08004335
4336 return mNetworkScanRequestTracker.startNetworkScan(
4337 request, messenger, binder, getPhone(subId),
4338 callingPackage);
yinxu504e1392017-04-12 16:03:22 -07004339 }
4340
4341 /**
4342 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004343 *
4344 * @param subId id of the subscription
4345 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004346 */
4347 @Override
4348 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004349 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4350 mApp, subId, "stopNetworkScan");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004351
4352 final long identity = Binder.clearCallingIdentity();
4353 try {
4354 mNetworkScanRequestTracker.stopNetworkScan(scanId);
4355 } finally {
4356 Binder.restoreCallingIdentity(identity);
4357 }
yinxu504e1392017-04-12 16:03:22 -07004358 }
4359
4360 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004361 * Get the calculated preferred network type.
4362 * Used for debugging incorrect network type.
4363 *
4364 * @return the preferred network type, defined in RILConstants.java.
4365 */
4366 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004367 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004368 final Phone defaultPhone = getDefaultPhone();
4369 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4370 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004371 return RILConstants.PREFERRED_NETWORK_MODE;
4372 }
4373
Malcolm Chend965c8b2018-02-28 15:00:40 -08004374 final long identity = Binder.clearCallingIdentity();
4375 try {
4376 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004377 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004378 } finally {
4379 Binder.restoreCallingIdentity(identity);
4380 }
Junda Liu84d15a22014-07-02 11:21:04 -07004381 }
4382
4383 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004384 * Get the preferred network type.
4385 * Used for device configuration by some CDMA operators.
4386 *
4387 * @return the preferred network type, defined in RILConstants.java.
4388 */
4389 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004390 public int getPreferredNetworkType(int subId) {
Pengquan Meng4848cd02018-12-20 11:00:24 -08004391 TelephonyPermissions
4392 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4393 mApp, subId, "getPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004394
4395 final long identity = Binder.clearCallingIdentity();
4396 try {
4397 if (DBG) log("getPreferredNetworkType");
4398 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4399 int networkType = (result != null ? result[0] : -1);
4400 if (DBG) log("getPreferredNetworkType: " + networkType);
4401 return networkType;
4402 } finally {
4403 Binder.restoreCallingIdentity(identity);
4404 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004405 }
4406
4407 /**
4408 * Set the preferred network type.
4409 * Used for device configuration by some CDMA operators.
4410 *
4411 * @param networkType the preferred network type, defined in RILConstants.java.
4412 * @return true on success; false on any failure.
4413 */
4414 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004415 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4417 mApp, subId, "setPreferredNetworkType");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004418
4419 final long identity = Binder.clearCallingIdentity();
4420 try {
4421 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4422 Boolean success = (Boolean) sendRequest(
4423 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4424 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4425 if (success) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004426 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chend965c8b2018-02-28 15:00:40 -08004427 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4428 }
4429 return success;
4430 } finally {
4431 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004432 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004433 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004434
4435 /**
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004436 * Check whether DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004437 *
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004438 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004439 * @hide
4440 */
4441 @Override
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004442 public boolean getTetherApnRequired() {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004443 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004444 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004445 final Phone defaultPhone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004446 try {
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004447 return defaultPhone.hasMatchedTetherApnSetting();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004448 } finally {
4449 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004450 }
Junda Liu475951f2014-11-07 16:45:03 -08004451 }
4452
4453 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004454 * Set mobile data enabled
4455 * Used by the user through settings etc to turn on/off mobile data
4456 *
4457 * @param enable {@code true} turn turn data on, else {@code false}
4458 */
4459 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004460 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004461 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4462 mApp, subId, "setUserDataEnabled");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004463
4464 final long identity = Binder.clearCallingIdentity();
4465 try {
4466 int phoneId = mSubscriptionController.getPhoneId(subId);
4467 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4468 Phone phone = PhoneFactory.getPhone(phoneId);
4469 if (phone != null) {
4470 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yu7a030e52018-12-13 11:51:28 -08004471 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004472 } else {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004473 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004474 }
4475 } finally {
4476 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004477 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004478 }
4479
4480 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004481 * Get the user enabled state of Mobile Data.
4482 *
4483 * TODO: remove and use isUserDataEnabled.
4484 * This can't be removed now because some vendor codes
4485 * calls through ITelephony directly while they should
4486 * use TelephonyManager.
4487 *
4488 * @return true on enabled
4489 */
4490 @Override
4491 public boolean getDataEnabled(int subId) {
4492 return isUserDataEnabled(subId);
4493 }
4494
4495 /**
4496 * Get whether mobile data is enabled per user setting.
4497 *
4498 * There are other factors deciding whether mobile data is actually enabled, but they are
4499 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004500 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004501 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004502 *
4503 * @return {@code true} if data is enabled else {@code false}
4504 */
4505 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004506 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004507 try {
4508 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4509 null);
4510 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004513 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004514
4515 final long identity = Binder.clearCallingIdentity();
4516 try {
4517 int phoneId = mSubscriptionController.getPhoneId(subId);
4518 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4519 Phone phone = PhoneFactory.getPhone(phoneId);
4520 if (phone != null) {
4521 boolean retVal = phone.isUserDataEnabled();
4522 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4523 return retVal;
4524 } else {
4525 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4526 return false;
4527 }
4528 } finally {
4529 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004530 }
4531 }
4532
4533 /**
4534 * Get whether mobile data is enabled.
4535 *
4536 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4537 * whether mobile data is actually enabled.
4538 *
4539 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4540 *
4541 * @return {@code true} if data is enabled else {@code false}
4542 */
4543 @Override
4544 public boolean isDataEnabled(int subId) {
4545 try {
4546 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4547 null);
4548 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4550 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004551 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004552
4553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 int phoneId = mSubscriptionController.getPhoneId(subId);
4556 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4557 Phone phone = PhoneFactory.getPhone(phoneId);
4558 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08004559 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004560 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4561 return retVal;
4562 } else {
4563 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4564 return false;
4565 }
4566 } finally {
4567 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004568 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004569 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004570
4571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004572 public int getCarrierPrivilegeStatus(int subId) {
4573 final Phone phone = getPhone(subId);
4574 if (phone == null) {
4575 loge("getCarrierPrivilegeStatus: Invalid subId");
4576 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4577 }
4578 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004579 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004580 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004581 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4582 }
4583 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004584 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004585 }
Junda Liu29340342014-07-10 15:23:27 -07004586
4587 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004588 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4589 final Phone phone = getPhone(subId);
4590 if (phone == null) {
4591 loge("getCarrierPrivilegeStatus: Invalid subId");
4592 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4593 }
4594 UiccProfile profile =
4595 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4596 if (profile == null) {
4597 loge("getCarrierPrivilegeStatus: No UICC");
4598 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4599 }
4600 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4601 }
4602
4603 @Override
Zach Johnson50ecba32015-05-19 00:24:21 -07004604 public int checkCarrierPrivilegesForPackage(String pkgName) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004605 final Phone defaultPhone = getDefaultPhone();
Junda Liu317d70b2016-03-08 09:33:53 -08004606 if (TextUtils.isEmpty(pkgName))
4607 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004608 UiccCard card = UiccController.getInstance().getUiccCard(defaultPhone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004609 if (card == null) {
4610 loge("checkCarrierPrivilegesForPackage: No UICC");
4611 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4612 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004613 return card.getCarrierPrivilegeStatus(defaultPhone.getContext().getPackageManager(),
4614 pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004615 }
4616
4617 @Override
4618 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004619 if (TextUtils.isEmpty(pkgName))
4620 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004621 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4622 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4623 UiccCard card = UiccController.getInstance().getUiccCard(i);
4624 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004625 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004626 continue;
4627 }
4628
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004629 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004630 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4631 break;
4632 }
4633 }
4634
4635 return result;
Junda Liu29340342014-07-10 15:23:27 -07004636 }
Derek Tan89e89d42014-07-08 17:00:10 -07004637
4638 @Override
Junda Liue64de782015-04-16 17:19:16 -07004639 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4640 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4641 loge("phoneId " + phoneId + " is not valid.");
4642 return null;
4643 }
4644 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004645 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004646 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004647 return null ;
4648 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004649 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004650 }
4651
Amith Yamasani6e118872016-02-19 12:53:51 -08004652 @Override
4653 public List<String> getPackagesWithCarrierPrivileges() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004654 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004655 List<String> privilegedPackages = new ArrayList<>();
4656 List<PackageInfo> packages = null;
4657 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4658 UiccCard card = UiccController.getInstance().getUiccCard(i);
4659 if (card == null) {
4660 // No UICC in that slot.
4661 continue;
4662 }
4663 if (card.hasCarrierPrivilegeRules()) {
4664 if (packages == null) {
4665 // Only check packages in user 0 for now
4666 packages = pm.getInstalledPackagesAsUser(
4667 PackageManager.MATCH_DISABLED_COMPONENTS
4668 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4669 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
4670 }
4671 for (int p = packages.size() - 1; p >= 0; p--) {
4672 PackageInfo pkgInfo = packages.get(p);
4673 if (pkgInfo != null && pkgInfo.packageName != null
4674 && card.getCarrierPrivilegeStatus(pkgInfo)
4675 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4676 privilegedPackages.add(pkgInfo.packageName);
4677 }
4678 }
4679 }
4680 }
4681 return privilegedPackages;
4682 }
4683
Wink Savilleb564aae2014-10-23 10:18:09 -07004684 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004685 final Phone phone = getPhone(subId);
4686 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004687 if (card == null) {
4688 loge("getIccId: No UICC");
4689 return null;
4690 }
4691 String iccId = card.getIccId();
4692 if (TextUtils.isEmpty(iccId)) {
4693 loge("getIccId: ICC ID is null or empty.");
4694 return null;
4695 }
4696 return iccId;
4697 }
4698
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004699 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004700 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4701 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004702 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4703 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004704
Malcolm Chend965c8b2018-02-28 15:00:40 -08004705 final long identity = Binder.clearCallingIdentity();
4706 try {
4707 final String iccId = getIccId(subId);
4708 final Phone phone = getPhone(subId);
4709 if (phone == null) {
4710 return false;
4711 }
4712 final String subscriberId = phone.getSubscriberId();
4713
4714 if (DBG_MERGE) {
4715 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4716 + subscriberId + " to " + number);
4717 }
4718
4719 if (TextUtils.isEmpty(iccId)) {
4720 return false;
4721 }
4722
4723 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4724
4725 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4726 if (alphaTag == null) {
4727 editor.remove(alphaTagPrefKey);
4728 } else {
4729 editor.putString(alphaTagPrefKey, alphaTag);
4730 }
4731
4732 // Record both the line number and IMSI for this ICCID, since we need to
4733 // track all merged IMSIs based on line number
4734 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4735 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4736 if (number == null) {
4737 editor.remove(numberPrefKey);
4738 editor.remove(subscriberPrefKey);
4739 } else {
4740 editor.putString(numberPrefKey, number);
4741 editor.putString(subscriberPrefKey, subscriberId);
4742 }
4743
4744 editor.commit();
4745 return true;
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004748 }
Derek Tan7226c842014-07-02 17:42:23 -07004749 }
4750
4751 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004752 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004753 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004754 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004755 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004756 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004757 return null;
4758 }
Derek Tan97ebb422014-09-05 16:55:38 -07004759
Malcolm Chend965c8b2018-02-28 15:00:40 -08004760 final long identity = Binder.clearCallingIdentity();
4761 try {
4762 String iccId = getIccId(subId);
4763 if (iccId != null) {
4764 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4765 if (DBG_MERGE) {
4766 log("getLine1NumberForDisplay returning "
4767 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4768 }
4769 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004770 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004771 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4772 return null;
4773 } finally {
4774 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004775 }
Derek Tan7226c842014-07-02 17:42:23 -07004776 }
4777
4778 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004779 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004781 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004782 return null;
4783 }
Derek Tan97ebb422014-09-05 16:55:38 -07004784
Malcolm Chend965c8b2018-02-28 15:00:40 -08004785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 String iccId = getIccId(subId);
4788 if (iccId != null) {
4789 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4790 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
4791 }
4792 return null;
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004795 }
Derek Tan7226c842014-07-02 17:42:23 -07004796 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004797
4798 @Override
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004799 public String[] getMergedSubscriberIds(String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004800 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
4801 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08004803 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
4804 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004805 return null;
4806 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004807
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004808 final long identity = Binder.clearCallingIdentity();
4809 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004810 final Context context = mApp;
Malcolm Chend965c8b2018-02-28 15:00:40 -08004811 final TelephonyManager tele = TelephonyManager.from(context);
4812 final SubscriptionManager sub = SubscriptionManager.from(context);
4813
4814 // Figure out what subscribers are currently active
4815 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
4816 // Clear calling identity, when calling TelephonyManager, because callerUid must be
4817 // the process, where TelephonyManager was instantiated.
4818 // Otherwise AppOps check will fail.
4819
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004820 final int[] subIds = sub.getActiveSubscriptionIdList();
4821 for (int subId : subIds) {
4822 activeSubscriberIds.add(tele.getSubscriberId(subId));
4823 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004824
4825 // First pass, find a number override for an active subscriber
4826 String mergeNumber = null;
4827 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
4828 for (String key : prefs.keySet()) {
4829 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
4830 final String subscriberId = (String) prefs.get(key);
4831 if (activeSubscriberIds.contains(subscriberId)) {
4832 final String iccId = key.substring(
4833 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
4834 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4835 mergeNumber = (String) prefs.get(numberKey);
4836 if (DBG_MERGE) {
4837 Slog.d(LOG_TAG, "Found line number " + mergeNumber
4838 + " for active subscriber " + subscriberId);
4839 }
4840 if (!TextUtils.isEmpty(mergeNumber)) {
4841 break;
4842 }
4843 }
4844 }
4845 }
4846
4847 // Shortcut when no active merged subscribers
4848 if (TextUtils.isEmpty(mergeNumber)) {
4849 return null;
4850 }
4851
4852 // Second pass, find all subscribers under that line override
4853 final ArraySet<String> result = new ArraySet<>();
4854 for (String key : prefs.keySet()) {
4855 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
4856 final String number = (String) prefs.get(key);
4857 if (mergeNumber.equals(number)) {
4858 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
4859 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4860 final String subscriberId = (String) prefs.get(subscriberKey);
4861 if (!TextUtils.isEmpty(subscriberId)) {
4862 result.add(subscriberId);
4863 }
4864 }
4865 }
4866 }
4867
4868 final String[] resultArray = result.toArray(new String[result.size()]);
4869 Arrays.sort(resultArray);
4870 if (DBG_MERGE) {
4871 Slog.d(LOG_TAG,
4872 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
4873 }
4874 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07004875 } finally {
4876 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08004877 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08004878 }
4879
4880 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004881 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004882 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4883 subId, "setOperatorBrandOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004884
4885 final long identity = Binder.clearCallingIdentity();
4886 try {
4887 final Phone phone = getPhone(subId);
4888 return phone == null ? false : phone.setOperatorBrandOverride(brand);
4889 } finally {
4890 Binder.restoreCallingIdentity(identity);
4891 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07004892 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05004893
4894 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004895 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004896 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
4897 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004898 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chend965c8b2018-02-28 15:00:40 -08004899
4900 final long identity = Binder.clearCallingIdentity();
4901 try {
4902 final Phone phone = getPhone(subId);
4903 if (phone == null) {
4904 return false;
4905 }
4906 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
4907 cdmaNonRoamingList);
4908 } finally {
4909 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004910 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08004911 }
4912
4913 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004914 @Deprecated
4915 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
4916 enforceModifyPermission();
4917
4918 int returnValue = 0;
4919 try {
vagdevie435a3e2018-08-15 16:01:53 -07004920 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00004921 if(result.exception == null) {
4922 if (result.result != null) {
4923 byte[] responseData = (byte[])(result.result);
4924 if(responseData.length > oemResp.length) {
4925 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
4926 responseData.length + "bytes. Buffer Size is " +
4927 oemResp.length + "bytes.");
4928 }
4929 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
4930 returnValue = responseData.length;
4931 }
4932 } else {
4933 CommandException ex = (CommandException) result.exception;
4934 returnValue = ex.getCommandError().ordinal();
4935 if(returnValue > 0) returnValue *= -1;
4936 }
4937 } catch (RuntimeException e) {
4938 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
4939 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
4940 if(returnValue > 0) returnValue *= -1;
4941 }
4942
4943 return returnValue;
4944 }
4945
4946 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07004947 public void setRadioCapability(RadioAccessFamily[] rafs) {
4948 try {
4949 ProxyController.getInstance().setRadioCapability(rafs);
4950 } catch (RuntimeException e) {
4951 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
4952 }
4953 }
4954
4955 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004956 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08004957 Phone phone = PhoneFactory.getPhone(phoneId);
chen xufeeed752018-10-26 14:17:57 -07004958 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08004959 if (phone == null) {
chen xufeeed752018-10-26 14:17:57 -07004960 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08004961 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
chen xufeeed752018-10-26 14:17:57 -07004964 TelephonyPermissions
4965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4966 mApp, phone.getSubId(), "getRadioAccessFamily");
4967 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004968 } finally {
4969 Binder.restoreCallingIdentity(identity);
4970 }
chen xufeeed752018-10-26 14:17:57 -07004971 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07004972 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004973
4974 @Override
4975 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004976 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07004977 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08004978
4979 final long identity = Binder.clearCallingIdentity();
4980 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004981 ImsManager.getInstance(defaultPhone.getContext(),
4982 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chend965c8b2018-02-28 15:00:40 -08004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Andrew Leedf14ead2014-10-17 14:22:52 -07004986 }
4987
4988 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004989 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004990 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00004991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08004992 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00004993 return false;
4994 }
Svet Ganovb320e182015-04-16 12:30:10 -07004995
Malcolm Chend965c8b2018-02-28 15:00:40 -08004996 final long identity = Binder.clearCallingIdentity();
4997 try {
4998 // Check the user preference and the system-level IMS setting. Even if the user has
4999 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5000 // In the long run, we may instead need to check if there exists a connection service
5001 // which can support video calling.
5002 ImsManager imsManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005003 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005004 return imsManager.isVtEnabledByPlatform()
5005 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5006 && imsManager.isVtEnabledByUser();
5007 } finally {
5008 Binder.restoreCallingIdentity(identity);
5009 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005010 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005011
Andrew Leea1239f22015-03-02 17:44:07 -08005012 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005013 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5015 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5016 return false;
5017 }
5018
5019 final long identity = Binder.clearCallingIdentity();
5020 try {
5021 CarrierConfigManager configManager =
5022 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005023 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005024 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Andrew Leea1239f22015-03-02 17:44:07 -08005028 }
5029
5030 @Override
Malcolm Chend965c8b2018-02-28 15:00:40 -08005031 public boolean isWorldPhone(int subId, String callingPackage) {
5032 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5033 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5034 return false;
5035 }
5036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 CarrierConfigManager configManager =
5040 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005041 return configManager.getConfigForSubId(subId)
Malcolm Chend965c8b2018-02-28 15:00:40 -08005042 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5043 } finally {
5044 Binder.restoreCallingIdentity(identity);
5045 }
Andrew Leea1239f22015-03-02 17:44:07 -08005046 }
5047
Andrew Lee9431b832015-03-09 18:46:45 -07005048 @Override
5049 public boolean isTtyModeSupported() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005050 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005051 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005052 }
5053
5054 @Override
5055 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005056 final long identity = Binder.clearCallingIdentity();
5057 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005058 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005059 } finally {
5060 Binder.restoreCallingIdentity(identity);
5061 }
Andrew Lee9431b832015-03-09 18:46:45 -07005062 }
5063
Hall Liuf6668912018-10-31 17:05:23 -07005064 /**
5065 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5066 * support for the feature and device firmware support.
5067 *
5068 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5069 */
5070 @Override
5071 public boolean isRttSupported(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005072 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005073 final Phone phone = getPhone(subscriptionId);
5074 if (phone == null) {
5075 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5076 return false;
5077 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005078 try {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005079 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chend965c8b2018-02-28 15:00:40 -08005080 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5081 boolean isDeviceSupported =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005082 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005083 return isCarrierSupported && isDeviceSupported;
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
Hall Liu98187582018-01-22 19:15:32 -08005087 }
5088
Hall Liuf6668912018-10-31 17:05:23 -07005089 /**
5090 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5091 * both also support RTT.
5092 */
5093 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005094 final long identity = Binder.clearCallingIdentity();
5095 try {
Hall Liuf6668912018-10-31 17:05:23 -07005096 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005097 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005098 } finally {
5099 Binder.restoreCallingIdentity(identity);
5100 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005101 }
5102
Sanket Padawe7310cc72015-01-14 09:53:20 -08005103 /**
5104 * Returns the unique device ID of phone, for example, the IMEI for
5105 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5106 *
5107 * <p>Requires Permission:
5108 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5109 */
5110 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005111 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005112 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005113 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005114 return null;
5115 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005116 int subId = phone.getSubId();
5117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5118 mApp, subId, callingPackage, "getDeviceId")) {
5119 return null;
5120 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 return phone.getDeviceId();
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
5127 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005128 }
5129
Ping Sunc67b7c22016-03-02 19:16:45 +08005130 /**
5131 * {@hide}
5132 * Returns the IMS Registration Status on a particular subid
5133 *
5134 * @param subId
5135 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005136 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005137 Phone phone = getPhone(subId);
5138 if (phone != null) {
5139 return phone.isImsRegistered();
5140 } else {
5141 return false;
5142 }
5143 }
5144
Santos Cordon7a1885b2015-02-03 11:15:19 -08005145 @Override
5146 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5150 } finally {
5151 Binder.restoreCallingIdentity(identity);
5152 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005153 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005154
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005155 /**
5156 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005157 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005158 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005159 final long identity = Binder.clearCallingIdentity();
5160 try {
5161 Phone phone = getPhone(subId);
5162 if (phone != null) {
5163 return phone.isWifiCallingEnabled();
5164 } else {
5165 return false;
5166 }
5167 } finally {
5168 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005169 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005170 }
5171
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005172 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005173 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005174 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005175 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005176 final long identity = Binder.clearCallingIdentity();
5177 try {
5178 Phone phone = getPhone(subId);
5179 if (phone != null) {
5180 return phone.isVideoEnabled();
5181 } else {
5182 return false;
5183 }
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005186 }
5187 }
5188
5189 /**
5190 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5191 * defined in {@link ImsRegistrationImplBase}.
5192 */
5193 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005194 final long identity = Binder.clearCallingIdentity();
5195 try {
5196 Phone phone = getPhone(subId);
5197 if (phone != null) {
5198 return phone.getImsRegistrationTech();
5199 } else {
5200 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5201 }
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005204 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005205 }
5206
Stuart Scott8eef64f2015-04-08 15:13:54 -07005207 @Override
5208 public void factoryReset(int subId) {
5209 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005210 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5211 return;
5212 }
5213
Svet Ganovcc087f82015-05-12 20:35:54 -07005214 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005215
Svet Ganovcc087f82015-05-12 20:35:54 -07005216 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005217 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5218 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005219 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005220 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005221 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005222 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5223 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005224 }
5225 } finally {
5226 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005227 }
5228 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005229
5230 @Override
chen xu2e6dfec2019-01-21 23:31:38 -08005231 public String getSimLocaleForSubscriber(int subId) {
5232 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5233 final Phone phone = getPhone(subId);
5234 if (phone == null) {
5235 log("getSimLocaleForSubscriber, invalid subId");
Pengquan Meng9c291482019-01-28 16:26:29 -08005236 return null;
chen xu2e6dfec2019-01-21 23:31:38 -08005237 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
chen xu2e6dfec2019-01-21 23:31:38 -08005240 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5241 phone.getContext().getOpPackageName());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005242 // Try and fetch the locale from the carrier properties or from the SIM language
5243 // preferences (EF-PL and EF-LI)...
5244 final int mcc = info.getMcc();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005245 String simLanguage = null;
chen xu2e6dfec2019-01-21 23:31:38 -08005246 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5247 if (localeFromDefaultSim != null) {
5248 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5249 if (DBG) log("Using locale from subId: " + subId + " locale: "
5250 + localeFromDefaultSim);
5251 return localeFromDefaultSim.toLanguageTag();
5252 } else {
5253 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005254 }
5255 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005256
Malcolm Chend965c8b2018-02-28 15:00:40 -08005257 // The SIM language preferences only store a language (e.g. fr = French), not an
5258 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5259 // the SIM and carrier preferences does not include a country we add the country
5260 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005261 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005262 if (mccLocale != null) {
chen xu2e6dfec2019-01-21 23:31:38 -08005263 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005264 return mccLocale.toLanguageTag();
5265 }
5266
5267 if (DBG) log("No locale found - returning null");
5268 return null;
5269 } finally {
5270 Binder.restoreCallingIdentity(identity);
5271 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005272 }
5273
5274 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005275 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005276 }
5277
Malcolm Chend965c8b2018-02-28 15:00:40 -08005278 /**
5279 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5280 */
5281 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005282 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005283 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005284
Chenjie Yu1ba97252018-01-11 18:16:20 -08005285 private final ModemActivityInfo mLastModemActivityInfo =
5286 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5287
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005288 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005289 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5290 * representing the state of the modem.
5291 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005292 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5293 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005294 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005295 */
5296 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005297 public void requestModemActivityInfo(ResultReceiver result) {
5298 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 ModemActivityInfo ret = null;
5304 synchronized (mLastModemActivityInfo) {
vagdevie435a3e2018-08-15 16:01:53 -07005305 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5306 CMD_GET_MODEM_ACTIVITY_INFO,
5307 null, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005308 if (isModemActivityInfoValid(info)) {
5309 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5310 for (int i = 0; i < mergedTxTimeMs.length; i++) {
5311 mergedTxTimeMs[i] =
5312 info.getTxTimeMillis()[i] + mLastModemActivityInfo.getTxTimeMillis()[i];
5313 }
5314 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
5315 mLastModemActivityInfo.setSleepTimeMillis(
5316 info.getSleepTimeMillis() + mLastModemActivityInfo.getSleepTimeMillis());
5317 mLastModemActivityInfo.setIdleTimeMillis(
5318 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5319 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5320 mLastModemActivityInfo.setRxTimeMillis(
5321 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5322 mLastModemActivityInfo.setEnergyUsed(
5323 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005324 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005325 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5326 mLastModemActivityInfo.getSleepTimeMillis(),
5327 mLastModemActivityInfo.getIdleTimeMillis(),
5328 mLastModemActivityInfo.getTxTimeMillis(),
5329 mLastModemActivityInfo.getRxTimeMillis(),
5330 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005331 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005332 Bundle bundle = new Bundle();
5333 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5334 result.send(0, bundle);
5335 } finally {
5336 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005337 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005338 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005339
Siddharth Rayf5d29552018-06-17 15:02:38 -07005340 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5341 // less than total activity duration.
5342 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5343 if (info == null) {
5344 return false;
5345 }
5346 int activityDurationMs =
5347 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5348 int totalTxTimeMs = 0;
5349 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5350 totalTxTimeMs += info.getTxTimeMillis()[i];
5351 }
5352 return (info.isValid()
5353 && (info.getSleepTimeMillis() <= activityDurationMs)
5354 && (info.getIdleTimeMillis() <= activityDurationMs)
5355 && (info.getRxTimeMillis() <= activityDurationMs)
5356 && (totalTxTimeMs <= activityDurationMs));
5357 }
5358
Jack Yu85bd38a2015-11-09 11:34:32 -08005359 /**
5360 * {@hide}
5361 * Returns the service state information on specified subscription.
5362 */
5363 @Override
5364 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005365 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005366 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005367 return null;
5368 }
5369
Hall Liuf19c44f2018-11-27 14:38:17 -08005370 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5371 LocationAccessPolicy.checkLocationPermission(mApp,
5372 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5373 .setCallingPackage(callingPackage)
5374 .setCallingPid(Binder.getCallingPid())
5375 .setCallingUid(Binder.getCallingUid())
5376 .setMethod("getServiceStateForSubscriber")
5377 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5378 .build());
5379
5380 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5381 LocationAccessPolicy.checkLocationPermission(mApp,
5382 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5383 .setCallingPackage(callingPackage)
5384 .setCallingPid(Binder.getCallingPid())
5385 .setCallingUid(Binder.getCallingUid())
5386 .setMethod("getServiceStateForSubscriber")
5387 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5388 .build());
5389 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5390 boolean hasFinePermission =
5391 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5392 boolean hasCoarsePermission =
5393 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5394
Malcolm Chend965c8b2018-02-28 15:00:40 -08005395 final long identity = Binder.clearCallingIdentity();
5396 try {
5397 final Phone phone = getPhone(subId);
5398 if (phone == null) {
5399 return null;
5400 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005401
Hall Liuf19c44f2018-11-27 14:38:17 -08005402 ServiceState ss = phone.getServiceState();
5403
5404 // Scrub out the location info in ServiceState depending on what level of access
5405 // the caller has.
5406 if (hasFinePermission) return ss;
5407 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5408 return ss.sanitizeLocationInfo(true);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005409 } finally {
5410 Binder.restoreCallingIdentity(identity);
5411 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005412 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005413
5414 /**
5415 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5416 *
5417 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5418 * voicemail ringtone.
5419 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5420 * PhoneAccount.
5421 */
5422 @Override
5423 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5427 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005428 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005429 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005430
Malcolm Chend965c8b2018-02-28 15:00:40 -08005431 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
5434 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005435 }
5436
5437 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005438 * Sets the per-account voicemail ringtone.
5439 *
5440 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5441 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5442 *
5443 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5444 * voicemail ringtone.
5445 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5446 * PhoneAccount.
5447 */
5448 @Override
5449 public void setVoicemailRingtoneUri(String callingPackage,
5450 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005451 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005452 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5453 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005454 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5456 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5457 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005458 }
Malcolm Chend965c8b2018-02-28 15:00:40 -08005459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5463 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005464 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005465 }
5466 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005469 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005470 }
5471
5472 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005473 * Returns whether vibration is set for voicemail notification in Phone settings.
5474 *
5475 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5476 * voicemail vibration setting.
5477 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5478 */
5479 @Override
5480 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005481 final long identity = Binder.clearCallingIdentity();
5482 try {
5483 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5484 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005485 phone = getDefaultPhone();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005486 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005487
Malcolm Chend965c8b2018-02-28 15:00:40 -08005488 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005492 }
5493
Youhan Wange64578a2016-05-02 15:32:42 -07005494 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005495 * Sets the per-account voicemail vibration.
5496 *
5497 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5498 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5499 *
5500 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5501 * voicemail vibration setting.
5502 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5503 * specific PhoneAccount.
5504 */
5505 @Override
5506 public void setVoicemailVibrationEnabled(String callingPackage,
5507 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005508 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005509 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5510 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005511 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005512 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5513 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5514 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005515 }
5516
Malcolm Chend965c8b2018-02-28 15:00:40 -08005517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5520 if (phone == null) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005521 phone = defaultPhone;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005522 }
5523 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5524 } finally {
5525 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005526 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005527 }
5528
5529 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005530 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5531 *
5532 * @throws SecurityException if the caller does not have the required permission
5533 */
Brad Ebinger4c460712018-10-01 10:40:55 -07005534 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005535 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger4c460712018-10-01 10:40:55 -07005536 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005537 }
5538
5539 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005540 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5541 * permission.
5542 *
5543 * @throws SecurityException if the caller does not have the required permission
5544 */
5545 private void enforceSendSmsPermission() {
5546 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5547 }
5548
5549 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005550 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005551 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005552 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005553 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005554 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005555 final long identity = Binder.clearCallingIdentity();
5556 try {
5557 ComponentName componentName =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005558 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005559 if (componentName == null) {
5560 throw new SecurityException(
5561 "Caller not current active visual voicemail package[null]");
5562 }
5563 String vvmPackage = componentName.getPackageName();
5564 if (!callingPackage.equals(vvmPackage)) {
5565 throw new SecurityException("Caller not current active visual voicemail package["
5566 + vvmPackage + "]");
5567 }
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005570 }
5571 }
5572
5573 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005574 * Return the application ID for the app type.
5575 *
5576 * @param subId the subscription ID that this request applies to.
5577 * @param appType the uicc app type.
5578 * @return Application ID for specificied app type, or null if no uicc.
5579 */
5580 @Override
5581 public String getAidForAppType(int subId, int appType) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005582 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005583 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005584
5585 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005586 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005587 if (phone == null) {
5588 return null;
5589 }
5590 String aid = null;
5591 try {
5592 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5593 .getApplicationByType(appType).getAid();
5594 } catch (Exception e) {
5595 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5596 }
5597 return aid;
5598 } finally {
5599 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005600 }
Youhan Wange64578a2016-05-02 15:32:42 -07005601 }
5602
Youhan Wang4001d252016-05-11 10:29:41 -07005603 /**
5604 * Return the Electronic Serial Number.
5605 *
5606 * @param subId the subscription ID that this request applies to.
5607 * @return ESN or null if error.
5608 */
5609 @Override
5610 public String getEsn(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005611 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005612 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005613
5614 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005615 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005616 if (phone == null) {
5617 return null;
5618 }
5619 String esn = null;
5620 try {
5621 esn = phone.getEsn();
5622 } catch (Exception e) {
5623 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5624 }
5625 return esn;
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005628 }
Youhan Wang4001d252016-05-11 10:29:41 -07005629 }
5630
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005631 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005632 * Return the Preferred Roaming List Version.
5633 *
5634 * @param subId the subscription ID that this request applies to.
5635 * @return PRLVersion or null if error.
5636 */
5637 @Override
5638 public String getCdmaPrlVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005639 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005640 Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005641
5642 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005643 try {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005644 if (phone == null) {
5645 return null;
5646 }
5647 String cdmaPrlVersion = null;
5648 try {
5649 cdmaPrlVersion = phone.getCdmaPrlVersion();
5650 } catch (Exception e) {
5651 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5652 }
5653 return cdmaPrlVersion;
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005656 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005657 }
5658
5659 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005660 * Get snapshot of Telephony histograms
5661 * @return List of Telephony histograms
5662 * @hide
5663 */
5664 @Override
5665 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005666 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5667 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chend965c8b2018-02-28 15:00:40 -08005668
5669 final long identity = Binder.clearCallingIdentity();
5670 try {
5671 return RIL.getTelephonyRILTimingHistograms();
5672 } finally {
5673 Binder.restoreCallingIdentity(identity);
5674 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005675 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005676
5677 /**
5678 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005679 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5680 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005681 * Require system privileges. In the future we may add this to carrier APIs.
5682 *
Michele Berionne0963c862018-11-27 18:57:59 -08005683 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005684 */
5685 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005686 @TelephonyManager.SetCarrierRestrictionResult
5687 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005688 enforceModifyPermission();
vagdevie435a3e2018-08-15 16:01:53 -07005689 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005690
Michele Berionne0963c862018-11-27 18:57:59 -08005691 if (carrierRestrictionRules == null) {
5692 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005693 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005694
Malcolm Chend965c8b2018-02-28 15:00:40 -08005695 final long identity = Binder.clearCallingIdentity();
5696 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005697 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdevie435a3e2018-08-15 16:01:53 -07005698 workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005702 }
5703
5704 /**
5705 * {@hide}
Michele Berionne0963c862018-11-27 18:57:59 -08005706 * Get the allowed carrier list and the excluded carrier list, including the priority between
5707 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005708 * Require system privileges. In the future we may add this to carrier APIs.
5709 *
Michele Berionne0963c862018-11-27 18:57:59 -08005710 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07005711 */
5712 @Override
Michele Berionne0963c862018-11-27 18:57:59 -08005713 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger4c460712018-10-01 10:40:55 -07005714 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdevie435a3e2018-08-15 16:01:53 -07005715 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chend965c8b2018-02-28 15:00:40 -08005716
5717 final long identity = Binder.clearCallingIdentity();
5718 try {
Michele Berionne0963c862018-11-27 18:57:59 -08005719 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
5720 if (response instanceof CarrierRestrictionRules) {
5721 return (CarrierRestrictionRules) response;
5722 }
5723 // Response is an Exception of some kind,
5724 // which is signalled to the user as a NULL retval
5725 return null;
5726 } catch (Exception e) {
5727 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
5728 return null;
Malcolm Chend965c8b2018-02-28 15:00:40 -08005729 } finally {
5730 Binder.restoreCallingIdentity(identity);
5731 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005732 }
5733
fionaxu59545b42016-05-25 15:53:37 -07005734 /**
5735 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
5736 * @param subId the subscription ID that this action applies to.
5737 * @param enabled control enable or disable metered apns.
5738 * {@hide}
5739 */
5740 @Override
5741 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
5742 enforceModifyPermission();
5743 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005744
5745 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005746 if (phone == null) {
5747 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
5748 return;
5749 }
5750 try {
5751 phone.carrierActionSetMeteredApnsEnabled(enabled);
5752 } catch (Exception e) {
5753 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005754 } finally {
5755 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005756 }
5757 }
5758
5759 /**
5760 * Action set from carrier signalling broadcast receivers to enable/disable radio
5761 * @param subId the subscription ID that this action applies to.
5762 * @param enabled control enable or disable radio.
5763 * {@hide}
5764 */
5765 @Override
5766 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
5767 enforceModifyPermission();
5768 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005769
5770 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07005771 if (phone == null) {
5772 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
5773 return;
5774 }
5775 try {
5776 phone.carrierActionSetRadioEnabled(enabled);
5777 } catch (Exception e) {
5778 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005779 } finally {
5780 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07005781 }
5782 }
5783
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005784 /**
fionaxu8da9cb12017-05-23 15:02:46 -07005785 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
5786 * network status based on which carrier apps could apply actions accordingly,
5787 * enable/disable default url handler for example.
5788 *
5789 * @param subId the subscription ID that this action applies to.
5790 * @param report control start/stop reporting the default network status.
5791 * {@hide}
5792 */
5793 @Override
5794 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
5795 enforceModifyPermission();
5796 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005797
5798 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07005799 if (phone == null) {
5800 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
5801 return;
5802 }
5803 try {
5804 phone.carrierActionReportDefaultNetworkStatus(report);
5805 } catch (Exception e) {
5806 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005807 } finally {
5808 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07005809 }
5810 }
5811
5812 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005813 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
5814 * bug report is being generated.
5815 */
5816 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07005817 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005818 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
5819 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07005820 writer.println("Permission Denial: can't dump Phone from pid="
5821 + Binder.getCallingPid()
5822 + ", uid=" + Binder.getCallingUid()
5823 + "without permission "
5824 + android.Manifest.permission.DUMP);
5825 return;
5826 }
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005827 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07005828 }
Jack Yueb89b242016-06-22 13:27:47 -07005829
Brad Ebingerdac2f002018-04-03 15:17:52 -07005830 @Override
5831 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
5832 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
5833 throws RemoteException {
5834 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
5835 }
5836
Jack Yueb89b242016-06-22 13:27:47 -07005837 /**
Jack Yu84291ec2017-05-26 16:07:50 -07005838 * Get aggregated video call data usage since boot.
5839 *
5840 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
5841 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07005842 * {@hide}
5843 */
5844 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07005845 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07005846 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
5847 null);
5848
Malcolm Chend965c8b2018-02-28 15:00:40 -08005849 final long identity = Binder.clearCallingIdentity();
5850 try {
5851 // NetworkStatsService keeps tracking the active network interface and identity. It
5852 // records the delta with the corresponding network identity.
5853 // We just return the total video call data usage snapshot since boot.
5854 Phone phone = getPhone(subId);
5855 if (phone != null) {
5856 return phone.getVtDataUsage(perUidStats);
5857 }
5858 return null;
5859 } finally {
5860 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07005861 }
Jack Yueb89b242016-06-22 13:27:47 -07005862 }
Jack Yu75ab2952016-07-08 14:29:33 -07005863
5864 /**
5865 * Policy control of data connection. Usually used when data limit is passed.
5866 * @param enabled True if enabling the data, otherwise disabling.
5867 * @param subId Subscription index
5868 * {@hide}
5869 */
5870 @Override
5871 public void setPolicyDataEnabled(boolean enabled, int subId) {
5872 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08005873
5874 final long identity = Binder.clearCallingIdentity();
5875 try {
5876 Phone phone = getPhone(subId);
5877 if (phone != null) {
Jack Yu7a030e52018-12-13 11:51:28 -08005878 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005879 }
5880 } finally {
5881 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07005882 }
5883 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005884
5885 /**
5886 * Get Client request stats
5887 * @return List of Client Request Stats
5888 * @hide
5889 */
5890 @Override
5891 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005892 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005893 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005894 return null;
5895 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005896 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005897
Malcolm Chend965c8b2018-02-28 15:00:40 -08005898 final long identity = Binder.clearCallingIdentity();
5899 try {
5900 if (phone != null) {
5901 return phone.getClientRequestStats();
5902 }
5903
5904 return null;
5905 } finally {
5906 Binder.restoreCallingIdentity(identity);
5907 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005908 }
5909
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005910 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005911 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00005912 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07005913 }
Jack Yueb4124c2017-02-16 15:32:43 -08005914
5915 /**
Grace Chen70990072017-03-24 17:21:30 -07005916 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08005917 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005918 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07005919 * @param state State of SIM (power down, power up, pass through)
5920 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
5921 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
5922 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08005923 *
5924 **/
5925 @Override
Grace Chen70990072017-03-24 17:21:30 -07005926 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08005927 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005928 Phone phone = PhoneFactory.getPhone(slotIndex);
5929
vagdevie435a3e2018-08-15 16:01:53 -07005930 WorkSource workSource = getWorkSource(Binder.getCallingUid());
5931
Malcolm Chend965c8b2018-02-28 15:00:40 -08005932 final long identity = Binder.clearCallingIdentity();
5933 try {
5934 if (phone != null) {
vagdevie435a3e2018-08-15 16:01:53 -07005935 phone.setSimPowerState(state, workSource);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005936 }
5937 } finally {
5938 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08005939 }
5940 }
Shuo Qiandd210312017-04-12 22:11:33 +00005941
Tyler Gunn65d45c22017-06-05 11:22:26 -07005942 private boolean isUssdApiAllowed(int subId) {
5943 CarrierConfigManager configManager =
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08005944 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07005945 if (configManager == null) {
5946 return false;
5947 }
5948 PersistableBundle pb = configManager.getConfigForSubId(subId);
5949 if (pb == null) {
5950 return false;
5951 }
5952 return pb.getBoolean(
5953 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
5954 }
5955
Shuo Qiandd210312017-04-12 22:11:33 +00005956 /**
5957 * Check if phone is in emergency callback mode
5958 * @return true if phone is in emergency callback mode
5959 * @param subId sub id
5960 */
goneil9c5f4872017-12-05 14:07:56 -08005961 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00005962 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07005963 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00005964 final Phone phone = getPhone(subId);
Malcolm Chend965c8b2018-02-28 15:00:40 -08005965
5966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 if (phone != null) {
5969 return phone.isInEcm();
5970 } else {
5971 return false;
5972 }
5973 } finally {
5974 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00005975 }
5976 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005977
5978 /**
5979 * Get the current signal strength information for the given subscription.
5980 * Because this information is not updated when the device is in a low power state
5981 * it should not be relied-upon to be current.
5982 * @param subId Subscription index
5983 * @return the most recent cached signal strength info from the modem
5984 */
5985 @Override
5986 public SignalStrength getSignalStrength(int subId) {
Malcolm Chend965c8b2018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 Phone p = getPhone(subId);
5990 if (p == null) {
5991 return null;
5992 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005993
Malcolm Chend965c8b2018-02-28 15:00:40 -08005994 return p.getSignalStrength();
5995 } finally {
5996 Binder.restoreCallingIdentity(identity);
5997 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08005998 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00005999
Pengquan Meng9140aec2018-08-22 14:49:57 -07006000 /**
chen xu907e5a22018-10-11 13:21:04 -07006001 * Get the current modem radio state for the given slot.
6002 * @param slotIndex slot index.
6003 * @param callingPackage the name of the package making the call.
6004 * @return the current radio power state from the modem
6005 */
6006 @Override
6007 public int getRadioPowerState(int slotIndex, String callingPackage) {
6008 Phone phone = PhoneFactory.getPhone(slotIndex);
6009 if (phone != null) {
6010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6011 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6012 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6013 }
6014
6015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 return phone.getRadioPowerState();
6018 } finally {
6019 Binder.restoreCallingIdentity(identity);
6020 }
6021 }
6022 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6023 }
6024
6025 /**
Pengquan Meng9140aec2018-08-22 14:49:57 -07006026 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6027 *
6028 * <p>Requires one of the following permissions:
6029 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6030 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6031 * privileges.
6032 *
6033 * @param subId subscription id
6034 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6035 * {@code false}.
6036 */
6037 @Override
6038 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006039 boolean isEnabled = false;
6040 final long identity = Binder.clearCallingIdentity();
Pengquan Meng9140aec2018-08-22 14:49:57 -07006041 try {
6042 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
Pengquan Meng0c05b502018-09-06 09:59:22 -07006043 null /* message */);
6044 Phone phone = getPhone(subId);
6045 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006046 } catch (Exception e) {
6047 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6048 mApp, subId, "isDataRoamingEnabled");
Pengquan Meng0c05b502018-09-06 09:59:22 -07006049 } finally {
6050 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006051 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006052 return isEnabled;
Pengquan Meng9140aec2018-08-22 14:49:57 -07006053 }
6054
6055
6056 /**
6057 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6058 *
6059 * <p> Requires permission:
6060 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6061 * privileges.
6062 *
6063 * @param subId subscription id
6064 * @param isEnabled {@code true} means enable, {@code false} means disable.
6065 */
6066 @Override
6067 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng0c05b502018-09-06 09:59:22 -07006068 final long identity = Binder.clearCallingIdentity();
6069 try {
6070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6071 mApp, subId, "setDataRoamingEnabled");
Pengquan Meng9140aec2018-08-22 14:49:57 -07006072
Pengquan Meng0c05b502018-09-06 09:59:22 -07006073 Phone phone = getPhone(subId);
6074 if (phone != null) {
6075 phone.setDataRoamingEnabled(isEnabled);
6076 }
6077 } finally {
6078 Binder.restoreCallingIdentity(identity);
Pengquan Meng9140aec2018-08-22 14:49:57 -07006079 }
6080 }
6081
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006082 @Override
Pengquan Meng312de0c2018-10-03 12:19:13 -07006083 public boolean isManualNetworkSelectionAllowed(int subId) {
6084 boolean isAllowed = true;
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6088 mApp, subId, "isManualNetworkSelectionAllowed");
6089 Phone phone = getPhone(subId);
6090 if (phone != null) {
6091 isAllowed = phone.isCspPlmnEnabled();
6092 }
6093 } finally {
6094 Binder.restoreCallingIdentity(identity);
6095 }
6096 return isAllowed;
6097 }
6098
6099 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006100 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu53fdb782019-02-12 17:54:02 -08006101 try {
6102 enforceReadPrivilegedPermission("getUiccCardsInfo");
6103 } catch (SecurityException e) {
6104 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6105 // has carrier privileges on an active UICC
6106 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6107 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6108 throw new SecurityException("Caller does not have carrier privileges on any UICC");
6109 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006110 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006111
6112 final long identity = Binder.clearCallingIdentity();
6113 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006114 UiccController uiccController = UiccController.getInstance();
6115 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
6116
6117 ApplicationInfo ai = mApp.getPackageManager().getApplicationInfo(callingPackage, 0);
6118 if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
6119 // Remove private info if the caller doesn't have access
6120 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6121 for (UiccCardInfo cardInfo : cardInfos) {
6122 UiccCard card = uiccController.getUiccCard(cardInfo.getSlotIndex());
6123 UiccProfile profile = card.getUiccProfile();
6124 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6125 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6126 filteredInfos.add(cardInfo.getUnprivileged());
6127 } else {
6128 filteredInfos.add(cardInfo);
6129 }
6130 }
6131 return filteredInfos;
6132 }
6133 return cardInfos;
6134 } catch (PackageManager.NameNotFoundException e) {
6135 // This should not happen since we pass the package info in from TelephonyManager
6136 throw new SecurityException("Invalid calling package.");
Jordan Liu5aa07002018-12-18 15:44:48 -08006137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006143 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger4c460712018-10-01 10:40:55 -07006144 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006145
Malcolm Chend965c8b2018-02-28 15:00:40 -08006146 final long identity = Binder.clearCallingIdentity();
6147 try {
6148 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6149 if (slots == null) {
6150 Rlog.i(LOG_TAG, "slots is null.");
6151 return null;
6152 }
6153
6154 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6155 for (int i = 0; i < slots.length; i++) {
6156 UiccSlot slot = slots[i];
6157 if (slot == null) {
6158 continue;
6159 }
6160
6161 String cardId;
6162 UiccCard card = slot.getUiccCard();
6163 if (card != null) {
6164 cardId = card.getCardId();
6165 } else {
6166 cardId = slot.getIccId();
6167 }
6168
6169 int cardState = 0;
6170 switch (slot.getCardState()) {
6171 case CARDSTATE_ABSENT:
6172 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6173 break;
6174 case CARDSTATE_PRESENT:
6175 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6176 break;
6177 case CARDSTATE_ERROR:
6178 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6179 break;
6180 case CARDSTATE_RESTRICTED:
6181 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6182 break;
6183 default:
6184 break;
6185
6186 }
6187
6188 infos[i] = new UiccSlotInfo(
6189 slot.isActive(),
6190 slot.isEuicc(),
6191 cardId,
6192 cardState,
6193 slot.getPhoneId(),
Jordan Liuef65d872019-02-14 12:56:40 -08006194 slot.isExtendedApduSupported(),
6195 slot.isRemovable());
Malcolm Chend965c8b2018-02-28 15:00:40 -08006196 }
6197 return infos;
6198 } finally {
6199 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006200 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006201 }
6202
6203 @Override
6204 public boolean switchSlots(int[] physicalSlots) {
6205 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006206
6207 final long identity = Binder.clearCallingIdentity();
6208 try {
6209 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6210 } finally {
6211 Binder.restoreCallingIdentity(identity);
6212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006213 }
Jack Yu4c988042018-02-27 15:30:01 -08006214
6215 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006216 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 return UiccController.getInstance().getCardIdForDefaultEuicc();
6220 } finally {
6221 Binder.restoreCallingIdentity(identity);
6222 }
6223 }
6224
6225 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006226 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6227 enforceModifyPermission();
6228 final Phone phone = getPhone(subId);
6229 if (phone == null) {
6230 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6231 return;
6232 }
6233
Malcolm Chend965c8b2018-02-28 15:00:40 -08006234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 phone.setRadioIndicationUpdateMode(filters, mode);
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Jack Yu4c988042018-02-27 15:30:01 -08006240 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006241
6242 /**
goneil47ffb6e2018-04-06 15:40:58 -07006243 * A test API to reload the UICC profile.
6244 *
6245 * <p>Requires that the calling app has permission
6246 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6247 * @hide
6248 */
6249 @Override
6250 public void refreshUiccProfile(int subId) {
6251 enforceModifyPermission();
6252
6253 final long identity = Binder.clearCallingIdentity();
6254 try {
6255 Phone phone = getPhone(subId);
6256 if (phone == null) {
6257 return;
6258 }
6259 UiccCard uiccCard = phone.getUiccCard();
6260 if (uiccCard == null) {
6261 return;
6262 }
6263 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6264 if (uiccProfile == null) {
6265 return;
6266 }
6267 uiccProfile.refresh();
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270 }
6271 }
6272
6273 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006274 * Returns false if the mobile data is disabled by default, otherwise return true.
6275 */
6276 private boolean getDefaultDataEnabled() {
6277 return "true".equalsIgnoreCase(
6278 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6279 }
6280
6281 /**
6282 * Returns true if the data roaming is enabled by default, i.e the system property
6283 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6284 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6285 */
6286 private boolean getDefaultDataRoamingEnabled(int subId) {
6287 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshi2f2cc692018-12-11 15:15:39 -08006288 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006289 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6290 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6291 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6292 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6293 return isDataRoamingEnabled;
6294 }
6295
6296 /**
6297 * Returns the default network type for the given {@code subId}, if the default network type is
6298 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6299 */
6300 private int getDefaultNetworkType(int subId) {
6301 return Integer.parseInt(
6302 TelephonyManager.getTelephonyProperty(
6303 mSubscriptionController.getPhoneId(subId),
6304 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6305 String.valueOf(Phone.PREFERRED_NT_MODE)));
6306 }
fionaxua13278b2018-03-21 00:08:13 -07006307
6308 @Override
6309 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
6310 gid1, String gid2, String plmn, String spn) {
6311 enforceModifyPermission();
Malcolm Chend965c8b2018-02-28 15:00:40 -08006312
6313 final long identity = Binder.clearCallingIdentity();
6314 try {
6315 final Phone phone = getPhone(subId);
6316 if (phone == null) {
6317 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6318 return;
6319 }
6320 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn);
6321 } finally {
6322 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006323 }
fionaxua13278b2018-03-21 00:08:13 -07006324 }
6325
6326 @Override
6327 public int getCarrierIdListVersion(int subId) {
Brad Ebinger4c460712018-10-01 10:40:55 -07006328 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chend965c8b2018-02-28 15:00:40 -08006329
6330 final long identity = Binder.clearCallingIdentity();
6331 try {
6332 final Phone phone = getPhone(subId);
6333 if (phone == null) {
6334 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6335 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6336 }
6337 return phone.getCarrierIdListVersion();
6338 } finally {
6339 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006340 }
fionaxua13278b2018-03-21 00:08:13 -07006341 }
Malcolm Chenf144d942018-08-14 16:00:53 -07006342
6343 @Override
6344 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6345 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6346 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6347 return -1;
6348 }
6349
6350 final long identity = Binder.clearCallingIdentity();
6351 try {
6352 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
6356 }
Pengquan Meng0c05b502018-09-06 09:59:22 -07006357
6358 @Override
6359 public int getCdmaRoamingMode(int subId) {
6360 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6361 mApp, subId, "getCdmaRoamingMode");
6362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
6365 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
6369 }
6370
6371 @Override
6372 public boolean setCdmaRoamingMode(int subId, int mode) {
6373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6374 mApp, subId, "setCdmaRoamingMode");
6375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
6378 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
6382 }
6383
6384 @Override
6385 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6386 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6387 mApp, subId, "setCdmaSubscriptionMode");
6388
6389 final long identity = Binder.clearCallingIdentity();
6390 try {
6391 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
6395 }
chen xu7ee67862018-10-30 22:27:10 -07006396
sqian2fff4a32018-11-05 14:18:37 -08006397 private void ensureUserRunning(int userId) {
6398 if (!mUserManager.isUserRunning(userId)) {
6399 throw new IllegalStateException("User " + userId + " does not exist or not running");
6400 }
6401 }
6402
6403 /**
6404 * Returns a list of SMS apps on a given user.
6405 *
6406 * Only the shell user (UID 2000 or 0) can call it.
6407 * Target user must be running.
6408 */
6409 @Override
6410 public String[] getSmsApps(int userId) {
6411 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6412 ensureUserRunning(userId);
6413
6414 final Collection<SmsApplicationData> apps =
6415 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6416
6417 String[] ret = new String[apps.size()];
6418 int i = 0;
6419 for (SmsApplicationData app : apps) {
6420 ret[i++] = app.mPackageName;
6421 }
6422 return ret;
6423 }
6424
6425 /**
6426 * Returns the default SMS app package name on a given user.
6427 *
6428 * Only the shell user (UID 2000 or 0) can call it.
6429 * Target user must be running.
6430 */
6431 @Override
6432 public String getDefaultSmsApp(int userId) {
6433 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6434 ensureUserRunning(userId);
6435
6436 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6437 /* updateIfNeeded= */ true, userId);
6438 return cn == null ? null : cn.getPackageName();
6439 }
6440
6441 /**
6442 * Set a package as the default SMS app on a given user.
6443 *
6444 * Only the shell user (UID 2000 or 0) can call it.
6445 * Target user must be running.
6446 */
6447 @Override
6448 public void setDefaultSmsApp(int userId, String packageName) {
6449 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6450 ensureUserRunning(userId);
6451
6452 boolean found = false;
6453 for (String pkg : getSmsApps(userId)) {
6454 if (TextUtils.equals(packageName, pkg)) {
6455 found = true;
6456 break;
6457 }
6458 }
6459 if (!found) {
6460 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6461 }
6462
6463 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6464 }
6465
chen xu7ee67862018-10-30 22:27:10 -07006466 @Override
sqian04b86072018-11-07 14:02:21 -08006467 public Map<Integer, List<EmergencyNumber>> getCurrentEmergencyNumberList(
6468 String callingPackage) {
sqian03bca152018-12-05 18:48:28 -08006469 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6470 mApp, getDefaultSubscription(), callingPackage, "getCurrentEmergencyNumberList")) {
6471 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6472 }
6473 final long identity = Binder.clearCallingIdentity();
6474 try {
sqian991b35e2018-12-12 16:48:18 -08006475 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6476 for (Phone phone: PhoneFactory.getPhones()) {
6477 if (phone.getEmergencyNumberTracker() != null
6478 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6479 emergencyNumberListInternal.put(
6480 phone.getSubId(),
6481 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6482 }
sqian03bca152018-12-05 18:48:28 -08006483 }
sqian991b35e2018-12-12 16:48:18 -08006484 return emergencyNumberListInternal;
sqian03bca152018-12-05 18:48:28 -08006485 } finally {
6486 Binder.restoreCallingIdentity(identity);
6487 }
sqian04b86072018-11-07 14:02:21 -08006488 }
6489
6490 @Override
sqian03bca152018-12-05 18:48:28 -08006491 public boolean isCurrentEmergencyNumber(String number, boolean exactMatch) {
6492 final Phone defaultPhone = getDefaultPhone();
6493 if (!exactMatch) {
6494 TelephonyPermissions
6495 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6496 mApp, defaultPhone.getSubId(), "isCurrentEmergencyNumber(Potential)");
6497 }
6498 final long identity = Binder.clearCallingIdentity();
6499 try {
sqian991b35e2018-12-12 16:48:18 -08006500 for (Phone phone: PhoneFactory.getPhones()) {
6501 if (phone.getEmergencyNumberTracker() != null
6502 && phone.getEmergencyNumberTracker() != null) {
6503 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6504 number, exactMatch)) {
6505 return true;
sqian03bca152018-12-05 18:48:28 -08006506 }
6507 }
sqian03bca152018-12-05 18:48:28 -08006508 }
6509 return false;
6510 } finally {
6511 Binder.restoreCallingIdentity(identity);
6512 }
6513 }
6514
sqian9d4df8b2019-01-15 18:32:07 -08006515 /**
6516 * Update emergency number list for test mode.
6517 */
6518 @Override
6519 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6520 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6521 "updateEmergencyNumberListTestMode");
6522
6523 final long identity = Binder.clearCallingIdentity();
6524 try {
6525 for (Phone phone: PhoneFactory.getPhones()) {
6526 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6527 if (tracker != null) {
6528 tracker.executeEmergencyNumberTestModeCommand(action, num);
6529 }
6530 }
6531 } finally {
6532 Binder.restoreCallingIdentity(identity);
6533 }
6534 }
6535
6536 /**
6537 * Get the full emergency number list for test mode.
6538 */
6539 @Override
6540 public List<String> getEmergencyNumberListTestMode() {
6541 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6542 "getEmergencyNumberListTestMode");
6543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 Set<String> emergencyNumbers = new HashSet<>();
6547 for (Phone phone: PhoneFactory.getPhones()) {
6548 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6549 if (tracker != null) {
6550 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6551 emergencyNumbers.add(num.getNumber());
6552 }
6553 }
6554 }
6555 return new ArrayList<>(emergencyNumbers);
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
6558 }
6559 }
6560
sqian04b86072018-11-07 14:02:21 -08006561 @Override
chen xu7ee67862018-10-30 22:27:10 -07006562 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6563 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6564 Phone phone = getPhone(subId);
6565 if (phone == null) {
6566 return null;
6567 }
6568 final long identity = Binder.clearCallingIdentity();
6569 try {
6570 UiccProfile profile = UiccController.getInstance()
6571 .getUiccProfileForPhone(phone.getPhoneId());
6572 if (profile != null) {
6573 return profile.getCertsFromCarrierPrivilegeAccessRules();
6574 }
6575 } finally {
6576 Binder.restoreCallingIdentity(identity);
6577 }
6578 return null;
6579 }
Malcolm Chen509b5b72019-01-15 20:22:16 -08006580
6581 /**
6582 * Enable or disable a modem stack.
6583 */
6584 @Override
6585 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6586 enforceModifyPermission();
6587
6588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 Phone phone = PhoneFactory.getPhone(slotIndex);
6591 if (phone == null) {
6592 return false;
6593 } else {
6594 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
6598 }
6599 }
Micheled3107c52018-12-21 15:00:11 -08006600
6601 @Override
6602 public void setMultisimCarrierRestriction(boolean isMultisimCarrierRestricted) {
6603 enforceModifyPermission();
6604
6605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 mTelephonySharedPreferences.edit()
6608 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultisimCarrierRestricted)
6609 .commit();
6610 } finally {
6611 Binder.restoreCallingIdentity(identity);
6612 }
6613 }
6614
6615 @Override
Michelebcb01bc2019-02-04 11:36:23 -08006616 public boolean isMultisimSupported(String callingPackage) {
6617 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
6618 getDefaultPhone().getSubId(), callingPackage, "isMultisimSupported")) {
6619 return false;
6620 }
Micheled3107c52018-12-21 15:00:11 -08006621
6622 final long identity = Binder.clearCallingIdentity();
6623 try {
Michele30b57b22019-03-01 12:01:14 -08006624 return isMultisimSupportedInternal();
Micheled3107c52018-12-21 15:00:11 -08006625 } finally {
6626 Binder.restoreCallingIdentity(identity);
6627 }
6628 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006629
Michele30b57b22019-03-01 12:01:14 -08006630 private boolean isMultisimSupportedInternal() {
6631 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6632 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6633 if (numPhysicalSlots < 2) {
6634 loge("isMultisimSupportedInternal: requires at least 2 cards");
6635 return false;
6636 }
6637 // Check if the hardware supports multisim functionality. If usage of multisim is not
6638 // supported by the modem, indicate that it is restricted.
6639 PhoneCapability staticCapability =
6640 mPhoneConfigurationManager.getStaticPhoneCapability();
6641 if (staticCapability == null) {
6642 loge("isMultisimSupportedInternal: no static configuration available");
6643 return false;
6644 }
6645 if (staticCapability.logicalModemList.size() < 2) {
6646 loge("isMultisimSupportedInternal: maximum number of modem is < 2");
6647 return false;
6648 }
6649 // Check if support of multiple SIMs is restricted by carrier
6650 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
6651 return false;
6652 }
6653
6654 return true;
6655 }
6656
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006657 /**
6658 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006659 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
6660 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
6661 * or carrier privileges
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006662 * @param numOfSims number of active sims we want to switch to
6663 */
6664 @Override
6665 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi814dc222019-03-01 11:56:08 -08006666 if (numOfSims == 1) {
6667 enforceModifyPermission();
6668 } else {
6669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6670 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
6671 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006672 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08006673
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006674 try {
Michele30b57b22019-03-01 12:01:14 -08006675 //only proceed if multi-sim is not restricted
6676 if (!isMultisimSupportedInternal()) {
6677 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
6678 return;
6679 }
Nazanin Bakhshiadbfdcc2019-01-30 14:59:50 -08006680 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
6681 } finally {
6682 Binder.restoreCallingIdentity(identity);
6683 }
6684 }
6685
6686 /**
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006687 * Get whether reboot is required or not after making changes to modem configurations.
Nazanin Bakhshi4a68f5f2019-02-08 14:31:19 -08006688 * Return value defaults to true
Nazanin Bakhshicd417af2019-01-30 10:52:09 -08006689 */
6690 @Override
6691 public boolean isRebootRequiredForModemConfigChange() {
6692 enforceReadPrivilegedPermission("isRebootRequiredForModemConfigChange");
6693 final long identity = Binder.clearCallingIdentity();
6694 try {
6695 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
6696 } finally {
6697 Binder.restoreCallingIdentity(identity);
6698 }
6699 }
6700
Pengquan Meng92d253b2019-02-06 11:12:53 -08006701 private void updateModemStateMetrics() {
6702 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
6703 // TODO: check the state for each modem if the api is ready.
6704 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
6705 }
6706
Pengquan Meng3aceaec2019-01-23 11:16:29 -08006707 @Override
6708 public int[] getSlotsMapping() {
6709 enforceReadPrivilegedPermission("getSlotsMapping");
6710
6711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
6714 // All logical slots should have a mapping to a physical slot.
6715 int[] logicalSlotsMapping = new int[phoneCount];
6716 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
6717 for (int i = 0; i < slotInfos.length; i++) {
6718 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
6719 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
6720 }
6721 }
6722 return logicalSlotsMapping;
6723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
6726 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08006727
6728 /**
6729 * Get the IRadio HAL Version
6730 */
6731 @Override
6732 public int getRadioHalVersion() {
6733 Phone phone = getDefaultPhone();
6734 if (phone == null) return -1;
6735 HalVersion hv = phone.getHalVersion();
6736 if (hv.equals(HalVersion.UNKNOWN)) return -1;
6737 return hv.major * 100 + hv.minor;
6738 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006739}