blob: 37b72b4a966e62fe9bb1f21fd3c2b2709fb2a3e9 [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;
Tyler Gunnf70ed162019-04-03 15:28:53 -070024import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070027import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070028import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.content.Context;
30import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070031import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070032import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070033import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080034import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070035import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070036import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070047import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070048import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080049import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070050import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070052import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070053import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070054import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080061import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080062import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070063import android.telecom.TelecomManager;
Junda Liu12f7d802015-05-01 12:06:44 -070064import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080065import android.telephony.CarrierRestrictionRules;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070066import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070067import android.telephony.CellInfoGsm;
68import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070069import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070070import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070071import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070072import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080073import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070074import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080075import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070076import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080077import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080078import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070079import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080080import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070081import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070082import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080083import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080084import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080085import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070086import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070087import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080089import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000090import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070091import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070093import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080094import android.telephony.data.ApnSetting;
Jack Yu41407ee2019-05-13 16:54:09 -070095import android.telephony.data.ApnSetting.ApnType;
Jack Yub5d8f642018-11-26 11:20:48 -080096import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070097import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070098import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -080099import android.telephony.ims.ProvisioningManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700100import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800101import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700102import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800103import android.telephony.ims.aidl.IImsMmTelFeature;
104import android.telephony.ims.aidl.IImsRcsFeature;
105import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800107import android.telephony.ims.feature.MmTelFeature;
108import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800109import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700110import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800111import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700112import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800113import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800114import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800115
Andrew Lee312e8172014-10-23 17:01:36 -0700116import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800117import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700118import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700119import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700120import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800121import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700122import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700124import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800125import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700126import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800127import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800129import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700130import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100131import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700132import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700133import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700135import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800136import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700137import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700138import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700139import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700140import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700141import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.ServiceStateTracker;
Makoto Onukida3bf792018-09-18 16:06:29 -0700143import com.android.internal.telephony.SmsApplication;
144import com.android.internal.telephony.SmsApplication.SmsApplicationData;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700145import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700146import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800147import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800148import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700149import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800150import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700151import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800152import com.android.internal.telephony.ims.ImsResolver;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800153import com.android.internal.telephony.metrics.TelephonyMetrics;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700154import com.android.internal.telephony.uicc.IccIoResult;
155import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800156import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700157import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800158import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800160import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000161import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700162import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800163import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700165import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800166import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700167import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700168import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800169
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700170import java.io.FileDescriptor;
171import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700172import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800173import java.util.Arrays;
Makoto Onukida3bf792018-09-18 16:06:29 -0700174import java.util.Collection;
sqian11b7a0e2018-12-05 18:48:28 -0800175import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800176import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800177import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100178import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800179import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700180import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800181import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182
183/**
184 * Implementation of the ITelephony interface.
185 */
Santos Cordon117fee72014-05-16 17:56:12 -0700186public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700187 private static final String LOG_TAG = "PhoneInterfaceManager";
188 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
189 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800190 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192 // Message codes used with mMainThreadHandler
193 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700194 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
195 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700196 private static final int CMD_OPEN_CHANNEL = 9;
197 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
198 private static final int CMD_CLOSE_CHANNEL = 11;
199 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800200 private static final int CMD_NV_READ_ITEM = 13;
201 private static final int EVENT_NV_READ_ITEM_DONE = 14;
202 private static final int CMD_NV_WRITE_ITEM = 15;
203 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
204 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
205 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700206 private static final int CMD_RESET_MODEM_CONFIG = 19;
207 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800208 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
209 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
210 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
211 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800212 private static final int CMD_SEND_ENVELOPE = 25;
213 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000214 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
215 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700216 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
217 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
218 private static final int CMD_EXCHANGE_SIM_IO = 31;
219 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800220 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
221 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700222 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
223 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700224 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
225 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700226 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
227 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
228 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
229 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700230 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
231 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
232 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
233 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700234 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800235 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
236 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000237 private static final int CMD_SWITCH_SLOTS = 50;
238 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700239 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
240 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
241 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
242 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
243 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
244 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
245 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
246 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700247 private static final int CMD_GET_ALL_CELL_INFO = 60;
248 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
249 private static final int CMD_GET_CELL_LOCATION = 62;
250 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700251 private static final int CMD_MODEM_REBOOT = 64;
252 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700253 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
254 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800255 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
256 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700257 private static final int CMD_GET_MODEM_STATUS = 70;
258 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700259
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800260 // Parameters of select command.
261 private static final int SELECT_COMMAND = 0xA4;
262 private static final int SELECT_P1 = 0x04;
263 private static final int SELECT_P2 = 0;
264 private static final int SELECT_P3 = 0x10;
265
Pengquan Meng85728fb2018-03-12 16:31:21 -0700266 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
267 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
268 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
269
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700270 /** The singleton instance. */
271 private static PhoneInterfaceManager sInstance;
272
Wink Saville3ab207e2014-11-20 13:07:20 -0800273 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800274 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700275 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800276 private AppOpsManager mAppOps;
277 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800278 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700280 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700281
Derek Tan97ebb422014-09-05 16:55:38 -0700282 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
283 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800284 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800285 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700286
Michelecea4cf22018-12-21 15:00:11 -0800287 // String to store multi SIM allowed
288 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
289
Derek Tan740e1672017-06-27 14:56:27 -0700290 // The AID of ISD-R.
291 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
292
yinxub1bed742017-04-17 11:45:04 -0700293 private NetworkScanRequestTracker mNetworkScanRequestTracker;
294
David Kelly5e06a7f2018-03-12 14:10:59 +0000295 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
296 private static final int MANUFACTURER_CODE_LENGTH = 8;
297
Derek Tan89e89d42014-07-08 17:00:10 -0700298 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700299 * A request object to use for transmitting data to an ICC.
300 */
301 private static final class IccAPDUArgument {
302 public int channel, cla, command, p1, p2, p3;
303 public String data;
304
305 public IccAPDUArgument(int channel, int cla, int command,
306 int p1, int p2, int p3, String data) {
307 this.channel = channel;
308 this.cla = cla;
309 this.command = command;
310 this.p1 = p1;
311 this.p2 = p2;
312 this.p3 = p3;
313 this.data = data;
314 }
315 }
316
317 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700318 * A request object to use for transmitting data to an ICC.
319 */
320 private static final class ManualNetworkSelectionArgument {
321 public OperatorInfo operatorInfo;
322 public boolean persistSelection;
323
324 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
325 this.operatorInfo = operatorInfo;
326 this.persistSelection = persistSelection;
327 }
328 }
329
330 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
332 * request after sending. The main thread will notify the request when it is complete.
333 */
334 private static final class MainThreadRequest {
335 /** The argument to use for the request */
336 public Object argument;
337 /** The result of the request that is run on the main thread */
338 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800339 // The subscriber id that this request applies to. Defaults to
340 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
341 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342
Nathan Harold92bed182018-10-12 18:16:49 -0700343 // In cases where subId is unavailable, the caller needs to specify the phone.
344 public Phone phone;
345
vagdeviaf9a5b92018-08-15 16:01:53 -0700346 public WorkSource workSource;
347
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348 public MainThreadRequest(Object argument) {
349 this.argument = argument;
350 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800351
Nathan Harold92bed182018-10-12 18:16:49 -0700352 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
353 this.argument = argument;
354 if (phone != null) {
355 this.phone = phone;
356 }
357 this.workSource = workSource;
358 }
359
vagdeviaf9a5b92018-08-15 16:01:53 -0700360 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800361 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800362 if (subId != null) {
363 this.subId = subId;
364 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700365 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800366 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700367 }
368
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800369 private static final class IncomingThirdPartyCallArgs {
370 public final ComponentName component;
371 public final String callId;
372 public final String callerDisplayName;
373
374 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
375 String callerDisplayName) {
376 this.component = component;
377 this.callId = callId;
378 this.callerDisplayName = callerDisplayName;
379 }
380 }
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 /**
383 * A handler that processes messages on the main thread in the phone process. Since many
384 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
385 * inbound binder threads to the main thread in the phone process. The Binder thread
386 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
387 * on, which will be notified when the operation completes and will contain the result of the
388 * request.
389 *
390 * <p>If a MainThreadRequest object is provided in the msg.obj field,
391 * note that request.result must be set to something non-null for the calling thread to
392 * unblock.
393 */
394 private final class MainThreadHandler extends Handler {
395 @Override
396 public void handleMessage(Message msg) {
397 MainThreadRequest request;
398 Message onCompleted;
399 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800400 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700401 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800402 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700403
404 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700405 case CMD_HANDLE_USSD_REQUEST: {
406 request = (MainThreadRequest) msg.obj;
407 final Phone phone = getPhoneFromRequest(request);
408 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
409 String ussdRequest = ussdObject.first;
410 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700411
Pengquan Menga1bb6272018-09-06 09:59:22 -0700412 if (!isUssdApiAllowed(request.subId)) {
413 // Carrier does not support use of this API, return failure.
414 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
415 UssdResponse response = new UssdResponse(ussdRequest, null);
416 Bundle returnData = new Bundle();
417 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
418 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700419
Pengquan Menga1bb6272018-09-06 09:59:22 -0700420 request.result = true;
421 notifyRequester(request);
422 return;
423 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700424
Pengquan Menga1bb6272018-09-06 09:59:22 -0700425 try {
426 request.result = phone != null
427 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
428 } catch (CallStateException cse) {
429 request.result = false;
430 }
431 // Wake up the requesting thread
432 notifyRequester(request);
433 break;
pkanwar32d516d2016-10-14 19:37:38 -0700434 }
435
Yorke Lee716f67e2015-06-17 15:39:16 -0700436 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700438 final Phone phone = getPhoneFromRequest(request);
439 request.result = phone != null ?
440 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
441 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700442 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700444 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700447 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700448 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700449 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800450 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700451 if (uiccCard == null) {
452 loge("iccTransmitApduLogicalChannel: No UICC");
453 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700455 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700456 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
457 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700458 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700459 iccArgument.channel, iccArgument.cla, iccArgument.command,
460 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700461 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700463 break;
464
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700466 ar = (AsyncResult) msg.obj;
467 request = (MainThreadRequest) ar.userObj;
468 if (ar.exception == null && ar.result != null) {
469 request.result = ar.result;
470 } else {
471 request.result = new IccIoResult(0x6F, 0, (byte[])null);
472 if (ar.result == null) {
473 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800474 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700475 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800476 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 } else {
478 loge("iccTransmitApduLogicalChannel: Unknown exception");
479 }
480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 break;
483
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
485 request = (MainThreadRequest) msg.obj;
486 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800487 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700488 if (uiccCard == null) {
489 loge("iccTransmitApduBasicChannel: No UICC");
490 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 } else {
493 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
494 request);
495 uiccCard.iccTransmitApduBasicChannel(
496 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
497 iccArgument.p3, iccArgument.data, onCompleted);
498 }
499 break;
500
501 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
502 ar = (AsyncResult) msg.obj;
503 request = (MainThreadRequest) ar.userObj;
504 if (ar.exception == null && ar.result != null) {
505 request.result = ar.result;
506 } else {
507 request.result = new IccIoResult(0x6F, 0, (byte[])null);
508 if (ar.result == null) {
509 loge("iccTransmitApduBasicChannel: Empty response");
510 } else if (ar.exception instanceof CommandException) {
511 loge("iccTransmitApduBasicChannel: CommandException: " +
512 ar.exception);
513 } else {
514 loge("iccTransmitApduBasicChannel: Unknown exception");
515 }
516 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700517 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 break;
519
520 case CMD_EXCHANGE_SIM_IO:
521 request = (MainThreadRequest) msg.obj;
522 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800523 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 if (uiccCard == null) {
525 loge("iccExchangeSimIO: No UICC");
526 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700527 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 } else {
529 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
530 request);
531 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
532 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
533 iccArgument.data, onCompleted);
534 }
535 break;
536
537 case EVENT_EXCHANGE_SIM_IO_DONE:
538 ar = (AsyncResult) msg.obj;
539 request = (MainThreadRequest) ar.userObj;
540 if (ar.exception == null && ar.result != null) {
541 request.result = ar.result;
542 } else {
543 request.result = new IccIoResult(0x6f, 0, (byte[])null);
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 break;
547
Derek Tan4d5e5c12014-02-04 11:54:58 -0800548 case CMD_SEND_ENVELOPE:
549 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800550 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700551 if (uiccCard == null) {
552 loge("sendEnvelopeWithStatus: No UICC");
553 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700554 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700555 } else {
556 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
557 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
558 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 break;
560
561 case EVENT_SEND_ENVELOPE_DONE:
562 ar = (AsyncResult) msg.obj;
563 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700564 if (ar.exception == null && ar.result != null) {
565 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800566 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700567 request.result = new IccIoResult(0x6F, 0, (byte[])null);
568 if (ar.result == null) {
569 loge("sendEnvelopeWithStatus: Empty response");
570 } else if (ar.exception instanceof CommandException) {
571 loge("sendEnvelopeWithStatus: CommandException: " +
572 ar.exception);
573 } else {
574 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
575 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700577 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800578 break;
579
Shishir Agrawal566b7612013-10-28 14:41:00 -0700580 case CMD_OPEN_CHANNEL:
581 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800582 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800583 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700584 if (uiccCard == null) {
585 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800586 request.result = new IccOpenLogicalChannelResponse(-1,
587 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800591 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
592 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700594 break;
595
596 case EVENT_OPEN_CHANNEL_DONE:
597 ar = (AsyncResult) msg.obj;
598 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700599 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700601 int[] result = (int[]) ar.result;
602 int channelId = result[0];
603 byte[] selectResponse = null;
604 if (result.length > 1) {
605 selectResponse = new byte[result.length - 1];
606 for (int i = 1; i < result.length; ++i) {
607 selectResponse[i - 1] = (byte) result[i];
608 }
609 }
610 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700611 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700612 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700613 if (ar.result == null) {
614 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700616 if (ar.exception != null) {
617 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
618 }
619
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700620 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700621 if (ar.exception instanceof CommandException) {
622 CommandException.Error error =
623 ((CommandException) (ar.exception)).getCommandError();
624 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700625 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700626 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700627 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700628 }
629 }
630 openChannelResp = new IccOpenLogicalChannelResponse(
631 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700633 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700634 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 break;
636
637 case CMD_CLOSE_CHANNEL:
638 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800639 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700640 if (uiccCard == null) {
641 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900642 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700643 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700644 } else {
645 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
646 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
647 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 break;
649
650 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800651 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
652 break;
653
654 case CMD_NV_READ_ITEM:
655 request = (MainThreadRequest) msg.obj;
656 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800657 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
658 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800659 break;
660
661 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 ar = (AsyncResult) msg.obj;
663 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800664 if (ar.exception == null && ar.result != null) {
665 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800667 request.result = "";
668 if (ar.result == null) {
669 loge("nvReadItem: Empty response");
670 } else if (ar.exception instanceof CommandException) {
671 loge("nvReadItem: CommandException: " +
672 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800674 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
676 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
Jake Hambye994d462014-02-03 13:10:13 -0800680 case CMD_NV_WRITE_ITEM:
681 request = (MainThreadRequest) msg.obj;
682 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
683 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800684 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700685 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800686 break;
687
688 case EVENT_NV_WRITE_ITEM_DONE:
689 handleNullReturnEvent(msg, "nvWriteItem");
690 break;
691
692 case CMD_NV_WRITE_CDMA_PRL:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800696 break;
697
698 case EVENT_NV_WRITE_CDMA_PRL_DONE:
699 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
700 break;
701
chen xu6dac5ab2018-10-26 17:39:23 -0700702 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800703 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700704 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800705 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case EVENT_RESET_MODEM_CONFIG_DONE:
709 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800710 break;
711
Jake Hamby7c27be32014-03-03 13:25:59 -0800712 case CMD_GET_PREFERRED_NETWORK_TYPE:
713 request = (MainThreadRequest) msg.obj;
714 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700715 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800716 break;
717
718 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
719 ar = (AsyncResult) msg.obj;
720 request = (MainThreadRequest) ar.userObj;
721 if (ar.exception == null && ar.result != null) {
722 request.result = ar.result; // Integer
723 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800724 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800725 if (ar.result == null) {
726 loge("getPreferredNetworkType: Empty response");
727 } else if (ar.exception instanceof CommandException) {
728 loge("getPreferredNetworkType: CommandException: " +
729 ar.exception);
730 } else {
731 loge("getPreferredNetworkType: Unknown exception");
732 }
733 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700734 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800735 break;
736
737 case CMD_SET_PREFERRED_NETWORK_TYPE:
738 request = (MainThreadRequest) msg.obj;
739 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
740 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700741 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800742 break;
743
744 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
745 handleNullReturnEvent(msg, "setPreferredNetworkType");
746 break;
747
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000748 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
749 request = (MainThreadRequest)msg.obj;
750 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000752 break;
753
754 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
755 ar = (AsyncResult)msg.obj;
756 request = (MainThreadRequest)ar.userObj;
757 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700758 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 break;
760
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800761 case CMD_SET_VOICEMAIL_NUMBER:
762 request = (MainThreadRequest) msg.obj;
763 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
764 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800765 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
766 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 break;
768
769 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
770 handleNullReturnEvent(msg, "setVoicemailNumber");
771 break;
772
Stuart Scott54788802015-03-30 13:18:01 -0700773 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
776 request);
777 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
778 break;
779
780 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
781 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
782 break;
783
Shishir Agrawal302c8692015-06-19 13:49:39 -0700784 case CMD_PERFORM_NETWORK_SCAN:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
787 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
788 break;
789
790 case EVENT_PERFORM_NETWORK_SCAN_DONE:
791 ar = (AsyncResult) msg.obj;
792 request = (MainThreadRequest) ar.userObj;
793 CellNetworkScanResult cellScanResult;
794 if (ar.exception == null && ar.result != null) {
795 cellScanResult = new CellNetworkScanResult(
796 CellNetworkScanResult.STATUS_SUCCESS,
797 (List<OperatorInfo>) ar.result);
798 } else {
799 if (ar.result == null) {
800 loge("getCellNetworkScanResults: Empty response");
801 }
802 if (ar.exception != null) {
803 loge("getCellNetworkScanResults: Exception: " + ar.exception);
804 }
805 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
806 if (ar.exception instanceof CommandException) {
807 CommandException.Error error =
808 ((CommandException) (ar.exception)).getCommandError();
809 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
810 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
811 } else if (error == CommandException.Error.GENERIC_FAILURE) {
812 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
813 }
814 }
815 cellScanResult = new CellNetworkScanResult(errorCode, null);
816 }
817 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700818 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700819 break;
820
821 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
822 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700823 ManualNetworkSelectionArgument selArg =
824 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
826 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700827 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
828 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700829 break;
830
831 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700832 ar = (AsyncResult) msg.obj;
833 request = (MainThreadRequest) ar.userObj;
834 if (ar.exception == null) {
835 request.result = true;
836 } else {
837 request.result = false;
838 loge("setNetworkSelectionModeManual " + ar.exception);
839 }
840 notifyRequester(request);
841 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700842 break;
843
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700844 case CMD_GET_MODEM_ACTIVITY_INFO:
845 request = (MainThreadRequest) msg.obj;
846 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700847 if (defaultPhone != null) {
848 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
849 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 break;
851
852 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
853 ar = (AsyncResult) msg.obj;
854 request = (MainThreadRequest) ar.userObj;
855 if (ar.exception == null && ar.result != null) {
856 request.result = ar.result;
857 } else {
858 if (ar.result == null) {
859 loge("queryModemActivityInfo: Empty response");
860 } else if (ar.exception instanceof CommandException) {
861 loge("queryModemActivityInfo: CommandException: " +
862 ar.exception);
863 } else {
864 loge("queryModemActivityInfo: Unknown exception");
865 }
866 }
Amit Mahajand4766222016-01-28 15:28:28 -0800867 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
868 if (request.result == null) {
869 request.result = new ModemActivityInfo(0, 0, 0, null, 0, 0);
870 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700871 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700872 break;
873
Meng Wang1a7c35a2016-05-05 20:56:15 -0700874 case CMD_SET_ALLOWED_CARRIERS:
875 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800876 CarrierRestrictionRules argument =
877 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700878 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800879 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 break;
881
882 case EVENT_SET_ALLOWED_CARRIERS_DONE:
883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result;
887 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800888 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
889 if (ar.exception instanceof CommandException) {
890 loge("setAllowedCarriers: CommandException: " + ar.exception);
891 CommandException.Error error =
892 ((CommandException) (ar.exception)).getCommandError();
893 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
894 request.result =
895 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
896 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700897 } else {
898 loge("setAllowedCarriers: Unknown exception");
899 }
900 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700901 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700902 break;
903
904 case CMD_GET_ALLOWED_CARRIERS:
905 request = (MainThreadRequest) msg.obj;
906 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800907 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case EVENT_GET_ALLOWED_CARRIERS_DONE:
911 ar = (AsyncResult) msg.obj;
912 request = (MainThreadRequest) ar.userObj;
913 if (ar.exception == null && ar.result != null) {
914 request.result = ar.result;
915 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800916 request.result = new IllegalStateException(
917 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700918 if (ar.result == null) {
919 loge("getAllowedCarriers: Empty response");
920 } else if (ar.exception instanceof CommandException) {
921 loge("getAllowedCarriers: CommandException: " +
922 ar.exception);
923 } else {
924 loge("getAllowedCarriers: Unknown exception");
925 }
926 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700927 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700928 break;
929
Nathan Haroldb3014052017-01-25 15:57:32 -0800930 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
931 ar = (AsyncResult) msg.obj;
932 request = (MainThreadRequest) ar.userObj;
933 if (ar.exception == null && ar.result != null) {
934 request.result = ar.result;
935 } else {
936 request.result = new IllegalArgumentException(
937 "Failed to retrieve Forbidden Plmns");
938 if (ar.result == null) {
939 loge("getForbiddenPlmns: Empty response");
940 } else {
941 loge("getForbiddenPlmns: Unknown exception");
942 }
943 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700944 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800945 break;
946
947 case CMD_GET_FORBIDDEN_PLMNS:
948 request = (MainThreadRequest) msg.obj;
949 uiccCard = getUiccCardFromRequest(request);
950 if (uiccCard == null) {
951 loge("getForbiddenPlmns() UiccCard is null");
952 request.result = new IllegalArgumentException(
953 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700954 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800955 break;
956 }
957 Integer appType = (Integer) request.argument;
958 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
959 if (uiccApp == null) {
960 loge("getForbiddenPlmns() no app with specified type -- "
961 + appType);
962 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700963 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800964 break;
965 } else {
966 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
967 + " specified type -- " + appType);
968 }
969 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
970 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
971 onCompleted);
972 break;
973
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000974 case CMD_SWITCH_SLOTS:
975 request = (MainThreadRequest) msg.obj;
976 int[] physicalSlots = (int[]) request.argument;
977 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
978 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
979 break;
980
981 case EVENT_SWITCH_SLOTS_DONE:
982 ar = (AsyncResult) msg.obj;
983 request = (MainThreadRequest) ar.userObj;
984 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700985 notifyRequester(request);
986 break;
987 case CMD_GET_NETWORK_SELECTION_MODE:
988 request = (MainThreadRequest) msg.obj;
989 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
990 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
991 break;
992
993 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
994 ar = (AsyncResult) msg.obj;
995 request = (MainThreadRequest) ar.userObj;
996 if (ar.exception != null) {
997 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
998 } else {
999 int mode = ((int[]) ar.result)[0];
1000 if (mode == 0) {
1001 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1002 } else {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1004 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001005 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001006 notifyRequester(request);
1007 break;
1008 case CMD_GET_CDMA_ROAMING_MODE:
1009 request = (MainThreadRequest) msg.obj;
1010 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1011 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1012 break;
1013 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception != null) {
1017 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1018 } else {
1019 request.result = ((int[]) ar.result)[0];
1020 }
1021 notifyRequester(request);
1022 break;
1023 case CMD_SET_CDMA_ROAMING_MODE:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1026 int mode = (int) request.argument;
1027 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1028 break;
1029 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1030 ar = (AsyncResult) msg.obj;
1031 request = (MainThreadRequest) ar.userObj;
1032 request.result = ar.exception == null;
1033 notifyRequester(request);
1034 break;
1035 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1036 request = (MainThreadRequest) msg.obj;
1037 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1038 int subscriptionMode = (int) request.argument;
1039 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1040 break;
1041 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1042 ar = (AsyncResult) msg.obj;
1043 request = (MainThreadRequest) ar.userObj;
1044 request.result = ar.exception == null;
1045 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001046 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001047 case CMD_GET_ALL_CELL_INFO:
1048 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001049 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001050 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001051 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001052 case EVENT_GET_ALL_CELL_INFO_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001055 // If a timeout occurs, the response will be null
1056 request.result = (ar.exception == null && ar.result != null)
1057 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 synchronized (request) {
1059 request.notifyAll();
1060 }
1061 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001062 case CMD_REQUEST_CELL_INFO_UPDATE:
1063 request = (MainThreadRequest) msg.obj;
1064 request.phone.requestCellInfoUpdate(request.workSource,
1065 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1066 break;
1067 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1068 ar = (AsyncResult) msg.obj;
1069 request = (MainThreadRequest) ar.userObj;
1070 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1071 try {
1072 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Nathan Harolde82c4b82018-12-18 19:40:37 -08001074 cb.onError(TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1075 new android.os.ParcelableException(ar.exception));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001076 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001077 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Nathan Harolde82c4b82018-12-18 19:40:37 -08001078 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 } else {
1080 // use the result as returned
1081 cb.onCellInfo((List<CellInfo>) ar.result);
1082 }
1083 } catch (RemoteException re) {
1084 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1085 }
1086 break;
1087 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001088 request = (MainThreadRequest) msg.obj;
1089 WorkSource ws = (WorkSource) request.argument;
1090 Phone phone = getPhoneFromRequest(request);
1091 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1092 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001093 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null) {
1097 request.result = ar.result;
1098 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001099 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001100 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1101 ? new CdmaCellLocation() : new GsmCellLocation();
1102 }
1103
1104 synchronized (request) {
1105 request.notifyAll();
1106 }
1107 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001108 case CMD_MODEM_REBOOT:
1109 request = (MainThreadRequest) msg.obj;
1110 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001111 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001112 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001113 case EVENT_CMD_MODEM_REBOOT_DONE:
1114 handleNullReturnEvent(msg, "rebootModem");
1115 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001116 case CMD_REQUEST_ENABLE_MODEM:
1117 request = (MainThreadRequest) msg.obj;
1118 boolean enable = (boolean) request.argument;
1119 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001120 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001121 PhoneConfigurationManager.getInstance()
1122 .enablePhone(request.phone, enable, onCompleted);
1123 break;
1124 case EVENT_ENABLE_MODEM_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001128 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001129 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001130 if ((boolean) request.result) {
1131 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1132 updateModemStateMetrics();
1133 } else {
1134 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1135 + ar.exception);
1136 }
1137 notifyRequester(request);
1138 break;
1139 case CMD_GET_MODEM_STATUS:
1140 request = (MainThreadRequest) msg.obj;
1141 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1142 PhoneConfigurationManager.getInstance()
1143 .getPhoneStatusFromModem(request.phone, onCompleted);
1144 break;
1145 case EVENT_GET_MODEM_STATUS_DONE:
1146 ar = (AsyncResult) msg.obj;
1147 request = (MainThreadRequest) ar.userObj;
1148 int id = request.phone.getPhoneId();
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 //update the cache as modem status has changed
1152 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1153 (boolean) request.result);
1154 } else {
1155 // Return true if modem status cannot be retrieved. For most cases,
1156 // modem status is on. And for older version modems, GET_MODEM_STATUS
1157 // and disable modem are not supported. Modem is always on.
1158 // TODO: this should be fixed in R to support a third
1159 // status UNKNOWN b/131631629
1160 request.result = true;
1161 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1162 + ar.exception);
1163 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001164 notifyRequester(request);
1165 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001166 default:
1167 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1168 break;
1169 }
1170 }
Jake Hambye994d462014-02-03 13:10:13 -08001171
Pengquan Menga1bb6272018-09-06 09:59:22 -07001172 private void notifyRequester(MainThreadRequest request) {
1173 synchronized (request) {
1174 request.notifyAll();
1175 }
1176 }
1177
Jake Hambye994d462014-02-03 13:10:13 -08001178 private void handleNullReturnEvent(Message msg, String command) {
1179 AsyncResult ar = (AsyncResult) msg.obj;
1180 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1181 if (ar.exception == null) {
1182 request.result = true;
1183 } else {
1184 request.result = false;
1185 if (ar.exception instanceof CommandException) {
1186 loge(command + ": CommandException: " + ar.exception);
1187 } else {
1188 loge(command + ": Unknown exception");
1189 }
1190 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001191 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001193 }
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(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001201 return sendRequest(
1202 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001203 }
1204
1205 /**
1206 * Posts the specified command to be executed on the main thread,
1207 * waits for the request to complete, and returns the result.
1208 * @see #sendRequestAsync
1209 */
1210 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1211 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001212 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001213 }
1214
1215 /**
1216 * Posts the specified command to be executed on the main thread,
1217 * waits for the request to complete, and returns the result.
1218 * @see #sendRequestAsync
1219 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001220 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001221 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001222 }
1223
1224 /**
1225 * Posts the specified command to be executed on the main thread,
1226 * waits for the request to complete, and returns the result.
1227 * @see #sendRequestAsync
1228 */
Nathan Harold92bed182018-10-12 18:16:49 -07001229 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1230 return sendRequest(command, argument, subId, null, workSource);
1231 }
1232
1233 /**
1234 * Posts the specified command to be executed on the main thread,
1235 * waits for the request to complete, and returns the result.
1236 * @see #sendRequestAsync
1237 */
1238 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1239 return sendRequest(
1240 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1241 }
1242
1243 /**
1244 * Posts the specified command to be executed on the main thread,
1245 * waits for the request to complete, and returns the result.
1246 * @see #sendRequestAsync
1247 */
1248 private Object sendRequest(
1249 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001250 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1251 throw new RuntimeException("This method will deadlock if called from the main thread.");
1252 }
1253
Nathan Harold92bed182018-10-12 18:16:49 -07001254 MainThreadRequest request = null;
1255 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1256 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1257 } else if (phone != null) {
1258 request = new MainThreadRequest(argument, phone, workSource);
1259 } else {
1260 request = new MainThreadRequest(argument, subId, workSource);
1261 }
1262
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001263 Message msg = mMainThreadHandler.obtainMessage(command, request);
1264 msg.sendToTarget();
1265
1266 // Wait for the request to complete
1267 synchronized (request) {
1268 while (request.result == null) {
1269 try {
1270 request.wait();
1271 } catch (InterruptedException e) {
1272 // Do nothing, go back and wait until the request is complete
1273 }
1274 }
1275 }
1276 return request.result;
1277 }
1278
1279 /**
1280 * Asynchronous ("fire and forget") version of sendRequest():
1281 * Posts the specified command to be executed on the main thread, and
1282 * returns immediately.
1283 * @see #sendRequest
1284 */
1285 private void sendRequestAsync(int command) {
1286 mMainThreadHandler.sendEmptyMessage(command);
1287 }
1288
1289 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001290 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001292 */
1293 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 sendRequestAsync(command, argument, null, null);
1295 }
1296
1297 /**
1298 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1299 * @see {@link #sendRequest(int,Object)}
1300 */
1301 private void sendRequestAsync(
1302 int command, Object argument, Phone phone, WorkSource workSource) {
1303 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001304 Message msg = mMainThreadHandler.obtainMessage(command, request);
1305 msg.sendToTarget();
1306 }
1307
1308 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001309 * Initialize the singleton PhoneInterfaceManager instance.
1310 * This is only done once, at startup, from PhoneApp.onCreate().
1311 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001312 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001313 synchronized (PhoneInterfaceManager.class) {
1314 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001315 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001316 } else {
1317 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1318 }
1319 return sInstance;
1320 }
1321 }
1322
1323 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001324 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001325 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001326 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001327 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1329 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001330 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001331 mTelephonySharedPreferences =
1332 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001333 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001334 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001335
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001336 publish();
1337 }
1338
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001339 private Phone getDefaultPhone() {
1340 Phone thePhone = getPhone(getDefaultSubscription());
1341 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1342 }
1343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001344 private void publish() {
1345 if (DBG) log("publish: " + this);
1346
1347 ServiceManager.addService("phone", this);
1348 }
1349
Stuart Scott584921c2015-01-15 17:10:34 -08001350 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001351 if (request.phone != null) {
1352 return request.phone;
1353 } else {
1354 return getPhoneFromSubId(request.subId);
1355 }
1356 }
1357
1358 private Phone getPhoneFromSubId(int subId) {
1359 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1360 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001361 }
1362
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001363 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1364 Phone phone = getPhoneFromRequest(request);
1365 return phone == null ? null :
1366 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1367 }
1368
Wink Saville36469e72014-06-11 15:17:00 -07001369 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001370 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001371 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001373
1374 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001375 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001376 }
1377
Wink Savilleb564aae2014-10-23 10:18:09 -07001378 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001379 if (DBG) log("dial: " + number);
1380 // No permission check needed here: This is just a wrapper around the
1381 // ACTION_DIAL intent, which is available to any app since it puts up
1382 // the UI before it does anything.
1383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001384 final long identity = Binder.clearCallingIdentity();
1385 try {
1386 String url = createTelUrl(number);
1387 if (url == null) {
1388 return;
1389 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001391 // PENDING: should we just silently fail if phone is offhook or ringing?
1392 PhoneConstants.State state = mCM.getState(subId);
1393 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1394 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1395 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1396 mApp.startActivity(intent);
1397 }
1398 } finally {
1399 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001400 }
1401 }
1402
1403 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001404 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001405 }
1406
Wink Savilleb564aae2014-10-23 10:18:09 -07001407 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001408 if (DBG) log("call: " + number);
1409
1410 // This is just a wrapper around the ACTION_CALL intent, but we still
1411 // need to do a permission check since we're calling startActivity()
1412 // from the context of the phone app.
1413 enforceCallPermission();
1414
Jordan Liu1617b712019-07-10 15:06:26 -07001415 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001416 != AppOpsManager.MODE_ALLOWED) {
1417 return;
1418 }
1419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001420 final long identity = Binder.clearCallingIdentity();
1421 try {
1422 String url = createTelUrl(number);
1423 if (url == null) {
1424 return;
1425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001427 boolean isValid = false;
1428 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1429 if (slist != null) {
1430 for (SubscriptionInfo subInfoRecord : slist) {
1431 if (subInfoRecord.getSubscriptionId() == subId) {
1432 isValid = true;
1433 break;
1434 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001435 }
Wink Saville08874612014-08-31 19:19:58 -07001436 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001437 if (!isValid) {
1438 return;
1439 }
Wink Saville08874612014-08-31 19:19:58 -07001440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001441 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1442 intent.putExtra(SUBSCRIPTION_KEY, subId);
1443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1444 mApp.startActivity(intent);
1445 } finally {
1446 Binder.restoreCallingIdentity(identity);
1447 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001448 }
1449
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001450 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001451 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001452 }
1453
Wink Savilleb564aae2014-10-23 10:18:09 -07001454 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001456 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1457 }
1458
1459 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001460 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001461 }
1462
Wink Savilleb564aae2014-10-23 10:18:09 -07001463 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001464 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001465 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1466 }
1467
1468 /** {@hide} */
1469 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001470 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001471 }
1472
Wink Savilleb564aae2014-10-23 10:18:09 -07001473 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001475
1476 final long identity = Binder.clearCallingIdentity();
1477 try {
1478 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1479 checkSimPin.start();
1480 return checkSimPin.unlockSim(null, pin);
1481 } finally {
1482 Binder.restoreCallingIdentity(identity);
1483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 }
1485
Wink Saville9de0f752013-10-22 19:04:03 -07001486 /** {@hide} */
1487 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001488 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001489 }
1490
Wink Savilleb564aae2014-10-23 10:18:09 -07001491 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493
1494 final long identity = Binder.clearCallingIdentity();
1495 try {
1496 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1497 checkSimPuk.start();
1498 return checkSimPuk.unlockSim(puk, pin);
1499 } finally {
1500 Binder.restoreCallingIdentity(identity);
1501 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 }
1503
1504 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001505 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506 * a synchronous one.
1507 */
1508 private static class UnlockSim extends Thread {
1509
1510 private final IccCard mSimCard;
1511
1512 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001513 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1514 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001515
1516 // For replies from SimCard interface
1517 private Handler mHandler;
1518
1519 // For async handler to identify request type
1520 private static final int SUPPLY_PIN_COMPLETE = 100;
1521
1522 public UnlockSim(IccCard simCard) {
1523 mSimCard = simCard;
1524 }
1525
1526 @Override
1527 public void run() {
1528 Looper.prepare();
1529 synchronized (UnlockSim.this) {
1530 mHandler = new Handler() {
1531 @Override
1532 public void handleMessage(Message msg) {
1533 AsyncResult ar = (AsyncResult) msg.obj;
1534 switch (msg.what) {
1535 case SUPPLY_PIN_COMPLETE:
1536 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1537 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001538 mRetryCount = msg.arg1;
1539 if (ar.exception != null) {
1540 if (ar.exception instanceof CommandException &&
1541 ((CommandException)(ar.exception)).getCommandError()
1542 == CommandException.Error.PASSWORD_INCORRECT) {
1543 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1544 } else {
1545 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1546 }
1547 } else {
1548 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1549 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001550 mDone = true;
1551 UnlockSim.this.notifyAll();
1552 }
1553 break;
1554 }
1555 }
1556 };
1557 UnlockSim.this.notifyAll();
1558 }
1559 Looper.loop();
1560 }
1561
1562 /*
1563 * Use PIN or PUK to unlock SIM card
1564 *
1565 * If PUK is null, unlock SIM card with PIN
1566 *
1567 * If PUK is not null, unlock SIM card with PUK and set PIN code
1568 */
Wink Saville9de0f752013-10-22 19:04:03 -07001569 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570
1571 while (mHandler == null) {
1572 try {
1573 wait();
1574 } catch (InterruptedException e) {
1575 Thread.currentThread().interrupt();
1576 }
1577 }
1578 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1579
1580 if (puk == null) {
1581 mSimCard.supplyPin(pin, callback);
1582 } else {
1583 mSimCard.supplyPuk(puk, pin, callback);
1584 }
1585
1586 while (!mDone) {
1587 try {
1588 Log.d(LOG_TAG, "wait for done");
1589 wait();
1590 } catch (InterruptedException e) {
1591 // Restore the interrupted status
1592 Thread.currentThread().interrupt();
1593 }
1594 }
1595 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001596 int[] resultArray = new int[2];
1597 resultArray[0] = mResult;
1598 resultArray[1] = mRetryCount;
1599 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001600 }
1601 }
1602
1603 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001604 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001605
1606 }
1607
Wink Savilleb564aae2014-10-23 10:18:09 -07001608 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001609 // No permission check needed here: this call is harmless, and it's
1610 // needed for the ServiceState.requestStateUpdate() call (which is
1611 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001612 final long identity = Binder.clearCallingIdentity();
1613 try {
1614 final Phone phone = getPhone(subId);
1615 if (phone != null) {
1616 phone.updateServiceLocation();
1617 }
1618 } finally {
1619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001621 }
1622
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001623 @Override
1624 public boolean isRadioOn(String callingPackage) {
1625 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001626 }
1627
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001628 @Override
1629 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001631 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001632 return false;
1633 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001634
1635 final long identity = Binder.clearCallingIdentity();
1636 try {
1637 return isRadioOnForSubscriber(subId);
1638 } finally {
1639 Binder.restoreCallingIdentity(identity);
1640 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001641 }
1642
1643 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001644 final long identity = Binder.clearCallingIdentity();
1645 try {
1646 final Phone phone = getPhone(subId);
1647 if (phone != null) {
1648 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1649 } else {
1650 return false;
1651 }
1652 } finally {
1653 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001654 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 }
1656
1657 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001658 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001659 }
Wink Saville36469e72014-06-11 15:17:00 -07001660
Wink Savilleb564aae2014-10-23 10:18:09 -07001661 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001662 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001663
1664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Wink Saville36469e72014-06-11 15:17:00 -07001673 }
1674
1675 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001676 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001677 }
1678
Wink Savilleb564aae2014-10-23 10:18:09 -07001679 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001681
1682 final long identity = Binder.clearCallingIdentity();
1683 try {
1684 final Phone phone = getPhone(subId);
1685 if (phone == null) {
1686 return false;
1687 }
1688 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1689 toggleRadioOnOffForSubscriber(subId);
1690 }
1691 return true;
1692 } finally {
1693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001695 }
Wink Saville36469e72014-06-11 15:17:00 -07001696
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001697 public boolean needMobileRadioShutdown() {
1698 /*
1699 * If any of the Radios are available, it will need to be
1700 * shutdown. So return true if any Radio is available.
1701 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001702 final long identity = Binder.clearCallingIdentity();
1703 try {
1704 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1705 Phone phone = PhoneFactory.getPhone(i);
1706 if (phone != null && phone.isRadioAvailable()) return true;
1707 }
1708 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1709 return false;
1710 } finally {
1711 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001712 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001713 }
1714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001716 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001717 enforceModifyPermission();
1718
1719 final long identity = Binder.clearCallingIdentity();
1720 try {
1721 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1722 logv("Shutting down Phone " + i);
1723 shutdownRadioUsingPhoneId(i);
1724 }
1725 } finally {
1726 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001727 }
1728 }
1729
1730 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001731 Phone phone = PhoneFactory.getPhone(phoneId);
1732 if (phone != null && phone.isRadioAvailable()) {
1733 phone.shutdownRadio();
1734 }
1735 }
1736
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001738 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001739
1740 final long identity = Binder.clearCallingIdentity();
1741 try {
1742 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1743 if (defaultPhone != null) {
1744 defaultPhone.setRadioPower(turnOn);
1745 return true;
1746 } else {
1747 loge("There's no default phone.");
1748 return false;
1749 }
1750 } finally {
1751 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001752 }
Wink Saville36469e72014-06-11 15:17:00 -07001753 }
1754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(turnOn);
1763 return true;
1764 } else {
1765 return false;
1766 }
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
Wink Saville36469e72014-06-11 15:17:00 -07001772 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001773 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 public boolean enableDataConnectivity() {
1775 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001776
1777 final long identity = Binder.clearCallingIdentity();
1778 try {
1779 int subId = mSubscriptionController.getDefaultDataSubId();
1780 final Phone phone = getPhone(subId);
1781 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001782 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001783 return true;
1784 } else {
1785 return false;
1786 }
1787 } finally {
1788 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001789 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001790 }
1791
Wink Saville36469e72014-06-11 15:17:00 -07001792 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001793 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001794 public boolean disableDataConnectivity() {
1795 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001796
1797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 int subId = mSubscriptionController.getDefaultDataSubId();
1800 final Phone phone = getPhone(subId);
1801 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001802 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001803 return true;
1804 } else {
1805 return false;
1806 }
1807 } finally {
1808 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001809 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001810 }
1811
Sanket Padawe356d7632015-06-22 14:03:32 -07001812 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001813 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 final Phone phone = getPhone(subId);
1817 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001818 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819 } else {
1820 return false;
1821 }
1822 } finally {
1823 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001824 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001825 }
1826
1827 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001828 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001829 }
1830
pkanwarae03a6b2016-11-06 20:37:09 -08001831 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001832 enforceCallPermission();
1833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1837 return;
1838 }
1839 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1840 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
pkanwar32d516d2016-10-14 19:37:38 -07001844 };
1845
Wink Savilleb564aae2014-10-23 10:18:09 -07001846 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1852 return false;
1853 }
1854 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1855 } finally {
1856 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001857 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858 }
1859
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001860 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001861 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001862 }
1863
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001864 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001865 final long identity = Binder.clearCallingIdentity();
1866 try {
1867 Phone phone = PhoneFactory.getPhone(slotIndex);
1868 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1869 PhoneConstantConversions.convertCallState(phone.getState());
1870 } finally {
1871 Binder.restoreCallingIdentity(identity);
1872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001873 }
1874
Sanket Padawe356d7632015-06-22 14:03:32 -07001875 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001876 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001877 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1878 }
1879
1880 @Override
1881 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001882 final long identity = Binder.clearCallingIdentity();
1883 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001884 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001885 if (phone != null) {
1886 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1887 } else {
1888 return PhoneConstantConversions.convertDataState(
1889 PhoneConstants.DataState.DISCONNECTED);
1890 }
1891 } finally {
1892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001894 }
1895
Sanket Padawe356d7632015-06-22 14:03:32 -07001896 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001897 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001898 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1899 }
1900
1901 @Override
1902 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001903 final long identity = Binder.clearCallingIdentity();
1904 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001905 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001906 if (phone != null) {
1907 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1908 } else {
1909 return TelephonyManager.DATA_ACTIVITY_NONE;
1910 }
1911 } finally {
1912 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001913 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001914 }
1915
1916 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001917 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001918 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001919 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001920
1921 LocationAccessPolicy.LocationPermissionResult locationResult =
1922 LocationAccessPolicy.checkLocationPermission(mApp,
1923 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1924 .setCallingPackage(callingPackage)
1925 .setCallingPid(Binder.getCallingPid())
1926 .setCallingUid(Binder.getCallingUid())
1927 .setMethod("getCellLocation")
1928 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1929 .build());
1930 switch (locationResult) {
1931 case DENIED_HARD:
1932 throw new SecurityException("Not allowed to access cell location");
1933 case DENIED_SOFT:
1934 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001935 }
1936
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001937 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001938 final long identity = Binder.clearCallingIdentity();
1939 try {
1940 if (DBG_LOC) log("getCellLocation: is active user");
1941 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001942 int subId = mSubscriptionController.getDefaultDataSubId();
1943 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1944 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945 return data;
1946 } finally {
1947 Binder.restoreCallingIdentity(identity);
1948 }
Svetoslav64fad262015-04-14 14:35:21 -07001949 }
1950
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001951 @Override
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001952 public String getNetworkCountryIsoForPhone(int phoneId) {
1953 // Reporting the correct network country is ambiguous when IWLAN could conflict with
1954 // registered cell info, so return a NULL country instead.
1955 final long identity = Binder.clearCallingIdentity();
1956 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07001957 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
1958 // Get default phone in this case.
1959 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
1960 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001961 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07001962 // Todo: fix this when we can get the actual cellular network info when the device
1963 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001964 if (TelephonyManager.NETWORK_TYPE_IWLAN
1965 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
1966 return "";
1967 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001968 Phone phone = PhoneFactory.getPhone(phoneId);
1969 if (phone != null) {
1970 ServiceStateTracker sst = phone.getServiceStateTracker();
1971 if (sst != null) {
1972 LocaleTracker lt = sst.getLocaleTracker();
1973 if (lt != null) {
1974 return lt.getCurrentCountry();
1975 }
1976 }
1977 }
1978 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001979 } finally {
1980 Binder.restoreCallingIdentity(identity);
1981 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07001982 }
1983
1984 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001986 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001987 }
1988
Sanket Padawe356d7632015-06-22 14:03:32 -07001989 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07001990 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001991 mApp.enforceCallingOrSelfPermission(
1992 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001993
1994 final long identity = Binder.clearCallingIdentity();
1995 try {
1996 final Phone phone = getPhone(subId);
1997 if (phone != null) {
1998 phone.enableLocationUpdates();
1999 }
2000 } finally {
2001 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 }
2004
2005 @Override
2006 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002007 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002008 }
2009
Sanket Padawe356d7632015-06-22 14:03:32 -07002010 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002011 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002012 mApp.enforceCallingOrSelfPermission(
2013 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002014
2015 final long identity = Binder.clearCallingIdentity();
2016 try {
2017 final Phone phone = getPhone(subId);
2018 if (phone != null) {
2019 phone.disableLocationUpdates();
2020 }
2021 } finally {
2022 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002023 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024 }
2025
Nathan Harold31d7ff32018-10-15 20:20:30 -07002026 /**
2027 * Returns the target SDK version number for a given package name.
2028 *
Nathan Haroldec184742019-07-10 17:04:16 -07002029 * This call MUST be invoked before clearing the calling UID.
2030 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002031 * @return target SDK if the package is found or INT_MAX.
2032 */
2033 private int getTargetSdk(String packageName) {
2034 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002035 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
2036 packageName, 0, UserHandle.getUserId(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002037 if (ai != null) return ai.targetSdkVersion;
2038 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002039 loge("Failed to get package info for pkg="
2040 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002041 }
2042 return Integer.MAX_VALUE;
2043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 @Override
2046 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002047 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2048 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002049 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2050 throw new SecurityException(
2051 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2052 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002053
Jordan Liu1617b712019-07-10 15:06:26 -07002054 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002055 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2056 return null;
2057 }
Svetoslav64fad262015-04-14 14:35:21 -07002058
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002059 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002060
Nathan Haroldf180aac2018-06-01 18:43:55 -07002061 List<CellInfo> info = getAllCellInfo(callingPackage);
2062 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002063
Nathan Haroldf180aac2018-06-01 18:43:55 -07002064 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2065 for (CellInfo ci : info) {
2066 if (ci instanceof CellInfoGsm) {
2067 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2068 } else if (ci instanceof CellInfoWcdma) {
2069 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2070 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002072 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
2074
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002075 private List<CellInfo> getCachedCellInfo() {
2076 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2077 for (Phone phone : PhoneFactory.getPhones()) {
2078 List<CellInfo> info = phone.getAllCellInfo();
2079 if (info != null) cellInfos.addAll(info);
2080 }
2081 return cellInfos;
2082 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083
2084 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002085 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002086 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002087 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002088
2089 LocationAccessPolicy.LocationPermissionResult locationResult =
2090 LocationAccessPolicy.checkLocationPermission(mApp,
2091 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2092 .setCallingPackage(callingPackage)
2093 .setCallingPid(Binder.getCallingPid())
2094 .setCallingUid(Binder.getCallingUid())
2095 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002096 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002097 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2098 .build());
2099 switch (locationResult) {
2100 case DENIED_HARD:
2101 throw new SecurityException("Not allowed to access cell info");
2102 case DENIED_SOFT:
2103 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 }
2105
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002106 final int targetSdk = getTargetSdk(callingPackage);
2107 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2108 return getCachedCellInfo();
2109 }
2110
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002111 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113 final long identity = Binder.clearCallingIdentity();
2114 try {
2115 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2116 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002117 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002118 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002119 if (info != null) cellInfos.addAll(info);
2120 }
2121 return cellInfos;
2122 } finally {
2123 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002124 }
2125 }
2126
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002127 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002128 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2129 requestCellInfoUpdateInternal(
2130 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2131 }
2132
2133 @Override
2134 public void requestCellInfoUpdateWithWorkSource(
2135 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2136 enforceModifyPermission();
2137 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2138 }
2139
2140 private void requestCellInfoUpdateInternal(
2141 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002142 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002143 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002144
2145 LocationAccessPolicy.LocationPermissionResult locationResult =
2146 LocationAccessPolicy.checkLocationPermission(mApp,
2147 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2148 .setCallingPackage(callingPackage)
2149 .setCallingPid(Binder.getCallingPid())
2150 .setCallingUid(Binder.getCallingUid())
2151 .setMethod("requestCellInfoUpdate")
2152 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2153 .build());
2154 switch (locationResult) {
2155 case DENIED_HARD:
2156 throw new SecurityException("Not allowed to access cell info");
2157 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002158 try {
2159 cb.onCellInfo(new ArrayList<CellInfo>());
2160 } catch (RemoteException re) {
2161 // Drop without consequences
2162 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002163 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002164 }
2165
Nathan Harolda939a962019-05-09 10:13:47 -07002166
2167 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002168 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2169
2170 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2171 }
2172
2173 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002174 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002175 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002176 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177
2178 final long identity = Binder.clearCallingIdentity();
2179 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002180 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 } finally {
2182 Binder.restoreCallingIdentity(identity);
2183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
Shishir Agrawala9f32182016-04-12 12:00:16 -07002186 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002187 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002188 Phone phone = PhoneFactory.getPhone(slotIndex);
2189 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002190 return null;
2191 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002192 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002193 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2194 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002195 return null;
2196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197
2198 final long identity = Binder.clearCallingIdentity();
2199 try {
2200 return phone.getImei();
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002204 }
2205
2206 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002207 public String getTypeAllocationCodeForSlot(int slotIndex) {
2208 Phone phone = PhoneFactory.getPhone(slotIndex);
2209 String tac = null;
2210 if (phone != null) {
2211 String imei = phone.getImei();
2212 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2213 }
2214 return tac;
2215 }
2216
2217 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002218 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002219 Phone phone = PhoneFactory.getPhone(slotIndex);
2220 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002221 return null;
2222 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002223
Jeff Davidson913390f2018-02-23 17:11:49 -08002224 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002225 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2226 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002227 return null;
2228 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002229
2230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 return phone.getMeid();
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
2235 }
Jack Yu2af8d712017-03-15 17:14:14 -07002236 }
2237
2238 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002239 public String getManufacturerCodeForSlot(int slotIndex) {
2240 Phone phone = PhoneFactory.getPhone(slotIndex);
2241 String manufacturerCode = null;
2242 if (phone != null) {
2243 String meid = phone.getMeid();
2244 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2245 }
2246 return manufacturerCode;
2247 }
2248
2249 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002250 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002251 Phone phone = PhoneFactory.getPhone(slotIndex);
2252 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002253 return null;
2254 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002255 int subId = phone.getSubId();
2256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2257 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2258 return null;
2259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260
2261 final long identity = Binder.clearCallingIdentity();
2262 try {
2263 return phone.getDeviceSvn();
2264 } finally {
2265 Binder.restoreCallingIdentity(identity);
2266 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002267 }
2268
fionaxu43304da2017-11-27 22:51:16 -08002269 @Override
2270 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 final long identity = Binder.clearCallingIdentity();
2272 try {
2273 final Phone phone = getPhone(subId);
2274 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2275 } finally {
2276 Binder.restoreCallingIdentity(identity);
2277 }
fionaxu43304da2017-11-27 22:51:16 -08002278 }
2279
2280 @Override
2281 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
2284 final Phone phone = getPhone(subId);
2285 return phone == null ? null : phone.getCarrierName();
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
2288 }
fionaxu43304da2017-11-27 22:51:16 -08002289 }
2290
calvinpanffe225e2018-11-01 19:43:06 +08002291 @Override
chen xu0026ca62019-03-06 15:28:50 -08002292 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002293 final long identity = Binder.clearCallingIdentity();
2294 try {
2295 final Phone phone = getPhone(subId);
2296 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002297 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
2301 }
2302
2303 @Override
chen xu0026ca62019-03-06 15:28:50 -08002304 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002305 final long identity = Binder.clearCallingIdentity();
2306 try {
2307 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002308 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002309 } finally {
2310 Binder.restoreCallingIdentity(identity);
2311 }
2312 }
2313
chen xu651eec72018-11-11 19:03:44 -08002314 @Override
chen xu864e11c2018-12-06 22:10:03 -08002315 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2316 if (!isSubscriptionMccMnc) {
2317 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2318 }
chen xu651eec72018-11-11 19:03:44 -08002319 final Phone phone = PhoneFactory.getPhone(slotIndex);
2320 if (phone == null) {
2321 return TelephonyManager.UNKNOWN_CARRIER_ID;
2322 }
2323 final long identity = Binder.clearCallingIdentity();
2324 try {
2325 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2326 } finally {
2327 Binder.restoreCallingIdentity(identity);
2328 }
2329 }
2330
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 //
2332 // Internal helper methods.
2333 //
2334
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002335 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2337 *
2338 * @throws SecurityException if the caller does not have the required permission
2339 */
2340 private void enforceModifyPermission() {
2341 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2342 }
2343
2344 /**
2345 * Make sure the caller has the CALL_PHONE permission.
2346 *
2347 * @throws SecurityException if the caller does not have the required permission
2348 */
2349 private void enforceCallPermission() {
2350 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2351 }
2352
Stuart Scott8eef64f2015-04-08 15:13:54 -07002353 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002354 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002355 "ConnectivityService");
2356 }
2357
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358 private String createTelUrl(String number) {
2359 if (TextUtils.isEmpty(number)) {
2360 return null;
2361 }
2362
Jake Hambye994d462014-02-03 13:10:13 -08002363 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002364 }
2365
Ihab Awadf9e92732013-12-05 18:02:52 -08002366 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002367 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2368 }
2369
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002370 private static void logv(String msg) {
2371 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2372 }
2373
Ihab Awadf9e92732013-12-05 18:02:52 -08002374 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2376 }
2377
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002378 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002380 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002381 }
2382
Sanket Padawe356d7632015-06-22 14:03:32 -07002383 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002384 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002385 final long identity = Binder.clearCallingIdentity();
2386 try {
2387 final Phone phone = PhoneFactory.getPhone(slotIndex);
2388 if (phone == null) {
2389 return PhoneConstants.PHONE_TYPE_NONE;
2390 } else {
2391 return phone.getPhoneType();
2392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 }
2397
2398 /**
2399 * Returns the CDMA ERI icon index to display
2400 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002401 @Override
2402 public int getCdmaEriIconIndex(String callingPackage) {
2403 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002404 }
2405
Sanket Padawe356d7632015-06-22 14:03:32 -07002406 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002407 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002408 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002409 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002410 return -1;
2411 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 final Phone phone = getPhone(subId);
2416 if (phone != null) {
2417 return phone.getCdmaEriIconIndex();
2418 } else {
2419 return -1;
2420 }
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002423 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002424 }
2425
2426 /**
2427 * Returns the CDMA ERI icon mode,
2428 * 0 - ON
2429 * 1 - FLASHING
2430 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002431 @Override
2432 public int getCdmaEriIconMode(String callingPackage) {
2433 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002434 }
2435
Sanket Padawe356d7632015-06-22 14:03:32 -07002436 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002437 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002438 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002439 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002440 return -1;
2441 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002442
2443 final long identity = Binder.clearCallingIdentity();
2444 try {
2445 final Phone phone = getPhone(subId);
2446 if (phone != null) {
2447 return phone.getCdmaEriIconMode();
2448 } else {
2449 return -1;
2450 }
2451 } finally {
2452 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002454 }
2455
2456 /**
2457 * Returns the CDMA ERI text,
2458 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002459 @Override
2460 public String getCdmaEriText(String callingPackage) {
2461 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002462 }
2463
Sanket Padawe356d7632015-06-22 14:03:32 -07002464 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002465 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002466 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002467 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002468 return null;
2469 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470
2471 final long identity = Binder.clearCallingIdentity();
2472 try {
2473 final Phone phone = getPhone(subId);
2474 if (phone != null) {
2475 return phone.getCdmaEriText();
2476 } else {
2477 return null;
2478 }
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002481 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002482 }
2483
2484 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002485 * Returns the CDMA MDN.
2486 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002488 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002489 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2490 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002495 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002496 return phone.getLine1Number();
2497 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002498 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 return null;
2500 }
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002503 }
2504 }
2505
2506 /**
2507 * Returns the CDMA MIN.
2508 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002509 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002510 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2512 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002513
2514 final long identity = Binder.clearCallingIdentity();
2515 try {
2516 final Phone phone = getPhone(subId);
2517 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2518 return phone.getCdmaMin();
2519 } else {
2520 return null;
2521 }
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002524 }
2525 }
2526
Hall Liud892bec2018-11-30 14:51:45 -08002527 @Override
2528 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2529 INumberVerificationCallback callback, String callingPackage) {
2530 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2531 != PERMISSION_GRANTED) {
2532 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2533 }
2534 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2535
2536 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2537 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2538 throw new SecurityException("Calling package must be configured in the device config");
2539 }
2540
2541 if (range == null) {
2542 throw new NullPointerException("Range must be non-null");
2543 }
2544
2545 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002546 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002547
2548 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2549 }
2550
Junda Liuca05d5d2014-08-14 22:36:34 -07002551 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 * Returns true if CDMA provisioning needs to run.
2553 */
2554 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555 final long identity = Binder.clearCallingIdentity();
2556 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002557 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002558 } finally {
2559 Binder.restoreCallingIdentity(identity);
2560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
2562
2563 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002564 * Sets the voice mail number of a given subId.
2565 */
2566 @Override
2567 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002568 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2573 new Pair<String, String>(alphaTag, number), new Integer(subId));
2574 return success;
2575 } finally {
2576 Binder.restoreCallingIdentity(identity);
2577 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002578 }
2579
Ta-wei Yen87c49842016-05-13 21:19:52 -07002580 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002581 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2582 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002583 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002584 if (!TextUtils.equals(callingPackage, systemDialer)) {
2585 throw new SecurityException("caller must be system dialer");
2586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2591 if (phoneAccountHandle == null) {
2592 return null;
2593 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002594 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002595 } finally {
2596 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002597 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002598 }
2599
2600 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002601 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002602 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002603 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002604 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002605 return null;
2606 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002608 final long identity = Binder.clearCallingIdentity();
2609 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002610 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002611 } finally {
2612 Binder.restoreCallingIdentity(identity);
2613 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002614 }
2615
2616 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002617 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2618 VisualVoicemailSmsFilterSettings settings) {
2619 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002624 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 } finally {
2626 Binder.restoreCallingIdentity(identity);
2627 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002628 }
2629
2630 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002631 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2632 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002633
2634 final long identity = Binder.clearCallingIdentity();
2635 try {
2636 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002637 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002638 } finally {
2639 Binder.restoreCallingIdentity(identity);
2640 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002641 }
2642
2643 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002644 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2645 String callingPackage, int subId) {
2646 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647
2648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002651 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002655 }
2656
2657 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002658 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002659 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660
2661 final long identity = Binder.clearCallingIdentity();
2662 try {
2663 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002664 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 } finally {
2666 Binder.restoreCallingIdentity(identity);
2667 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002668 }
2669
2670 @Override
2671 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2672 String number, int port, String text, PendingIntent sentIntent) {
2673 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002674 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002675 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002676 SmsController smsController = PhoneFactory.getSmsController();
2677 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2678 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002679 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002680
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002681 /**
fionaxu0152e512016-11-14 13:36:14 -08002682 * Sets the voice activation state of a given subId.
2683 */
2684 @Override
2685 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002686 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2687 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002688
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 final Phone phone = getPhone(subId);
2692 if (phone != null) {
2693 phone.setVoiceActivationState(activationState);
2694 } else {
2695 loge("setVoiceActivationState fails with invalid subId: " + subId);
2696 }
2697 } finally {
2698 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002699 }
2700 }
2701
2702 /**
2703 * Sets the data activation state of a given subId.
2704 */
2705 @Override
2706 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2708 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002709
2710 final long identity = Binder.clearCallingIdentity();
2711 try {
2712 final Phone phone = getPhone(subId);
2713 if (phone != null) {
2714 phone.setDataActivationState(activationState);
2715 } else {
2716 loge("setVoiceActivationState fails with invalid subId: " + subId);
2717 }
2718 } finally {
2719 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002720 }
2721 }
2722
2723 /**
2724 * Returns the voice activation state of a given subId.
2725 */
2726 @Override
2727 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002728 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002729
fionaxu0152e512016-11-14 13:36:14 -08002730 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002731 final long identity = Binder.clearCallingIdentity();
2732 try {
2733 if (phone != null) {
2734 return phone.getVoiceActivationState();
2735 } else {
2736 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2737 }
2738 } finally {
2739 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002740 }
2741 }
2742
2743 /**
2744 * Returns the data activation state of a given subId.
2745 */
2746 @Override
2747 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002748 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002749
fionaxu0152e512016-11-14 13:36:14 -08002750 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751 final long identity = Binder.clearCallingIdentity();
2752 try {
2753 if (phone != null) {
2754 return phone.getDataActivationState();
2755 } else {
2756 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2757 }
2758 } finally {
2759 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002760 }
2761 }
2762
2763 /**
Wink Saville36469e72014-06-11 15:17:00 -07002764 * Returns the unread count of voicemails for a subId
2765 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002766 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002767 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2768 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2769 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2770 return 0;
2771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 final Phone phone = getPhone(subId);
2775 if (phone != null) {
2776 return phone.getVoiceMessageCount();
2777 } else {
2778 return 0;
2779 }
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
2785 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002786 * returns true, if the device is in a state where both voice and data
2787 * are supported simultaneously. This can change based on location or network condition.
2788 */
2789 @Override
2790 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2795 } finally {
2796 Binder.restoreCallingIdentity(identity);
2797 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002798 }
2799
2800 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002801 * Send the dialer code if called from the current default dialer or the caller has
2802 * carrier privilege.
2803 * @param inputCode The dialer code to send
2804 */
2805 @Override
2806 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002807 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002809 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2810 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002811 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002812 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2813 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002814 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002815
2816 final long identity = Binder.clearCallingIdentity();
2817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002818 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819 } finally {
2820 Binder.restoreCallingIdentity(identity);
2821 }
fionaxu235cc5e2017-03-06 22:25:57 -08002822 }
2823
Pengquan Menga1bb6272018-09-06 09:59:22 -07002824 @Override
2825 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002826 if (!isActiveSubscription(subId)) {
2827 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2828 }
2829
Pengquan Menga1bb6272018-09-06 09:59:22 -07002830 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2831 }
2832
Brad Ebinger35c841c2018-10-01 10:40:55 -07002833 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002834 public boolean isInEmergencySmsMode() {
2835 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 for (Phone phone : PhoneFactory.getPhones()) {
2839 if (phone.isInEmergencySmsMode()) {
2840 return true;
2841 }
2842 }
2843 } finally {
2844 Binder.restoreCallingIdentity(identity);
2845 }
2846 return false;
2847 }
2848
2849 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002850 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2851 throws RemoteException {
2852 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002853 final long token = Binder.clearCallingIdentity();
2854 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002856 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002857 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002858 } catch (ImsException e) {
2859 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002860 } finally {
2861 Binder.restoreCallingIdentity(token);
2862 }
2863 }
2864
2865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002866 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2867 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002868 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2869 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2870 }
2871 Binder.withCleanCallingIdentity(() -> {
2872 try {
2873 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002874 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002875 .removeRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002876 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002877 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2878 + "is inactive, ignoring unregister.");
2879 // If the subscription is no longer active, just return, since the callback
2880 // will already have been removed internally.
2881 }
2882 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002883 }
2884
2885 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002886 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
2887 throws RemoteException {
2888 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002889 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2890 final long token = Binder.clearCallingIdentity();
2891 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002893 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002894 } catch (ImsException e) {
2895 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002896 } finally {
2897 Binder.restoreCallingIdentity(token);
2898 }
2899 }
2900
2901 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002902 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
2903 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002904
2905 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2906 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2907 }
2908 Binder.withCleanCallingIdentity(() -> {
2909 try {
2910 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002911 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002912 .removeCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002913 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002914 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
2915 + "is inactive, ignoring unregister.");
2916 // If the subscription is no longer active, just return, since the callback
2917 // will already have been removed internally.
2918 }
2919 });
Brad Ebinger35c841c2018-10-01 10:40:55 -07002920 }
2921
2922 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002923 public boolean isCapable(int subId, int capability, int regTech) {
2924 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002925 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2926 final long token = Binder.clearCallingIdentity();
2927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002928 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002930 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002931 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
2932 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002933 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08002934 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
2935 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07002936 } finally {
2937 Binder.restoreCallingIdentity(token);
2938 }
2939 }
2940
2941 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002942 public boolean isAvailable(int subId, int capability, int regTech) {
2943 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002944 final long token = Binder.clearCallingIdentity();
2945 try {
2946 Phone phone = getPhone(subId);
2947 if (phone == null) return false;
2948 return phone.isImsCapabilityAvailable(capability, regTech);
2949 } finally {
2950 Binder.restoreCallingIdentity(token);
2951 }
2952 }
2953
2954 @Override
2955 public boolean isAdvancedCallingSettingEnabled(int subId) {
2956 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
2957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
2958 final long token = Binder.clearCallingIdentity();
2959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002960 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002961 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002962 } catch (ImsException e) {
2963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002964 } finally {
2965 Binder.restoreCallingIdentity(token);
2966 }
2967 }
2968
2969 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08002970 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08002972 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002973 final long identity = Binder.clearCallingIdentity();
2974 try {
2975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002976 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07002977 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002978 } catch (ImsException e) {
2979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002980 } finally {
2981 Binder.restoreCallingIdentity(identity);
2982 }
2983 }
2984
2985 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002986 public boolean isVtSettingEnabled(int subId) {
2987 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002991 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
2992 } catch (ImsException e) {
2993 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 } finally {
2995 Binder.restoreCallingIdentity(identity);
2996 }
2997 }
2998
2999 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003000 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003001 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003002 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003007 } catch (ImsException e) {
3008 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
3014 @Override
3015 public boolean isVoWiFiSettingEnabled(int subId) {
3016 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3017 final long identity = Binder.clearCallingIdentity();
3018 try {
3019 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003020 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003022 } catch (ImsException e) {
3023 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003024 } finally {
3025 Binder.restoreCallingIdentity(identity);
3026 }
3027 }
3028
3029 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003030 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003032 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003037 } catch (ImsException e) {
3038 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
3042 }
3043
3044 @Override
3045 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3046 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3047 final long identity = Binder.clearCallingIdentity();
3048 try {
3049 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003050 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003051 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003052 } catch (ImsException e) {
3053 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003054 } finally {
3055 Binder.restoreCallingIdentity(identity);
3056 }
3057 }
3058
3059 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003060 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003061 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003062 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 final long identity = Binder.clearCallingIdentity();
3064 try {
3065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003066 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003067 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003068 } catch (ImsException e) {
3069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
3073 }
3074
3075 @Override
3076 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3078 "setVoWiFiNonPersistent");
3079 final long identity = Binder.clearCallingIdentity();
3080 try {
3081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003082 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003083 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003084 } catch (ImsException e) {
3085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
3089 }
3090
3091 @Override
3092 public int getVoWiFiModeSetting(int subId) {
3093 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3094 final long identity = Binder.clearCallingIdentity();
3095 try {
3096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003097 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003098 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003099 } catch (ImsException e) {
3100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003101 } finally {
3102 Binder.restoreCallingIdentity(identity);
3103 }
3104 }
3105
3106 @Override
3107 public void setVoWiFiModeSetting(int subId, int mode) {
3108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3109 "setVoWiFiModeSetting");
3110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003113 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003114 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003115 } catch (ImsException e) {
3116 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 } finally {
3118 Binder.restoreCallingIdentity(identity);
3119 }
3120 }
3121
3122 @Override
3123 public int getVoWiFiRoamingModeSetting(int subId) {
3124 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003128 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003130 } catch (ImsException e) {
3131 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
3137 @Override
3138 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3140 "setVoWiFiRoamingModeSetting");
3141 final long identity = Binder.clearCallingIdentity();
3142 try {
3143 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003144 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003146 } catch (ImsException e) {
3147 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003148 } finally {
3149 Binder.restoreCallingIdentity(identity);
3150 }
3151 }
3152
3153 @Override
3154 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3155 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3156 "setRttCapabilityEnabled");
3157 final long identity = Binder.clearCallingIdentity();
3158 try {
3159 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003160 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3161 } catch (ImsException e) {
3162 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 } finally {
3164 Binder.restoreCallingIdentity(identity);
3165 }
3166 }
3167
3168 @Override
3169 public boolean isTtyOverVolteEnabled(int subId) {
3170 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3171 final long identity = Binder.clearCallingIdentity();
3172 try {
3173 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003174 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003176 } catch (ImsException e) {
3177 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003178 } finally {
3179 Binder.restoreCallingIdentity(identity);
3180 }
3181 }
3182
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003183 @Override
3184 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3185 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3186 final long identity = Binder.clearCallingIdentity();
3187 try {
3188 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003189 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003190 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003191 } catch (ImsException e) {
3192 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003193 } finally {
3194 Binder.restoreCallingIdentity(identity);
3195 }
3196 }
3197
3198 @Override
3199 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3200 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3201 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003202 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3203 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3204 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003205 try {
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003208 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003209 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003210 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3211 + "is inactive, ignoring unregister.");
3212 // If the subscription is no longer active, just return, since the callback will already
3213 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003214 } finally {
3215 Binder.restoreCallingIdentity(identity);
3216 }
3217 }
3218
3219 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003220 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3221 boolean isProvisioned) {
3222 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3223 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3224 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3225 }
3226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3227 "setProvisioningStatusForCapability");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3231 Phone phone = getPhone(subId);
3232 if (phone == null) {
3233 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3234 + subId);
3235 return;
3236 }
3237 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3238 return;
3239 }
3240
3241 // this capability requires provisioning, route to the correct API.
3242 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3243 switch (capability) {
3244 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3245 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3246 ims.setVolteProvisioned(isProvisioned);
3247 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3248 ims.setWfcProvisioned(isProvisioned);
3249 }
3250 break;
3251 }
3252 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3253 // There is currently no difference in VT provisioning type.
3254 ims.setVtProvisioned(isProvisioned);
3255 break;
3256 }
3257 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3258 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3259 // change the capability of the feature instead if needed.
3260 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3261 == isProvisioned) {
3262 // No change in provisioning.
3263 return;
3264 }
3265 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3266 try {
3267 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003268 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003269 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3270 + ", Exception" + e.getMessage());
3271 }
3272 break;
3273 }
3274 default: {
3275 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3276 + capability + "', which does not require provisioning.");
3277 }
3278 }
3279
3280 } finally {
3281 Binder.restoreCallingIdentity(identity);
3282 }
3283 }
3284
3285 @Override
3286 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3287 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3288 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3289 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3290 }
3291 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3292 final long identity = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3295 Phone phone = getPhone(subId);
3296 if (phone == null) {
3297 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3298 + subId);
3299 // We will fail with "true" as the provisioning status because this is the default
3300 // if we do not require provisioning.
3301 return true;
3302 }
3303
3304 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3305 return true;
3306 }
3307
3308 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3309 switch (capability) {
3310 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3311 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3312 return ims.isVolteProvisionedOnDevice();
3313 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3314 return ims.isWfcProvisionedOnDevice();
3315 }
3316 // This should never happen, since we are checking tech above to make sure it
3317 // is either LTE or IWLAN.
3318 throw new IllegalArgumentException("Invalid radio technology for voice "
3319 + "capability.");
3320 }
3321 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3322 // There is currently no difference in VT provisioning type.
3323 return ims.isVtProvisionedOnDevice();
3324 }
3325 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3326 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3327 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3328 }
3329 default: {
3330 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3331 + capability + "', which does not require provisioning.");
3332 }
3333 }
3334
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3342 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3343 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3344 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3345 }
3346 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3347 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3348 return (provisionedBits & capability) > 0;
3349 }
3350
3351 @Override
3352 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3353 boolean isProvisioned) {
3354 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3355 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3356 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3357 }
3358 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3359 "setProvisioningStatusForCapability");
3360 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3361 // If the current provisioning status for capability already matches isProvisioned,
3362 // do nothing.
3363 if (((provisionedBits & capability) > 0) == isProvisioned) {
3364 return;
3365 }
3366 if (isProvisioned) {
3367 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3368 } else {
3369 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3370 }
3371 }
3372
3373 /**
3374 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3375 * technology. The bitfield should mirror the bitfield defined by
3376 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3377 */
3378 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3379 String key = getMmTelProvisioningKey(subId, tech);
3380 // Default is no capabilities are provisioned.
3381 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3382 }
3383
3384 /**
3385 * Sets the MmTel capability provisioning bitfield (defined by
3386 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3387 * technology specified.
3388 *
3389 * Note: This is a synchronous command and should not be called on UI thread.
3390 */
3391 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3392 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3393 String key = getMmTelProvisioningKey(subId, tech);
3394 editor.putInt(key, newField);
3395 editor.commit();
3396 }
3397
3398 private static String getMmTelProvisioningKey(int subId, int tech) {
3399 // resulting key is provision_ims_mmtel_{subId}_{tech}
3400 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3401 }
3402
3403 /**
3404 * Query CarrierConfig to see if the specified capability requires provisioning for the
3405 * carrier associated with the subscription id.
3406 */
3407 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3408 int capability) {
3409 CarrierConfigManager configManager = new CarrierConfigManager(context);
3410 PersistableBundle c = configManager.getConfigForSubId(subId);
3411 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003412 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003413 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3414 false);
3415 boolean requireVoiceVtProvisioning = c.getBoolean(
3416 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3417
3418 // First check to make sure that the capability requires provisioning.
3419 switch (capability) {
3420 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3421 // intentional fallthrough
3422 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3423 if (requireVoiceVtProvisioning) {
3424 // Voice and Video requires provisioning
3425 return true;
3426 }
3427 break;
3428 }
3429 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3430 if (requireUtProvisioning) {
3431 // UT requires provisioning
3432 return true;
3433 }
3434 break;
3435 }
3436 }
3437 return false;
3438 }
3439
3440 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003441 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003442 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3443 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3444 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003445 enforceReadPrivilegedPermission("getImsProvisioningInt");
3446 final long identity = Binder.clearCallingIdentity();
3447 try {
3448 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003449 int slotId = getSlotIndex(subId);
3450 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3451 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3452 + subId + "' for key:" + key);
3453 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3454 }
3455 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003456 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003457 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3458 + subId + "' for key:" + key);
3459 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003460 } finally {
3461 Binder.restoreCallingIdentity(identity);
3462 }
3463 }
3464
3465 @Override
3466 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003467 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3468 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3469 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003470 enforceReadPrivilegedPermission("getImsProvisioningString");
3471 final long identity = Binder.clearCallingIdentity();
3472 try {
3473 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003474 int slotId = getSlotIndex(subId);
3475 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3476 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3477 + subId + "' for key:" + key);
3478 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3479 }
3480 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003481 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003482 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3483 + subId + "' for key:" + key);
3484 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003485 } finally {
3486 Binder.restoreCallingIdentity(identity);
3487 }
3488 }
3489
3490 @Override
3491 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003492 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3493 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3494 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3496 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003497 final long identity = Binder.clearCallingIdentity();
3498 try {
3499 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003500 int slotId = getSlotIndex(subId);
3501 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3502 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3503 + subId + "' for key:" + key);
3504 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3505 }
3506 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003507 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003508 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3509 + "' for key:" + key);
3510 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003511 } finally {
3512 Binder.restoreCallingIdentity(identity);
3513 }
3514 }
3515
3516 @Override
3517 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003518 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3519 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3520 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003521 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3522 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003523 final long identity = Binder.clearCallingIdentity();
3524 try {
3525 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003526 int slotId = getSlotIndex(subId);
3527 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3528 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3529 + subId + "' for key:" + key);
3530 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3531 }
3532 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003533 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003534 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3535 + "' for key:" + key);
3536 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
3540 }
3541
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003542 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003543 int slotId = SubscriptionManager.getSlotIndex(subId);
3544 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003545 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3546 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003547 }
3548 return slotId;
3549 }
3550
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003551 private int getSlotIndex(int subId) {
3552 int slotId = SubscriptionManager.getSlotIndex(subId);
3553 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3554 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3555 }
3556 return slotId;
3557 }
3558
Wink Saville36469e72014-06-11 15:17:00 -07003559 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003560 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003561 */
3562 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003563 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003564 final int targetSdk = getTargetSdk(callingPackage);
3565 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3566 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3567 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003568 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3569 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003570 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3571 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 final Phone phone = getPhone(subId);
3576 if (phone != null) {
3577 return phone.getServiceState().getDataNetworkType();
3578 } else {
3579 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3580 }
3581 } finally {
3582 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003583 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003584 }
3585
3586 /**
3587 * Returns the data network type
3588 */
3589 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003590 public int getDataNetworkType(String callingPackage) {
3591 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003592 }
3593
3594 /**
3595 * Returns the data network type for a subId
3596 */
3597 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003598 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003599 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003600 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003601 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3602 }
3603
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 final Phone phone = getPhone(subId);
3607 if (phone != null) {
3608 return phone.getServiceState().getDataNetworkType();
3609 } else {
3610 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3611 }
3612 } finally {
3613 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003615 }
3616
3617 /**
Wink Saville36469e72014-06-11 15:17:00 -07003618 * Returns the Voice network type for a subId
3619 */
3620 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003621 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003622 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003623 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003624 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3625 }
3626
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 final Phone phone = getPhone(subId);
3630 if (phone != null) {
3631 return phone.getServiceState().getVoiceNetworkType();
3632 } else {
3633 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3634 }
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003638 }
3639
3640 /**
3641 * @return true if a ICC card is present
3642 */
3643 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003644 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003645 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3646 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003647 }
3648
3649 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003650 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003651 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003652 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003653 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003654 final long identity = Binder.clearCallingIdentity();
3655 try {
3656 final Phone phone = PhoneFactory.getPhone(slotIndex);
3657 if (phone != null) {
3658 return phone.getIccCard().hasIccCard();
3659 } else {
3660 return false;
3661 }
3662 } finally {
3663 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003664 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003665 }
3666
3667 /**
3668 * Return if the current radio is LTE on CDMA. This
3669 * is a tri-state return value as for a period of time
3670 * the mode may be unknown.
3671 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003672 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003673 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003674 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003675 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003676 @Override
3677 public int getLteOnCdmaMode(String callingPackage) {
3678 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003679 }
3680
Sanket Padawe356d7632015-06-22 14:03:32 -07003681 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003682 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003683 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003684 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003685 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3686 }
3687
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003688 final long identity = Binder.clearCallingIdentity();
3689 try {
3690 final Phone phone = getPhone(subId);
3691 if (phone == null) {
3692 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3693 } else {
3694 return phone.getLteOnCdmaMode();
3695 }
3696 } finally {
3697 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003698 }
Wink Saville36469e72014-06-11 15:17:00 -07003699 }
3700
Wink Saville36469e72014-06-11 15:17:00 -07003701 /**
3702 * {@hide}
3703 * Returns Default subId, 0 in the case of single standby.
3704 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003705 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003706 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003707 }
3708
Shishir Agrawala9f32182016-04-12 12:00:16 -07003709 private int getSlotForDefaultSubscription() {
3710 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3711 }
3712
Wink Savilleb564aae2014-10-23 10:18:09 -07003713 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003714 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003715 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003716
Pengquan Menge92a50d2018-09-21 15:54:48 -07003717 private boolean isActiveSubscription(int subId) {
3718 return mSubscriptionController.isActiveSubId(subId);
3719 }
3720
Ihab Awadf2177b72013-11-25 13:33:23 -08003721 /**
3722 * @see android.telephony.TelephonyManager.WifiCallingChoices
3723 */
3724 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003725 final long identity = Binder.clearCallingIdentity();
3726 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003727 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003728 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3729 getWhenToMakeWifiCallsDefaultPreference());
3730 } finally {
3731 Binder.restoreCallingIdentity(identity);
3732 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003733 }
3734
3735 /**
3736 * @see android.telephony.TelephonyManager.WifiCallingChoices
3737 */
3738 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003739 final long identity = Binder.clearCallingIdentity();
3740 try {
3741 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003742 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003743 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003747 }
3748
Sailesh Nepald1e68152013-12-12 19:08:02 -08003749 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003750 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003751 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003752 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003753
Jordan Liu4c733742019-02-28 12:03:40 -08003754 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3755 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3756 if (phoneId == -1) {
3757 throw new IllegalArgumentException("Given slot index: " + slotIndex
3758 + " does not correspond to an active phone");
3759 }
3760 return PhoneFactory.getPhone(phoneId);
3761 }
3762
Shishir Agrawal566b7612013-10-28 14:41:00 -07003763 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003764 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3765 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3767 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003768 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003769 if (DBG) {
3770 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3771 }
3772 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3773 p2);
3774 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003775
Jordan Liu4c733742019-02-28 12:03:40 -08003776
3777 @Override
3778 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3779 int slotIndex, String callingPackage, String aid, int p2) {
3780 enforceModifyPermission();
3781 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3782 if (DBG) {
3783 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3784 }
3785 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3786 callingPackage, aid, p2);
3787 }
3788
3789 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3790 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003791 final long identity = Binder.clearCallingIdentity();
3792 try {
3793 if (TextUtils.equals(ISDR_AID, aid)) {
3794 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3796 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003797 if (bestComponent == null
3798 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3799 loge("The calling package is not allowed to access ISD-R.");
3800 throw new SecurityException(
3801 "The calling package is not allowed to access ISD-R.");
3802 }
Derek Tan740e1672017-06-27 14:56:27 -07003803 }
Derek Tan740e1672017-06-27 14:56:27 -07003804
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003805 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003806 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3807 null /* workSource */);
3808 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003809 return response;
3810 } finally {
3811 Binder.restoreCallingIdentity(identity);
3812 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003813 }
3814
3815 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003816 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3818 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003819 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
3820 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
3821 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003822
Jordan Liu4c733742019-02-28 12:03:40 -08003823 @Override
3824 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
3825 enforceModifyPermission();
3826 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
3827 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3828 channel);
3829 }
3830
3831 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003832 final long identity = Binder.clearCallingIdentity();
3833 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003834 if (channel < 0) {
3835 return false;
3836 }
Jordan Liu4c733742019-02-28 12:03:40 -08003837 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
3838 null /* workSource */);
3839 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003840 return success;
3841 } finally {
3842 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003843 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003844 }
3845
3846 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003847 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07003848 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003849 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3850 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08003851 if (DBG) {
3852 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
3853 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3854 + p3 + " data=" + data);
3855 }
3856 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
3857 command, p1, p2, p3, data);
3858 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003859
Jordan Liu4c733742019-02-28 12:03:40 -08003860 @Override
3861 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
3862 int command, int p1, int p2, int p3, String data) {
3863 enforceModifyPermission();
3864 if (DBG) {
3865 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
3866 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
3867 + p3 + " data=" + data);
3868 }
3869 return iccTransmitApduLogicalChannelWithPermission(
3870 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
3871 data);
3872 }
3873
3874 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
3875 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003876 final long identity = Binder.clearCallingIdentity();
3877 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07003878 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003879 return "";
3880 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003881
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003882 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003883 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
3884 null /* workSource */);
3885 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07003886
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003887 // Append the returned status code to the end of the response payload.
3888 String s = Integer.toHexString(
3889 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3890 if (response.payload != null) {
3891 s = IccUtils.bytesToHexString(response.payload) + s;
3892 }
3893 return s;
3894 } finally {
3895 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003896 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003897 }
Jake Hambye994d462014-02-03 13:10:13 -08003898
Evan Charltonc66da362014-05-16 14:06:40 -07003899 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003900 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
3901 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3903 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003904 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003905 if (DBG) {
3906 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
3907 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
3908 }
3909 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
3910 cla, command, p1, p2, p3, data);
3911 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003912
Jordan Liu4c733742019-02-28 12:03:40 -08003913 @Override
3914 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
3915 int command, int p1, int p2, int p3, String data) {
3916 enforceModifyPermission();
3917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3918 if (DBG) {
3919 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
3920 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
3921 + " data=" + data);
3922 }
3923
3924 return iccTransmitApduBasicChannelWithPermission(
3925 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
3926 p2, p3, data);
3927 }
3928
3929 // open APDU basic channel assuming the caller has sufficient permissions
3930 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
3931 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003932 final long identity = Binder.clearCallingIdentity();
3933 try {
3934 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
3935 && TextUtils.equals(ISDR_AID, data)) {
3936 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003937 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3938 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003939 if (bestComponent == null
3940 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3941 loge("The calling package is not allowed to select ISD-R.");
3942 throw new SecurityException(
3943 "The calling package is not allowed to select ISD-R.");
3944 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003945 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08003946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08003948 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
3949 null /* workSource */);
3950 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003952 // Append the returned status code to the end of the response payload.
3953 String s = Integer.toHexString(
3954 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
3955 if (response.payload != null) {
3956 s = IccUtils.bytesToHexString(response.payload) + s;
3957 }
3958 return s;
3959 } finally {
3960 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07003961 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003962 }
3963
3964 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003965 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003966 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003967 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3968 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07003969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 if (DBG) {
3973 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
3974 + p1 + " " + p2 + " " + p3 + ":" + filePath);
3975 }
3976
3977 IccIoResult response =
3978 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
3979 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
3980 subId);
3981
3982 if (DBG) {
3983 log("Exchange SIM_IO [R]" + response);
3984 }
3985
3986 byte[] result = null;
3987 int length = 2;
3988 if (response.payload != null) {
3989 length = 2 + response.payload.length;
3990 result = new byte[length];
3991 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
3992 } else {
3993 result = new byte[length];
3994 }
3995
3996 result[length - 1] = (byte) response.sw2;
3997 result[length - 2] = (byte) response.sw1;
3998 return result;
3999 } finally {
4000 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004001 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004002 }
4003
Nathan Haroldb3014052017-01-25 15:57:32 -08004004 /**
4005 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4006 * on a particular subscription
4007 */
sqianb6e41952018-03-12 14:54:01 -07004008 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4009 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4010 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4011 return null;
4012 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013
4014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 if (appType != TelephonyManager.APPTYPE_USIM
4017 && appType != TelephonyManager.APPTYPE_SIM) {
4018 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4019 return null;
4020 }
4021 Object response = sendRequest(
4022 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4023 if (response instanceof String[]) {
4024 return (String[]) response;
4025 }
4026 // Response is an Exception of some kind,
4027 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004028 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004029 } finally {
4030 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004031 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004032 }
4033
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004034 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004035 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4037 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004039 final long identity = Binder.clearCallingIdentity();
4040 try {
4041 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4042 if (response.payload == null) {
4043 return "";
4044 }
Evan Charltonc66da362014-05-16 14:06:40 -07004045
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004046 // Append the returned status code to the end of the response payload.
4047 String s = Integer.toHexString(
4048 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4049 s = IccUtils.bytesToHexString(response.payload) + s;
4050 return s;
4051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
Evan Charltonc66da362014-05-16 14:06:40 -07004054 }
4055
Jake Hambye994d462014-02-03 13:10:13 -08004056 /**
4057 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4058 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4059 *
4060 * @param itemID the ID of the item to read
4061 * @return the NV item as a String, or null on error.
4062 */
4063 @Override
4064 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004065 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4067 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
4071 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004072 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004073 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4074 return value;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
Jake Hambye994d462014-02-03 13:10:13 -08004078 }
4079
4080 /**
4081 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4082 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4083 *
4084 * @param itemID the ID of the item to read
4085 * @param itemValue the value to write, as a String
4086 * @return true on success; false on any failure
4087 */
4088 @Override
4089 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004090 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4092 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4097 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004098 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4100 return success;
4101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
Jake Hambye994d462014-02-03 13:10:13 -08004104 }
4105
4106 /**
4107 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4108 * Used for device configuration by some CDMA operators.
4109 *
4110 * @param preferredRoamingList byte array containing the new PRL
4111 * @return true on success; false on any failure
4112 */
4113 @Override
4114 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004115 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4116 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004117
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4121 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4122 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4123 return success;
4124 } finally {
4125 Binder.restoreCallingIdentity(identity);
4126 }
Jake Hambye994d462014-02-03 13:10:13 -08004127 }
4128
4129 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004130 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004131 * Used for device configuration by some CDMA operators.
4132 *
chen xu6dac5ab2018-10-26 17:39:23 -07004133 * @param slotIndex - device slot.
4134 *
Jake Hambye994d462014-02-03 13:10:13 -08004135 * @return true on success; false on any failure
4136 */
4137 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004138 public boolean resetModemConfig(int slotIndex) {
4139 Phone phone = PhoneFactory.getPhone(slotIndex);
4140 if (phone != null) {
4141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4142 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004143
chen xu6dac5ab2018-10-26 17:39:23 -07004144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4147 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4148 return success;
4149 } finally {
4150 Binder.restoreCallingIdentity(identity);
4151 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004152 }
chen xu6dac5ab2018-10-26 17:39:23 -07004153 return false;
4154 }
4155
4156 /**
4157 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4158 *
4159 * @param slotIndex - device slot.
4160 *
4161 * @return true on success; false on any failure
4162 */
4163 @Override
4164 public boolean rebootModem(int slotIndex) {
4165 Phone phone = PhoneFactory.getPhone(slotIndex);
4166 if (phone != null) {
4167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4168 mApp, phone.getSubId(), "rebootModem");
4169
4170 final long identity = Binder.clearCallingIdentity();
4171 try {
4172 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4173 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4174 return success;
4175 } finally {
4176 Binder.restoreCallingIdentity(identity);
4177 }
4178 }
4179 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004180 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004181
Svet Ganovb320e182015-04-16 12:30:10 -07004182 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004183 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004185 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004186 return new String[0];
4187 }
4188
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004189 final long identity = Binder.clearCallingIdentity();
4190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004191 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004192 } finally {
4193 Binder.restoreCallingIdentity(identity);
4194 }
Wink Saville36469e72014-06-11 15:17:00 -07004195 }
4196
Brad Ebinger51f743a2017-01-23 13:50:20 -08004197 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004198 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4199 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004200 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004201 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004202 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004203
4204 final long identity = Binder.clearCallingIdentity();
4205 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004206 ImsResolver resolver = PhoneFactory.getImsResolver();
4207 if (resolver == null) {
4208 // may happen if the device does not support IMS.
4209 return;
4210 }
4211 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004212 } finally {
4213 Binder.restoreCallingIdentity(identity);
4214 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004215 }
4216
4217 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004218 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4219 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004220 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004221 public void disableIms(int slotId) {
4222 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004223
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004226 ImsResolver resolver = PhoneFactory.getImsResolver();
4227 if (resolver == null) {
4228 // may happen if the device does not support IMS.
4229 return;
4230 }
4231 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004232 } finally {
4233 Binder.restoreCallingIdentity(identity);
4234 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004235 }
4236
4237 /**
4238 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4239 * feature or {@link null} if the service is not available. If the feature is available, the
4240 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4241 */
4242 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004243 IImsServiceFeatureCallback callback) {
4244 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245
4246 final long identity = Binder.clearCallingIdentity();
4247 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004248 ImsResolver resolver = PhoneFactory.getImsResolver();
4249 if (resolver == null) {
4250 // may happen if the device does not support IMS.
4251 return null;
4252 }
4253 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004254 } finally {
4255 Binder.restoreCallingIdentity(identity);
4256 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004257 }
4258
4259 /**
4260 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4261 * feature during emergency calling or {@link null} if the service is not available. If the
4262 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4263 * listener for feature updates.
4264 */
4265 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004267
4268 final long identity = Binder.clearCallingIdentity();
4269 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004270 ImsResolver resolver = PhoneFactory.getImsResolver();
4271 if (resolver == null) {
4272 // may happen if the device does not support IMS.
4273 return null;
4274 }
4275 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004276 } finally {
4277 Binder.restoreCallingIdentity(identity);
4278 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004279 }
4280
Brad Ebinger5f64b052017-12-14 14:26:15 -08004281 /**
4282 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004283 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004284 */
4285 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287
4288 final long identity = Binder.clearCallingIdentity();
4289 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004290 ImsResolver resolver = PhoneFactory.getImsResolver();
4291 if (resolver == null) {
4292 // may happen if the device does not support IMS.
4293 return null;
4294 }
4295 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004296 } finally {
4297 Binder.restoreCallingIdentity(identity);
4298 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004299 }
4300
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004301 /**
4302 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004303 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004304 */
4305 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4306 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004310 ImsResolver resolver = PhoneFactory.getImsResolver();
4311 if (resolver == null) {
4312 // may happen if the device does not support IMS.
4313 return null;
4314 }
4315 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 } finally {
4317 Binder.restoreCallingIdentity(identity);
4318 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004319 }
4320
Brad Ebinger884c07b2018-02-15 16:17:40 -08004321 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004322 * Sets the ImsService Package Name that Telephony will bind to.
4323 *
4324 * @param slotId the slot ID that the ImsService should bind for.
4325 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4326 * ImsService is the device default ImsService.
4327 * @param packageName The package name of the application that contains the ImsService to bind
4328 * to.
4329 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4330 * @hide
4331 */
4332 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004333 int[] subIds = SubscriptionManager.getSubId(slotId);
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4335 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4336 "setImsService");
4337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004338 final long identity = Binder.clearCallingIdentity();
4339 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004340 ImsResolver resolver = PhoneFactory.getImsResolver();
4341 if (resolver == null) {
4342 // may happen if the device does not support IMS.
4343 return false;
4344 }
4345 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4346 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004347 } finally {
4348 Binder.restoreCallingIdentity(identity);
4349 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004350 }
4351
4352 /**
4353 * Return the ImsService configuration.
4354 *
4355 * @param slotId The slot that the ImsService is associated with.
4356 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4357 * the device default.
4358 * @return the package name of the ImsService configuration.
4359 */
4360 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004361 int[] subIds = SubscriptionManager.getSubId(slotId);
4362 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4363 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4364 "getImsService");
4365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004366 final long identity = Binder.clearCallingIdentity();
4367 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004368 ImsResolver resolver = PhoneFactory.getImsResolver();
4369 if (resolver == null) {
4370 // may happen if the device does not support IMS.
4371 return "";
4372 }
4373 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 } finally {
4375 Binder.restoreCallingIdentity(identity);
4376 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004377 }
4378
Wink Saville36469e72014-06-11 15:17:00 -07004379 public void setImsRegistrationState(boolean registered) {
4380 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004381
4382 final long identity = Binder.clearCallingIdentity();
4383 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004384 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004385 } finally {
4386 Binder.restoreCallingIdentity(identity);
4387 }
Wink Saville36469e72014-06-11 15:17:00 -07004388 }
4389
4390 /**
Stuart Scott54788802015-03-30 13:18:01 -07004391 * Set the network selection mode to automatic.
4392 *
4393 */
4394 @Override
4395 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4397 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004398
Pengquan Menge92a50d2018-09-21 15:54:48 -07004399 if (!isActiveSubscription(subId)) {
4400 return;
4401 }
4402
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004403 final long identity = Binder.clearCallingIdentity();
4404 try {
4405 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4406 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4407 } finally {
4408 Binder.restoreCallingIdentity(identity);
4409 }
Stuart Scott54788802015-03-30 13:18:01 -07004410 }
4411
Pengquan Mengea84e042018-09-20 14:57:26 -07004412 /**
4413 * Ask the radio to connect to the input network and change selection mode to manual.
4414 *
4415 * @param subId the id of the subscription.
4416 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4417 * the operator to attach to.
4418 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4419 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4420 * normal network selection next time.
4421 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004422 */
4423 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004424 public boolean setNetworkSelectionModeManual(
4425 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004426 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4427 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004428
4429 if (!isActiveSubscription(subId)) {
4430 return false;
4431 }
4432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004435 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004437 if (DBG) {
4438 log("setNetworkSelectionModeManual: subId: " + subId
4439 + " operator: " + operatorInfo);
4440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004441 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4442 } finally {
4443 Binder.restoreCallingIdentity(identity);
4444 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004445 }
4446
4447 /**
4448 * Scans for available networks.
4449 */
4450 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004451 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4453 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004454 LocationAccessPolicy.LocationPermissionResult locationResult =
4455 LocationAccessPolicy.checkLocationPermission(mApp,
4456 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4457 .setCallingPackage(callingPackage)
4458 .setCallingPid(Binder.getCallingPid())
4459 .setCallingUid(Binder.getCallingUid())
4460 .setMethod("getCellNetworkScanResults")
4461 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4462 .build());
4463 switch (locationResult) {
4464 case DENIED_HARD:
4465 throw new SecurityException("Not allowed to access scan results -- location");
4466 case DENIED_SOFT:
4467 return null;
4468 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004469
Pengquan Menga1bb6272018-09-06 09:59:22 -07004470 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004471 try {
4472 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004473 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 } finally {
4476 Binder.restoreCallingIdentity(identity);
4477 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004478 }
4479
4480 /**
yinxub1bed742017-04-17 11:45:04 -07004481 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004482 *
yinxub1bed742017-04-17 11:45:04 -07004483 * @param subId id of the subscription
4484 * @param request contains the radio access networks with bands/channels to scan
4485 * @param messenger callback messenger for scan results or errors
4486 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004487 * @return the id of the requested scan which can be used to stop the scan.
4488 */
4489 @Override
4490 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004491 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004492 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4493 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004494 LocationAccessPolicy.LocationPermissionResult locationResult =
4495 LocationAccessPolicy.checkLocationPermission(mApp,
4496 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4497 .setCallingPackage(callingPackage)
4498 .setCallingPid(Binder.getCallingPid())
4499 .setCallingUid(Binder.getCallingUid())
4500 .setMethod("requestNetworkScan")
4501 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4502 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004503 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004504 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004505 if (e != null) {
4506 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4507 throw e;
4508 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004509 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004510 return TelephonyScanManager.INVALID_SCAN_ID;
4511 }
4512 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004513 }
Hall Liu912dfd32019-04-25 14:02:26 -07004514 int callingUid = Binder.getCallingUid();
4515 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004516 final long identity = Binder.clearCallingIdentity();
4517 try {
4518 return mNetworkScanRequestTracker.startNetworkScan(
4519 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004520 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004521 } finally {
4522 Binder.restoreCallingIdentity(identity);
4523 }
yinxu504e1392017-04-12 16:03:22 -07004524 }
4525
Hall Liub2ac8ef2019-02-28 15:56:23 -08004526 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004527 NetworkScanRequest request, int subId) {
4528 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4529 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4530 boolean hasNetworkScanPermission =
4531 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4532 == PERMISSION_GRANTED;
4533
4534 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4535 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4536 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004537 }
4538
4539 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4540 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004541 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4542 return new SecurityException("Specific channels must not be"
4543 + " scanned without location access.");
4544 }
4545 }
4546 }
4547
Hall Liub2ac8ef2019-02-28 15:56:23 -08004548 return null;
4549 }
4550
yinxu504e1392017-04-12 16:03:22 -07004551 /**
4552 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004553 *
4554 * @param subId id of the subscription
4555 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004556 */
4557 @Override
4558 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4560 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004561
Hall Liu912dfd32019-04-25 14:02:26 -07004562 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004563 final long identity = Binder.clearCallingIdentity();
4564 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004565 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
yinxu504e1392017-04-12 16:03:22 -07004569 }
4570
4571 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004572 * Get the calculated preferred network type.
4573 * Used for debugging incorrect network type.
4574 *
4575 * @return the preferred network type, defined in RILConstants.java.
4576 */
4577 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004578 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004579 final Phone defaultPhone = getDefaultPhone();
4580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4581 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004582 return RILConstants.PREFERRED_NETWORK_MODE;
4583 }
4584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
4587 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004588 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
Junda Liu84d15a22014-07-02 11:21:04 -07004592 }
4593
4594 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004595 * Get the preferred network type.
4596 * Used for device configuration by some CDMA operators.
4597 *
4598 * @return the preferred network type, defined in RILConstants.java.
4599 */
4600 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004601 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004602 TelephonyPermissions
4603 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4604 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
4608 if (DBG) log("getPreferredNetworkType");
4609 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4610 int networkType = (result != null ? result[0] : -1);
4611 if (DBG) log("getPreferredNetworkType: " + networkType);
4612 return networkType;
4613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004616 }
4617
4618 /**
4619 * Set the preferred network type.
4620 * Used for device configuration by some CDMA operators.
4621 *
4622 * @param networkType the preferred network type, defined in RILConstants.java.
4623 * @return true on success; false on any failure.
4624 */
4625 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004626 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004627 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4628 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004629
4630 final long identity = Binder.clearCallingIdentity();
4631 try {
4632 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4633 Boolean success = (Boolean) sendRequest(
4634 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4635 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4636 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004637 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004638 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4639 }
4640 return success;
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004643 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004644 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004645
4646 /**
Miaoa84611c2019-03-15 09:21:10 +08004647 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004648 *
Miaoa84611c2019-03-15 09:21:10 +08004649 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004650 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004651 * @hide
4652 */
4653 @Override
Miaoa84611c2019-03-15 09:21:10 +08004654 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004655 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004657 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 try {
Miaoa84611c2019-03-15 09:21:10 +08004659 if (phone != null) {
4660 return phone.hasMatchedTetherApnSetting();
4661 } else {
4662 return false;
4663 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 } finally {
4665 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004666 }
Junda Liu475951f2014-11-07 16:45:03 -08004667 }
4668
4669 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004670 * Set mobile data enabled
4671 * Used by the user through settings etc to turn on/off mobile data
4672 *
4673 * @param enable {@code true} turn turn data on, else {@code false}
4674 */
4675 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004676 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4678 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679
4680 final long identity = Binder.clearCallingIdentity();
4681 try {
4682 int phoneId = mSubscriptionController.getPhoneId(subId);
4683 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4684 Phone phone = PhoneFactory.getPhone(phoneId);
4685 if (phone != null) {
4686 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004687 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004688 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004689 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 }
4691 } finally {
4692 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004693 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004694 }
4695
4696 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004697 * Get the user enabled state of Mobile Data.
4698 *
4699 * TODO: remove and use isUserDataEnabled.
4700 * This can't be removed now because some vendor codes
4701 * calls through ITelephony directly while they should
4702 * use TelephonyManager.
4703 *
4704 * @return true on enabled
4705 */
4706 @Override
4707 public boolean getDataEnabled(int subId) {
4708 return isUserDataEnabled(subId);
4709 }
4710
4711 /**
4712 * Get whether mobile data is enabled per user setting.
4713 *
4714 * There are other factors deciding whether mobile data is actually enabled, but they are
4715 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004716 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004717 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004718 *
4719 * @return {@code true} if data is enabled else {@code false}
4720 */
4721 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004722 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004723 try {
4724 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4725 null);
4726 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004727 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4728 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004729 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730
4731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 int phoneId = mSubscriptionController.getPhoneId(subId);
4734 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4735 Phone phone = PhoneFactory.getPhone(phoneId);
4736 if (phone != null) {
4737 boolean retVal = phone.isUserDataEnabled();
4738 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4739 return retVal;
4740 } else {
4741 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4742 return false;
4743 }
4744 } finally {
4745 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08004746 }
4747 }
4748
4749 /**
4750 * Get whether mobile data is enabled.
4751 *
4752 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
4753 * whether mobile data is actually enabled.
4754 *
4755 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
4756 *
4757 * @return {@code true} if data is enabled else {@code false}
4758 */
4759 @Override
4760 public boolean isDataEnabled(int subId) {
4761 try {
4762 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4763 null);
4764 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4766 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08004767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004768
4769 final long identity = Binder.clearCallingIdentity();
4770 try {
4771 int phoneId = mSubscriptionController.getPhoneId(subId);
4772 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4773 Phone phone = PhoneFactory.getPhone(phoneId);
4774 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08004775 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
4777 return retVal;
4778 } else {
4779 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
4780 return false;
4781 }
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004784 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004785 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004786
4787 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004788 public int getCarrierPrivilegeStatus(int subId) {
4789 final Phone phone = getPhone(subId);
4790 if (phone == null) {
4791 loge("getCarrierPrivilegeStatus: Invalid subId");
4792 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4793 }
4794 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004795 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08004796 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004797 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4798 }
4799 return card.getCarrierPrivilegeStatusForCurrentTransaction(
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004800 phone.getContext().getPackageManager());
Shishir Agrawal60f9c952014-06-23 12:00:43 -07004801 }
Junda Liu29340342014-07-10 15:23:27 -07004802
4803 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08004804 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
4805 final Phone phone = getPhone(subId);
4806 if (phone == null) {
4807 loge("getCarrierPrivilegeStatus: Invalid subId");
4808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
4809 }
4810 UiccProfile profile =
4811 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
4812 if (profile == null) {
4813 loge("getCarrierPrivilegeStatus: No UICC");
4814 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4815 }
4816 return profile.getCarrierPrivilegeStatusForUid(phone.getContext().getPackageManager(), uid);
4817 }
4818
4819 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004820 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
4821 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08004822 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07004823 }
4824
4825 int phoneId = SubscriptionManager.getPhoneId(subId);
4826 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004827 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07004828 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07004829 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4830 }
chen xuf7e9fe82019-05-09 19:31:02 -07004831
4832 return card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004833 }
4834
4835 @Override
4836 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08004837 if (TextUtils.isEmpty(pkgName))
4838 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07004839 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
4840 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4841 UiccCard card = UiccController.getInstance().getUiccCard(i);
4842 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07004843 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07004844 continue;
4845 }
4846
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004847 result = card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07004848 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
4849 break;
4850 }
4851 }
4852
4853 return result;
Junda Liu29340342014-07-10 15:23:27 -07004854 }
Derek Tan89e89d42014-07-08 17:00:10 -07004855
4856 @Override
Junda Liue64de782015-04-16 17:19:16 -07004857 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
4858 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
4859 loge("phoneId " + phoneId + " is not valid.");
4860 return null;
4861 }
4862 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004863 if (card == null) {
Diego Pontorieroaf74c862014-08-28 11:51:16 -07004864 loge("getCarrierPackageNamesForIntent: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004865 return null ;
4866 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004867 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004868 }
4869
Amith Yamasani6e118872016-02-19 12:53:51 -08004870 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07004871 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004872 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08004873 List<String> privilegedPackages = new ArrayList<>();
4874 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07004875 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
4876 // has UICC in that slot.
4877 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004878 if (card.hasCarrierPrivilegeRules()) {
4879 if (packages == null) {
4880 // Only check packages in user 0 for now
4881 packages = pm.getInstalledPackagesAsUser(
4882 PackageManager.MATCH_DISABLED_COMPONENTS
chen xuf7e9fe82019-05-09 19:31:02 -07004883 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
4884 | PackageManager.GET_SIGNATURES, UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08004885 }
4886 for (int p = packages.size() - 1; p >= 0; p--) {
4887 PackageInfo pkgInfo = packages.get(p);
4888 if (pkgInfo != null && pkgInfo.packageName != null
4889 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07004890 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08004891 privilegedPackages.add(pkgInfo.packageName);
4892 }
4893 }
4894 }
4895 }
4896 return privilegedPackages;
4897 }
4898
chen xuf7e9fe82019-05-09 19:31:02 -07004899 @Override
4900 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
4901 List<String> privilegedPackages = new ArrayList<>();
4902 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
4903 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
4904 }
4905 return privilegedPackages;
4906 }
4907
Wink Savilleb564aae2014-10-23 10:18:09 -07004908 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07004909 final Phone phone = getPhone(subId);
4910 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07004911 if (card == null) {
4912 loge("getIccId: No UICC");
4913 return null;
4914 }
4915 String iccId = card.getIccId();
4916 if (TextUtils.isEmpty(iccId)) {
4917 loge("getIccId: ICC ID is null or empty.");
4918 return null;
4919 }
4920 return iccId;
4921 }
4922
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07004923 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08004924 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
4925 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
4927 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07004928
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 final long identity = Binder.clearCallingIdentity();
4930 try {
4931 final String iccId = getIccId(subId);
4932 final Phone phone = getPhone(subId);
4933 if (phone == null) {
4934 return false;
4935 }
4936 final String subscriberId = phone.getSubscriberId();
4937
4938 if (DBG_MERGE) {
4939 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
4940 + subscriberId + " to " + number);
4941 }
4942
4943 if (TextUtils.isEmpty(iccId)) {
4944 return false;
4945 }
4946
4947 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4948
4949 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
4950 if (alphaTag == null) {
4951 editor.remove(alphaTagPrefKey);
4952 } else {
4953 editor.putString(alphaTagPrefKey, alphaTag);
4954 }
4955
4956 // Record both the line number and IMSI for this ICCID, since we need to
4957 // track all merged IMSIs based on line number
4958 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4959 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
4960 if (number == null) {
4961 editor.remove(numberPrefKey);
4962 editor.remove(subscriberPrefKey);
4963 } else {
4964 editor.putString(numberPrefKey, number);
4965 editor.putString(subscriberPrefKey, subscriberId);
4966 }
4967
4968 editor.commit();
4969 return true;
4970 } finally {
4971 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004972 }
Derek Tan7226c842014-07-02 17:42:23 -07004973 }
4974
4975 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004976 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07004977 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08004978 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08004979 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08004980 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07004981 return null;
4982 }
Derek Tan97ebb422014-09-05 16:55:38 -07004983
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004984 final long identity = Binder.clearCallingIdentity();
4985 try {
4986 String iccId = getIccId(subId);
4987 if (iccId != null) {
4988 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
4989 if (DBG_MERGE) {
4990 log("getLine1NumberForDisplay returning "
4991 + mTelephonySharedPreferences.getString(numberPrefKey, null));
4992 }
4993 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08004994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004995 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
4996 return null;
4997 } finally {
4998 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07004999 }
Derek Tan7226c842014-07-02 17:42:23 -07005000 }
5001
5002 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005003 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005004 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005005 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005006 return null;
5007 }
Derek Tan97ebb422014-09-05 16:55:38 -07005008
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 final long identity = Binder.clearCallingIdentity();
5010 try {
5011 String iccId = getIccId(subId);
5012 if (iccId != null) {
5013 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5014 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5015 }
5016 return null;
5017 } finally {
5018 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005019 }
Derek Tan7226c842014-07-02 17:42:23 -07005020 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005021
5022 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005023 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005024 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5025 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005026 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005027 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5028 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005029 return null;
5030 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005031
Jordan Liub49b04b2019-05-06 14:45:15 -07005032 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5033 // the process, where TelephonyManager was instantiated.
5034 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005035 final long identity = Binder.clearCallingIdentity();
5036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005037 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 final TelephonyManager tele = TelephonyManager.from(context);
5039 final SubscriptionManager sub = SubscriptionManager.from(context);
5040
5041 // Figure out what subscribers are currently active
5042 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005043
Jordan Liub49b04b2019-05-06 14:45:15 -07005044 // Only consider subs which match the current subId
5045 // This logic can be simplified. See b/131189269 for progress.
5046 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005047 activeSubscriberIds.add(tele.getSubscriberId(subId));
5048 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005049
5050 // First pass, find a number override for an active subscriber
5051 String mergeNumber = null;
5052 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5053 for (String key : prefs.keySet()) {
5054 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5055 final String subscriberId = (String) prefs.get(key);
5056 if (activeSubscriberIds.contains(subscriberId)) {
5057 final String iccId = key.substring(
5058 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5059 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5060 mergeNumber = (String) prefs.get(numberKey);
5061 if (DBG_MERGE) {
5062 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5063 + " for active subscriber " + subscriberId);
5064 }
5065 if (!TextUtils.isEmpty(mergeNumber)) {
5066 break;
5067 }
5068 }
5069 }
5070 }
5071
5072 // Shortcut when no active merged subscribers
5073 if (TextUtils.isEmpty(mergeNumber)) {
5074 return null;
5075 }
5076
5077 // Second pass, find all subscribers under that line override
5078 final ArraySet<String> result = new ArraySet<>();
5079 for (String key : prefs.keySet()) {
5080 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5081 final String number = (String) prefs.get(key);
5082 if (mergeNumber.equals(number)) {
5083 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5084 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5085 final String subscriberId = (String) prefs.get(subscriberKey);
5086 if (!TextUtils.isEmpty(subscriberId)) {
5087 result.add(subscriberId);
5088 }
5089 }
5090 }
5091 }
5092
5093 final String[] resultArray = result.toArray(new String[result.size()]);
5094 Arrays.sort(resultArray);
5095 if (DBG_MERGE) {
5096 Slog.d(LOG_TAG,
5097 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5098 }
5099 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005102 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005103 }
5104
5105 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005106 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5107 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5108
5109 final long identity = Binder.clearCallingIdentity();
5110 try {
5111 final TelephonyManager telephonyManager = mApp.getSystemService(
5112 TelephonyManager.class);
5113 String subscriberId = telephonyManager.getSubscriberId(subId);
5114 if (subscriberId == null) {
5115 if (DBG) {
5116 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5117 + subId);
5118 }
5119 return null;
5120 }
5121
5122 final SubscriptionInfo info = SubscriptionController.getInstance()
5123 .getSubscriptionInfo(subId);
5124 final ParcelUuid groupUuid = info.getGroupUuid();
5125 // If it doesn't belong to any group, return just subscriberId of itself.
5126 if (groupUuid == null) {
5127 return new String[]{subscriberId};
5128 }
5129
5130 // Get all subscriberIds from the group.
5131 final List<String> mergedSubscriberIds = new ArrayList<>();
5132 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5133 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5134 for (SubscriptionInfo subInfo : groupInfos) {
5135 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5136 if (subscriberId != null) {
5137 mergedSubscriberIds.add(subscriberId);
5138 }
5139 }
5140
5141 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5142 } finally {
5143 Binder.restoreCallingIdentity(identity);
5144
5145 }
5146 }
5147
5148 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005149 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5151 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 final Phone phone = getPhone(subId);
5156 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5157 } finally {
5158 Binder.restoreCallingIdentity(identity);
5159 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005160 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005161
5162 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005163 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005164 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5165 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005166 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167
5168 final long identity = Binder.clearCallingIdentity();
5169 try {
5170 final Phone phone = getPhone(subId);
5171 if (phone == null) {
5172 return false;
5173 }
5174 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5175 cdmaNonRoamingList);
5176 } finally {
5177 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005178 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005179 }
5180
5181 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005182 @Deprecated
5183 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5184 enforceModifyPermission();
5185
5186 int returnValue = 0;
5187 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005188 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005189 if(result.exception == null) {
5190 if (result.result != null) {
5191 byte[] responseData = (byte[])(result.result);
5192 if(responseData.length > oemResp.length) {
5193 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5194 responseData.length + "bytes. Buffer Size is " +
5195 oemResp.length + "bytes.");
5196 }
5197 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5198 returnValue = responseData.length;
5199 }
5200 } else {
5201 CommandException ex = (CommandException) result.exception;
5202 returnValue = ex.getCommandError().ordinal();
5203 if(returnValue > 0) returnValue *= -1;
5204 }
5205 } catch (RuntimeException e) {
5206 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5207 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5208 if(returnValue > 0) returnValue *= -1;
5209 }
5210
5211 return returnValue;
5212 }
5213
5214 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005215 public void setRadioCapability(RadioAccessFamily[] rafs) {
5216 try {
5217 ProxyController.getInstance().setRadioCapability(rafs);
5218 } catch (RuntimeException e) {
5219 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5220 }
5221 }
5222
5223 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005224 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005225 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005226 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005227 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005228 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005230 final long identity = Binder.clearCallingIdentity();
5231 try {
chen xub97461a2018-10-26 14:17:57 -07005232 TelephonyPermissions
5233 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5234 mApp, phone.getSubId(), "getRadioAccessFamily");
5235 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
chen xub97461a2018-10-26 14:17:57 -07005239 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005240 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005241
5242 @Override
5243 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005244 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005245 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005249 ImsManager.getInstance(defaultPhone.getContext(),
5250 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 } finally {
5252 Binder.restoreCallingIdentity(identity);
5253 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005254 }
5255
5256 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005257 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005258 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005259 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005260 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005261 return false;
5262 }
Svet Ganovb320e182015-04-16 12:30:10 -07005263
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 // Check the user preference and the system-level IMS setting. Even if the user has
5267 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5268 // In the long run, we may instead need to check if there exists a connection service
5269 // which can support video calling.
5270 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005271 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272 return imsManager.isVtEnabledByPlatform()
5273 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5274 && imsManager.isVtEnabledByUser();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005278 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005279
Andrew Leea1239f22015-03-02 17:44:07 -08005280 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5282 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5283 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5284 return false;
5285 }
5286
5287 final long identity = Binder.clearCallingIdentity();
5288 try {
5289 CarrierConfigManager configManager =
5290 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005291 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005292 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5293 } finally {
5294 Binder.restoreCallingIdentity(identity);
5295 }
Andrew Leea1239f22015-03-02 17:44:07 -08005296 }
5297
5298 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299 public boolean isWorldPhone(int subId, String callingPackage) {
5300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5301 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5302 return false;
5303 }
5304
5305 final long identity = Binder.clearCallingIdentity();
5306 try {
5307 CarrierConfigManager configManager =
5308 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005309 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5311 } finally {
5312 Binder.restoreCallingIdentity(identity);
5313 }
Andrew Leea1239f22015-03-02 17:44:07 -08005314 }
5315
Andrew Lee9431b832015-03-09 18:46:45 -07005316 @Override
5317 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005318 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005319 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005320 }
5321
5322 @Override
5323 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005324 final long identity = Binder.clearCallingIdentity();
5325 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005326 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Andrew Lee9431b832015-03-09 18:46:45 -07005330 }
5331
Hall Liuf6668912018-10-31 17:05:23 -07005332 /**
5333 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5334 * support for the feature and device firmware support.
5335 *
5336 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5337 */
5338 @Override
5339 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005340 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005341 final Phone phone = getPhone(subscriptionId);
5342 if (phone == null) {
5343 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5344 return false;
5345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005346 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005347 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5349 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005350 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351 return isCarrierSupported && isDeviceSupported;
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
Hall Liu98187582018-01-22 19:15:32 -08005355 }
5356
Hall Liuf6668912018-10-31 17:05:23 -07005357 /**
5358 * Determines whether the user has turned on RTT. Only returns true if the device and carrier
5359 * both also support RTT.
5360 */
5361 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005362 final long identity = Binder.clearCallingIdentity();
5363 try {
Hall Liuf6668912018-10-31 17:05:23 -07005364 return isRttSupported(subscriptionId) && Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005365 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005369 }
5370
Sanket Padawe7310cc72015-01-14 09:53:20 -08005371 /**
5372 * Returns the unique device ID of phone, for example, the IMEI for
5373 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5374 *
5375 * <p>Requires Permission:
5376 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5377 */
5378 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005379 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005380 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005381 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005382 return null;
5383 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005384 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005385 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5386 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005387 return null;
5388 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005389
5390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 return phone.getDeviceId();
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005396 }
5397
Ping Sunc67b7c22016-03-02 19:16:45 +08005398 /**
5399 * {@hide}
5400 * Returns the IMS Registration Status on a particular subid
5401 *
5402 * @param subId
5403 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005404 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005405 Phone phone = getPhone(subId);
5406 if (phone != null) {
5407 return phone.isImsRegistered();
5408 } else {
5409 return false;
5410 }
5411 }
5412
Santos Cordon7a1885b2015-02-03 11:15:19 -08005413 @Override
5414 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005415 final long identity = Binder.clearCallingIdentity();
5416 try {
5417 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005421 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005422
Tyler Gunnf70ed162019-04-03 15:28:53 -07005423 @Override
5424 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5425 final long identity = Binder.clearCallingIdentity();
5426 try {
5427 Phone phone = getPhone(subscriptionId);
5428 if (phone == null) {
5429 return null;
5430 }
5431 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5432 } finally {
5433 Binder.restoreCallingIdentity(identity);
5434 }
5435 }
5436
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005437 /**
5438 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005439 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005440 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 final long identity = Binder.clearCallingIdentity();
5442 try {
5443 Phone phone = getPhone(subId);
5444 if (phone != null) {
5445 return phone.isWifiCallingEnabled();
5446 } else {
5447 return false;
5448 }
5449 } finally {
5450 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005451 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005452 }
5453
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005454 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005455 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005456 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005457 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005458 final long identity = Binder.clearCallingIdentity();
5459 try {
5460 Phone phone = getPhone(subId);
5461 if (phone != null) {
5462 return phone.isVideoEnabled();
5463 } else {
5464 return false;
5465 }
5466 } finally {
5467 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005468 }
5469 }
5470
5471 /**
5472 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5473 * defined in {@link ImsRegistrationImplBase}.
5474 */
5475 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476 final long identity = Binder.clearCallingIdentity();
5477 try {
5478 Phone phone = getPhone(subId);
5479 if (phone != null) {
5480 return phone.getImsRegistrationTech();
5481 } else {
5482 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5483 }
5484 } finally {
5485 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005486 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005487 }
5488
Stuart Scott8eef64f2015-04-08 15:13:54 -07005489 @Override
5490 public void factoryReset(int subId) {
5491 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005492 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5493 return;
5494 }
5495
Svet Ganovcc087f82015-05-12 20:35:54 -07005496 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005497
Svet Ganovcc087f82015-05-12 20:35:54 -07005498 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005499 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5500 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005501 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005502 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005503 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005504 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5505 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005506 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005507 // There has been issues when Sms raw table somehow stores orphan
5508 // fragments. They lead to garbled message when new fragments come
5509 // in and combined with those stale ones. In case this happens again,
5510 // user can reset all network settings which will clean up this table.
5511 cleanUpSmsRawTable(getDefaultPhone().getContext());
Svet Ganovcc087f82015-05-12 20:35:54 -07005512 } finally {
5513 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005514 }
5515 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005516
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005517 private void cleanUpSmsRawTable(Context context) {
5518 ContentResolver resolver = context.getContentResolver();
5519 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5520 resolver.delete(uri, null, null);
5521 }
5522
Narayan Kamath1c496c22015-04-16 14:40:19 +01005523 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005524 public String getSimLocaleForSubscriber(int subId) {
5525 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5526 final Phone phone = getPhone(subId);
5527 if (phone == null) {
5528 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005529 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005530 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005531 final long identity = Binder.clearCallingIdentity();
5532 try {
chen xu5d3637b2019-01-21 23:31:38 -08005533 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5534 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005535 if (info == null) {
5536 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5537 return null;
5538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 // Try and fetch the locale from the carrier properties or from the SIM language
5540 // preferences (EF-PL and EF-LI)...
5541 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005543 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5544 if (localeFromDefaultSim != null) {
5545 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5546 if (DBG) log("Using locale from subId: " + subId + " locale: "
5547 + localeFromDefaultSim);
5548 return localeFromDefaultSim.toLanguageTag();
5549 } else {
5550 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005551 }
5552 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005553
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005554 // The SIM language preferences only store a language (e.g. fr = French), not an
5555 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5556 // the SIM and carrier preferences does not include a country we add the country
5557 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005558 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005559 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005560 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 return mccLocale.toLanguageTag();
5562 }
5563
5564 if (DBG) log("No locale found - returning null");
5565 return null;
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005569 }
5570
5571 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005572 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005573 }
5574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 /**
5576 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5577 */
5578 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005579 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005580 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005581
Chenjie Yu1ba97252018-01-11 18:16:20 -08005582 private final ModemActivityInfo mLastModemActivityInfo =
5583 new ModemActivityInfo(0, 0, 0, new int[0], 0, 0);
5584
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005585 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005586 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5587 * representing the state of the modem.
5588 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005589 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5590 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005591 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005592 */
5593 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005594 public void requestModemActivityInfo(ResultReceiver result) {
5595 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005596 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005597
5598 final long identity = Binder.clearCallingIdentity();
5599 try {
5600 ModemActivityInfo ret = null;
5601 synchronized (mLastModemActivityInfo) {
5602 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5603 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005604 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005605 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005606 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
5607 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005608 mergedTxTimeMs[i] = info.getTxTimeMillis()[i]
5609 + mLastModemActivityInfo.getTxTimeMillis()[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 }
5611 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005612 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5613 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005614 mLastModemActivityInfo.setIdleTimeMillis(
5615 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
5616 mLastModemActivityInfo.setTxTimeMillis(mergedTxTimeMs);
5617 mLastModemActivityInfo.setRxTimeMillis(
5618 info.getRxTimeMillis() + mLastModemActivityInfo.getRxTimeMillis());
5619 mLastModemActivityInfo.setEnergyUsed(
5620 info.getEnergyUsed() + mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005621 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5623 mLastModemActivityInfo.getSleepTimeMillis(),
5624 mLastModemActivityInfo.getIdleTimeMillis(),
5625 mLastModemActivityInfo.getTxTimeMillis(),
5626 mLastModemActivityInfo.getRxTimeMillis(),
5627 mLastModemActivityInfo.getEnergyUsed());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 Bundle bundle = new Bundle();
5630 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5631 result.send(0, bundle);
5632 } finally {
5633 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005634 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005635 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005636
Siddharth Rayb8114062018-06-17 15:02:38 -07005637 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5638 // less than total activity duration.
5639 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5640 if (info == null) {
5641 return false;
5642 }
5643 int activityDurationMs =
5644 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5645 int totalTxTimeMs = 0;
5646 for (int i = 0; i < info.getTxTimeMillis().length; i++) {
5647 totalTxTimeMs += info.getTxTimeMillis()[i];
5648 }
5649 return (info.isValid()
5650 && (info.getSleepTimeMillis() <= activityDurationMs)
5651 && (info.getIdleTimeMillis() <= activityDurationMs)
5652 && (info.getRxTimeMillis() <= activityDurationMs)
5653 && (totalTxTimeMs <= activityDurationMs));
5654 }
5655
Jack Yu85bd38a2015-11-09 11:34:32 -08005656 /**
5657 * {@hide}
5658 * Returns the service state information on specified subscription.
5659 */
5660 @Override
5661 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005662 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005663 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005664 return null;
5665 }
5666
Hall Liuf19c44f2018-11-27 14:38:17 -08005667 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5668 LocationAccessPolicy.checkLocationPermission(mApp,
5669 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5670 .setCallingPackage(callingPackage)
5671 .setCallingPid(Binder.getCallingPid())
5672 .setCallingUid(Binder.getCallingUid())
5673 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005674 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005675 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5676 .build());
5677
5678 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
5679 LocationAccessPolicy.checkLocationPermission(mApp,
5680 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5681 .setCallingPackage(callingPackage)
5682 .setCallingPid(Binder.getCallingPid())
5683 .setCallingUid(Binder.getCallingUid())
5684 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005685 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005686 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5687 .build());
5688 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
5689 boolean hasFinePermission =
5690 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5691 boolean hasCoarsePermission =
5692 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
5693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 final Phone phone = getPhone(subId);
5697 if (phone == null) {
5698 return null;
5699 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005700
Hall Liuf19c44f2018-11-27 14:38:17 -08005701 ServiceState ss = phone.getServiceState();
5702
5703 // Scrub out the location info in ServiceState depending on what level of access
5704 // the caller has.
5705 if (hasFinePermission) return ss;
5706 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
5707 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005711 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005712
5713 /**
5714 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
5715 *
5716 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5717 * voicemail ringtone.
5718 * @return The URI for the ringtone to play when receiving a voicemail from a specific
5719 * PhoneAccount.
5720 */
5721 @Override
5722 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 final long identity = Binder.clearCallingIdentity();
5724 try {
5725 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5726 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005727 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005729
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
5731 } finally {
5732 Binder.restoreCallingIdentity(identity);
5733 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005734 }
5735
5736 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005737 * Sets the per-account voicemail ringtone.
5738 *
5739 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5740 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5741 *
5742 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5743 * voicemail ringtone.
5744 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
5745 * PhoneAccount.
5746 */
5747 @Override
5748 public void setVoicemailRingtoneUri(String callingPackage,
5749 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005750 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005751 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5752 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005753 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005754 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5755 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5756 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005757 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005758
5759 final long identity = Binder.clearCallingIdentity();
5760 try {
5761 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5762 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005763 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005764 }
5765 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
5766 } finally {
5767 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005768 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005769 }
5770
5771 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08005772 * Returns whether vibration is set for voicemail notification in Phone settings.
5773 *
5774 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
5775 * voicemail vibration setting.
5776 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
5777 */
5778 @Override
5779 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 final long identity = Binder.clearCallingIdentity();
5781 try {
5782 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
5783 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005784 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005787 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
5790 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08005791 }
5792
Youhan Wange64578a2016-05-02 15:32:42 -07005793 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005794 * Sets the per-account voicemail vibration.
5795 *
5796 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
5797 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
5798 *
5799 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
5800 * voicemail vibration setting.
5801 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
5802 * specific PhoneAccount.
5803 */
5804 @Override
5805 public void setVoicemailVibrationEnabled(String callingPackage,
5806 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005807 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005808 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5809 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005810 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5812 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
5813 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005814 }
5815
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005816 final long identity = Binder.clearCallingIdentity();
5817 try {
5818 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
5819 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005820 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005821 }
5822 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
5823 } finally {
5824 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005825 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08005826 }
5827
5828 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005829 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
5830 *
5831 * @throws SecurityException if the caller does not have the required permission
5832 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07005833 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07005834 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07005835 message);
Youhan Wange64578a2016-05-02 15:32:42 -07005836 }
5837
5838 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005839 * Make sure either called from same process as self (phone) or IPC caller has send SMS
5840 * permission.
5841 *
5842 * @throws SecurityException if the caller does not have the required permission
5843 */
5844 private void enforceSendSmsPermission() {
5845 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
5846 }
5847
5848 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005849 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005850 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005851 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005852 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08005853 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854 final long identity = Binder.clearCallingIdentity();
5855 try {
5856 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005857 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005858 if (componentName == null) {
5859 throw new SecurityException(
5860 "Caller not current active visual voicemail package[null]");
5861 }
5862 String vvmPackage = componentName.getPackageName();
5863 if (!callingPackage.equals(vvmPackage)) {
5864 throw new SecurityException("Caller not current active visual voicemail package["
5865 + vvmPackage + "]");
5866 }
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08005869 }
5870 }
5871
5872 /**
Youhan Wange64578a2016-05-02 15:32:42 -07005873 * Return the application ID for the app type.
5874 *
5875 * @param subId the subscription ID that this request applies to.
5876 * @param appType the uicc app type.
5877 * @return Application ID for specificied app type, or null if no uicc.
5878 */
5879 @Override
5880 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005881 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07005882 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005883
5884 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07005885 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005886 if (phone == null) {
5887 return null;
5888 }
5889 String aid = null;
5890 try {
5891 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
5892 .getApplicationByType(appType).getAid();
5893 } catch (Exception e) {
5894 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
5895 }
5896 return aid;
5897 } finally {
5898 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07005899 }
Youhan Wange64578a2016-05-02 15:32:42 -07005900 }
5901
Youhan Wang4001d252016-05-11 10:29:41 -07005902 /**
5903 * Return the Electronic Serial Number.
5904 *
5905 * @param subId the subscription ID that this request applies to.
5906 * @return ESN or null if error.
5907 */
5908 @Override
5909 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005910 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07005911 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005912
5913 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07005914 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 if (phone == null) {
5916 return null;
5917 }
5918 String esn = null;
5919 try {
5920 esn = phone.getEsn();
5921 } catch (Exception e) {
5922 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
5923 }
5924 return esn;
5925 } finally {
5926 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07005927 }
Youhan Wang4001d252016-05-11 10:29:41 -07005928 }
5929
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005930 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07005931 * Return the Preferred Roaming List Version.
5932 *
5933 * @param subId the subscription ID that this request applies to.
5934 * @return PRLVersion or null if error.
5935 */
5936 @Override
5937 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07005938 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07005939 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940
5941 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07005942 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 if (phone == null) {
5944 return null;
5945 }
5946 String cdmaPrlVersion = null;
5947 try {
5948 cdmaPrlVersion = phone.getCdmaPrlVersion();
5949 } catch (Exception e) {
5950 Log.e(LOG_TAG, "Not getting PRLVersion", e);
5951 }
5952 return cdmaPrlVersion;
5953 } finally {
5954 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07005955 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07005956 }
5957
5958 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005959 * Get snapshot of Telephony histograms
5960 * @return List of Telephony histograms
5961 * @hide
5962 */
5963 @Override
5964 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005965 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5966 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return RIL.getTelephonyRILTimingHistograms();
5971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07005974 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07005975
5976 /**
5977 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08005978 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
5979 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005980 * Require system privileges. In the future we may add this to carrier APIs.
5981 *
Michele Berionne482f8202018-11-27 18:57:59 -08005982 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07005983 */
5984 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08005985 @TelephonyManager.SetCarrierRestrictionResult
5986 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07005987 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005989
Michele Berionne482f8202018-11-27 18:57:59 -08005990 if (carrierRestrictionRules == null) {
5991 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08005992 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07005993
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005994 final long identity = Binder.clearCallingIdentity();
5995 try {
Michele Berionne482f8202018-11-27 18:57:59 -08005996 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07005997 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 } finally {
5999 Binder.restoreCallingIdentity(identity);
6000 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006001 }
6002
6003 /**
6004 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006005 * Get the allowed carrier list and the excluded carrier list, including the priority between
6006 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006007 * Require system privileges. In the future we may add this to carrier APIs.
6008 *
Michele Berionne482f8202018-11-27 18:57:59 -08006009 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006010 */
6011 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006012 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006013 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006014 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015
6016 final long identity = Binder.clearCallingIdentity();
6017 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006018 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6019 if (response instanceof CarrierRestrictionRules) {
6020 return (CarrierRestrictionRules) response;
6021 }
6022 // Response is an Exception of some kind,
6023 // which is signalled to the user as a NULL retval
6024 return null;
6025 } catch (Exception e) {
6026 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6027 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006031 }
6032
fionaxu59545b42016-05-25 15:53:37 -07006033 /**
6034 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6035 * @param subId the subscription ID that this action applies to.
6036 * @param enabled control enable or disable metered apns.
6037 * {@hide}
6038 */
6039 @Override
6040 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6041 enforceModifyPermission();
6042 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043
6044 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006045 if (phone == null) {
6046 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6047 return;
6048 }
6049 try {
6050 phone.carrierActionSetMeteredApnsEnabled(enabled);
6051 } catch (Exception e) {
6052 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 } finally {
6054 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006055 }
6056 }
6057
6058 /**
6059 * Action set from carrier signalling broadcast receivers to enable/disable radio
6060 * @param subId the subscription ID that this action applies to.
6061 * @param enabled control enable or disable radio.
6062 * {@hide}
6063 */
6064 @Override
6065 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6066 enforceModifyPermission();
6067 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006068
6069 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006070 if (phone == null) {
6071 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6072 return;
6073 }
6074 try {
6075 phone.carrierActionSetRadioEnabled(enabled);
6076 } catch (Exception e) {
6077 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 } finally {
6079 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006080 }
6081 }
6082
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006083 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006084 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6085 * network status based on which carrier apps could apply actions accordingly,
6086 * enable/disable default url handler for example.
6087 *
6088 * @param subId the subscription ID that this action applies to.
6089 * @param report control start/stop reporting the default network status.
6090 * {@hide}
6091 */
6092 @Override
6093 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6094 enforceModifyPermission();
6095 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096
6097 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006098 if (phone == null) {
6099 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6100 return;
6101 }
6102 try {
6103 phone.carrierActionReportDefaultNetworkStatus(report);
6104 } catch (Exception e) {
6105 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 } finally {
6107 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006108 }
6109 }
6110
6111 /**
fionaxud9622282017-07-17 17:51:30 -07006112 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6113 * @param subId the subscription ID that this action applies to.
6114 * {@hide}
6115 */
6116 @Override
6117 public void carrierActionResetAll(int subId) {
6118 enforceModifyPermission();
6119 final Phone phone = getPhone(subId);
6120 if (phone == null) {
6121 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6122 return;
6123 }
6124 try {
6125 phone.carrierActionResetAll();
6126 } catch (Exception e) {
6127 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6128 }
6129 }
6130
6131 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006132 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6133 * bug report is being generated.
6134 */
6135 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006136 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006137 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6138 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006139 writer.println("Permission Denial: can't dump Phone from pid="
6140 + Binder.getCallingPid()
6141 + ", uid=" + Binder.getCallingUid()
6142 + "without permission "
6143 + android.Manifest.permission.DUMP);
6144 return;
6145 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006146 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006147 }
Jack Yueb89b242016-06-22 13:27:47 -07006148
Brad Ebingerdac2f002018-04-03 15:17:52 -07006149 @Override
6150 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6151 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6152 throws RemoteException {
6153 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6154 }
6155
Jack Yueb89b242016-06-22 13:27:47 -07006156 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006157 * Get aggregated video call data usage since boot.
6158 *
6159 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6160 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006161 * {@hide}
6162 */
6163 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006164 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006165 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6166 null);
6167
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 final long identity = Binder.clearCallingIdentity();
6169 try {
6170 // NetworkStatsService keeps tracking the active network interface and identity. It
6171 // records the delta with the corresponding network identity.
6172 // We just return the total video call data usage snapshot since boot.
6173 Phone phone = getPhone(subId);
6174 if (phone != null) {
6175 return phone.getVtDataUsage(perUidStats);
6176 }
6177 return null;
6178 } finally {
6179 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006180 }
Jack Yueb89b242016-06-22 13:27:47 -07006181 }
Jack Yu75ab2952016-07-08 14:29:33 -07006182
6183 /**
6184 * Policy control of data connection. Usually used when data limit is passed.
6185 * @param enabled True if enabling the data, otherwise disabling.
6186 * @param subId Subscription index
6187 * {@hide}
6188 */
6189 @Override
6190 public void setPolicyDataEnabled(boolean enabled, int subId) {
6191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192
6193 final long identity = Binder.clearCallingIdentity();
6194 try {
6195 Phone phone = getPhone(subId);
6196 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006197 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006198 }
6199 } finally {
6200 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006201 }
6202 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006203
6204 /**
6205 * Get Client request stats
6206 * @return List of Client Request Stats
6207 * @hide
6208 */
6209 @Override
6210 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006211 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006212 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006213 return null;
6214 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006215 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006217 final long identity = Binder.clearCallingIdentity();
6218 try {
6219 if (phone != null) {
6220 return phone.getClientRequestStats();
6221 }
6222
6223 return null;
6224 } finally {
6225 Binder.restoreCallingIdentity(identity);
6226 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006227 }
6228
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006229 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006230 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006231 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006232 }
Jack Yueb4124c2017-02-16 15:32:43 -08006233
6234 /**
Grace Chen70990072017-03-24 17:21:30 -07006235 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006236 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006237 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006238 * @param state State of SIM (power down, power up, pass through)
6239 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6240 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6241 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006242 *
6243 **/
6244 @Override
Grace Chen70990072017-03-24 17:21:30 -07006245 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006246 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006247 Phone phone = PhoneFactory.getPhone(slotIndex);
6248
vagdeviaf9a5b92018-08-15 16:01:53 -07006249 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006251 final long identity = Binder.clearCallingIdentity();
6252 try {
6253 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006254 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255 }
6256 } finally {
6257 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006258 }
6259 }
Shuo Qiandd210312017-04-12 22:11:33 +00006260
Tyler Gunn65d45c22017-06-05 11:22:26 -07006261 private boolean isUssdApiAllowed(int subId) {
6262 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006263 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006264 if (configManager == null) {
6265 return false;
6266 }
6267 PersistableBundle pb = configManager.getConfigForSubId(subId);
6268 if (pb == null) {
6269 return false;
6270 }
6271 return pb.getBoolean(
6272 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6273 }
6274
Shuo Qiandd210312017-04-12 22:11:33 +00006275 /**
6276 * Check if phone is in emergency callback mode
6277 * @return true if phone is in emergency callback mode
6278 * @param subId sub id
6279 */
goneil9c5f4872017-12-05 14:07:56 -08006280 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006281 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006282 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 if (phone != null) {
6288 return phone.isInEcm();
6289 } else {
6290 return false;
6291 }
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006294 }
6295 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006296
6297 /**
6298 * Get the current signal strength information for the given subscription.
6299 * Because this information is not updated when the device is in a low power state
6300 * it should not be relied-upon to be current.
6301 * @param subId Subscription index
6302 * @return the most recent cached signal strength info from the modem
6303 */
6304 @Override
6305 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 final long identity = Binder.clearCallingIdentity();
6307 try {
6308 Phone p = getPhone(subId);
6309 if (p == null) {
6310 return null;
6311 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006313 return p.getSignalStrength();
6314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006317 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006318
Pengquan Meng77b7f132018-08-22 14:49:57 -07006319 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006320 * Get the current modem radio state for the given slot.
6321 * @param slotIndex slot index.
6322 * @param callingPackage the name of the package making the call.
6323 * @return the current radio power state from the modem
6324 */
6325 @Override
6326 public int getRadioPowerState(int slotIndex, String callingPackage) {
6327 Phone phone = PhoneFactory.getPhone(slotIndex);
6328 if (phone != null) {
6329 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6330 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6331 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6332 }
6333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 return phone.getRadioPowerState();
6337 } finally {
6338 Binder.restoreCallingIdentity(identity);
6339 }
6340 }
6341 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6342 }
6343
6344 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006345 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6346 *
6347 * <p>Requires one of the following permissions:
6348 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6349 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6350 * privileges.
6351 *
6352 * @param subId subscription id
6353 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6354 * {@code false}.
6355 */
6356 @Override
6357 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006358 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6359 null /* message */);
6360
Pengquan Menga1bb6272018-09-06 09:59:22 -07006361 boolean isEnabled = false;
6362 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006363 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006364 Phone phone = getPhone(subId);
6365 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006366 } catch (Exception e) {
6367 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6368 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006369 } finally {
6370 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006371 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006372 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006373 }
6374
6375
6376 /**
6377 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6378 *
6379 * <p> Requires permission:
6380 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6381 * privileges.
6382 *
6383 * @param subId subscription id
6384 * @param isEnabled {@code true} means enable, {@code false} means disable.
6385 */
6386 @Override
6387 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6389 mApp, subId, "setDataRoamingEnabled");
6390
Pengquan Menga1bb6272018-09-06 09:59:22 -07006391 final long identity = Binder.clearCallingIdentity();
6392 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006393 Phone phone = getPhone(subId);
6394 if (phone != null) {
6395 phone.setDataRoamingEnabled(isEnabled);
6396 }
6397 } finally {
6398 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006399 }
6400 }
6401
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006402 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006403 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006404 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6405 mApp, subId, "isManualNetworkSelectionAllowed");
6406
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006407 boolean isAllowed = true;
6408 final long identity = Binder.clearCallingIdentity();
6409 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006410 Phone phone = getPhone(subId);
6411 if (phone != null) {
6412 isAllowed = phone.isCspPlmnEnabled();
6413 }
6414 } finally {
6415 Binder.restoreCallingIdentity(identity);
6416 }
6417 return isAllowed;
6418 }
6419
6420 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006421 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006422 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006423 try {
6424 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006425 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006426 } catch (SecurityException e) {
6427 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6428 // has carrier privileges on an active UICC
6429 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6430 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006431 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006432 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006433 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006434
6435 final long identity = Binder.clearCallingIdentity();
6436 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006437 UiccController uiccController = UiccController.getInstance();
6438 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006439 if (hasReadPermission) {
6440 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006441 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006442
6443 // Remove private info if the caller doesn't have access
6444 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6445 for (UiccCardInfo cardInfo : cardInfos) {
6446 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6447 // is available
6448 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6449 if (card == null || card.getUiccProfile() == null) {
6450 // assume no access if the card or profile is unavailable
6451 filteredInfos.add(cardInfo.getUnprivileged());
6452 continue;
6453 }
6454 UiccProfile profile = card.getUiccProfile();
6455 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6456 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6457 filteredInfos.add(cardInfo);
6458 } else {
6459 filteredInfos.add(cardInfo.getUnprivileged());
6460 }
6461 }
6462 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006463 } finally {
6464 Binder.restoreCallingIdentity(identity);
6465 }
6466 }
6467
6468 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006469 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006470 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
6474 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6475 if (slots == null) {
6476 Rlog.i(LOG_TAG, "slots is null.");
6477 return null;
6478 }
6479
6480 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6481 for (int i = 0; i < slots.length; i++) {
6482 UiccSlot slot = slots[i];
6483 if (slot == null) {
6484 continue;
6485 }
6486
Jordan Liu7be7e652019-05-06 18:55:02 +00006487 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006488 UiccCard card = slot.getUiccCard();
6489 if (card != null) {
6490 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006491 } else {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 cardId = slot.getIccId();
6493 }
6494
Jordan Liu857451f2019-05-09 16:35:35 -07006495 if (cardId != null) {
6496 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6497 // if cardId is an EID, it's all digits so this is fine
6498 cardId = IccUtils.stripTrailingFs(cardId);
6499 }
6500
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 int cardState = 0;
6502 switch (slot.getCardState()) {
6503 case CARDSTATE_ABSENT:
6504 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6505 break;
6506 case CARDSTATE_PRESENT:
6507 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6508 break;
6509 case CARDSTATE_ERROR:
6510 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6511 break;
6512 case CARDSTATE_RESTRICTED:
6513 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6514 break;
6515 default:
6516 break;
6517
6518 }
6519
6520 infos[i] = new UiccSlotInfo(
6521 slot.isActive(),
6522 slot.isEuicc(),
6523 cardId,
6524 cardState,
6525 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006526 slot.isExtendedApduSupported(),
6527 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 }
6529 return infos;
6530 } finally {
6531 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006532 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006533 }
6534
6535 @Override
6536 public boolean switchSlots(int[] physicalSlots) {
6537 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538
6539 final long identity = Binder.clearCallingIdentity();
6540 try {
6541 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6542 } finally {
6543 Binder.restoreCallingIdentity(identity);
6544 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006545 }
Jack Yu4c988042018-02-27 15:30:01 -08006546
6547 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006548 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006549 final long identity = Binder.clearCallingIdentity();
6550 try {
6551 return UiccController.getInstance().getCardIdForDefaultEuicc();
6552 } finally {
6553 Binder.restoreCallingIdentity(identity);
6554 }
6555 }
6556
6557 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006558 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6559 enforceModifyPermission();
6560 final Phone phone = getPhone(subId);
6561 if (phone == null) {
6562 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6563 return;
6564 }
6565
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006566 final long identity = Binder.clearCallingIdentity();
6567 try {
6568 phone.setRadioIndicationUpdateMode(filters, mode);
6569 } finally {
6570 Binder.restoreCallingIdentity(identity);
6571 }
Jack Yu4c988042018-02-27 15:30:01 -08006572 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006573
6574 /**
goneil47ffb6e2018-04-06 15:40:58 -07006575 * A test API to reload the UICC profile.
6576 *
6577 * <p>Requires that the calling app has permission
6578 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6579 * @hide
6580 */
6581 @Override
6582 public void refreshUiccProfile(int subId) {
6583 enforceModifyPermission();
6584
6585 final long identity = Binder.clearCallingIdentity();
6586 try {
6587 Phone phone = getPhone(subId);
6588 if (phone == null) {
6589 return;
6590 }
6591 UiccCard uiccCard = phone.getUiccCard();
6592 if (uiccCard == null) {
6593 return;
6594 }
6595 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6596 if (uiccProfile == null) {
6597 return;
6598 }
6599 uiccProfile.refresh();
6600 } finally {
6601 Binder.restoreCallingIdentity(identity);
6602 }
6603 }
6604
6605 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006606 * Returns false if the mobile data is disabled by default, otherwise return true.
6607 */
6608 private boolean getDefaultDataEnabled() {
6609 return "true".equalsIgnoreCase(
6610 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6611 }
6612
6613 /**
6614 * Returns true if the data roaming is enabled by default, i.e the system property
6615 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6616 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6617 */
6618 private boolean getDefaultDataRoamingEnabled(int subId) {
6619 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006620 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006621 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6622 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6623 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6624 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6625 return isDataRoamingEnabled;
6626 }
6627
6628 /**
6629 * Returns the default network type for the given {@code subId}, if the default network type is
6630 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6631 */
6632 private int getDefaultNetworkType(int subId) {
6633 return Integer.parseInt(
6634 TelephonyManager.getTelephonyProperty(
6635 mSubscriptionController.getPhoneId(subId),
6636 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6637 String.valueOf(Phone.PREFERRED_NT_MODE)));
6638 }
fionaxua13278b2018-03-21 00:08:13 -07006639
6640 @Override
6641 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006642 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644
6645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 final Phone phone = getPhone(subId);
6648 if (phone == null) {
6649 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6650 return;
6651 }
chen xueaba88a2019-03-15 13:15:10 -07006652 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6653 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 } finally {
6655 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006656 }
fionaxua13278b2018-03-21 00:08:13 -07006657 }
6658
6659 @Override
6660 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006661 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662
6663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 final Phone phone = getPhone(subId);
6666 if (phone == null) {
6667 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6668 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6669 }
6670 return phone.getCarrierIdListVersion();
6671 } finally {
6672 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006673 }
fionaxua13278b2018-03-21 00:08:13 -07006674 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006675
6676 @Override
6677 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
6678 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6679 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
6680 return -1;
6681 }
6682
6683 final long identity = Binder.clearCallingIdentity();
6684 try {
6685 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
6686 } finally {
6687 Binder.restoreCallingIdentity(identity);
6688 }
6689 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006690
6691 @Override
6692 public int getCdmaRoamingMode(int subId) {
6693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6694 mApp, subId, "getCdmaRoamingMode");
6695
6696 final long identity = Binder.clearCallingIdentity();
6697 try {
6698 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
6699 } finally {
6700 Binder.restoreCallingIdentity(identity);
6701 }
6702 }
6703
6704 @Override
6705 public boolean setCdmaRoamingMode(int subId, int mode) {
6706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6707 mApp, subId, "setCdmaRoamingMode");
6708
6709 final long identity = Binder.clearCallingIdentity();
6710 try {
6711 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
6712 } finally {
6713 Binder.restoreCallingIdentity(identity);
6714 }
6715 }
6716
6717 @Override
6718 public boolean setCdmaSubscriptionMode(int subId, int mode) {
6719 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6720 mApp, subId, "setCdmaSubscriptionMode");
6721
6722 final long identity = Binder.clearCallingIdentity();
6723 try {
6724 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
6728 }
Makoto Onukida3bf792018-09-18 16:06:29 -07006729
6730 private void ensureUserRunning(int userId) {
6731 if (!mUserManager.isUserRunning(userId)) {
6732 throw new IllegalStateException("User " + userId + " does not exist or not running");
6733 }
6734 }
6735
6736 /**
6737 * Returns a list of SMS apps on a given user.
6738 *
6739 * Only the shell user (UID 2000 or 0) can call it.
6740 * Target user must be running.
6741 */
6742 @Override
6743 public String[] getSmsApps(int userId) {
6744 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getSmsApps");
6745 ensureUserRunning(userId);
6746
6747 final Collection<SmsApplicationData> apps =
6748 SmsApplication.getApplicationCollectionAsUser(mApp, userId);
6749
6750 String[] ret = new String[apps.size()];
6751 int i = 0;
6752 for (SmsApplicationData app : apps) {
6753 ret[i++] = app.mPackageName;
6754 }
6755 return ret;
6756 }
6757
6758 /**
6759 * Returns the default SMS app package name on a given user.
6760 *
6761 * Only the shell user (UID 2000 or 0) can call it.
6762 * Target user must be running.
6763 */
6764 @Override
6765 public String getDefaultSmsApp(int userId) {
6766 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDefaultSmsApp");
6767 ensureUserRunning(userId);
6768
6769 final ComponentName cn = SmsApplication.getDefaultSmsApplicationAsUser(mApp,
6770 /* updateIfNeeded= */ true, userId);
6771 return cn == null ? null : cn.getPackageName();
6772 }
6773
6774 /**
6775 * Set a package as the default SMS app on a given user.
6776 *
6777 * Only the shell user (UID 2000 or 0) can call it.
6778 * Target user must be running.
6779 */
6780 @Override
6781 public void setDefaultSmsApp(int userId, String packageName) {
6782 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDefaultSmsApp");
6783 ensureUserRunning(userId);
6784
6785 boolean found = false;
6786 for (String pkg : getSmsApps(userId)) {
6787 if (TextUtils.equals(packageName, pkg)) {
6788 found = true;
6789 break;
6790 }
6791 }
6792 if (!found) {
6793 throw new IllegalArgumentException("Package " + packageName + " is not an SMS app");
6794 }
6795
6796 SmsApplication.setDefaultApplicationAsUser(packageName, mApp, userId);
6797 }
sqianc5eccab2018-10-19 18:46:41 -07006798
6799 @Override
sqian8c685422019-02-22 15:55:18 -08006800 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07006801 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08006802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08006803 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08006804 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6805 }
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
sqian854d44b2018-12-12 16:48:18 -08006808 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
6809 for (Phone phone: PhoneFactory.getPhones()) {
6810 if (phone.getEmergencyNumberTracker() != null
6811 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
6812 emergencyNumberListInternal.put(
6813 phone.getSubId(),
6814 phone.getEmergencyNumberTracker().getEmergencyNumberList());
6815 }
sqian11b7a0e2018-12-05 18:48:28 -08006816 }
sqian854d44b2018-12-12 16:48:18 -08006817 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08006818 } finally {
6819 Binder.restoreCallingIdentity(identity);
6820 }
sqianc5eccab2018-10-19 18:46:41 -07006821 }
6822
6823 @Override
sqian8c685422019-02-22 15:55:18 -08006824 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08006826 if (!exactMatch) {
6827 TelephonyPermissions
6828 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08006829 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08006830 }
6831 final long identity = Binder.clearCallingIdentity();
6832 try {
sqian854d44b2018-12-12 16:48:18 -08006833 for (Phone phone: PhoneFactory.getPhones()) {
6834 if (phone.getEmergencyNumberTracker() != null
6835 && phone.getEmergencyNumberTracker() != null) {
6836 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
6837 number, exactMatch)) {
6838 return true;
sqian11b7a0e2018-12-05 18:48:28 -08006839 }
6840 }
sqian11b7a0e2018-12-05 18:48:28 -08006841 }
6842 return false;
6843 } finally {
6844 Binder.restoreCallingIdentity(identity);
6845 }
6846 }
6847
sqianf4ca7ed2019-01-15 18:32:07 -08006848 /**
6849 * Update emergency number list for test mode.
6850 */
6851 @Override
6852 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
6853 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6854 "updateEmergencyNumberListTestMode");
6855
6856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 for (Phone phone: PhoneFactory.getPhones()) {
6859 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6860 if (tracker != null) {
6861 tracker.executeEmergencyNumberTestModeCommand(action, num);
6862 }
6863 }
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
6867 }
6868
6869 /**
6870 * Get the full emergency number list for test mode.
6871 */
6872 @Override
6873 public List<String> getEmergencyNumberListTestMode() {
6874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
6875 "getEmergencyNumberListTestMode");
6876
6877 final long identity = Binder.clearCallingIdentity();
6878 try {
6879 Set<String> emergencyNumbers = new HashSet<>();
6880 for (Phone phone: PhoneFactory.getPhones()) {
6881 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
6882 if (tracker != null) {
6883 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
6884 emergencyNumbers.add(num.getNumber());
6885 }
6886 }
6887 }
6888 return new ArrayList<>(emergencyNumbers);
6889 } finally {
6890 Binder.restoreCallingIdentity(identity);
6891 }
6892 }
6893
chen xud6b45bd2018-10-30 22:27:10 -07006894 @Override
6895 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
6896 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
6897 Phone phone = getPhone(subId);
6898 if (phone == null) {
6899 return null;
6900 }
6901 final long identity = Binder.clearCallingIdentity();
6902 try {
6903 UiccProfile profile = UiccController.getInstance()
6904 .getUiccProfileForPhone(phone.getPhoneId());
6905 if (profile != null) {
6906 return profile.getCertsFromCarrierPrivilegeAccessRules();
6907 }
6908 } finally {
6909 Binder.restoreCallingIdentity(identity);
6910 }
6911 return null;
6912 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08006913
6914 /**
6915 * Enable or disable a modem stack.
6916 */
6917 @Override
6918 public boolean enableModemForSlot(int slotIndex, boolean enable) {
6919 enforceModifyPermission();
6920
6921 final long identity = Binder.clearCallingIdentity();
6922 try {
6923 Phone phone = PhoneFactory.getPhone(slotIndex);
6924 if (phone == null) {
6925 return false;
6926 } else {
6927 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
6928 }
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
6931 }
6932 }
Michelecea4cf22018-12-21 15:00:11 -08006933
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006934 /**
6935 * Whether a modem stack is enabled or not.
6936 */
6937 @Override
6938 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
6939 Phone phone = PhoneFactory.getPhone(slotIndex);
6940 if (phone == null) return false;
6941
6942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6943 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
6944 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6945 }
6946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07006949 try {
6950 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
6951 } catch (NoSuchElementException ex) {
6952 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
6953 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07006954 } finally {
6955 Binder.restoreCallingIdentity(identity);
6956 }
6957 }
6958
Michelecea4cf22018-12-21 15:00:11 -08006959 @Override
Michele0ea7d782019-03-19 14:58:42 -07006960 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08006961 enforceModifyPermission();
6962
6963 final long identity = Binder.clearCallingIdentity();
6964 try {
6965 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07006966 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08006967 .commit();
6968 } finally {
6969 Binder.restoreCallingIdentity(identity);
6970 }
6971 }
6972
6973 @Override
Michele0ea7d782019-03-19 14:58:42 -07006974 @TelephonyManager.IsMultiSimSupportedResult
6975 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08006976 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07006977 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
6978 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08006979 }
Michelecea4cf22018-12-21 15:00:11 -08006980
6981 final long identity = Binder.clearCallingIdentity();
6982 try {
Michele0ea7d782019-03-19 14:58:42 -07006983 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08006984 } finally {
6985 Binder.restoreCallingIdentity(identity);
6986 }
6987 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08006988
Michele0ea7d782019-03-19 14:58:42 -07006989 @TelephonyManager.IsMultiSimSupportedResult
6990 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08006991 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
6992 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
6993 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07006994 loge("isMultiSimSupportedInternal: requires at least 2 cards");
6995 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08006996 }
6997 // Check if the hardware supports multisim functionality. If usage of multisim is not
6998 // supported by the modem, indicate that it is restricted.
6999 PhoneCapability staticCapability =
7000 mPhoneConfigurationManager.getStaticPhoneCapability();
7001 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007002 loge("isMultiSimSupportedInternal: no static configuration available");
7003 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007004 }
7005 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007006 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7007 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007008 }
7009 // Check if support of multiple SIMs is restricted by carrier
7010 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007011 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007012 }
7013
Michele0ea7d782019-03-19 14:58:42 -07007014 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007015 }
7016
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007017 /**
7018 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007019 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7020 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7021 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007022 * @param numOfSims number of active sims we want to switch to
7023 */
7024 @Override
7025 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007026 if (numOfSims == 1) {
7027 enforceModifyPermission();
7028 } else {
7029 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7030 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7031 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007032 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007033
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007034 try {
Michele30b57b22019-03-01 12:01:14 -08007035 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007036 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007037 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7038 return;
7039 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007040 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
7044 }
7045
7046 /**
chen xub4baa772019-04-03 10:23:41 -07007047 * Get whether making changes to modem configurations will trigger reboot.
7048 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007049 */
7050 @Override
chen xub4baa772019-04-03 10:23:41 -07007051 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7053 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7054 return false;
7055 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007056 final long identity = Binder.clearCallingIdentity();
7057 try {
7058 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
7062 }
7063
Nathan Harold29f5f052019-02-15 13:41:57 -08007064 private void updateModemStateMetrics() {
7065 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7066 // TODO: check the state for each modem if the api is ready.
7067 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7068 }
7069
Pengquan Meng3889a572019-01-23 11:16:29 -08007070 @Override
7071 public int[] getSlotsMapping() {
7072 enforceReadPrivilegedPermission("getSlotsMapping");
7073
7074 final long identity = Binder.clearCallingIdentity();
7075 try {
7076 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7077 // All logical slots should have a mapping to a physical slot.
7078 int[] logicalSlotsMapping = new int[phoneCount];
7079 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7080 for (int i = 0; i < slotInfos.length; i++) {
7081 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7082 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7083 }
7084 }
7085 return logicalSlotsMapping;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
7089 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007090
7091 /**
7092 * Get the IRadio HAL Version
7093 */
7094 @Override
7095 public int getRadioHalVersion() {
7096 Phone phone = getDefaultPhone();
7097 if (phone == null) return -1;
7098 HalVersion hv = phone.getHalVersion();
7099 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7100 return hv.major * 100 + hv.minor;
7101 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007102
7103 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007104 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7105 * corresponding network requests on a subId.
7106 *
7107 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007108 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007109 * 2) APN is un-metered for this subscription, or
7110 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7111 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7112 *
7113 * @return whether data is allowed for a apn type.
7114 *
7115 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007116 */
7117 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007118 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007119 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Malcolm Chene5ad5792019-04-18 13:51:02 -07007120 mApp, subId, callingPackage, "isDataEnabledForApn")) {
7121 throw new SecurityException("Needs READ_PHONE_STATE for isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007122 }
7123
7124 // Now that all security checks passes, perform the operation as ourselves.
7125 final long identity = Binder.clearCallingIdentity();
7126 try {
7127 Phone phone = getPhone(subId);
7128 if (phone == null) return false;
7129
Jack Yu41407ee2019-05-13 16:54:09 -07007130 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007131 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
7135 }
7136
7137 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007138 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007139 enforceReadPrivilegedPermission("isApnMetered");
7140
7141 // Now that all security checks passes, perform the operation as ourselves.
7142 final long identity = Binder.clearCallingIdentity();
7143 try {
7144 Phone phone = getPhone(subId);
7145 if (phone == null) return true; // By default return true.
7146
Jack Yu41407ee2019-05-13 16:54:09 -07007147 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007148 } finally {
7149 Binder.restoreCallingIdentity(identity);
7150 }
7151 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007152
7153 @Override
7154 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7155 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7156 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7157 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7158 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7159 }
7160 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7161 Intent intent = new Intent();
7162 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7163 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7164 // Bring up choose default SMS subscription dialog right now
7165 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7166 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7167 mApp.startActivity(intent);
7168 }
chen xud5ca2d52019-05-28 15:20:57 -07007169
7170 @Override
7171 public String getMmsUAProfUrl(int subId) {
7172 //TODO investigate if this API should require proper permission check in R b/133791609
7173 final long identity = Binder.clearCallingIdentity();
7174 try {
7175 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7176 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
7179 }
7180 }
7181
7182 @Override
7183 public String getMmsUserAgent(int subId) {
7184 //TODO investigate if this API should require proper permission check in R b/133791609
7185 final long identity = Binder.clearCallingIdentity();
7186 try {
7187 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7188 .getString(com.android.internal.R.string.config_mms_user_agent);
7189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
7192 }
Jack Yub07d4972019-05-28 16:12:25 -07007193
7194 @Override
7195 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7196 enforceModifyPermission();
7197
7198 // Now that all security checks passes, perform the operation as ourselves.
7199 final long identity = Binder.clearCallingIdentity();
7200 try {
7201 Phone phone = getPhone(subId);
7202 if (phone == null) return false;
7203
7204 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
7207 }
7208 }
7209
7210 @Override
7211 public boolean isDataAllowedInVoiceCall(int subId) {
7212 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7213
7214 // Now that all security checks passes, perform the operation as ourselves.
7215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 Phone phone = getPhone(subId);
7218 if (phone == null) return false;
7219
7220 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7221 } finally {
7222 Binder.restoreCallingIdentity(identity);
7223 }
7224 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007225}