blob: b122743565219a6116e652fd7433e4106a85b18d [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
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Tyler Gunnf70ed162019-04-03 15:28:53 -070025import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070026import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080027import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070028import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070029import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030import android.content.Context;
31import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070032import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070033import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Jack Yu84291ec2017-05-26 16:07:50 -070037import android.net.NetworkStats;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Brad Ebinger5f64b052017-12-14 14:26:15 -080050import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070051import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070052import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070054import android.os.ShellCallback;
Pengquan Meng85728fb2018-03-12 16:31:21 -070055import android.os.SystemProperties;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070066import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080067import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070068import android.telephony.CellIdentity;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070069import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070070import android.telephony.CellInfoGsm;
71import android.telephony.CellInfoWcdma;
Nathan Harold3ff88932018-08-14 10:19:49 -070072import android.telephony.CellLocation;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070073import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070074import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070075import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080076import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070077import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080078import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070079import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080080import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080081import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070082import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080083import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070084import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070085import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080086import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080087import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080088import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070089import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070090import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080092import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000093import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070094import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.VisualVoicemailSmsFilterSettings;
Nathan Harold3ff88932018-08-14 10:19:49 -070096import android.telephony.cdma.CdmaCellLocation;
Jack Yub5d8f642018-11-26 11:20:48 -080097import android.telephony.data.ApnSetting;
98import android.telephony.emergency.EmergencyNumber;
Nathan Harold3ff88932018-08-14 10:19:49 -070099import android.telephony.gsm.GsmCellLocation;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700100import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800101import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700102import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700103import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800104import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700105import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsMmTelFeature;
107import android.telephony.ims.aidl.IImsRcsFeature;
108import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700109import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700110import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.feature.MmTelFeature;
112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800117import android.util.Pair;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.Slog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700122import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700123import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700124import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800125import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700126import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CommandException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800129import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700130import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800131import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800133import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700134import com.android.internal.telephony.LocaleTracker;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100135import com.android.internal.telephony.MccTable;
yinxub1bed742017-04-17 11:45:04 -0700136import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700137import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700139import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800140import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700141import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700142import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700143import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700144import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700145import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700146import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700147import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800149import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800150import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700151import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800152import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700153import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800154import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700155import com.android.internal.telephony.imsphone.ImsPhone;
156import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800157import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700158import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700159import com.android.internal.telephony.uicc.IccIoResult;
160import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800161import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700162import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800163import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800165import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000166import com.android.internal.telephony.uicc.UiccSlot;
fionaxu7ed723d2017-05-30 18:58:54 -0700167import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800168import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700169import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700170import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800171import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700172import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700173import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800174
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700175import java.io.FileDescriptor;
176import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700177import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800178import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800179import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800180import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800181import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100182import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700184import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186
187/**
188 * Implementation of the ITelephony interface.
189 */
Santos Cordon117fee72014-05-16 17:56:12 -0700190public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191 private static final String LOG_TAG = "PhoneInterfaceManager";
192 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
193 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196 // Message codes used with mMainThreadHandler
197 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700198 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
199 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700200 private static final int CMD_OPEN_CHANNEL = 9;
201 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
202 private static final int CMD_CLOSE_CHANNEL = 11;
203 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800204 private static final int CMD_NV_READ_ITEM = 13;
205 private static final int EVENT_NV_READ_ITEM_DONE = 14;
206 private static final int CMD_NV_WRITE_ITEM = 15;
207 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
208 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
209 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700210 private static final int CMD_RESET_MODEM_CONFIG = 19;
211 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800212 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
213 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
214 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
215 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800216 private static final int CMD_SEND_ENVELOPE = 25;
217 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000218 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
219 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700220 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
221 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
222 private static final int CMD_EXCHANGE_SIM_IO = 31;
223 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800224 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
225 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700226 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
227 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700228 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
229 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700230 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
231 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
232 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
233 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700234 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
235 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
236 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
237 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700238 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800239 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
240 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000241 private static final int CMD_SWITCH_SLOTS = 50;
242 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700243 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
244 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
245 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
246 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
247 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
248 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
249 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
250 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700251 private static final int CMD_GET_ALL_CELL_INFO = 60;
252 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
253 private static final int CMD_GET_CELL_LOCATION = 62;
254 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700255 private static final int CMD_MODEM_REBOOT = 64;
256 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700257 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
258 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800259 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
260 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700261 private static final int CMD_GET_MODEM_STATUS = 70;
262 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700263 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
264 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700265
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800266 // Parameters of select command.
267 private static final int SELECT_COMMAND = 0xA4;
268 private static final int SELECT_P1 = 0x04;
269 private static final int SELECT_P2 = 0;
270 private static final int SELECT_P3 = 0x10;
271
Pengquan Meng85728fb2018-03-12 16:31:21 -0700272 private static final String DEFAULT_NETWORK_MODE_PROPERTY_NAME = "ro.telephony.default_network";
273 private static final String DEFAULT_DATA_ROAMING_PROPERTY_NAME = "ro.com.android.dataroaming";
274 private static final String DEFAULT_MOBILE_DATA_PROPERTY_NAME = "ro.com.android.mobiledata";
275
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700276 /** The singleton instance. */
277 private static PhoneInterfaceManager sInstance;
278
Wink Saville3ab207e2014-11-20 13:07:20 -0800279 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800280 private CallManager mCM;
Stuart Scott981d8582015-04-21 14:09:50 -0700281 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800282 private AppOpsManager mAppOps;
283 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800284 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800285 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700286 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700287
Derek Tan97ebb422014-09-05 16:55:38 -0700288 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
289 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800290 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800291 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700292
Michelecea4cf22018-12-21 15:00:11 -0800293 // String to store multi SIM allowed
294 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
295
Derek Tan740e1672017-06-27 14:56:27 -0700296 // The AID of ISD-R.
297 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
298
yinxub1bed742017-04-17 11:45:04 -0700299 private NetworkScanRequestTracker mNetworkScanRequestTracker;
300
David Kelly5e06a7f2018-03-12 14:10:59 +0000301 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
302 private static final int MANUFACTURER_CODE_LENGTH = 8;
303
Derek Tan89e89d42014-07-08 17:00:10 -0700304 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700305 * A request object to use for transmitting data to an ICC.
306 */
307 private static final class IccAPDUArgument {
308 public int channel, cla, command, p1, p2, p3;
309 public String data;
310
311 public IccAPDUArgument(int channel, int cla, int command,
312 int p1, int p2, int p3, String data) {
313 this.channel = channel;
314 this.cla = cla;
315 this.command = command;
316 this.p1 = p1;
317 this.p2 = p2;
318 this.p3 = p3;
319 this.data = data;
320 }
321 }
322
323 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700324 * A request object to use for transmitting data to an ICC.
325 */
326 private static final class ManualNetworkSelectionArgument {
327 public OperatorInfo operatorInfo;
328 public boolean persistSelection;
329
330 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
331 this.operatorInfo = operatorInfo;
332 this.persistSelection = persistSelection;
333 }
334 }
335
336 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700337 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
338 * request after sending. The main thread will notify the request when it is complete.
339 */
340 private static final class MainThreadRequest {
341 /** The argument to use for the request */
342 public Object argument;
343 /** The result of the request that is run on the main thread */
344 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800345 // The subscriber id that this request applies to. Defaults to
346 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
347 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700348
Nathan Harold92bed182018-10-12 18:16:49 -0700349 // In cases where subId is unavailable, the caller needs to specify the phone.
350 public Phone phone;
351
vagdeviaf9a5b92018-08-15 16:01:53 -0700352 public WorkSource workSource;
353
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700354 public MainThreadRequest(Object argument) {
355 this.argument = argument;
356 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800357
Nathan Harold92bed182018-10-12 18:16:49 -0700358 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
359 this.argument = argument;
360 if (phone != null) {
361 this.phone = phone;
362 }
363 this.workSource = workSource;
364 }
365
vagdeviaf9a5b92018-08-15 16:01:53 -0700366 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800367 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800368 if (subId != null) {
369 this.subId = subId;
370 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 }
374
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800375 private static final class IncomingThirdPartyCallArgs {
376 public final ComponentName component;
377 public final String callId;
378 public final String callerDisplayName;
379
380 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
381 String callerDisplayName) {
382 this.component = component;
383 this.callId = callId;
384 this.callerDisplayName = callerDisplayName;
385 }
386 }
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 /**
389 * A handler that processes messages on the main thread in the phone process. Since many
390 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
391 * inbound binder threads to the main thread in the phone process. The Binder thread
392 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
393 * on, which will be notified when the operation completes and will contain the result of the
394 * request.
395 *
396 * <p>If a MainThreadRequest object is provided in the msg.obj field,
397 * note that request.result must be set to something non-null for the calling thread to
398 * unblock.
399 */
400 private final class MainThreadHandler extends Handler {
401 @Override
402 public void handleMessage(Message msg) {
403 MainThreadRequest request;
404 Message onCompleted;
405 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800406 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700407 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800408 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
410 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700411 case CMD_HANDLE_USSD_REQUEST: {
412 request = (MainThreadRequest) msg.obj;
413 final Phone phone = getPhoneFromRequest(request);
414 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
415 String ussdRequest = ussdObject.first;
416 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700417
Pengquan Menga1bb6272018-09-06 09:59:22 -0700418 if (!isUssdApiAllowed(request.subId)) {
419 // Carrier does not support use of this API, return failure.
420 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
421 UssdResponse response = new UssdResponse(ussdRequest, null);
422 Bundle returnData = new Bundle();
423 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
424 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700425
Pengquan Menga1bb6272018-09-06 09:59:22 -0700426 request.result = true;
427 notifyRequester(request);
428 return;
429 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 try {
432 request.result = phone != null
433 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
434 } catch (CallStateException cse) {
435 request.result = false;
436 }
437 // Wake up the requesting thread
438 notifyRequester(request);
439 break;
pkanwar32d516d2016-10-14 19:37:38 -0700440 }
441
Yorke Lee716f67e2015-06-17 15:39:16 -0700442 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700444 final Phone phone = getPhoneFromRequest(request);
445 request.result = phone != null ?
446 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
447 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700449 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700451 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700452
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700453 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700454 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700455 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800456 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700457 if (uiccCard == null) {
458 loge("iccTransmitApduLogicalChannel: No UICC");
459 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700461 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700462 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
463 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700464 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700465 iccArgument.channel, iccArgument.cla, iccArgument.command,
466 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700467 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700469 break;
470
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700471 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 ar = (AsyncResult) msg.obj;
473 request = (MainThreadRequest) ar.userObj;
474 if (ar.exception == null && ar.result != null) {
475 request.result = ar.result;
476 } else {
477 request.result = new IccIoResult(0x6F, 0, (byte[])null);
478 if (ar.result == null) {
479 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800480 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700481 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800482 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 } else {
484 loge("iccTransmitApduLogicalChannel: Unknown exception");
485 }
486 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 break;
489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
491 request = (MainThreadRequest) msg.obj;
492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 if (uiccCard == null) {
495 loge("iccTransmitApduBasicChannel: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 } else {
499 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
500 request);
501 uiccCard.iccTransmitApduBasicChannel(
502 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
503 iccArgument.p3, iccArgument.data, onCompleted);
504 }
505 break;
506
507 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduBasicChannel: Empty response");
516 } else if (ar.exception instanceof CommandException) {
517 loge("iccTransmitApduBasicChannel: CommandException: " +
518 ar.exception);
519 } else {
520 loge("iccTransmitApduBasicChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 break;
525
526 case CMD_EXCHANGE_SIM_IO:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccExchangeSimIO: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
536 request);
537 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
538 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
539 iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_EXCHANGE_SIM_IO_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6f, 0, (byte[])null);
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
Derek Tan4d5e5c12014-02-04 11:54:58 -0800554 case CMD_SEND_ENVELOPE:
555 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800556 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700557 if (uiccCard == null) {
558 loge("sendEnvelopeWithStatus: No UICC");
559 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700561 } else {
562 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
563 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
564 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800565 break;
566
567 case EVENT_SEND_ENVELOPE_DONE:
568 ar = (AsyncResult) msg.obj;
569 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700570 if (ar.exception == null && ar.result != null) {
571 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800572 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700573 request.result = new IccIoResult(0x6F, 0, (byte[])null);
574 if (ar.result == null) {
575 loge("sendEnvelopeWithStatus: Empty response");
576 } else if (ar.exception instanceof CommandException) {
577 loge("sendEnvelopeWithStatus: CommandException: " +
578 ar.exception);
579 } else {
580 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
581 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800584 break;
585
Shishir Agrawal566b7612013-10-28 14:41:00 -0700586 case CMD_OPEN_CHANNEL:
587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800589 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 if (uiccCard == null) {
591 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800592 request.result = new IccOpenLogicalChannelResponse(-1,
593 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800597 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
598 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700599 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700600 break;
601
602 case EVENT_OPEN_CHANNEL_DONE:
603 ar = (AsyncResult) msg.obj;
604 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700605 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700606 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 int[] result = (int[]) ar.result;
608 int channelId = result[0];
609 byte[] selectResponse = null;
610 if (result.length > 1) {
611 selectResponse = new byte[result.length - 1];
612 for (int i = 1; i < result.length; ++i) {
613 selectResponse[i - 1] = (byte) result[i];
614 }
615 }
616 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700617 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700619 if (ar.result == null) {
620 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700621 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700622 if (ar.exception != null) {
623 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
624 }
625
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700626 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700627 if (ar.exception instanceof CommandException) {
628 CommandException.Error error =
629 ((CommandException) (ar.exception)).getCommandError();
630 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700632 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700633 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 }
635 }
636 openChannelResp = new IccOpenLogicalChannelResponse(
637 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700639 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700640 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 break;
642
643 case CMD_CLOSE_CHANNEL:
644 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800645 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700646 if (uiccCard == null) {
647 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900648 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700649 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700650 } else {
651 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
652 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
653 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 break;
655
656 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800657 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
658 break;
659
660 case CMD_NV_READ_ITEM:
661 request = (MainThreadRequest) msg.obj;
662 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800663 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
664 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800665 break;
666
667 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 ar = (AsyncResult) msg.obj;
669 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800670 if (ar.exception == null && ar.result != null) {
671 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800673 request.result = "";
674 if (ar.result == null) {
675 loge("nvReadItem: Empty response");
676 } else if (ar.exception instanceof CommandException) {
677 loge("nvReadItem: CommandException: " +
678 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800680 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 }
682 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 break;
685
Jake Hambye994d462014-02-03 13:10:13 -0800686 case CMD_NV_WRITE_ITEM:
687 request = (MainThreadRequest) msg.obj;
688 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
689 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800690 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700691 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800692 break;
693
694 case EVENT_NV_WRITE_ITEM_DONE:
695 handleNullReturnEvent(msg, "nvWriteItem");
696 break;
697
698 case CMD_NV_WRITE_CDMA_PRL:
699 request = (MainThreadRequest) msg.obj;
700 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800701 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_WRITE_CDMA_PRL_DONE:
705 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
706 break;
707
chen xu6dac5ab2018-10-26 17:39:23 -0700708 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800709 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700710 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800711 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800712 break;
713
chen xu6dac5ab2018-10-26 17:39:23 -0700714 case EVENT_RESET_MODEM_CONFIG_DONE:
715 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800716 break;
717
Jake Hamby7c27be32014-03-03 13:25:59 -0800718 case CMD_GET_PREFERRED_NETWORK_TYPE:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700721 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800722 break;
723
724 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
725 ar = (AsyncResult) msg.obj;
726 request = (MainThreadRequest) ar.userObj;
727 if (ar.exception == null && ar.result != null) {
728 request.result = ar.result; // Integer
729 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800730 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800731 if (ar.result == null) {
732 loge("getPreferredNetworkType: Empty response");
733 } else if (ar.exception instanceof CommandException) {
734 loge("getPreferredNetworkType: CommandException: " +
735 ar.exception);
736 } else {
737 loge("getPreferredNetworkType: Unknown exception");
738 }
739 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700740 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800741 break;
742
743 case CMD_SET_PREFERRED_NETWORK_TYPE:
744 request = (MainThreadRequest) msg.obj;
745 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
746 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700747 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800748 break;
749
750 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
751 handleNullReturnEvent(msg, "setPreferredNetworkType");
752 break;
753
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000754 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
755 request = (MainThreadRequest)msg.obj;
756 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800757 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000758 break;
759
760 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
761 ar = (AsyncResult)msg.obj;
762 request = (MainThreadRequest)ar.userObj;
763 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700764 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000765 break;
766
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800767 case CMD_SET_VOICEMAIL_NUMBER:
768 request = (MainThreadRequest) msg.obj;
769 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
770 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800771 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
772 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800773 break;
774
775 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
776 handleNullReturnEvent(msg, "setVoicemailNumber");
777 break;
778
Stuart Scott54788802015-03-30 13:18:01 -0700779 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
782 request);
783 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
784 break;
785
786 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
787 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
788 break;
789
Shishir Agrawal302c8692015-06-19 13:49:39 -0700790 case CMD_PERFORM_NETWORK_SCAN:
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
793 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
794 break;
795
796 case EVENT_PERFORM_NETWORK_SCAN_DONE:
797 ar = (AsyncResult) msg.obj;
798 request = (MainThreadRequest) ar.userObj;
799 CellNetworkScanResult cellScanResult;
800 if (ar.exception == null && ar.result != null) {
801 cellScanResult = new CellNetworkScanResult(
802 CellNetworkScanResult.STATUS_SUCCESS,
803 (List<OperatorInfo>) ar.result);
804 } else {
805 if (ar.result == null) {
806 loge("getCellNetworkScanResults: Empty response");
807 }
808 if (ar.exception != null) {
809 loge("getCellNetworkScanResults: Exception: " + ar.exception);
810 }
811 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
812 if (ar.exception instanceof CommandException) {
813 CommandException.Error error =
814 ((CommandException) (ar.exception)).getCommandError();
815 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
816 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
817 } else if (error == CommandException.Error.GENERIC_FAILURE) {
818 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
819 }
820 }
821 cellScanResult = new CellNetworkScanResult(errorCode, null);
822 }
823 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700824 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700825 break;
826
827 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
828 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700829 ManualNetworkSelectionArgument selArg =
830 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700831 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
832 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700833 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
834 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700835 break;
836
837 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700838 ar = (AsyncResult) msg.obj;
839 request = (MainThreadRequest) ar.userObj;
840 if (ar.exception == null) {
841 request.result = true;
842 } else {
843 request.result = false;
844 loge("setNetworkSelectionModeManual " + ar.exception);
845 }
846 notifyRequester(request);
847 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700848 break;
849
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700850 case CMD_GET_MODEM_ACTIVITY_INFO:
851 request = (MainThreadRequest) msg.obj;
852 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700853 if (defaultPhone != null) {
854 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
855 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700856 break;
857
858 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
859 ar = (AsyncResult) msg.obj;
860 request = (MainThreadRequest) ar.userObj;
861 if (ar.exception == null && ar.result != null) {
862 request.result = ar.result;
863 } else {
864 if (ar.result == null) {
865 loge("queryModemActivityInfo: Empty response");
866 } else if (ar.exception instanceof CommandException) {
867 loge("queryModemActivityInfo: CommandException: " +
868 ar.exception);
869 } else {
870 loge("queryModemActivityInfo: Unknown exception");
871 }
872 }
Amit Mahajand4766222016-01-28 15:28:28 -0800873 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
874 if (request.result == null) {
Chen Xud78231e2019-09-10 18:49:52 -0700875 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800876 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700877 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700878 break;
879
Meng Wang1a7c35a2016-05-05 20:56:15 -0700880 case CMD_SET_ALLOWED_CARRIERS:
881 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800882 CarrierRestrictionRules argument =
883 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700884 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800885 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700886 break;
887
888 case EVENT_SET_ALLOWED_CARRIERS_DONE:
889 ar = (AsyncResult) msg.obj;
890 request = (MainThreadRequest) ar.userObj;
891 if (ar.exception == null && ar.result != null) {
892 request.result = ar.result;
893 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800894 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
895 if (ar.exception instanceof CommandException) {
896 loge("setAllowedCarriers: CommandException: " + ar.exception);
897 CommandException.Error error =
898 ((CommandException) (ar.exception)).getCommandError();
899 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
900 request.result =
901 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
902 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700903 } else {
904 loge("setAllowedCarriers: Unknown exception");
905 }
906 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700907 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 break;
909
910 case CMD_GET_ALLOWED_CARRIERS:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800913 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700914 break;
915
916 case EVENT_GET_ALLOWED_CARRIERS_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 if (ar.exception == null && ar.result != null) {
920 request.result = ar.result;
921 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800922 request.result = new IllegalStateException(
923 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700924 if (ar.result == null) {
925 loge("getAllowedCarriers: Empty response");
926 } else if (ar.exception instanceof CommandException) {
927 loge("getAllowedCarriers: CommandException: " +
928 ar.exception);
929 } else {
930 loge("getAllowedCarriers: Unknown exception");
931 }
932 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700934 break;
935
Nathan Haroldb3014052017-01-25 15:57:32 -0800936 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
937 ar = (AsyncResult) msg.obj;
938 request = (MainThreadRequest) ar.userObj;
939 if (ar.exception == null && ar.result != null) {
940 request.result = ar.result;
941 } else {
942 request.result = new IllegalArgumentException(
943 "Failed to retrieve Forbidden Plmns");
944 if (ar.result == null) {
945 loge("getForbiddenPlmns: Empty response");
946 } else {
947 loge("getForbiddenPlmns: Unknown exception");
948 }
949 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700950 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800951 break;
952
953 case CMD_GET_FORBIDDEN_PLMNS:
954 request = (MainThreadRequest) msg.obj;
955 uiccCard = getUiccCardFromRequest(request);
956 if (uiccCard == null) {
957 loge("getForbiddenPlmns() UiccCard is null");
958 request.result = new IllegalArgumentException(
959 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700960 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800961 break;
962 }
963 Integer appType = (Integer) request.argument;
964 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
965 if (uiccApp == null) {
966 loge("getForbiddenPlmns() no app with specified type -- "
967 + appType);
968 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700969 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800970 break;
971 } else {
972 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
973 + " specified type -- " + appType);
974 }
975 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
976 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
977 onCompleted);
978 break;
979
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000980 case CMD_SWITCH_SLOTS:
981 request = (MainThreadRequest) msg.obj;
982 int[] physicalSlots = (int[]) request.argument;
983 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
984 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
985 break;
986
987 case EVENT_SWITCH_SLOTS_DONE:
988 ar = (AsyncResult) msg.obj;
989 request = (MainThreadRequest) ar.userObj;
990 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700991 notifyRequester(request);
992 break;
993 case CMD_GET_NETWORK_SELECTION_MODE:
994 request = (MainThreadRequest) msg.obj;
995 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
996 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
997 break;
998
999 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1000 ar = (AsyncResult) msg.obj;
1001 request = (MainThreadRequest) ar.userObj;
1002 if (ar.exception != null) {
1003 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1004 } else {
1005 int mode = ((int[]) ar.result)[0];
1006 if (mode == 0) {
1007 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1008 } else {
1009 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1010 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001011 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001012 notifyRequester(request);
1013 break;
1014 case CMD_GET_CDMA_ROAMING_MODE:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1017 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1018 break;
1019 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1020 ar = (AsyncResult) msg.obj;
1021 request = (MainThreadRequest) ar.userObj;
1022 if (ar.exception != null) {
1023 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1024 } else {
1025 request.result = ((int[]) ar.result)[0];
1026 }
1027 notifyRequester(request);
1028 break;
1029 case CMD_SET_CDMA_ROAMING_MODE:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1032 int mode = (int) request.argument;
1033 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1034 break;
1035 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1036 ar = (AsyncResult) msg.obj;
1037 request = (MainThreadRequest) ar.userObj;
1038 request.result = ar.exception == null;
1039 notifyRequester(request);
1040 break;
1041 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1042 request = (MainThreadRequest) msg.obj;
1043 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1044 int subscriptionMode = (int) request.argument;
1045 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1046 break;
1047 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1048 ar = (AsyncResult) msg.obj;
1049 request = (MainThreadRequest) ar.userObj;
1050 request.result = ar.exception == null;
1051 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001052 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001053 case CMD_GET_ALL_CELL_INFO:
1054 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001055 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001056 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case EVENT_GET_ALL_CELL_INFO_DONE:
1059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001061 // If a timeout occurs, the response will be null
1062 request.result = (ar.exception == null && ar.result != null)
1063 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001064 synchronized (request) {
1065 request.notifyAll();
1066 }
1067 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001068 case CMD_REQUEST_CELL_INFO_UPDATE:
1069 request = (MainThreadRequest) msg.obj;
1070 request.phone.requestCellInfoUpdate(request.workSource,
1071 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1072 break;
1073 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1074 ar = (AsyncResult) msg.obj;
1075 request = (MainThreadRequest) ar.userObj;
1076 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1077 try {
1078 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001079 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001080 cb.onError(
1081 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1082 ar.exception.getClass().getName(),
1083 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001085 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001086 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001087 } else {
1088 // use the result as returned
1089 cb.onCellInfo((List<CellInfo>) ar.result);
1090 }
1091 } catch (RemoteException re) {
1092 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1093 }
1094 break;
1095 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001096 request = (MainThreadRequest) msg.obj;
1097 WorkSource ws = (WorkSource) request.argument;
1098 Phone phone = getPhoneFromRequest(request);
1099 phone.getCellLocation(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
1100 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001101 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001102 ar = (AsyncResult) msg.obj;
1103 request = (MainThreadRequest) ar.userObj;
1104 if (ar.exception == null) {
1105 request.result = ar.result;
1106 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001107 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001108 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
1109 ? new CdmaCellLocation() : new GsmCellLocation();
1110 }
1111
1112 synchronized (request) {
1113 request.notifyAll();
1114 }
1115 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001116 case CMD_MODEM_REBOOT:
1117 request = (MainThreadRequest) msg.obj;
1118 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001119 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case EVENT_CMD_MODEM_REBOOT_DONE:
1122 handleNullReturnEvent(msg, "rebootModem");
1123 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001124 case CMD_REQUEST_ENABLE_MODEM:
1125 request = (MainThreadRequest) msg.obj;
1126 boolean enable = (boolean) request.argument;
1127 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001128 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 PhoneConfigurationManager.getInstance()
1130 .enablePhone(request.phone, enable, onCompleted);
1131 break;
1132 case EVENT_ENABLE_MODEM_DONE:
1133 ar = (AsyncResult) msg.obj;
1134 request = (MainThreadRequest) ar.userObj;
1135 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001136 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001137 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001138 if ((boolean) request.result) {
1139 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1140 updateModemStateMetrics();
1141 } else {
1142 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1143 + ar.exception);
1144 }
1145 notifyRequester(request);
1146 break;
1147 case CMD_GET_MODEM_STATUS:
1148 request = (MainThreadRequest) msg.obj;
1149 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1150 PhoneConfigurationManager.getInstance()
1151 .getPhoneStatusFromModem(request.phone, onCompleted);
1152 break;
1153 case EVENT_GET_MODEM_STATUS_DONE:
1154 ar = (AsyncResult) msg.obj;
1155 request = (MainThreadRequest) ar.userObj;
1156 int id = request.phone.getPhoneId();
1157 if (ar.exception == null && ar.result != null) {
1158 request.result = ar.result;
1159 //update the cache as modem status has changed
1160 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1161 (boolean) request.result);
1162 } else {
1163 // Return true if modem status cannot be retrieved. For most cases,
1164 // modem status is on. And for older version modems, GET_MODEM_STATUS
1165 // and disable modem are not supported. Modem is always on.
1166 // TODO: this should be fixed in R to support a third
1167 // status UNKNOWN b/131631629
1168 request.result = true;
1169 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1170 + ar.exception);
1171 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001172 notifyRequester(request);
1173 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001174 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1175 ar = (AsyncResult) msg.obj;
1176 request = (MainThreadRequest) ar.userObj;
1177 if (ar.exception == null && ar.result != null) {
1178 request.result = ar.result;
1179 } else {
1180 request.result = -1;
1181 loge("Failed to set Forbidden Plmns");
1182 if (ar.result == null) {
1183 loge("setForbidenPlmns: Empty response");
1184 } else if (ar.exception != null) {
1185 loge("setForbiddenPlmns: Exception: " + ar.exception);
1186 request.result = -1;
1187 } else {
1188 loge("setForbiddenPlmns: Unknown exception");
1189 }
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_FORBIDDEN_PLMNS:
1194 request = (MainThreadRequest) msg.obj;
1195 uiccCard = getUiccCardFromRequest(request);
1196 if (uiccCard == null) {
1197 loge("setForbiddenPlmns: UiccCard is null");
1198 request.result = -1;
1199 notifyRequester(request);
1200 break;
1201 }
1202 Pair<Integer, List<String>> setFplmnsArgs =
1203 (Pair<Integer, List<String>>) request.argument;
1204 appType = setFplmnsArgs.first;
1205 List<String> fplmns = setFplmnsArgs.second;
1206 uiccApp = uiccCard.getApplicationByType(appType);
1207 if (uiccApp == null) {
1208 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1209 request.result = -1;
1210 loge("Failed to get UICC App");
1211 notifyRequester(request);
1212 } else {
1213 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1214 ((SIMRecords) uiccApp.getIccRecords())
1215 .setForbiddenPlmns(onCompleted, fplmns);
1216 }
1217 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001218 default:
1219 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1220 break;
1221 }
1222 }
Jake Hambye994d462014-02-03 13:10:13 -08001223
Pengquan Menga1bb6272018-09-06 09:59:22 -07001224 private void notifyRequester(MainThreadRequest request) {
1225 synchronized (request) {
1226 request.notifyAll();
1227 }
1228 }
1229
Jake Hambye994d462014-02-03 13:10:13 -08001230 private void handleNullReturnEvent(Message msg, String command) {
1231 AsyncResult ar = (AsyncResult) msg.obj;
1232 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1233 if (ar.exception == null) {
1234 request.result = true;
1235 } else {
1236 request.result = false;
1237 if (ar.exception instanceof CommandException) {
1238 loge(command + ": CommandException: " + ar.exception);
1239 } else {
1240 loge(command + ": Unknown exception");
1241 }
1242 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001244 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001245 }
1246
1247 /**
1248 * Posts the specified command to be executed on the main thread,
1249 * waits for the request to complete, and returns the result.
1250 * @see #sendRequestAsync
1251 */
1252 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001253 return sendRequest(
1254 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001255 }
1256
1257 /**
1258 * Posts the specified command to be executed on the main thread,
1259 * waits for the request to complete, and returns the result.
1260 * @see #sendRequestAsync
1261 */
1262 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1263 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001264 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001265 }
1266
1267 /**
1268 * Posts the specified command to be executed on the main thread,
1269 * waits for the request to complete, and returns the result.
1270 * @see #sendRequestAsync
1271 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001272 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001273 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001274 }
1275
1276 /**
1277 * Posts the specified command to be executed on the main thread,
1278 * waits for the request to complete, and returns the result.
1279 * @see #sendRequestAsync
1280 */
Nathan Harold92bed182018-10-12 18:16:49 -07001281 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1282 return sendRequest(command, argument, subId, null, workSource);
1283 }
1284
1285 /**
1286 * Posts the specified command to be executed on the main thread,
1287 * waits for the request to complete, and returns the result.
1288 * @see #sendRequestAsync
1289 */
1290 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1291 return sendRequest(
1292 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1293 }
1294
1295 /**
1296 * Posts the specified command to be executed on the main thread,
1297 * waits for the request to complete, and returns the result.
1298 * @see #sendRequestAsync
1299 */
1300 private Object sendRequest(
1301 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001302 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1303 throw new RuntimeException("This method will deadlock if called from the main thread.");
1304 }
1305
Nathan Harold92bed182018-10-12 18:16:49 -07001306 MainThreadRequest request = null;
1307 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1308 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1309 } else if (phone != null) {
1310 request = new MainThreadRequest(argument, phone, workSource);
1311 } else {
1312 request = new MainThreadRequest(argument, subId, workSource);
1313 }
1314
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 Message msg = mMainThreadHandler.obtainMessage(command, request);
1316 msg.sendToTarget();
1317
1318 // Wait for the request to complete
1319 synchronized (request) {
1320 while (request.result == null) {
1321 try {
1322 request.wait();
1323 } catch (InterruptedException e) {
1324 // Do nothing, go back and wait until the request is complete
1325 }
1326 }
1327 }
1328 return request.result;
1329 }
1330
1331 /**
1332 * Asynchronous ("fire and forget") version of sendRequest():
1333 * Posts the specified command to be executed on the main thread, and
1334 * returns immediately.
1335 * @see #sendRequest
1336 */
1337 private void sendRequestAsync(int command) {
1338 mMainThreadHandler.sendEmptyMessage(command);
1339 }
1340
1341 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001342 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001343 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001344 */
1345 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001346 sendRequestAsync(command, argument, null, null);
1347 }
1348
1349 /**
1350 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1351 * @see {@link #sendRequest(int,Object)}
1352 */
1353 private void sendRequestAsync(
1354 int command, Object argument, Phone phone, WorkSource workSource) {
1355 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001356 Message msg = mMainThreadHandler.obtainMessage(command, request);
1357 msg.sendToTarget();
1358 }
1359
1360 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001361 * Initialize the singleton PhoneInterfaceManager instance.
1362 * This is only done once, at startup, from PhoneApp.onCreate().
1363 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001364 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001365 synchronized (PhoneInterfaceManager.class) {
1366 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001367 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001368 } else {
1369 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1370 }
1371 return sInstance;
1372 }
1373 }
1374
1375 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001376 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001377 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 mCM = PhoneGlobals.getInstance().mCM;
Stuart Scott981d8582015-04-21 14:09:50 -07001379 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001380 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1381 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001382 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001383 mTelephonySharedPreferences =
1384 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001385 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001386 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001387
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001388 publish();
1389 }
1390
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001391 private Phone getDefaultPhone() {
1392 Phone thePhone = getPhone(getDefaultSubscription());
1393 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1394 }
1395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001396 private void publish() {
1397 if (DBG) log("publish: " + this);
1398
1399 ServiceManager.addService("phone", this);
1400 }
1401
Stuart Scott584921c2015-01-15 17:10:34 -08001402 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001403 if (request.phone != null) {
1404 return request.phone;
1405 } else {
1406 return getPhoneFromSubId(request.subId);
1407 }
1408 }
1409
1410 private Phone getPhoneFromSubId(int subId) {
1411 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1412 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001413 }
1414
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001415 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1416 Phone phone = getPhoneFromRequest(request);
1417 return phone == null ? null :
1418 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1419 }
1420
Wink Saville36469e72014-06-11 15:17:00 -07001421 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001422 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001423 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001424 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001425
1426 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001427 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001428 }
1429
Wink Savilleb564aae2014-10-23 10:18:09 -07001430 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001431 if (DBG) log("dial: " + number);
1432 // No permission check needed here: This is just a wrapper around the
1433 // ACTION_DIAL intent, which is available to any app since it puts up
1434 // the UI before it does anything.
1435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001436 final long identity = Binder.clearCallingIdentity();
1437 try {
1438 String url = createTelUrl(number);
1439 if (url == null) {
1440 return;
1441 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001443 // PENDING: should we just silently fail if phone is offhook or ringing?
1444 PhoneConstants.State state = mCM.getState(subId);
1445 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1446 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1447 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1448 mApp.startActivity(intent);
1449 }
1450 } finally {
1451 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001452 }
1453 }
1454
1455 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001456 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001457 }
1458
Wink Savilleb564aae2014-10-23 10:18:09 -07001459 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001460 if (DBG) log("call: " + number);
1461
1462 // This is just a wrapper around the ACTION_CALL intent, but we still
1463 // need to do a permission check since we're calling startActivity()
1464 // from the context of the phone app.
1465 enforceCallPermission();
1466
Jordan Liu1617b712019-07-10 15:06:26 -07001467 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001468 != AppOpsManager.MODE_ALLOWED) {
1469 return;
1470 }
1471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001472 final long identity = Binder.clearCallingIdentity();
1473 try {
1474 String url = createTelUrl(number);
1475 if (url == null) {
1476 return;
1477 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001478
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001479 boolean isValid = false;
1480 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1481 if (slist != null) {
1482 for (SubscriptionInfo subInfoRecord : slist) {
1483 if (subInfoRecord.getSubscriptionId() == subId) {
1484 isValid = true;
1485 break;
1486 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001487 }
Wink Saville08874612014-08-31 19:19:58 -07001488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001489 if (!isValid) {
1490 return;
1491 }
Wink Saville08874612014-08-31 19:19:58 -07001492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001493 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1494 intent.putExtra(SUBSCRIPTION_KEY, subId);
1495 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1496 mApp.startActivity(intent);
1497 } finally {
1498 Binder.restoreCallingIdentity(identity);
1499 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001500 }
1501
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001502 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001503 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001504 }
1505
Wink Savilleb564aae2014-10-23 10:18:09 -07001506 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001507 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001508 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1509 }
1510
1511 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001512 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001513 }
1514
Wink Savilleb564aae2014-10-23 10:18:09 -07001515 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001516 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001517 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1518 }
1519
1520 /** {@hide} */
1521 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001522 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001523 }
1524
Wink Savilleb564aae2014-10-23 10:18:09 -07001525 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001526 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001527
1528 final long identity = Binder.clearCallingIdentity();
1529 try {
1530 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1531 checkSimPin.start();
1532 return checkSimPin.unlockSim(null, pin);
1533 } finally {
1534 Binder.restoreCallingIdentity(identity);
1535 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001536 }
1537
Wink Saville9de0f752013-10-22 19:04:03 -07001538 /** {@hide} */
1539 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001544 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001545
1546 final long identity = Binder.clearCallingIdentity();
1547 try {
1548 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1549 checkSimPuk.start();
1550 return checkSimPuk.unlockSim(puk, pin);
1551 } finally {
1552 Binder.restoreCallingIdentity(identity);
1553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 }
1555
1556 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001557 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001558 * a synchronous one.
1559 */
1560 private static class UnlockSim extends Thread {
1561
1562 private final IccCard mSimCard;
1563
1564 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001565 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1566 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001567
1568 // For replies from SimCard interface
1569 private Handler mHandler;
1570
1571 // For async handler to identify request type
1572 private static final int SUPPLY_PIN_COMPLETE = 100;
1573
1574 public UnlockSim(IccCard simCard) {
1575 mSimCard = simCard;
1576 }
1577
1578 @Override
1579 public void run() {
1580 Looper.prepare();
1581 synchronized (UnlockSim.this) {
1582 mHandler = new Handler() {
1583 @Override
1584 public void handleMessage(Message msg) {
1585 AsyncResult ar = (AsyncResult) msg.obj;
1586 switch (msg.what) {
1587 case SUPPLY_PIN_COMPLETE:
1588 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1589 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001590 mRetryCount = msg.arg1;
1591 if (ar.exception != null) {
1592 if (ar.exception instanceof CommandException &&
1593 ((CommandException)(ar.exception)).getCommandError()
1594 == CommandException.Error.PASSWORD_INCORRECT) {
1595 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1596 } else {
1597 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1598 }
1599 } else {
1600 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1601 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001602 mDone = true;
1603 UnlockSim.this.notifyAll();
1604 }
1605 break;
1606 }
1607 }
1608 };
1609 UnlockSim.this.notifyAll();
1610 }
1611 Looper.loop();
1612 }
1613
1614 /*
1615 * Use PIN or PUK to unlock SIM card
1616 *
1617 * If PUK is null, unlock SIM card with PIN
1618 *
1619 * If PUK is not null, unlock SIM card with PUK and set PIN code
1620 */
Wink Saville9de0f752013-10-22 19:04:03 -07001621 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001622
1623 while (mHandler == null) {
1624 try {
1625 wait();
1626 } catch (InterruptedException e) {
1627 Thread.currentThread().interrupt();
1628 }
1629 }
1630 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1631
1632 if (puk == null) {
1633 mSimCard.supplyPin(pin, callback);
1634 } else {
1635 mSimCard.supplyPuk(puk, pin, callback);
1636 }
1637
1638 while (!mDone) {
1639 try {
1640 Log.d(LOG_TAG, "wait for done");
1641 wait();
1642 } catch (InterruptedException e) {
1643 // Restore the interrupted status
1644 Thread.currentThread().interrupt();
1645 }
1646 }
1647 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001648 int[] resultArray = new int[2];
1649 resultArray[0] = mResult;
1650 resultArray[1] = mRetryCount;
1651 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001652 }
1653 }
1654
1655 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001656 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001657
1658 }
1659
Wink Savilleb564aae2014-10-23 10:18:09 -07001660 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 // No permission check needed here: this call is harmless, and it's
1662 // needed for the ServiceState.requestStateUpdate() call (which is
1663 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001664 final long identity = Binder.clearCallingIdentity();
1665 try {
1666 final Phone phone = getPhone(subId);
1667 if (phone != null) {
1668 phone.updateServiceLocation();
1669 }
1670 } finally {
1671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001672 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001673 }
1674
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001675 @Override
1676 public boolean isRadioOn(String callingPackage) {
1677 return isRadioOnForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07001678 }
1679
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001680 @Override
1681 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001682 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08001683 mApp, subId, callingPackage, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001684 return false;
1685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001686
1687 final long identity = Binder.clearCallingIdentity();
1688 try {
1689 return isRadioOnForSubscriber(subId);
1690 } finally {
1691 Binder.restoreCallingIdentity(identity);
1692 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001693 }
1694
1695 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001696 final long identity = Binder.clearCallingIdentity();
1697 try {
1698 final Phone phone = getPhone(subId);
1699 if (phone != null) {
1700 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1701 } else {
1702 return false;
1703 }
1704 } finally {
1705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707 }
1708
1709 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001710 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001711 }
Wink Saville36469e72014-06-11 15:17:00 -07001712
Wink Savilleb564aae2014-10-23 10:18:09 -07001713 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001714 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001715
1716 final long identity = Binder.clearCallingIdentity();
1717 try {
1718 final Phone phone = getPhone(subId);
1719 if (phone != null) {
1720 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1721 }
1722 } finally {
1723 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001724 }
Wink Saville36469e72014-06-11 15:17:00 -07001725 }
1726
1727 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001728 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001729 }
1730
Wink Savilleb564aae2014-10-23 10:18:09 -07001731 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001732 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001733
1734 final long identity = Binder.clearCallingIdentity();
1735 try {
1736 final Phone phone = getPhone(subId);
1737 if (phone == null) {
1738 return false;
1739 }
1740 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1741 toggleRadioOnOffForSubscriber(subId);
1742 }
1743 return true;
1744 } finally {
1745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 }
Wink Saville36469e72014-06-11 15:17:00 -07001748
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001749 public boolean needMobileRadioShutdown() {
1750 /*
1751 * If any of the Radios are available, it will need to be
1752 * shutdown. So return true if any Radio is available.
1753 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001754 final long identity = Binder.clearCallingIdentity();
1755 try {
1756 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1757 Phone phone = PhoneFactory.getPhone(i);
1758 if (phone != null && phone.isRadioAvailable()) return true;
1759 }
1760 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1761 return false;
1762 } finally {
1763 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001764 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001765 }
1766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001767 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001768 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001769 enforceModifyPermission();
1770
1771 final long identity = Binder.clearCallingIdentity();
1772 try {
1773 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1774 logv("Shutting down Phone " + i);
1775 shutdownRadioUsingPhoneId(i);
1776 }
1777 } finally {
1778 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001779 }
1780 }
1781
1782 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001783 Phone phone = PhoneFactory.getPhone(phoneId);
1784 if (phone != null && phone.isRadioAvailable()) {
1785 phone.shutdownRadio();
1786 }
1787 }
1788
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001790 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001791
1792 final long identity = Binder.clearCallingIdentity();
1793 try {
1794 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1795 if (defaultPhone != null) {
1796 defaultPhone.setRadioPower(turnOn);
1797 return true;
1798 } else {
1799 loge("There's no default phone.");
1800 return false;
1801 }
1802 } finally {
1803 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001804 }
Wink Saville36469e72014-06-11 15:17:00 -07001805 }
1806
Wink Savilleb564aae2014-10-23 10:18:09 -07001807 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001809
1810 final long identity = Binder.clearCallingIdentity();
1811 try {
1812 final Phone phone = getPhone(subId);
1813 if (phone != null) {
1814 phone.setRadioPower(turnOn);
1815 return true;
1816 } else {
1817 return false;
1818 }
1819 } finally {
1820 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
Wink Saville36469e72014-06-11 15:17:00 -07001824 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001825 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001826 public boolean enableDataConnectivity() {
1827 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001828
1829 final long identity = Binder.clearCallingIdentity();
1830 try {
1831 int subId = mSubscriptionController.getDefaultDataSubId();
1832 final Phone phone = getPhone(subId);
1833 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001834 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835 return true;
1836 } else {
1837 return false;
1838 }
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
Wink Saville36469e72014-06-11 15:17:00 -07001844 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001845 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 public boolean disableDataConnectivity() {
1847 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001848
1849 final long identity = Binder.clearCallingIdentity();
1850 try {
1851 int subId = mSubscriptionController.getDefaultDataSubId();
1852 final Phone phone = getPhone(subId);
1853 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001854 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001855 return true;
1856 } else {
1857 return false;
1858 }
1859 } finally {
1860 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001862 }
1863
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001865 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001866 final long identity = Binder.clearCallingIdentity();
1867 try {
1868 final Phone phone = getPhone(subId);
1869 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001870 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871 } else {
1872 return false;
1873 }
1874 } finally {
1875 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001876 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 }
1878
1879 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001880 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001881 }
1882
pkanwarae03a6b2016-11-06 20:37:09 -08001883 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001884 enforceCallPermission();
1885
1886 final long identity = Binder.clearCallingIdentity();
1887 try {
1888 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1889 return;
1890 }
1891 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1892 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1893 } finally {
1894 Binder.restoreCallingIdentity(identity);
1895 }
pkanwar32d516d2016-10-14 19:37:38 -07001896 };
1897
Wink Savilleb564aae2014-10-23 10:18:09 -07001898 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001899 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001900
1901 final long identity = Binder.clearCallingIdentity();
1902 try {
1903 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1904 return false;
1905 }
1906 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1907 } finally {
1908 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001909 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001910 }
1911
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001912 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001913 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001914 }
1915
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001916 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 Phone phone = PhoneFactory.getPhone(slotIndex);
1920 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1921 PhoneConstantConversions.convertCallState(phone.getState());
1922 } finally {
1923 Binder.restoreCallingIdentity(identity);
1924 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001925 }
1926
Sanket Padawe356d7632015-06-22 14:03:32 -07001927 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001928 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001929 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1930 }
1931
1932 @Override
1933 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001934 final long identity = Binder.clearCallingIdentity();
1935 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001936 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001937 if (phone != null) {
1938 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1939 } else {
1940 return PhoneConstantConversions.convertDataState(
1941 PhoneConstants.DataState.DISCONNECTED);
1942 }
1943 } finally {
1944 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001945 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 }
1947
Sanket Padawe356d7632015-06-22 14:03:32 -07001948 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001949 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001950 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1951 }
1952
1953 @Override
1954 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001957 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001958 if (phone != null) {
1959 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
1960 } else {
1961 return TelephonyManager.DATA_ACTIVITY_NONE;
1962 }
1963 } finally {
1964 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001965 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001966 }
1967
1968 @Override
Svetoslav64fad262015-04-14 14:35:21 -07001969 public Bundle getCellLocation(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08001971 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08001972
1973 LocationAccessPolicy.LocationPermissionResult locationResult =
1974 LocationAccessPolicy.checkLocationPermission(mApp,
1975 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1976 .setCallingPackage(callingPackage)
1977 .setCallingPid(Binder.getCallingPid())
1978 .setCallingUid(Binder.getCallingUid())
1979 .setMethod("getCellLocation")
1980 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1981 .build());
1982 switch (locationResult) {
1983 case DENIED_HARD:
1984 throw new SecurityException("Not allowed to access cell location");
1985 case DENIED_SOFT:
1986 return new Bundle();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 }
1988
Narayan Kamathf04b5a12018-01-09 11:47:15 +00001989 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001990 final long identity = Binder.clearCallingIdentity();
1991 try {
1992 if (DBG_LOC) log("getCellLocation: is active user");
1993 Bundle data = new Bundle();
Nathan Harold3ff88932018-08-14 10:19:49 -07001994 int subId = mSubscriptionController.getDefaultDataSubId();
1995 CellLocation cl = (CellLocation) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
1996 cl.fillInNotifierBundle(data);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001997 return data;
1998 } finally {
1999 Binder.restoreCallingIdentity(identity);
2000 }
Svetoslav64fad262015-04-14 14:35:21 -07002001 }
2002
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 @Override
Jack Yu1e81ccd2019-09-26 11:48:33 -07002004 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage) {
2005 if (!TextUtils.isEmpty(callingPackage)) {
2006 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
2007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2008 mApp, subId, callingPackage, "getNetworkCountryIsoForPhone")) {
2009 return "";
2010 }
2011 }
2012
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002013 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2014 // registered cell info, so return a NULL country instead.
2015 final long identity = Binder.clearCallingIdentity();
2016 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002017 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2018 // Get default phone in this case.
2019 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2020 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002021 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002022 // Todo: fix this when we can get the actual cellular network info when the device
2023 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002024 if (TelephonyManager.NETWORK_TYPE_IWLAN
2025 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName())) {
2026 return "";
2027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028 Phone phone = PhoneFactory.getPhone(phoneId);
2029 if (phone != null) {
2030 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002031 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002032 if (sst != null) {
2033 LocaleTracker lt = sst.getLocaleTracker();
2034 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002035 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2036 return lt.getCurrentCountry();
2037 } else if (emergencyNumberTracker != null) {
2038 return emergencyNumberTracker.getEmergencyCountryIso();
2039 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 }
2041 }
2042 }
2043 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002044 } finally {
2045 Binder.restoreCallingIdentity(identity);
2046 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002047 }
2048
2049 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002050 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002051 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002052 }
2053
Sanket Padawe356d7632015-06-22 14:03:32 -07002054 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002055 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 mApp.enforceCallingOrSelfPermission(
2057 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058
2059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 final Phone phone = getPhone(subId);
2062 if (phone != null) {
2063 phone.enableLocationUpdates();
2064 }
2065 } finally {
2066 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002067 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002068 }
2069
2070 @Override
2071 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002072 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002073 }
2074
Sanket Padawe356d7632015-06-22 14:03:32 -07002075 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002076 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 mApp.enforceCallingOrSelfPermission(
2078 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079
2080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 final Phone phone = getPhone(subId);
2083 if (phone != null) {
2084 phone.disableLocationUpdates();
2085 }
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
2090
Nathan Harold31d7ff32018-10-15 20:20:30 -07002091 /**
2092 * Returns the target SDK version number for a given package name.
2093 *
Nathan Haroldec184742019-07-10 17:04:16 -07002094 * This call MUST be invoked before clearing the calling UID.
2095 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002096 * @return target SDK if the package is found or INT_MAX.
2097 */
2098 private int getTargetSdk(String packageName) {
2099 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002100 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002101 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002102 if (ai != null) return ai.targetSdkVersion;
2103 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002104 loge("Failed to get package info for pkg="
2105 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002106 }
2107 return Integer.MAX_VALUE;
2108 }
2109
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 @Override
2111 @SuppressWarnings("unchecked")
Nathan Harold31d7ff32018-10-15 20:20:30 -07002112 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage) {
2113 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002114 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2115 throw new SecurityException(
2116 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2117 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002118
Jordan Liu1617b712019-07-10 15:06:26 -07002119 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2121 return null;
2122 }
Svetoslav64fad262015-04-14 14:35:21 -07002123
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002124 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002125
Nathan Haroldf180aac2018-06-01 18:43:55 -07002126 List<CellInfo> info = getAllCellInfo(callingPackage);
2127 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002128
Nathan Haroldf180aac2018-06-01 18:43:55 -07002129 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2130 for (CellInfo ci : info) {
2131 if (ci instanceof CellInfoGsm) {
2132 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2133 } else if (ci instanceof CellInfoWcdma) {
2134 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002137 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002138 }
2139
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002140 private List<CellInfo> getCachedCellInfo() {
2141 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2142 for (Phone phone : PhoneFactory.getPhones()) {
2143 List<CellInfo> info = phone.getAllCellInfo();
2144 if (info != null) cellInfos.addAll(info);
2145 }
2146 return cellInfos;
2147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148
2149 @Override
Svetoslav64fad262015-04-14 14:35:21 -07002150 public List<CellInfo> getAllCellInfo(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002151 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002152 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002153
2154 LocationAccessPolicy.LocationPermissionResult locationResult =
2155 LocationAccessPolicy.checkLocationPermission(mApp,
2156 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2157 .setCallingPackage(callingPackage)
2158 .setCallingPid(Binder.getCallingPid())
2159 .setCallingUid(Binder.getCallingUid())
2160 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002161 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002162 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2163 .build());
2164 switch (locationResult) {
2165 case DENIED_HARD:
2166 throw new SecurityException("Not allowed to access cell info");
2167 case DENIED_SOFT:
2168 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002171 final int targetSdk = getTargetSdk(callingPackage);
2172 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2173 return getCachedCellInfo();
2174 }
2175
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002176 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002177 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 final long identity = Binder.clearCallingIdentity();
2179 try {
2180 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2181 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002182 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002183 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184 if (info != null) cellInfos.addAll(info);
2185 }
2186 return cellInfos;
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190 }
2191
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002192 @Override
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002193 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage) {
2194 requestCellInfoUpdateInternal(
2195 subId, cb, callingPackage, getWorkSource(Binder.getCallingUid()));
2196 }
2197
2198 @Override
2199 public void requestCellInfoUpdateWithWorkSource(
2200 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
2201 enforceModifyPermission();
2202 requestCellInfoUpdateInternal(subId, cb, callingPackage, workSource);
2203 }
2204
2205 private void requestCellInfoUpdateInternal(
2206 int subId, ICellInfoCallback cb, String callingPackage, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002207 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002208 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002209
2210 LocationAccessPolicy.LocationPermissionResult locationResult =
2211 LocationAccessPolicy.checkLocationPermission(mApp,
2212 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2213 .setCallingPackage(callingPackage)
2214 .setCallingPid(Binder.getCallingPid())
2215 .setCallingUid(Binder.getCallingUid())
2216 .setMethod("requestCellInfoUpdate")
2217 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2218 .build());
2219 switch (locationResult) {
2220 case DENIED_HARD:
2221 throw new SecurityException("Not allowed to access cell info");
2222 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002223 try {
2224 cb.onCellInfo(new ArrayList<CellInfo>());
2225 } catch (RemoteException re) {
2226 // Drop without consequences
2227 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002228 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002229 }
2230
Nathan Harolda939a962019-05-09 10:13:47 -07002231
2232 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002233 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2234
2235 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2236 }
2237
2238 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002240 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002241 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002242
2243 final long identity = Binder.clearCallingIdentity();
2244 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002245 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002246 } finally {
2247 Binder.restoreCallingIdentity(identity);
2248 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002249 }
2250
Shishir Agrawala9f32182016-04-12 12:00:16 -07002251 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002252 public String getImeiForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002253 Phone phone = PhoneFactory.getPhone(slotIndex);
2254 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002255 return null;
2256 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002257 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002258 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2259 callingPackage, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002260 return null;
2261 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262
2263 final long identity = Binder.clearCallingIdentity();
2264 try {
2265 return phone.getImei();
2266 } finally {
2267 Binder.restoreCallingIdentity(identity);
2268 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002269 }
2270
2271 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002272 public String getTypeAllocationCodeForSlot(int slotIndex) {
2273 Phone phone = PhoneFactory.getPhone(slotIndex);
2274 String tac = null;
2275 if (phone != null) {
2276 String imei = phone.getImei();
2277 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2278 }
2279 return tac;
2280 }
2281
2282 @Override
Jack Yu2af8d712017-03-15 17:14:14 -07002283 public String getMeidForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002284 Phone phone = PhoneFactory.getPhone(slotIndex);
2285 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002286 return null;
2287 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002288
Jeff Davidson913390f2018-02-23 17:11:49 -08002289 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002290 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
2291 callingPackage, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002292 return null;
2293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294
2295 final long identity = Binder.clearCallingIdentity();
2296 try {
2297 return phone.getMeid();
2298 } finally {
2299 Binder.restoreCallingIdentity(identity);
2300 }
Jack Yu2af8d712017-03-15 17:14:14 -07002301 }
2302
2303 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002304 public String getManufacturerCodeForSlot(int slotIndex) {
2305 Phone phone = PhoneFactory.getPhone(slotIndex);
2306 String manufacturerCode = null;
2307 if (phone != null) {
2308 String meid = phone.getMeid();
2309 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2310 }
2311 return manufacturerCode;
2312 }
2313
2314 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002315 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002316 Phone phone = PhoneFactory.getPhone(slotIndex);
2317 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002318 return null;
2319 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002320 int subId = phone.getSubId();
2321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2322 mApp, subId, callingPackage, "getDeviceSoftwareVersionForSlot")) {
2323 return null;
2324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325
2326 final long identity = Binder.clearCallingIdentity();
2327 try {
2328 return phone.getDeviceSvn();
2329 } finally {
2330 Binder.restoreCallingIdentity(identity);
2331 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002332 }
2333
fionaxu43304da2017-11-27 22:51:16 -08002334 @Override
2335 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2340 } finally {
2341 Binder.restoreCallingIdentity(identity);
2342 }
fionaxu43304da2017-11-27 22:51:16 -08002343 }
2344
2345 @Override
2346 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002347 final long identity = Binder.clearCallingIdentity();
2348 try {
2349 final Phone phone = getPhone(subId);
2350 return phone == null ? null : phone.getCarrierName();
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
2353 }
fionaxu43304da2017-11-27 22:51:16 -08002354 }
2355
calvinpanffe225e2018-11-01 19:43:06 +08002356 @Override
chen xu0026ca62019-03-06 15:28:50 -08002357 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002358 final long identity = Binder.clearCallingIdentity();
2359 try {
2360 final Phone phone = getPhone(subId);
2361 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002362 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002363 } finally {
2364 Binder.restoreCallingIdentity(identity);
2365 }
2366 }
2367
2368 @Override
chen xu0026ca62019-03-06 15:28:50 -08002369 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002373 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002374 } finally {
2375 Binder.restoreCallingIdentity(identity);
2376 }
2377 }
2378
chen xu651eec72018-11-11 19:03:44 -08002379 @Override
chen xu864e11c2018-12-06 22:10:03 -08002380 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2381 if (!isSubscriptionMccMnc) {
2382 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2383 }
chen xu651eec72018-11-11 19:03:44 -08002384 final Phone phone = PhoneFactory.getPhone(slotIndex);
2385 if (phone == null) {
2386 return TelephonyManager.UNKNOWN_CARRIER_ID;
2387 }
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2391 } finally {
2392 Binder.restoreCallingIdentity(identity);
2393 }
2394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 //
2397 // Internal helper methods.
2398 //
2399
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002400 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2402 *
2403 * @throws SecurityException if the caller does not have the required permission
2404 */
2405 private void enforceModifyPermission() {
2406 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2407 }
2408
2409 /**
2410 * Make sure the caller has the CALL_PHONE permission.
2411 *
2412 * @throws SecurityException if the caller does not have the required permission
2413 */
2414 private void enforceCallPermission() {
2415 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2416 }
2417
Stuart Scott8eef64f2015-04-08 15:13:54 -07002418 private void enforceConnectivityInternalPermission() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CONNECTIVITY_INTERNAL,
Stuart Scott8eef64f2015-04-08 15:13:54 -07002420 "ConnectivityService");
2421 }
2422
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 private String createTelUrl(String number) {
2424 if (TextUtils.isEmpty(number)) {
2425 return null;
2426 }
2427
Jake Hambye994d462014-02-03 13:10:13 -08002428 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Ihab Awadf9e92732013-12-05 18:02:52 -08002431 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2433 }
2434
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002435 private static void logv(String msg) {
2436 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2437 }
2438
Ihab Awadf9e92732013-12-05 18:02:52 -08002439 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2441 }
2442
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002445 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Sanket Padawe356d7632015-06-22 14:03:32 -07002448 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002449 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450 final long identity = Binder.clearCallingIdentity();
2451 try {
2452 final Phone phone = PhoneFactory.getPhone(slotIndex);
2453 if (phone == null) {
2454 return PhoneConstants.PHONE_TYPE_NONE;
2455 } else {
2456 return phone.getPhoneType();
2457 }
2458 } finally {
2459 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002460 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462
2463 /**
2464 * Returns the CDMA ERI icon index to display
2465 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 @Override
2467 public int getCdmaEriIconIndex(String callingPackage) {
2468 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002469 }
2470
Sanket Padawe356d7632015-06-22 14:03:32 -07002471 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002472 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002473 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002474 mApp, subId, callingPackage, "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002475 return -1;
2476 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477
2478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 final Phone phone = getPhone(subId);
2481 if (phone != null) {
2482 return phone.getCdmaEriIconIndex();
2483 } else {
2484 return -1;
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
2491 /**
2492 * Returns the CDMA ERI icon mode,
2493 * 0 - ON
2494 * 1 - FLASHING
2495 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002496 @Override
2497 public int getCdmaEriIconMode(String callingPackage) {
2498 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002499 }
2500
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002502 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002503 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002504 mApp, subId, callingPackage, "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002505 return -1;
2506 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002507
2508 final long identity = Binder.clearCallingIdentity();
2509 try {
2510 final Phone phone = getPhone(subId);
2511 if (phone != null) {
2512 return phone.getCdmaEriIconMode();
2513 } else {
2514 return -1;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
2521 /**
2522 * Returns the CDMA ERI text,
2523 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002524 @Override
2525 public String getCdmaEriText(String callingPackage) {
2526 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07002527 }
2528
Sanket Padawe356d7632015-06-22 14:03:32 -07002529 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002530 public String getCdmaEriTextForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002531 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002532 mApp, subId, callingPackage, "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002533 return null;
2534 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
2538 final Phone phone = getPhone(subId);
2539 if (phone != null) {
2540 return phone.getCdmaEriText();
2541 } else {
2542 return null;
2543 }
2544 } finally {
2545 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002546 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 }
2548
2549 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002550 * Returns the CDMA MDN.
2551 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002553 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2555 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002556
2557 final long identity = Binder.clearCallingIdentity();
2558 try {
2559 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002560 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 return phone.getLine1Number();
2562 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002563 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002564 return null;
2565 }
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002568 }
2569 }
2570
2571 /**
2572 * Returns the CDMA MIN.
2573 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002574 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002575 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2577 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578
2579 final long identity = Binder.clearCallingIdentity();
2580 try {
2581 final Phone phone = getPhone(subId);
2582 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2583 return phone.getCdmaMin();
2584 } else {
2585 return null;
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002589 }
2590 }
2591
Hall Liud892bec2018-11-30 14:51:45 -08002592 @Override
2593 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2594 INumberVerificationCallback callback, String callingPackage) {
2595 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2596 != PERMISSION_GRANTED) {
2597 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2598 }
2599 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2600
2601 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2602 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2603 throw new SecurityException("Calling package must be configured in the device config");
2604 }
2605
2606 if (range == null) {
2607 throw new NullPointerException("Range must be non-null");
2608 }
2609
2610 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002611 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002612
2613 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2614 }
2615
Junda Liuca05d5d2014-08-14 22:36:34 -07002616 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002617 * Returns true if CDMA provisioning needs to run.
2618 */
2619 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620 final long identity = Binder.clearCallingIdentity();
2621 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002622 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002623 } finally {
2624 Binder.restoreCallingIdentity(identity);
2625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 }
2627
2628 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002629 * Sets the voice mail number of a given subId.
2630 */
2631 @Override
2632 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002633 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002634
2635 final long identity = Binder.clearCallingIdentity();
2636 try {
2637 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2638 new Pair<String, String>(alphaTag, number), new Integer(subId));
2639 return success;
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
2642 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002643 }
2644
Ta-wei Yen87c49842016-05-13 21:19:52 -07002645 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002646 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2647 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002648 String systemDialer = TelecomManager.from(mApp).getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002649 if (!TextUtils.equals(callingPackage, systemDialer)) {
2650 throw new SecurityException("caller must be system dialer");
2651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652
2653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2656 if (phoneAccountHandle == null) {
2657 return null;
2658 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002659 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002660 } finally {
2661 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002662 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002663 }
2664
2665 @Override
Ta-wei Yen409ac562017-03-06 16:00:44 -08002666 public String getVisualVoicemailPackageName(String callingPackage, int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002667 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08002669 mApp, subId, callingPackage, "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002670 return null;
2671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002672
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002673 final long identity = Binder.clearCallingIdentity();
2674 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002675 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002676 } finally {
2677 Binder.restoreCallingIdentity(identity);
2678 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002679 }
2680
2681 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002682 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2683 VisualVoicemailSmsFilterSettings settings) {
2684 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002689 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002690 } finally {
2691 Binder.restoreCallingIdentity(identity);
2692 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002693 }
2694
2695 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002696 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2697 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698
2699 final long identity = Binder.clearCallingIdentity();
2700 try {
2701 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002702 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002706 }
2707
2708 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002709 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2710 String callingPackage, int subId) {
2711 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002712
2713 final long identity = Binder.clearCallingIdentity();
2714 try {
2715 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002716 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 } finally {
2718 Binder.restoreCallingIdentity(identity);
2719 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002720 }
2721
2722 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002723 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002724 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002725
2726 final long identity = Binder.clearCallingIdentity();
2727 try {
2728 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002729 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002730 } finally {
2731 Binder.restoreCallingIdentity(identity);
2732 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002733 }
2734
2735 @Override
2736 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2737 String number, int port, String text, PendingIntent sentIntent) {
2738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002739 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002740 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002741 SmsController smsController = PhoneFactory.getSmsController();
2742 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2743 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002744 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002745
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002746 /**
fionaxu0152e512016-11-14 13:36:14 -08002747 * Sets the voice activation state of a given subId.
2748 */
2749 @Override
2750 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2752 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002753
2754 final long identity = Binder.clearCallingIdentity();
2755 try {
2756 final Phone phone = getPhone(subId);
2757 if (phone != null) {
2758 phone.setVoiceActivationState(activationState);
2759 } else {
2760 loge("setVoiceActivationState fails with invalid subId: " + subId);
2761 }
2762 } finally {
2763 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002764 }
2765 }
2766
2767 /**
2768 * Sets the data activation state of a given subId.
2769 */
2770 @Override
2771 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2773 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774
2775 final long identity = Binder.clearCallingIdentity();
2776 try {
2777 final Phone phone = getPhone(subId);
2778 if (phone != null) {
2779 phone.setDataActivationState(activationState);
2780 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002781 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002782 }
2783 } finally {
2784 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002785 }
2786 }
2787
2788 /**
2789 * Returns the voice activation state of a given subId.
2790 */
2791 @Override
2792 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002793 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794
fionaxu0152e512016-11-14 13:36:14 -08002795 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 final long identity = Binder.clearCallingIdentity();
2797 try {
2798 if (phone != null) {
2799 return phone.getVoiceActivationState();
2800 } else {
2801 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2802 }
2803 } finally {
2804 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002805 }
2806 }
2807
2808 /**
2809 * Returns the data activation state of a given subId.
2810 */
2811 @Override
2812 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002813 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814
fionaxu0152e512016-11-14 13:36:14 -08002815 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816 final long identity = Binder.clearCallingIdentity();
2817 try {
2818 if (phone != null) {
2819 return phone.getDataActivationState();
2820 } else {
2821 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002825 }
2826 }
2827
2828 /**
Wink Saville36469e72014-06-11 15:17:00 -07002829 * Returns the unread count of voicemails for a subId
2830 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002831 @Override
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002832 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage) {
2833 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
2834 mApp, subId, callingPackage, "getVoiceMessageCountForSubscriber")) {
2835 return 0;
2836 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002837 final long identity = Binder.clearCallingIdentity();
2838 try {
2839 final Phone phone = getPhone(subId);
2840 if (phone != null) {
2841 return phone.getVoiceMessageCount();
2842 } else {
2843 return 0;
2844 }
2845 } finally {
2846 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002847 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002848 }
2849
2850 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002851 * returns true, if the device is in a state where both voice and data
2852 * are supported simultaneously. This can change based on location or network condition.
2853 */
2854 @Override
2855 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002856 final long identity = Binder.clearCallingIdentity();
2857 try {
2858 final Phone phone = getPhone(subId);
2859 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2860 } finally {
2861 Binder.restoreCallingIdentity(identity);
2862 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002863 }
2864
2865 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002866 * Send the dialer code if called from the current default dialer or the caller has
2867 * carrier privilege.
2868 * @param inputCode The dialer code to send
2869 */
2870 @Override
2871 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002872 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002874 String defaultDialer = TelecomManager.from(defaultPhone.getContext())
2875 .getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002876 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2878 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002883 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002884 } finally {
2885 Binder.restoreCallingIdentity(identity);
2886 }
fionaxu235cc5e2017-03-06 22:25:57 -08002887 }
2888
Pengquan Menga1bb6272018-09-06 09:59:22 -07002889 @Override
2890 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002891 if (!isActiveSubscription(subId)) {
2892 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2893 }
2894
Pengquan Menga1bb6272018-09-06 09:59:22 -07002895 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2896 }
2897
Brad Ebinger35c841c2018-10-01 10:40:55 -07002898 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002899 public boolean isInEmergencySmsMode() {
2900 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2901 final long identity = Binder.clearCallingIdentity();
2902 try {
2903 for (Phone phone : PhoneFactory.getPhones()) {
2904 if (phone.isInEmergencySmsMode()) {
2905 return true;
2906 }
2907 }
2908 } finally {
2909 Binder.restoreCallingIdentity(identity);
2910 }
2911 return false;
2912 }
2913
2914 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002915 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2916 throws RemoteException {
2917 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07002918 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2919 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2920 "IMS not available on device.");
2921 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002922 final long token = Binder.clearCallingIdentity();
2923 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002924 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002925 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002926 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002927 } catch (ImsException e) {
2928 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002929 } finally {
2930 Binder.restoreCallingIdentity(token);
2931 }
2932 }
2933
2934 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002935 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
2936 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002937 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2938 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
2939 }
Meng Wangafbc5852019-09-19 17:37:13 -07002940 final long token = Binder.clearCallingIdentity();
2941 try {
2942 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
2943 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
2944 .removeRegistrationCallbackForSubscription(c, subId);
2945 } catch (ImsException e) {
2946 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
2947 + "is inactive, ignoring unregister.");
2948 // If the subscription is no longer active, just return, since the callback
2949 // will already have been removed internally.
2950 } finally {
2951 Binder.restoreCallingIdentity(token);
2952 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002953 }
2954
Brad Ebingera34a6c22019-10-22 17:36:18 -07002955 /**
2956 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
2957 */
2958 @Override
2959 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
2960 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
2961 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2962 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2963 "IMS not available on device.");
2964 }
2965 final long token = Binder.clearCallingIdentity();
2966 try {
2967 Phone phone = getPhone(subId);
2968 if (phone == null) {
2969 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
2970 + subId + "'");
2971 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
2972 }
2973 phone.getImsRegistrationState(regState -> {
2974 try {
2975 consumer.accept((regState == null)
2976 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
2977 } catch (RemoteException e) {
2978 // Ignore if the remote process is no longer available to call back.
2979 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
2980 }
2981 });
2982 } finally {
2983 Binder.restoreCallingIdentity(token);
2984 }
2985 }
2986
2987 /**
2988 * Get the transport type for the IMS service registration state.
2989 */
2990 @Override
2991 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
2992 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
2993 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2994 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2995 "IMS not available on device.");
2996 }
2997 final long token = Binder.clearCallingIdentity();
2998 try {
2999 Phone phone = getPhone(subId);
3000 if (phone == null) {
3001 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3002 + subId + "'");
3003 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3004 }
3005 phone.getImsRegistrationTech(regTech -> {
3006 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3007 int regTechConverted = (regTech == null)
3008 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3009 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3010 regTechConverted);
3011 try {
3012 consumer.accept(regTechConverted);
3013 } catch (RemoteException e) {
3014 // Ignore if the remote process is no longer available to call back.
3015 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3016 }
3017 });
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
3021 }
3022
Brad Ebinger35c841c2018-10-01 10:40:55 -07003023 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003024 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3025 throws RemoteException {
3026 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003027 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3028 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3029 "IMS not available on device.");
3030 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3032 final long token = Binder.clearCallingIdentity();
3033 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003034 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003035 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003036 } catch (ImsException e) {
3037 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003038 } finally {
3039 Binder.restoreCallingIdentity(token);
3040 }
3041 }
3042
3043 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003044 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3045 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003046 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3047 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3048 }
Meng Wangafbc5852019-09-19 17:37:13 -07003049
3050 final long token = Binder.clearCallingIdentity();
3051 try {
3052 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3053 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003054 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003055 } catch (ImsException e) {
3056 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3057 + "is inactive, ignoring unregister.");
3058 // If the subscription is no longer active, just return, since the callback
3059 // will already have been removed internally.
3060 } finally {
3061 Binder.restoreCallingIdentity(token);
3062 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003063 }
3064
3065 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003066 public boolean isCapable(int subId, int capability, int regTech) {
3067 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003068 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3069 final long token = Binder.clearCallingIdentity();
3070 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003072 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003073 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003074 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3075 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003076 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003077 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3078 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003079 } finally {
3080 Binder.restoreCallingIdentity(token);
3081 }
3082 }
3083
3084 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003085 public boolean isAvailable(int subId, int capability, int regTech) {
3086 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003087 final long token = Binder.clearCallingIdentity();
3088 try {
3089 Phone phone = getPhone(subId);
3090 if (phone == null) return false;
3091 return phone.isImsCapabilityAvailable(capability, regTech);
3092 } finally {
3093 Binder.restoreCallingIdentity(token);
3094 }
3095 }
3096
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003097 /**
3098 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3099 * subscription.
3100 * @param subId The subscription to use to check the configuration.
3101 * @param callback The callback that will be used to send the result.
3102 * @param capability The MmTelFeature capability that will be used to send the result.
3103 * @param transportType The transport type of the MmTelFeature capability.
3104 */
3105 @Override
3106 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3107 int transportType) {
3108 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3109 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3110 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3111 "IMS not available on device.");
3112 }
3113 final long token = Binder.clearCallingIdentity();
3114 try {
3115 int slotId = getSlotIndex(subId);
3116 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3117 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3118 + subId + "'");
3119 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3120 }
3121 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3122 transportType, aBoolean -> {
3123 try {
3124 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3125 } catch (RemoteException e) {
3126 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3127 + "running. Ignore");
3128 }
3129 });
3130 } finally {
3131 Binder.restoreCallingIdentity(token);
3132 }
3133 }
3134
Brad Ebinger35c841c2018-10-01 10:40:55 -07003135 @Override
3136 public boolean isAdvancedCallingSettingEnabled(int subId) {
3137 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3139 final long token = Binder.clearCallingIdentity();
3140 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003141 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003143 } catch (ImsException e) {
3144 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003145 } finally {
3146 Binder.restoreCallingIdentity(token);
3147 }
3148 }
3149
3150 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003151 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003153 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003154 final long identity = Binder.clearCallingIdentity();
3155 try {
3156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003157 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003158 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003159 } catch (ImsException e) {
3160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 } finally {
3162 Binder.restoreCallingIdentity(identity);
3163 }
3164 }
3165
3166 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003167 public boolean isVtSettingEnabled(int subId) {
3168 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003172 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3173 } catch (ImsException e) {
3174 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003175 } finally {
3176 Binder.restoreCallingIdentity(identity);
3177 }
3178 }
3179
3180 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003181 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003183 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003184 final long identity = Binder.clearCallingIdentity();
3185 try {
3186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003187 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003188 } catch (ImsException e) {
3189 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003190 } finally {
3191 Binder.restoreCallingIdentity(identity);
3192 }
3193 }
3194
3195 @Override
3196 public boolean isVoWiFiSettingEnabled(int subId) {
3197 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003201 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003202 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003203 } catch (ImsException e) {
3204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003205 } finally {
3206 Binder.restoreCallingIdentity(identity);
3207 }
3208 }
3209
3210 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003211 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003212 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003213 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003214 final long identity = Binder.clearCallingIdentity();
3215 try {
3216 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003217 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003218 } catch (ImsException e) {
3219 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
3223 }
3224
3225 @Override
3226 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3227 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3228 final long identity = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003231 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003232 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003233 } catch (ImsException e) {
3234 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003235 } finally {
3236 Binder.restoreCallingIdentity(identity);
3237 }
3238 }
3239
3240 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003241 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003242 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003243 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003247 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003248 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003249 } catch (ImsException e) {
3250 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
3254 }
3255
3256 @Override
3257 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3259 "setVoWiFiNonPersistent");
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003263 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003264 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003265 } catch (ImsException e) {
3266 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
3270 }
3271
3272 @Override
3273 public int getVoWiFiModeSetting(int subId) {
3274 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003278 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003280 } catch (ImsException e) {
3281 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 } finally {
3283 Binder.restoreCallingIdentity(identity);
3284 }
3285 }
3286
3287 @Override
3288 public void setVoWiFiModeSetting(int subId, int mode) {
3289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3290 "setVoWiFiModeSetting");
3291 final long identity = Binder.clearCallingIdentity();
3292 try {
3293 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003294 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003296 } catch (ImsException e) {
3297 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003298 } finally {
3299 Binder.restoreCallingIdentity(identity);
3300 }
3301 }
3302
3303 @Override
3304 public int getVoWiFiRoamingModeSetting(int subId) {
3305 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003309 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003311 } catch (ImsException e) {
3312 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003313 } finally {
3314 Binder.restoreCallingIdentity(identity);
3315 }
3316 }
3317
3318 @Override
3319 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3321 "setVoWiFiRoamingModeSetting");
3322 final long identity = Binder.clearCallingIdentity();
3323 try {
3324 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003325 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003326 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003327 } catch (ImsException e) {
3328 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003329 } finally {
3330 Binder.restoreCallingIdentity(identity);
3331 }
3332 }
3333
3334 @Override
3335 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3336 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3337 "setRttCapabilityEnabled");
3338 final long identity = Binder.clearCallingIdentity();
3339 try {
3340 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003341 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3342 } catch (ImsException e) {
3343 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003344 } finally {
3345 Binder.restoreCallingIdentity(identity);
3346 }
3347 }
3348
3349 @Override
3350 public boolean isTtyOverVolteEnabled(int subId) {
3351 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3352 final long identity = Binder.clearCallingIdentity();
3353 try {
3354 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003355 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003357 } catch (ImsException e) {
3358 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003359 } finally {
3360 Binder.restoreCallingIdentity(identity);
3361 }
3362 }
3363
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003364 @Override
3365 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3366 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3367 final long identity = Binder.clearCallingIdentity();
3368 try {
3369 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003370 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003371 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003372 } catch (ImsException e) {
3373 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003374 } finally {
3375 Binder.restoreCallingIdentity(identity);
3376 }
3377 }
3378
3379 @Override
3380 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3381 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3382 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003383 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3384 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3385 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003386 try {
3387 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003388 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003389 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003390 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003391 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3392 + "is inactive, ignoring unregister.");
3393 // If the subscription is no longer active, just return, since the callback will already
3394 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
3398 }
3399
3400 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003401 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3402 boolean isProvisioned) {
3403 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3404 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3405 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3406 }
3407 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3408 "setProvisioningStatusForCapability");
3409 final long identity = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3412 Phone phone = getPhone(subId);
3413 if (phone == null) {
3414 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3415 + subId);
3416 return;
3417 }
3418 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3419 return;
3420 }
3421
3422 // this capability requires provisioning, route to the correct API.
3423 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3424 switch (capability) {
3425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3426 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3427 ims.setVolteProvisioned(isProvisioned);
3428 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3429 ims.setWfcProvisioned(isProvisioned);
3430 }
3431 break;
3432 }
3433 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3434 // There is currently no difference in VT provisioning type.
3435 ims.setVtProvisioned(isProvisioned);
3436 break;
3437 }
3438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3439 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3440 // change the capability of the feature instead if needed.
3441 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3442 == isProvisioned) {
3443 // No change in provisioning.
3444 return;
3445 }
3446 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3447 try {
3448 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003449 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003450 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3451 + ", Exception" + e.getMessage());
3452 }
3453 break;
3454 }
3455 default: {
3456 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3457 + capability + "', which does not require provisioning.");
3458 }
3459 }
3460
3461 } finally {
3462 Binder.restoreCallingIdentity(identity);
3463 }
3464 }
3465
3466 @Override
3467 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3468 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3469 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3470 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3471 }
3472 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3476 Phone phone = getPhone(subId);
3477 if (phone == null) {
3478 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3479 + subId);
3480 // We will fail with "true" as the provisioning status because this is the default
3481 // if we do not require provisioning.
3482 return true;
3483 }
3484
3485 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3486 return true;
3487 }
3488
3489 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3490 switch (capability) {
3491 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3492 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3493 return ims.isVolteProvisionedOnDevice();
3494 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3495 return ims.isWfcProvisionedOnDevice();
3496 }
3497 // This should never happen, since we are checking tech above to make sure it
3498 // is either LTE or IWLAN.
3499 throw new IllegalArgumentException("Invalid radio technology for voice "
3500 + "capability.");
3501 }
3502 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3503 // There is currently no difference in VT provisioning type.
3504 return ims.isVtProvisionedOnDevice();
3505 }
3506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3507 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3508 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3509 }
3510 default: {
3511 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3512 + capability + "', which does not require provisioning.");
3513 }
3514 }
3515
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
3518 }
3519 }
3520
3521 @Override
3522 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3523 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3524 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3525 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3526 }
3527 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3528 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3529 return (provisionedBits & capability) > 0;
3530 }
3531
3532 @Override
3533 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3534 boolean isProvisioned) {
3535 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3536 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3537 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3538 }
3539 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3540 "setProvisioningStatusForCapability");
3541 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3542 // If the current provisioning status for capability already matches isProvisioned,
3543 // do nothing.
3544 if (((provisionedBits & capability) > 0) == isProvisioned) {
3545 return;
3546 }
3547 if (isProvisioned) {
3548 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3549 } else {
3550 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3551 }
3552 }
3553
3554 /**
3555 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3556 * technology. The bitfield should mirror the bitfield defined by
3557 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3558 */
3559 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3560 String key = getMmTelProvisioningKey(subId, tech);
3561 // Default is no capabilities are provisioned.
3562 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3563 }
3564
3565 /**
3566 * Sets the MmTel capability provisioning bitfield (defined by
3567 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3568 * technology specified.
3569 *
3570 * Note: This is a synchronous command and should not be called on UI thread.
3571 */
3572 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3573 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3574 String key = getMmTelProvisioningKey(subId, tech);
3575 editor.putInt(key, newField);
3576 editor.commit();
3577 }
3578
3579 private static String getMmTelProvisioningKey(int subId, int tech) {
3580 // resulting key is provision_ims_mmtel_{subId}_{tech}
3581 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3582 }
3583
3584 /**
3585 * Query CarrierConfig to see if the specified capability requires provisioning for the
3586 * carrier associated with the subscription id.
3587 */
3588 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3589 int capability) {
3590 CarrierConfigManager configManager = new CarrierConfigManager(context);
3591 PersistableBundle c = configManager.getConfigForSubId(subId);
3592 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003593 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003594 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3595 false);
3596 boolean requireVoiceVtProvisioning = c.getBoolean(
3597 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3598
3599 // First check to make sure that the capability requires provisioning.
3600 switch (capability) {
3601 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3602 // intentional fallthrough
3603 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3604 if (requireVoiceVtProvisioning) {
3605 // Voice and Video requires provisioning
3606 return true;
3607 }
3608 break;
3609 }
3610 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3611 if (requireUtProvisioning) {
3612 // UT requires provisioning
3613 return true;
3614 }
3615 break;
3616 }
3617 }
3618 return false;
3619 }
3620
3621 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003622 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003623 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3624 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3625 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003626 enforceReadPrivilegedPermission("getImsProvisioningInt");
3627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003630 int slotId = getSlotIndex(subId);
3631 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3632 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3633 + subId + "' for key:" + key);
3634 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3635 }
3636 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003637 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003638 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3639 + subId + "' for key:" + key);
3640 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003641 } finally {
3642 Binder.restoreCallingIdentity(identity);
3643 }
3644 }
3645
3646 @Override
3647 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003648 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3649 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3650 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003651 enforceReadPrivilegedPermission("getImsProvisioningString");
3652 final long identity = Binder.clearCallingIdentity();
3653 try {
3654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003655 int slotId = getSlotIndex(subId);
3656 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3657 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3658 + subId + "' for key:" + key);
3659 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3660 }
3661 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003662 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003663 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3664 + subId + "' for key:" + key);
3665 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003666 } finally {
3667 Binder.restoreCallingIdentity(identity);
3668 }
3669 }
3670
3671 @Override
3672 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3674 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3675 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3677 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003678 final long identity = Binder.clearCallingIdentity();
3679 try {
3680 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003681 int slotId = getSlotIndex(subId);
3682 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3683 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3684 + subId + "' for key:" + key);
3685 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3686 }
3687 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003688 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003689 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3690 + "' for key:" + key);
3691 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
3698 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003699 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3700 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3701 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3703 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003707 int slotId = getSlotIndex(subId);
3708 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3709 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3710 + subId + "' for key:" + key);
3711 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3712 }
3713 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003714 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003715 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3716 + "' for key:" + key);
3717 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003718 } finally {
3719 Binder.restoreCallingIdentity(identity);
3720 }
3721 }
3722
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 int slotId = SubscriptionManager.getSlotIndex(subId);
3725 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3727 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 }
3729 return slotId;
3730 }
3731
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003732 private int getSlotIndex(int subId) {
3733 int slotId = SubscriptionManager.getSlotIndex(subId);
3734 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3735 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3736 }
3737 return slotId;
3738 }
3739
Wink Saville36469e72014-06-11 15:17:00 -07003740 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003741 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003742 */
3743 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003744 public int getNetworkTypeForSubscriber(int subId, String callingPackage) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003745 final int targetSdk = getTargetSdk(callingPackage);
3746 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
3747 return getDataNetworkTypeForSubscriber(subId, callingPackage);
3748 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003749 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
3750 mApp, subId, callingPackage, "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003751 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3752 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003753
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003754 final long identity = Binder.clearCallingIdentity();
3755 try {
3756 final Phone phone = getPhone(subId);
3757 if (phone != null) {
3758 return phone.getServiceState().getDataNetworkType();
3759 } else {
3760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3761 }
3762 } finally {
3763 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003764 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003765 }
3766
3767 /**
3768 * Returns the data network type
3769 */
3770 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003771 public int getDataNetworkType(String callingPackage) {
3772 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003773 }
3774
3775 /**
3776 * Returns the data network type for a subId
3777 */
3778 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003779 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003780 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003781 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003782 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3783 }
3784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003785 final long identity = Binder.clearCallingIdentity();
3786 try {
3787 final Phone phone = getPhone(subId);
3788 if (phone != null) {
3789 return phone.getServiceState().getDataNetworkType();
3790 } else {
3791 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3792 }
3793 } finally {
3794 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003796 }
3797
3798 /**
Wink Saville36469e72014-06-11 15:17:00 -07003799 * Returns the Voice network type for a subId
3800 */
3801 @Override
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003802 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003804 mApp, subId, callingPackage, "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003805 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3806 }
3807
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003808 final long identity = Binder.clearCallingIdentity();
3809 try {
3810 final Phone phone = getPhone(subId);
3811 if (phone != null) {
3812 return phone.getServiceState().getVoiceNetworkType();
3813 } else {
3814 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3815 }
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003818 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003819 }
3820
3821 /**
3822 * @return true if a ICC card is present
3823 */
3824 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003825 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003826 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3827 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003828 }
3829
3830 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003831 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003832 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003833 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003834 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003835 final long identity = Binder.clearCallingIdentity();
3836 try {
3837 final Phone phone = PhoneFactory.getPhone(slotIndex);
3838 if (phone != null) {
3839 return phone.getIccCard().hasIccCard();
3840 } else {
3841 return false;
3842 }
3843 } finally {
3844 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003845 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003846 }
3847
3848 /**
3849 * Return if the current radio is LTE on CDMA. This
3850 * is a tri-state return value as for a period of time
3851 * the mode may be unknown.
3852 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003853 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003854 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003855 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003856 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003857 @Override
3858 public int getLteOnCdmaMode(String callingPackage) {
3859 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage);
Wink Saville36469e72014-06-11 15:17:00 -07003860 }
3861
Sanket Padawe356d7632015-06-22 14:03:32 -07003862 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003863 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003864 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08003865 mApp, subId, callingPackage, "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003866 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3867 }
3868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 final Phone phone = getPhone(subId);
3872 if (phone == null) {
3873 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3874 } else {
3875 return phone.getLteOnCdmaMode();
3876 }
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003879 }
Wink Saville36469e72014-06-11 15:17:00 -07003880 }
3881
Wink Saville36469e72014-06-11 15:17:00 -07003882 /**
3883 * {@hide}
3884 * Returns Default subId, 0 in the case of single standby.
3885 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003886 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003887 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003888 }
3889
Shishir Agrawala9f32182016-04-12 12:00:16 -07003890 private int getSlotForDefaultSubscription() {
3891 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3892 }
3893
Wink Savilleb564aae2014-10-23 10:18:09 -07003894 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003895 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003896 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003897
Pengquan Menge92a50d2018-09-21 15:54:48 -07003898 private boolean isActiveSubscription(int subId) {
3899 return mSubscriptionController.isActiveSubId(subId);
3900 }
3901
Ihab Awadf2177b72013-11-25 13:33:23 -08003902 /**
3903 * @see android.telephony.TelephonyManager.WifiCallingChoices
3904 */
3905 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003906 final long identity = Binder.clearCallingIdentity();
3907 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003908 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003909 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3910 getWhenToMakeWifiCallsDefaultPreference());
3911 } finally {
3912 Binder.restoreCallingIdentity(identity);
3913 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003914 }
3915
3916 /**
3917 * @see android.telephony.TelephonyManager.WifiCallingChoices
3918 */
3919 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003924 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
3925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
Ihab Awadf9e92732013-12-05 18:02:52 -08003928 }
3929
Sailesh Nepald1e68152013-12-12 19:08:02 -08003930 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07003931 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08003932 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08003933 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08003934
Jordan Liu4c733742019-02-28 12:03:40 -08003935 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
3936 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
3937 if (phoneId == -1) {
3938 throw new IllegalArgumentException("Given slot index: " + slotIndex
3939 + " does not correspond to an active phone");
3940 }
3941 return PhoneFactory.getPhone(phoneId);
3942 }
3943
Shishir Agrawal566b7612013-10-28 14:41:00 -07003944 @Override
Derek Tan740e1672017-06-27 14:56:27 -07003945 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
3946 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003947 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3948 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003949 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08003950 if (DBG) {
3951 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
3952 }
3953 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
3954 p2);
3955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003956
Jordan Liu4c733742019-02-28 12:03:40 -08003957
3958 @Override
3959 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
3960 int slotIndex, String callingPackage, String aid, int p2) {
3961 enforceModifyPermission();
3962 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3963 if (DBG) {
3964 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
3965 }
3966 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
3967 callingPackage, aid, p2);
3968 }
3969
3970 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
3971 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 if (TextUtils.equals(ISDR_AID, aid)) {
3975 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
3977 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003978 if (bestComponent == null
3979 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
3980 loge("The calling package is not allowed to access ISD-R.");
3981 throw new SecurityException(
3982 "The calling package is not allowed to access ISD-R.");
3983 }
Derek Tan740e1672017-06-27 14:56:27 -07003984 }
Derek Tan740e1672017-06-27 14:56:27 -07003985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003986 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08003987 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
3988 null /* workSource */);
3989 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003990 return response;
3991 } finally {
3992 Binder.restoreCallingIdentity(identity);
3993 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07003994 }
3995
3996 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08003997 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003998 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3999 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004000 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4001 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4002 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004003
Jordan Liu4c733742019-02-28 12:03:40 -08004004 @Override
4005 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4006 enforceModifyPermission();
4007 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4008 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4009 channel);
4010 }
4011
4012 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004013 final long identity = Binder.clearCallingIdentity();
4014 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004015 if (channel < 0) {
4016 return false;
4017 }
Jordan Liu4c733742019-02-28 12:03:40 -08004018 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4019 null /* workSource */);
4020 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004021 return success;
4022 } finally {
4023 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004024 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004025 }
4026
4027 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004028 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004029 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4031 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004032 if (DBG) {
4033 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4034 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4035 + p3 + " data=" + data);
4036 }
4037 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4038 command, p1, p2, p3, data);
4039 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004040
Jordan Liu4c733742019-02-28 12:03:40 -08004041 @Override
4042 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4043 int command, int p1, int p2, int p3, String data) {
4044 enforceModifyPermission();
4045 if (DBG) {
4046 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4047 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4048 + p3 + " data=" + data);
4049 }
4050 return iccTransmitApduLogicalChannelWithPermission(
4051 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4052 data);
4053 }
4054
4055 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4056 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004057 final long identity = Binder.clearCallingIdentity();
4058 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004059 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004060 return "";
4061 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004063 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004064 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4065 null /* workSource */);
4066 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004067
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 // Append the returned status code to the end of the response payload.
4069 String s = Integer.toHexString(
4070 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4071 if (response.payload != null) {
4072 s = IccUtils.bytesToHexString(response.payload) + s;
4073 }
4074 return s;
4075 } finally {
4076 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004077 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004078 }
Jake Hambye994d462014-02-03 13:10:13 -08004079
Evan Charltonc66da362014-05-16 14:06:40 -07004080 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004081 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4082 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004083 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4084 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004085 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004086 if (DBG) {
4087 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4088 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4089 }
4090 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4091 cla, command, p1, p2, p3, data);
4092 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004093
Jordan Liu4c733742019-02-28 12:03:40 -08004094 @Override
4095 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4096 int command, int p1, int p2, int p3, String data) {
4097 enforceModifyPermission();
4098 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4099 if (DBG) {
4100 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4101 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4102 + " data=" + data);
4103 }
4104
4105 return iccTransmitApduBasicChannelWithPermission(
4106 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4107 p2, p3, data);
4108 }
4109
4110 // open APDU basic channel assuming the caller has sufficient permissions
4111 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4112 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004113 final long identity = Binder.clearCallingIdentity();
4114 try {
4115 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4116 && TextUtils.equals(ISDR_AID, data)) {
4117 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4119 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004120 if (bestComponent == null
4121 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4122 loge("The calling package is not allowed to select ISD-R.");
4123 throw new SecurityException(
4124 "The calling package is not allowed to select ISD-R.");
4125 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004126 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004128 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004129 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4130 null /* workSource */);
4131 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004133 // Append the returned status code to the end of the response payload.
4134 String s = Integer.toHexString(
4135 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4136 if (response.payload != null) {
4137 s = IccUtils.bytesToHexString(response.payload) + s;
4138 }
4139 return s;
4140 } finally {
4141 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004142 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004143 }
4144
4145 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004146 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004147 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4149 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 if (DBG) {
4154 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4155 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4156 }
4157
4158 IccIoResult response =
4159 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4160 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4161 subId);
4162
4163 if (DBG) {
4164 log("Exchange SIM_IO [R]" + response);
4165 }
4166
4167 byte[] result = null;
4168 int length = 2;
4169 if (response.payload != null) {
4170 length = 2 + response.payload.length;
4171 result = new byte[length];
4172 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4173 } else {
4174 result = new byte[length];
4175 }
4176
4177 result[length - 1] = (byte) response.sw2;
4178 result[length - 2] = (byte) response.sw1;
4179 return result;
4180 } finally {
4181 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004182 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004183 }
4184
Nathan Haroldb3014052017-01-25 15:57:32 -08004185 /**
4186 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4187 * on a particular subscription
4188 */
sqianb6e41952018-03-12 14:54:01 -07004189 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage) {
4190 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4191 mApp, subId, callingPackage, "getForbiddenPlmns")) {
4192 return null;
4193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004194
4195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 if (appType != TelephonyManager.APPTYPE_USIM
4198 && appType != TelephonyManager.APPTYPE_SIM) {
4199 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4200 return null;
4201 }
4202 Object response = sendRequest(
4203 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4204 if (response instanceof String[]) {
4205 return (String[]) response;
4206 }
yincheng zhao2737e882019-09-06 17:06:54 -07004207 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004208 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004209 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004210 } finally {
4211 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004212 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004213 }
4214
yincheng zhao2737e882019-09-06 17:06:54 -07004215 /**
4216 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4217 * subscription.
4218 *
4219 * @param subId the id of the subscription.
4220 * @param appType the uicc app type, must be USIM or SIM.
4221 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4222 * @param callingPackage the op Package name.
4223 * @return number of fplmns that is successfully written to the SIM.
4224 */
4225 public int setForbiddenPlmns(
4226 int subId, int appType, List<String> fplmns, String callingPackage) {
4227 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
4228 mApp, subId, callingPackage, "setForbiddenPlmns")) {
4229 if (DBG) logv("no permissions for setForbiddenplmns");
4230 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4231 }
4232 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4233 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4234 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4235 }
4236 if (fplmns == null) {
4237 throw new IllegalArgumentException("Fplmn List provided is null");
4238 }
4239 for (String fplmn : fplmns) {
4240 if (!CellIdentity.isValidPlmn(fplmn)) {
4241 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4242 }
4243 }
4244 final long identity = Binder.clearCallingIdentity();
4245 try {
4246 Object response = sendRequest(
4247 CMD_SET_FORBIDDEN_PLMNS,
4248 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4249 subId);
4250 return (int) response;
4251 } finally {
4252 Binder.restoreCallingIdentity(identity);
4253 }
4254 }
4255
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004257 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4259 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004260
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004261 final long identity = Binder.clearCallingIdentity();
4262 try {
4263 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4264 if (response.payload == null) {
4265 return "";
4266 }
Evan Charltonc66da362014-05-16 14:06:40 -07004267
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004268 // Append the returned status code to the end of the response payload.
4269 String s = Integer.toHexString(
4270 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4271 s = IccUtils.bytesToHexString(response.payload) + s;
4272 return s;
4273 } finally {
4274 Binder.restoreCallingIdentity(identity);
4275 }
Evan Charltonc66da362014-05-16 14:06:40 -07004276 }
4277
Jake Hambye994d462014-02-03 13:10:13 -08004278 /**
4279 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4280 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4281 *
4282 * @param itemID the ID of the item to read
4283 * @return the NV item as a String, or null on error.
4284 */
4285 @Override
4286 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004287 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4289 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004290
4291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004294 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004295 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4296 return value;
4297 } finally {
4298 Binder.restoreCallingIdentity(identity);
4299 }
Jake Hambye994d462014-02-03 13:10:13 -08004300 }
4301
4302 /**
4303 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4304 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4305 *
4306 * @param itemID the ID of the item to read
4307 * @param itemValue the value to write, as a String
4308 * @return true on success; false on any failure
4309 */
4310 @Override
4311 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004313 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4314 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004315
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4319 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004320 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004321 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4322 return success;
4323 } finally {
4324 Binder.restoreCallingIdentity(identity);
4325 }
Jake Hambye994d462014-02-03 13:10:13 -08004326 }
4327
4328 /**
4329 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4330 * Used for device configuration by some CDMA operators.
4331 *
4332 * @param preferredRoamingList byte array containing the new PRL
4333 * @return true on success; false on any failure
4334 */
4335 @Override
4336 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004337 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4338 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339
4340 final long identity = Binder.clearCallingIdentity();
4341 try {
4342 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4343 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4344 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4345 return success;
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
Jake Hambye994d462014-02-03 13:10:13 -08004349 }
4350
4351 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004352 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004353 * Used for device configuration by some CDMA operators.
4354 *
chen xu6dac5ab2018-10-26 17:39:23 -07004355 * @param slotIndex - device slot.
4356 *
Jake Hambye994d462014-02-03 13:10:13 -08004357 * @return true on success; false on any failure
4358 */
4359 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004360 public boolean resetModemConfig(int slotIndex) {
4361 Phone phone = PhoneFactory.getPhone(slotIndex);
4362 if (phone != null) {
4363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4364 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004365
chen xu6dac5ab2018-10-26 17:39:23 -07004366 final long identity = Binder.clearCallingIdentity();
4367 try {
4368 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4369 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4370 return success;
4371 } finally {
4372 Binder.restoreCallingIdentity(identity);
4373 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004374 }
chen xu6dac5ab2018-10-26 17:39:23 -07004375 return false;
4376 }
4377
4378 /**
4379 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4380 *
4381 * @param slotIndex - device slot.
4382 *
4383 * @return true on success; false on any failure
4384 */
4385 @Override
4386 public boolean rebootModem(int slotIndex) {
4387 Phone phone = PhoneFactory.getPhone(slotIndex);
4388 if (phone != null) {
4389 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4390 mApp, phone.getSubId(), "rebootModem");
4391
4392 final long identity = Binder.clearCallingIdentity();
4393 try {
4394 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4395 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4396 return success;
4397 } finally {
4398 Binder.restoreCallingIdentity(identity);
4399 }
4400 }
4401 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004402 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004403
Svet Ganovb320e182015-04-16 12:30:10 -07004404 public String[] getPcscfAddress(String apnType, String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004405 final Phone defaultPhone = getDefaultPhone();
Jeff Davidson7e17e312018-02-13 18:17:36 -08004406 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004407 mApp, defaultPhone.getSubId(), callingPackage, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004408 return new String[0];
4409 }
4410
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 final long identity = Binder.clearCallingIdentity();
4412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004413 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004414 } finally {
4415 Binder.restoreCallingIdentity(identity);
4416 }
Wink Saville36469e72014-06-11 15:17:00 -07004417 }
4418
Brad Ebinger51f743a2017-01-23 13:50:20 -08004419 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004420 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4421 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004422 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004423 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004424 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004425
4426 final long identity = Binder.clearCallingIdentity();
4427 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004428 ImsResolver resolver = PhoneFactory.getImsResolver();
4429 if (resolver == null) {
4430 // may happen if the device does not support IMS.
4431 return;
4432 }
4433 resolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 } finally {
4435 Binder.restoreCallingIdentity(identity);
4436 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004437 }
4438
4439 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004440 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4441 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004442 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004443 public void disableIms(int slotId) {
4444 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445
4446 final long identity = Binder.clearCallingIdentity();
4447 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004448 ImsResolver resolver = PhoneFactory.getImsResolver();
4449 if (resolver == null) {
4450 // may happen if the device does not support IMS.
4451 return;
4452 }
4453 resolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 } finally {
4455 Binder.restoreCallingIdentity(identity);
4456 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004457 }
4458
4459 /**
4460 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4461 * feature or {@link null} if the service is not available. If the feature is available, the
4462 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4463 */
4464 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004465 IImsServiceFeatureCallback callback) {
4466 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004467
4468 final long identity = Binder.clearCallingIdentity();
4469 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004470 ImsResolver resolver = PhoneFactory.getImsResolver();
4471 if (resolver == null) {
4472 // may happen if the device does not support IMS.
4473 return null;
4474 }
4475 return resolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004476 } finally {
4477 Binder.restoreCallingIdentity(identity);
4478 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004479 }
4480
4481 /**
4482 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4483 * feature during emergency calling or {@link null} if the service is not available. If the
4484 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4485 * listener for feature updates.
4486 */
4487 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4488 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004489
4490 final long identity = Binder.clearCallingIdentity();
4491 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004492 ImsResolver resolver = PhoneFactory.getImsResolver();
4493 if (resolver == null) {
4494 // may happen if the device does not support IMS.
4495 return null;
4496 }
4497 return resolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004501 }
4502
Brad Ebinger5f64b052017-12-14 14:26:15 -08004503 /**
4504 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004505 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004506 */
4507 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4508 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004509
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004512 ImsResolver resolver = PhoneFactory.getImsResolver();
4513 if (resolver == null) {
4514 // may happen if the device does not support IMS.
4515 return null;
4516 }
4517 return resolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004521 }
4522
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 /**
4524 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004525 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004526 */
4527 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4528 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004529
4530 final long identity = Binder.clearCallingIdentity();
4531 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004532 ImsResolver resolver = PhoneFactory.getImsResolver();
4533 if (resolver == null) {
4534 // may happen if the device does not support IMS.
4535 return null;
4536 }
4537 return resolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004538 } finally {
4539 Binder.restoreCallingIdentity(identity);
4540 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004541 }
4542
Brad Ebinger884c07b2018-02-15 16:17:40 -08004543 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004544 * Sets the ImsService Package Name that Telephony will bind to.
4545 *
4546 * @param slotId the slot ID that the ImsService should bind for.
4547 * @param isCarrierImsService true if the ImsService is the carrier override, false if the
4548 * ImsService is the device default ImsService.
4549 * @param packageName The package name of the application that contains the ImsService to bind
4550 * to.
4551 * @return true if setting the ImsService to bind to succeeded, false if it did not.
4552 * @hide
4553 */
4554 public boolean setImsService(int slotId, boolean isCarrierImsService, String packageName) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004555 int[] subIds = SubscriptionManager.getSubId(slotId);
4556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4557 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4558 "setImsService");
4559
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 final long identity = Binder.clearCallingIdentity();
4561 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004562 ImsResolver resolver = PhoneFactory.getImsResolver();
4563 if (resolver == null) {
4564 // may happen if the device does not support IMS.
4565 return false;
4566 }
4567 return resolver.overrideImsServiceConfiguration(slotId, isCarrierImsService,
4568 packageName);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 } finally {
4570 Binder.restoreCallingIdentity(identity);
4571 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004572 }
4573
4574 /**
4575 * Return the ImsService configuration.
4576 *
4577 * @param slotId The slot that the ImsService is associated with.
4578 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4579 * the device default.
4580 * @return the package name of the ImsService configuration.
4581 */
4582 public String getImsService(int slotId, boolean isCarrierImsService) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004583 int[] subIds = SubscriptionManager.getSubId(slotId);
4584 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4585 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4586 "getImsService");
4587
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 final long identity = Binder.clearCallingIdentity();
4589 try {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004590 ImsResolver resolver = PhoneFactory.getImsResolver();
4591 if (resolver == null) {
4592 // may happen if the device does not support IMS.
4593 return "";
4594 }
4595 return resolver.getImsServiceConfiguration(slotId, isCarrierImsService);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 } finally {
4597 Binder.restoreCallingIdentity(identity);
4598 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004599 }
4600
Brad Ebingerbc7dd582019-10-17 17:03:22 -07004601 /**
4602 * Get the MmTelFeature state associated with the requested subscription id.
4603 * @param subId The subscription that the MmTelFeature is associated with.
4604 * @param callback A callback with an integer containing the
4605 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4606 */
4607 @Override
4608 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4609 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4610 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4611 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4612 "IMS not available on device.");
4613 }
4614 final long token = Binder.clearCallingIdentity();
4615 try {
4616 int slotId = getSlotIndex(subId);
4617 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4618 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4619 + subId + "'");
4620 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4621 }
4622 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4623 try {
4624 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4625 } catch (RemoteException e) {
4626 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4627 + "Ignore");
4628 }
4629 });
4630 } finally {
4631 Binder.restoreCallingIdentity(token);
4632 }
4633 }
4634
Wink Saville36469e72014-06-11 15:17:00 -07004635 public void setImsRegistrationState(boolean registered) {
4636 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637
4638 final long identity = Binder.clearCallingIdentity();
4639 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004640 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 } finally {
4642 Binder.restoreCallingIdentity(identity);
4643 }
Wink Saville36469e72014-06-11 15:17:00 -07004644 }
4645
4646 /**
Stuart Scott54788802015-03-30 13:18:01 -07004647 * Set the network selection mode to automatic.
4648 *
4649 */
4650 @Override
4651 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004652 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4653 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654
Pengquan Menge92a50d2018-09-21 15:54:48 -07004655 if (!isActiveSubscription(subId)) {
4656 return;
4657 }
4658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 final long identity = Binder.clearCallingIdentity();
4660 try {
4661 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4662 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4663 } finally {
4664 Binder.restoreCallingIdentity(identity);
4665 }
Stuart Scott54788802015-03-30 13:18:01 -07004666 }
4667
Pengquan Mengea84e042018-09-20 14:57:26 -07004668 /**
4669 * Ask the radio to connect to the input network and change selection mode to manual.
4670 *
4671 * @param subId the id of the subscription.
4672 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4673 * the operator to attach to.
4674 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4675 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4676 * normal network selection next time.
4677 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004678 */
4679 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004680 public boolean setNetworkSelectionModeManual(
4681 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004682 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4683 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004684
4685 if (!isActiveSubscription(subId)) {
4686 return false;
4687 }
4688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004689 final long identity = Binder.clearCallingIdentity();
4690 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004691 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004692 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004693 if (DBG) {
4694 log("setNetworkSelectionModeManual: subId: " + subId
4695 + " operator: " + operatorInfo);
4696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
4700 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004701 }
4702
4703 /**
4704 * Scans for available networks.
4705 */
4706 @Override
Hall Liuf19c44f2018-11-27 14:38:17 -08004707 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4709 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004710 LocationAccessPolicy.LocationPermissionResult locationResult =
4711 LocationAccessPolicy.checkLocationPermission(mApp,
4712 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4713 .setCallingPackage(callingPackage)
4714 .setCallingPid(Binder.getCallingPid())
4715 .setCallingUid(Binder.getCallingUid())
4716 .setMethod("getCellNetworkScanResults")
4717 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4718 .build());
4719 switch (locationResult) {
4720 case DENIED_HARD:
4721 throw new SecurityException("Not allowed to access scan results -- location");
4722 case DENIED_SOFT:
4723 return null;
4724 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725
Pengquan Menga1bb6272018-09-06 09:59:22 -07004726 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004727 try {
4728 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004729 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004730 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 } finally {
4732 Binder.restoreCallingIdentity(identity);
4733 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004734 }
4735
4736 /**
yinxub1bed742017-04-17 11:45:04 -07004737 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004738 *
yinxub1bed742017-04-17 11:45:04 -07004739 * @param subId id of the subscription
4740 * @param request contains the radio access networks with bands/channels to scan
4741 * @param messenger callback messenger for scan results or errors
4742 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004743 * @return the id of the requested scan which can be used to stop the scan.
4744 */
4745 @Override
4746 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Hall Liuf19c44f2018-11-27 14:38:17 -08004747 IBinder binder, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4749 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004750 LocationAccessPolicy.LocationPermissionResult locationResult =
4751 LocationAccessPolicy.checkLocationPermission(mApp,
4752 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4753 .setCallingPackage(callingPackage)
4754 .setCallingPid(Binder.getCallingPid())
4755 .setCallingUid(Binder.getCallingUid())
4756 .setMethod("requestNetworkScan")
4757 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4758 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004759 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004760 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004761 if (e != null) {
4762 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4763 throw e;
4764 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004765 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004766 return TelephonyScanManager.INVALID_SCAN_ID;
4767 }
4768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004769 }
Hall Liu912dfd32019-04-25 14:02:26 -07004770 int callingUid = Binder.getCallingUid();
4771 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 return mNetworkScanRequestTracker.startNetworkScan(
4775 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004776 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004777 } finally {
4778 Binder.restoreCallingIdentity(identity);
4779 }
yinxu504e1392017-04-12 16:03:22 -07004780 }
4781
Hall Liub2ac8ef2019-02-28 15:56:23 -08004782 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004783 NetworkScanRequest request, int subId) {
4784 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4785 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4786 boolean hasNetworkScanPermission =
4787 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4788 == PERMISSION_GRANTED;
4789
4790 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4791 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4792 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004793 }
4794
4795 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4796 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004797 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4798 return new SecurityException("Specific channels must not be"
4799 + " scanned without location access.");
4800 }
4801 }
4802 }
4803
Hall Liub2ac8ef2019-02-28 15:56:23 -08004804 return null;
4805 }
4806
yinxu504e1392017-04-12 16:03:22 -07004807 /**
4808 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004809 *
4810 * @param subId id of the subscription
4811 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004812 */
4813 @Override
4814 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4816 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817
Hall Liu912dfd32019-04-25 14:02:26 -07004818 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 final long identity = Binder.clearCallingIdentity();
4820 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004821 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
yinxu504e1392017-04-12 16:03:22 -07004825 }
4826
4827 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004828 * Get the calculated preferred network type.
4829 * Used for debugging incorrect network type.
4830 *
4831 * @return the preferred network type, defined in RILConstants.java.
4832 */
4833 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07004834 public int getCalculatedPreferredNetworkType(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004835 final Phone defaultPhone = getDefaultPhone();
4836 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4837 callingPackage, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004838 return RILConstants.PREFERRED_NETWORK_MODE;
4839 }
4840
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004844 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845 } finally {
4846 Binder.restoreCallingIdentity(identity);
4847 }
Junda Liu84d15a22014-07-02 11:21:04 -07004848 }
4849
4850 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004851 * Get the preferred network type.
4852 * Used for device configuration by some CDMA operators.
4853 *
4854 * @return the preferred network type, defined in RILConstants.java.
4855 */
4856 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004857 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004858 TelephonyPermissions
4859 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4860 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861
4862 final long identity = Binder.clearCallingIdentity();
4863 try {
4864 if (DBG) log("getPreferredNetworkType");
4865 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4866 int networkType = (result != null ? result[0] : -1);
4867 if (DBG) log("getPreferredNetworkType: " + networkType);
4868 return networkType;
4869 } finally {
4870 Binder.restoreCallingIdentity(identity);
4871 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004872 }
4873
4874 /**
4875 * Set the preferred network type.
4876 * Used for device configuration by some CDMA operators.
4877 *
4878 * @param networkType the preferred network type, defined in RILConstants.java.
4879 * @return true on success; false on any failure.
4880 */
4881 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004882 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4884 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004885
4886 final long identity = Binder.clearCallingIdentity();
4887 try {
4888 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4889 Boolean success = (Boolean) sendRequest(
4890 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4891 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4892 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004893 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004894 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4895 }
4896 return success;
4897 } finally {
4898 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004899 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004900 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004901
4902 /**
Miaoa84611c2019-03-15 09:21:10 +08004903 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004904 *
Miaoa84611c2019-03-15 09:21:10 +08004905 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004906 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004907 * @hide
4908 */
4909 @Override
Miaoa84611c2019-03-15 09:21:10 +08004910 public boolean getTetherApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004911 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004912 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08004913 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 try {
Miaoa84611c2019-03-15 09:21:10 +08004915 if (phone != null) {
4916 return phone.hasMatchedTetherApnSetting();
4917 } else {
4918 return false;
4919 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004920 } finally {
4921 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08004922 }
Junda Liu475951f2014-11-07 16:45:03 -08004923 }
4924
4925 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07004926 * Set mobile data enabled
4927 * Used by the user through settings etc to turn on/off mobile data
4928 *
4929 * @param enable {@code true} turn turn data on, else {@code false}
4930 */
4931 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004932 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004933 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4934 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004935
4936 final long identity = Binder.clearCallingIdentity();
4937 try {
4938 int phoneId = mSubscriptionController.getPhoneId(subId);
4939 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4940 Phone phone = PhoneFactory.getPhone(phoneId);
4941 if (phone != null) {
4942 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08004943 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004945 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004946 }
4947 } finally {
4948 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08004949 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004950 }
4951
4952 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08004953 * Get the user enabled state of Mobile Data.
4954 *
4955 * TODO: remove and use isUserDataEnabled.
4956 * This can't be removed now because some vendor codes
4957 * calls through ITelephony directly while they should
4958 * use TelephonyManager.
4959 *
4960 * @return true on enabled
4961 */
4962 @Override
4963 public boolean getDataEnabled(int subId) {
4964 return isUserDataEnabled(subId);
4965 }
4966
4967 /**
4968 * Get whether mobile data is enabled per user setting.
4969 *
4970 * There are other factors deciding whether mobile data is actually enabled, but they are
4971 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07004972 *
Jeff Davidsona1920712016-11-18 17:05:56 -08004973 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07004974 *
4975 * @return {@code true} if data is enabled else {@code false}
4976 */
4977 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08004978 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07004979 try {
4980 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
4981 null);
4982 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07004985 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004986
4987 final long identity = Binder.clearCallingIdentity();
4988 try {
4989 int phoneId = mSubscriptionController.getPhoneId(subId);
4990 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
4991 Phone phone = PhoneFactory.getPhone(phoneId);
4992 if (phone != null) {
4993 boolean retVal = phone.isUserDataEnabled();
4994 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
4995 return retVal;
4996 } else {
4997 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
4998 return false;
4999 }
5000 } finally {
5001 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005002 }
5003 }
5004
5005 /**
5006 * Get whether mobile data is enabled.
5007 *
5008 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5009 * whether mobile data is actually enabled.
5010 *
5011 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5012 *
5013 * @return {@code true} if data is enabled else {@code false}
5014 */
5015 @Override
5016 public boolean isDataEnabled(int subId) {
5017 try {
5018 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5019 null);
5020 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005021 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5022 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 int phoneId = mSubscriptionController.getPhoneId(subId);
5028 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5029 Phone phone = PhoneFactory.getPhone(phoneId);
5030 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005031 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5033 return retVal;
5034 } else {
5035 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5036 return false;
5037 }
5038 } finally {
5039 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005040 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005041 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005042
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005043 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5044 Phone phone) {
5045 //load access rules from carrier configs, and check those as well: b/139133814
5046 SubscriptionController subController = SubscriptionController.getInstance();
5047 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5048 || subController == null) return privilegeFromSim;
5049
5050 int uid = Binder.getCallingUid();
5051 PackageManager pkgMgr = phone.getContext().getPackageManager();
5052 String[] packages = pkgMgr.getPackagesForUid(uid);
5053
5054 final long identity = Binder.clearCallingIdentity();
5055 try {
5056 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5057 SubscriptionManager subManager = (SubscriptionManager)
5058 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5059 for (String pkg : packages) {
5060 if (subManager.canManageSubscription(subInfo, pkg)) {
5061 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5062 }
5063 }
5064 return privilegeFromSim;
5065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
5068 }
5069
5070 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5071 String pkgName) {
5072 //load access rules from carrier configs, and check those as well: b/139133814
5073 SubscriptionController subController = SubscriptionController.getInstance();
5074 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5075 || subController == null) return privilegeFromSim;
5076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
5079 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5080 SubscriptionManager subManager = (SubscriptionManager)
5081 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5082 return subManager.canManageSubscription(subInfo, pkgName)
5083 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
5087 }
5088
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005089 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005090 public int getCarrierPrivilegeStatus(int subId) {
5091 final Phone phone = getPhone(subId);
5092 if (phone == null) {
5093 loge("getCarrierPrivilegeStatus: Invalid subId");
5094 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5095 }
5096 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005097 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005098 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005099 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5100 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005101
5102 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5103 card.getCarrierPrivilegeStatusForCurrentTransaction(
5104 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005105 }
Junda Liu29340342014-07-10 15:23:27 -07005106
5107 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5109 final Phone phone = getPhone(subId);
5110 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005111 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005112 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5113 }
5114 UiccProfile profile =
5115 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5116 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005117 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005118 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5119 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005120 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5121 profile.getCarrierPrivilegeStatusForUid(
5122 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005123 }
5124
5125 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005126 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5127 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005128 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005129 }
5130
5131 int phoneId = SubscriptionManager.getPhoneId(subId);
5132 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005133 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005134 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005135 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5136 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005137 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5138 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5139 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005140 }
5141
5142 @Override
5143 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005144 if (TextUtils.isEmpty(pkgName))
5145 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005146 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5147 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5148 UiccCard card = UiccController.getInstance().getUiccCard(i);
5149 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005150 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005151 continue;
5152 }
5153
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005154 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5155 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5156 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005157 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5158 break;
5159 }
5160 }
5161
5162 return result;
Junda Liu29340342014-07-10 15:23:27 -07005163 }
Derek Tan89e89d42014-07-08 17:00:10 -07005164
5165 @Override
Junda Liue64de782015-04-16 17:19:16 -07005166 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5167 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5168 loge("phoneId " + phoneId + " is not valid.");
5169 return null;
5170 }
5171 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005172 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005173 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005174 return null ;
5175 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005176 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005177 }
5178
Amith Yamasani6e118872016-02-19 12:53:51 -08005179 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005180 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005181 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005182 List<String> privilegedPackages = new ArrayList<>();
5183 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005184 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5185 // has UICC in that slot.
5186 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005187 if (card.hasCarrierPrivilegeRules()) {
5188 if (packages == null) {
5189 // Only check packages in user 0 for now
5190 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005191 PackageManager.MATCH_DISABLED_COMPONENTS
5192 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005193 | PackageManager.GET_SIGNING_CERTIFICATES,
5194 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005195 }
5196 for (int p = packages.size() - 1; p >= 0; p--) {
5197 PackageInfo pkgInfo = packages.get(p);
5198 if (pkgInfo != null && pkgInfo.packageName != null
5199 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005200 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005201 privilegedPackages.add(pkgInfo.packageName);
5202 }
5203 }
5204 }
5205 }
5206 return privilegedPackages;
5207 }
5208
chen xuf7e9fe82019-05-09 19:31:02 -07005209 @Override
5210 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
5211 List<String> privilegedPackages = new ArrayList<>();
5212 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5213 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5214 }
5215 return privilegedPackages;
5216 }
5217
Wink Savilleb564aae2014-10-23 10:18:09 -07005218 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005219 final Phone phone = getPhone(subId);
5220 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005221 if (card == null) {
5222 loge("getIccId: No UICC");
5223 return null;
5224 }
5225 String iccId = card.getIccId();
5226 if (TextUtils.isEmpty(iccId)) {
5227 loge("getIccId: ICC ID is null or empty.");
5228 return null;
5229 }
5230 return iccId;
5231 }
5232
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005233 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005234 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5235 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5237 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
5241 final String iccId = getIccId(subId);
5242 final Phone phone = getPhone(subId);
5243 if (phone == null) {
5244 return false;
5245 }
5246 final String subscriberId = phone.getSubscriberId();
5247
5248 if (DBG_MERGE) {
5249 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5250 + subscriberId + " to " + number);
5251 }
5252
5253 if (TextUtils.isEmpty(iccId)) {
5254 return false;
5255 }
5256
5257 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5258
5259 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5260 if (alphaTag == null) {
5261 editor.remove(alphaTagPrefKey);
5262 } else {
5263 editor.putString(alphaTagPrefKey, alphaTag);
5264 }
5265
5266 // Record both the line number and IMSI for this ICCID, since we need to
5267 // track all merged IMSIs based on line number
5268 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5269 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5270 if (number == null) {
5271 editor.remove(numberPrefKey);
5272 editor.remove(subscriberPrefKey);
5273 } else {
5274 editor.putString(numberPrefKey, number);
5275 editor.putString(subscriberPrefKey, subscriberId);
5276 }
5277
5278 editor.commit();
5279 return true;
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005282 }
Derek Tan7226c842014-07-02 17:42:23 -07005283 }
5284
5285 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005286 public String getLine1NumberForDisplay(int subId, String callingPackage) {
Makoto Onukifee69342015-06-29 14:44:50 -07005287 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005288 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Jeff Davidson913390f2018-02-23 17:11:49 -08005289 mApp, subId, callingPackage, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005290 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005291 return null;
5292 }
Derek Tan97ebb422014-09-05 16:55:38 -07005293
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294 final long identity = Binder.clearCallingIdentity();
5295 try {
5296 String iccId = getIccId(subId);
5297 if (iccId != null) {
5298 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5299 if (DBG_MERGE) {
5300 log("getLine1NumberForDisplay returning "
5301 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5302 }
5303 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5306 return null;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005309 }
Derek Tan7226c842014-07-02 17:42:23 -07005310 }
5311
5312 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005313 public String getLine1AlphaTagForDisplay(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005314 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005315 mApp, subId, callingPackage, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005316 return null;
5317 }
Derek Tan97ebb422014-09-05 16:55:38 -07005318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 final long identity = Binder.clearCallingIdentity();
5320 try {
5321 String iccId = getIccId(subId);
5322 if (iccId != null) {
5323 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5324 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5325 }
5326 return null;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005329 }
Derek Tan7226c842014-07-02 17:42:23 -07005330 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005331
5332 @Override
Jordan Liub49b04b2019-05-06 14:45:15 -07005333 public String[] getMergedSubscriberIds(int subId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005334 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5335 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005337 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
5338 "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005339 return null;
5340 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005341
Jordan Liub49b04b2019-05-06 14:45:15 -07005342 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5343 // the process, where TelephonyManager was instantiated.
5344 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005345 final long identity = Binder.clearCallingIdentity();
5346 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005347 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005348 final TelephonyManager tele = TelephonyManager.from(context);
5349 final SubscriptionManager sub = SubscriptionManager.from(context);
5350
5351 // Figure out what subscribers are currently active
5352 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005353
Jordan Liub49b04b2019-05-06 14:45:15 -07005354 // Only consider subs which match the current subId
5355 // This logic can be simplified. See b/131189269 for progress.
5356 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005357 activeSubscriberIds.add(tele.getSubscriberId(subId));
5358 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359
5360 // First pass, find a number override for an active subscriber
5361 String mergeNumber = null;
5362 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5363 for (String key : prefs.keySet()) {
5364 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5365 final String subscriberId = (String) prefs.get(key);
5366 if (activeSubscriberIds.contains(subscriberId)) {
5367 final String iccId = key.substring(
5368 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5369 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5370 mergeNumber = (String) prefs.get(numberKey);
5371 if (DBG_MERGE) {
5372 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5373 + " for active subscriber " + subscriberId);
5374 }
5375 if (!TextUtils.isEmpty(mergeNumber)) {
5376 break;
5377 }
5378 }
5379 }
5380 }
5381
5382 // Shortcut when no active merged subscribers
5383 if (TextUtils.isEmpty(mergeNumber)) {
5384 return null;
5385 }
5386
5387 // Second pass, find all subscribers under that line override
5388 final ArraySet<String> result = new ArraySet<>();
5389 for (String key : prefs.keySet()) {
5390 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5391 final String number = (String) prefs.get(key);
5392 if (mergeNumber.equals(number)) {
5393 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5394 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5395 final String subscriberId = (String) prefs.get(subscriberKey);
5396 if (!TextUtils.isEmpty(subscriberId)) {
5397 result.add(subscriberId);
5398 }
5399 }
5400 }
5401 }
5402
5403 final String[] resultArray = result.toArray(new String[result.size()]);
5404 Arrays.sort(resultArray);
5405 if (DBG_MERGE) {
5406 Slog.d(LOG_TAG,
5407 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5408 }
5409 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005410 } finally {
5411 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005412 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005413 }
5414
5415 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005416 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5417 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 final TelephonyManager telephonyManager = mApp.getSystemService(
5422 TelephonyManager.class);
5423 String subscriberId = telephonyManager.getSubscriberId(subId);
5424 if (subscriberId == null) {
5425 if (DBG) {
5426 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5427 + subId);
5428 }
5429 return null;
5430 }
5431
5432 final SubscriptionInfo info = SubscriptionController.getInstance()
5433 .getSubscriptionInfo(subId);
5434 final ParcelUuid groupUuid = info.getGroupUuid();
5435 // If it doesn't belong to any group, return just subscriberId of itself.
5436 if (groupUuid == null) {
5437 return new String[]{subscriberId};
5438 }
5439
5440 // Get all subscriberIds from the group.
5441 final List<String> mergedSubscriberIds = new ArrayList<>();
5442 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
5443 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName());
5444 for (SubscriptionInfo subInfo : groupInfos) {
5445 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5446 if (subscriberId != null) {
5447 mergedSubscriberIds.add(subscriberId);
5448 }
5449 }
5450
5451 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5452 } finally {
5453 Binder.restoreCallingIdentity(identity);
5454
5455 }
5456 }
5457
5458 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005459 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005460 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5461 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005462
5463 final long identity = Binder.clearCallingIdentity();
5464 try {
5465 final Phone phone = getPhone(subId);
5466 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5467 } finally {
5468 Binder.restoreCallingIdentity(identity);
5469 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005470 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005471
5472 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005473 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005474 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5475 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 final Phone phone = getPhone(subId);
5481 if (phone == null) {
5482 return false;
5483 }
5484 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5485 cdmaNonRoamingList);
5486 } finally {
5487 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005488 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005489 }
5490
5491 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005492 @Deprecated
5493 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5494 enforceModifyPermission();
5495
5496 int returnValue = 0;
5497 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005498 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005499 if(result.exception == null) {
5500 if (result.result != null) {
5501 byte[] responseData = (byte[])(result.result);
5502 if(responseData.length > oemResp.length) {
5503 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5504 responseData.length + "bytes. Buffer Size is " +
5505 oemResp.length + "bytes.");
5506 }
5507 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5508 returnValue = responseData.length;
5509 }
5510 } else {
5511 CommandException ex = (CommandException) result.exception;
5512 returnValue = ex.getCommandError().ordinal();
5513 if(returnValue > 0) returnValue *= -1;
5514 }
5515 } catch (RuntimeException e) {
5516 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5517 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5518 if(returnValue > 0) returnValue *= -1;
5519 }
5520
5521 return returnValue;
5522 }
5523
5524 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005525 public void setRadioCapability(RadioAccessFamily[] rafs) {
5526 try {
5527 ProxyController.getInstance().setRadioCapability(rafs);
5528 } catch (RuntimeException e) {
5529 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5530 }
5531 }
5532
5533 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005534 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005535 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005536 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005537 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005538 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005539 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 final long identity = Binder.clearCallingIdentity();
5541 try {
chen xub97461a2018-10-26 14:17:57 -07005542 TelephonyPermissions
5543 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5544 mApp, phone.getSubId(), "getRadioAccessFamily");
5545 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
5548 }
chen xub97461a2018-10-26 14:17:57 -07005549 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005550 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005551
5552 @Override
5553 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005554 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 ImsManager.getInstance(defaultPhone.getContext(),
5560 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561 } finally {
5562 Binder.restoreCallingIdentity(identity);
5563 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005564 }
5565
5566 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005567 public boolean isVideoCallingEnabled(String callingPackage) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005568 final Phone defaultPhone = getDefaultPhone();
Amit Mahajan578e53d2018-03-20 16:18:38 +00005569 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005570 mApp, defaultPhone.getSubId(), callingPackage, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005571 return false;
5572 }
Svet Ganovb320e182015-04-16 12:30:10 -07005573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005574 final long identity = Binder.clearCallingIdentity();
5575 try {
5576 // Check the user preference and the system-level IMS setting. Even if the user has
5577 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5578 // In the long run, we may instead need to check if there exists a connection service
5579 // which can support video calling.
5580 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005581 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005582 return imsManager.isVtEnabledByPlatform()
5583 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5584 && imsManager.isVtEnabledByUser();
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
5587 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005588 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005589
Andrew Leea1239f22015-03-02 17:44:07 -08005590 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 public boolean canChangeDtmfToneLength(int subId, String callingPackage) {
5592 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5593 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5594 return false;
5595 }
5596
5597 final long identity = Binder.clearCallingIdentity();
5598 try {
5599 CarrierConfigManager configManager =
5600 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005601 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005602 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5603 } finally {
5604 Binder.restoreCallingIdentity(identity);
5605 }
Andrew Leea1239f22015-03-02 17:44:07 -08005606 }
5607
5608 @Override
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005609 public boolean isWorldPhone(int subId, String callingPackage) {
5610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
5611 mApp, subId, callingPackage, "isVideoCallingEnabled")) {
5612 return false;
5613 }
5614
5615 final long identity = Binder.clearCallingIdentity();
5616 try {
5617 CarrierConfigManager configManager =
5618 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005619 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005620 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
Andrew Leea1239f22015-03-02 17:44:07 -08005624 }
5625
Andrew Lee9431b832015-03-09 18:46:45 -07005626 @Override
5627 public boolean isTtyModeSupported() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005628 TelecomManager telecomManager = TelecomManager.from(mApp);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005629 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005630 }
5631
5632 @Override
5633 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005634 final long identity = Binder.clearCallingIdentity();
5635 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005636 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 } finally {
5638 Binder.restoreCallingIdentity(identity);
5639 }
Andrew Lee9431b832015-03-09 18:46:45 -07005640 }
5641
Hall Liuf6668912018-10-31 17:05:23 -07005642 /**
5643 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5644 * support for the feature and device firmware support.
5645 *
5646 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5647 */
5648 @Override
5649 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005650 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005651 final Phone phone = getPhone(subscriptionId);
5652 if (phone == null) {
5653 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5654 return false;
5655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005656 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005657 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5659 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005660 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 return isCarrierSupported && isDeviceSupported;
5662 } finally {
5663 Binder.restoreCallingIdentity(identity);
5664 }
Hall Liu98187582018-01-22 19:15:32 -08005665 }
5666
Hall Liuf6668912018-10-31 17:05:23 -07005667 /**
Hall Liuf2daa022019-07-23 18:39:00 -07005668 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5669 * RTT setting, will return true if the device and carrier both support RTT.
5670 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005671 */
5672 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
Hall Liuf2daa022019-07-23 18:39:00 -07005675 boolean isRttSupported = isRttSupported(subscriptionId);
5676 boolean isUserRttSettingOn = Settings.Secure.getInt(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005677 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
Hall Liuf2daa022019-07-23 18:39:00 -07005678 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
5679 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
5680 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 } finally {
5682 Binder.restoreCallingIdentity(identity);
5683 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005684 }
5685
Sanket Padawe7310cc72015-01-14 09:53:20 -08005686 /**
5687 * Returns the unique device ID of phone, for example, the IMEI for
5688 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5689 *
5690 * <p>Requires Permission:
5691 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5692 */
5693 @Override
Svet Ganovb320e182015-04-16 12:30:10 -07005694 public String getDeviceId(String callingPackage) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005695 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005696 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005697 return null;
5698 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005699 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005700 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
5701 callingPackage, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005702 return null;
5703 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704
5705 final long identity = Binder.clearCallingIdentity();
5706 try {
5707 return phone.getDeviceId();
5708 } finally {
5709 Binder.restoreCallingIdentity(identity);
5710 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005711 }
5712
Ping Sunc67b7c22016-03-02 19:16:45 +08005713 /**
5714 * {@hide}
5715 * Returns the IMS Registration Status on a particular subid
5716 *
5717 * @param subId
5718 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005719 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005720 Phone phone = getPhone(subId);
5721 if (phone != null) {
5722 return phone.isImsRegistered();
5723 } else {
5724 return false;
5725 }
5726 }
5727
Santos Cordon7a1885b2015-02-03 11:15:19 -08005728 @Override
5729 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005730 final long identity = Binder.clearCallingIdentity();
5731 try {
5732 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005736 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005737
Tyler Gunnf70ed162019-04-03 15:28:53 -07005738 @Override
5739 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5740 final long identity = Binder.clearCallingIdentity();
5741 try {
5742 Phone phone = getPhone(subscriptionId);
5743 if (phone == null) {
5744 return null;
5745 }
5746 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5747 } finally {
5748 Binder.restoreCallingIdentity(identity);
5749 }
5750 }
5751
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005752 /**
5753 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005754 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005755 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756 final long identity = Binder.clearCallingIdentity();
5757 try {
5758 Phone phone = getPhone(subId);
5759 if (phone != null) {
5760 return phone.isWifiCallingEnabled();
5761 } else {
5762 return false;
5763 }
5764 } finally {
5765 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005766 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005767 }
5768
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005769 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005770 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005771 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005772 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 Phone phone = getPhone(subId);
5776 if (phone != null) {
5777 return phone.isVideoEnabled();
5778 } else {
5779 return false;
5780 }
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005783 }
5784 }
5785
5786 /**
5787 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5788 * defined in {@link ImsRegistrationImplBase}.
5789 */
5790 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 final long identity = Binder.clearCallingIdentity();
5792 try {
5793 Phone phone = getPhone(subId);
5794 if (phone != null) {
5795 return phone.getImsRegistrationTech();
5796 } else {
5797 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5798 }
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005801 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005802 }
5803
Stuart Scott8eef64f2015-04-08 15:13:54 -07005804 @Override
5805 public void factoryReset(int subId) {
5806 enforceConnectivityInternalPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005807 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5808 return;
5809 }
5810
Svet Ganovcc087f82015-05-12 20:35:54 -07005811 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005812
Svet Ganovcc087f82015-05-12 20:35:54 -07005813 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005814 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5815 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005816 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005817 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005818 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005819 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5820 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005821 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005822 // There has been issues when Sms raw table somehow stores orphan
5823 // fragments. They lead to garbled message when new fragments come
5824 // in and combined with those stale ones. In case this happens again,
5825 // user can reset all network settings which will clean up this table.
5826 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005827 // Clean up IMS settings as well here.
5828 int slotId = getSlotIndex(subId);
5829 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5830 ImsManager.getInstance(mApp, slotId).factoryReset();
5831 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005834 }
5835 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005836
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005837 private void cleanUpSmsRawTable(Context context) {
5838 ContentResolver resolver = context.getContentResolver();
5839 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5840 resolver.delete(uri, null, null);
5841 }
5842
Narayan Kamath1c496c22015-04-16 14:40:19 +01005843 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005844 public String getSimLocaleForSubscriber(int subId) {
5845 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5846 final Phone phone = getPhone(subId);
5847 if (phone == null) {
5848 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005849 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005851 final long identity = Binder.clearCallingIdentity();
5852 try {
chen xu5d3637b2019-01-21 23:31:38 -08005853 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
5854 phone.getContext().getOpPackageName());
chen xu6291c472019-02-04 12:55:53 -08005855 if (info == null) {
5856 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5857 return null;
5858 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 // Try and fetch the locale from the carrier properties or from the SIM language
5860 // preferences (EF-PL and EF-LI)...
5861 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005862 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005863 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5864 if (localeFromDefaultSim != null) {
5865 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5866 if (DBG) log("Using locale from subId: " + subId + " locale: "
5867 + localeFromDefaultSim);
5868 return localeFromDefaultSim.toLanguageTag();
5869 } else {
5870 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005871 }
5872 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 // The SIM language preferences only store a language (e.g. fr = French), not an
5875 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
5876 // the SIM and carrier preferences does not include a country we add the country
5877 // determined from the SIM MCC to provide an exact locale.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005878 final Locale mccLocale = MccTable.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005879 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08005880 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005881 return mccLocale.toLanguageTag();
5882 }
5883
5884 if (DBG) log("No locale found - returning null");
5885 return null;
5886 } finally {
5887 Binder.restoreCallingIdentity(identity);
5888 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005889 }
5890
5891 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005892 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005893 }
5894
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005895 /**
5896 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
5897 */
5898 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005899 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName());
Narayan Kamath1c496c22015-04-16 14:40:19 +01005900 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005901
Chenjie Yu1ba97252018-01-11 18:16:20 -08005902 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07005903 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005904
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005905 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07005906 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
5907 * representing the state of the modem.
5908 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08005909 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
5910 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07005911 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005912 */
5913 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07005914 public void requestModemActivityInfo(ResultReceiver result) {
5915 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07005916 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005917
5918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 ModemActivityInfo ret = null;
5921 synchronized (mLastModemActivityInfo) {
5922 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
5923 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07005924 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07005925 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005926 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xud78231e2019-09-10 18:49:52 -07005927 int[] txTimeMs = info.getTransmitTimeMillis();
5928 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005929 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xud78231e2019-09-10 18:49:52 -07005930 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005931 }
5932 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005933 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
5934 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005935 mLastModemActivityInfo.setIdleTimeMillis(
5936 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xud78231e2019-09-10 18:49:52 -07005937 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
5938 mLastModemActivityInfo.setReceiveTimeMillis(
5939 info.getReceiveTimeMillis() + mLastModemActivityInfo
5940 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005941 }
Chen Xud78231e2019-09-10 18:49:52 -07005942
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005943 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
5944 mLastModemActivityInfo.getSleepTimeMillis(),
5945 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xud78231e2019-09-10 18:49:52 -07005946 mLastModemActivityInfo.getTransmitTimeMillis(),
5947 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08005948 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005949 Bundle bundle = new Bundle();
5950 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
5951 result.send(0, bundle);
5952 } finally {
5953 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08005954 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07005955 }
Jack Yu85bd38a2015-11-09 11:34:32 -08005956
Siddharth Rayb8114062018-06-17 15:02:38 -07005957 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
5958 // less than total activity duration.
5959 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
5960 if (info == null) {
5961 return false;
5962 }
5963 int activityDurationMs =
5964 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
5965 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07005966 int[] txTimeMs = info.getTransmitTimeMillis();
5967 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
5968 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07005969 }
5970 return (info.isValid()
5971 && (info.getSleepTimeMillis() <= activityDurationMs)
5972 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07005973 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07005974 && (totalTxTimeMs <= activityDurationMs));
5975 }
5976
Jack Yu85bd38a2015-11-09 11:34:32 -08005977 /**
5978 * {@hide}
5979 * Returns the service state information on specified subscription.
5980 */
5981 @Override
5982 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005984 mApp, subId, callingPackage, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08005985 return null;
5986 }
5987
Hall Liuf19c44f2018-11-27 14:38:17 -08005988 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
5989 LocationAccessPolicy.checkLocationPermission(mApp,
5990 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5991 .setCallingPackage(callingPackage)
5992 .setCallingPid(Binder.getCallingPid())
5993 .setCallingUid(Binder.getCallingUid())
5994 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07005995 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08005996 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5997 .build());
5998
5999 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6000 LocationAccessPolicy.checkLocationPermission(mApp,
6001 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6002 .setCallingPackage(callingPackage)
6003 .setCallingPid(Binder.getCallingPid())
6004 .setCallingUid(Binder.getCallingUid())
6005 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006006 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006007 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6008 .build());
6009 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6010 boolean hasFinePermission =
6011 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6012 boolean hasCoarsePermission =
6013 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6014
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006015 final long identity = Binder.clearCallingIdentity();
6016 try {
6017 final Phone phone = getPhone(subId);
6018 if (phone == null) {
6019 return null;
6020 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006021
Hall Liuf19c44f2018-11-27 14:38:17 -08006022 ServiceState ss = phone.getServiceState();
6023
6024 // Scrub out the location info in ServiceState depending on what level of access
6025 // the caller has.
6026 if (hasFinePermission) return ss;
6027 if (hasCoarsePermission) return ss.sanitizeLocationInfo(false);
6028 return ss.sanitizeLocationInfo(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006029 } finally {
6030 Binder.restoreCallingIdentity(identity);
6031 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006032 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006033
6034 /**
6035 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6036 *
6037 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6038 * voicemail ringtone.
6039 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6040 * PhoneAccount.
6041 */
6042 @Override
6043 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6047 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006048 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006049 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6052 } finally {
6053 Binder.restoreCallingIdentity(identity);
6054 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006055 }
6056
6057 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006058 * Sets the per-account voicemail ringtone.
6059 *
6060 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6061 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6062 *
6063 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6064 * voicemail ringtone.
6065 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6066 * PhoneAccount.
6067 */
6068 @Override
6069 public void setVoicemailRingtoneUri(String callingPackage,
6070 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006071 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6073 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006074 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6076 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6077 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006078 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6083 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006084 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006085 }
6086 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006089 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006090 }
6091
6092 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006093 * Returns whether vibration is set for voicemail notification in Phone settings.
6094 *
6095 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6096 * voicemail vibration setting.
6097 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6098 */
6099 @Override
6100 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6104 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006105 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006106 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
6111 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006112 }
6113
Youhan Wange64578a2016-05-02 15:32:42 -07006114 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006115 * Sets the per-account voicemail vibration.
6116 *
6117 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6118 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6119 *
6120 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6121 * voicemail vibration setting.
6122 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6123 * specific PhoneAccount.
6124 */
6125 @Override
6126 public void setVoicemailVibrationEnabled(String callingPackage,
6127 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006128 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006129 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
6130 if (!TextUtils.equals(callingPackage,
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006131 TelecomManager.from(defaultPhone.getContext()).getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6133 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6134 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006135 }
6136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006137 final long identity = Binder.clearCallingIdentity();
6138 try {
6139 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6140 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006141 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 }
6143 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6144 } finally {
6145 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006146 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006147 }
6148
6149 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006150 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6151 *
6152 * @throws SecurityException if the caller does not have the required permission
6153 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006154 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006155 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006156 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006157 }
6158
6159 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006160 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6161 * permission.
6162 *
6163 * @throws SecurityException if the caller does not have the required permission
6164 */
6165 private void enforceSendSmsPermission() {
6166 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6167 }
6168
6169 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006170 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006171 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006172 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006173 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006174 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006175 final long identity = Binder.clearCallingIdentity();
6176 try {
6177 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006178 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 if (componentName == null) {
6180 throw new SecurityException(
6181 "Caller not current active visual voicemail package[null]");
6182 }
6183 String vvmPackage = componentName.getPackageName();
6184 if (!callingPackage.equals(vvmPackage)) {
6185 throw new SecurityException("Caller not current active visual voicemail package["
6186 + vvmPackage + "]");
6187 }
6188 } finally {
6189 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006190 }
6191 }
6192
6193 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006194 * Return the application ID for the app type.
6195 *
6196 * @param subId the subscription ID that this request applies to.
6197 * @param appType the uicc app type.
6198 * @return Application ID for specificied app type, or null if no uicc.
6199 */
6200 @Override
6201 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006202 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006203 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204
6205 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006206 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006207 if (phone == null) {
6208 return null;
6209 }
6210 String aid = null;
6211 try {
6212 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6213 .getApplicationByType(appType).getAid();
6214 } catch (Exception e) {
6215 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6216 }
6217 return aid;
6218 } finally {
6219 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006220 }
Youhan Wange64578a2016-05-02 15:32:42 -07006221 }
6222
Youhan Wang4001d252016-05-11 10:29:41 -07006223 /**
6224 * Return the Electronic Serial Number.
6225 *
6226 * @param subId the subscription ID that this request applies to.
6227 * @return ESN or null if error.
6228 */
6229 @Override
6230 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006231 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006232 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006233
6234 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006235 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 if (phone == null) {
6237 return null;
6238 }
6239 String esn = null;
6240 try {
6241 esn = phone.getEsn();
6242 } catch (Exception e) {
6243 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6244 }
6245 return esn;
6246 } finally {
6247 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006248 }
Youhan Wang4001d252016-05-11 10:29:41 -07006249 }
6250
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006251 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006252 * Return the Preferred Roaming List Version.
6253 *
6254 * @param subId the subscription ID that this request applies to.
6255 * @return PRLVersion or null if error.
6256 */
6257 @Override
6258 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006259 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006260 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261
6262 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006263 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006264 if (phone == null) {
6265 return null;
6266 }
6267 String cdmaPrlVersion = null;
6268 try {
6269 cdmaPrlVersion = phone.getCdmaPrlVersion();
6270 } catch (Exception e) {
6271 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6272 }
6273 return cdmaPrlVersion;
6274 } finally {
6275 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006276 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006277 }
6278
6279 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006280 * Get snapshot of Telephony histograms
6281 * @return List of Telephony histograms
6282 * @hide
6283 */
6284 @Override
6285 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6287 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006288
6289 final long identity = Binder.clearCallingIdentity();
6290 try {
6291 return RIL.getTelephonyRILTimingHistograms();
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
6294 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006295 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006296
6297 /**
6298 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006299 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6300 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006301 * Require system privileges. In the future we may add this to carrier APIs.
6302 *
Michele Berionne482f8202018-11-27 18:57:59 -08006303 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006304 */
6305 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006306 @TelephonyManager.SetCarrierRestrictionResult
6307 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006308 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006310
Michele Berionne482f8202018-11-27 18:57:59 -08006311 if (carrierRestrictionRules == null) {
6312 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006313 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006314
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006315 final long identity = Binder.clearCallingIdentity();
6316 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006317 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006318 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319 } finally {
6320 Binder.restoreCallingIdentity(identity);
6321 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006322 }
6323
6324 /**
6325 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006326 * Get the allowed carrier list and the excluded carrier list, including the priority between
6327 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006328 * Require system privileges. In the future we may add this to carrier APIs.
6329 *
Michele Berionne482f8202018-11-27 18:57:59 -08006330 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006331 */
6332 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006333 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006334 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336
6337 final long identity = Binder.clearCallingIdentity();
6338 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006339 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6340 if (response instanceof CarrierRestrictionRules) {
6341 return (CarrierRestrictionRules) response;
6342 }
6343 // Response is an Exception of some kind,
6344 // which is signalled to the user as a NULL retval
6345 return null;
6346 } catch (Exception e) {
6347 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6348 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006349 } finally {
6350 Binder.restoreCallingIdentity(identity);
6351 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006352 }
6353
fionaxu59545b42016-05-25 15:53:37 -07006354 /**
6355 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6356 * @param subId the subscription ID that this action applies to.
6357 * @param enabled control enable or disable metered apns.
6358 * {@hide}
6359 */
6360 @Override
6361 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6362 enforceModifyPermission();
6363 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364
6365 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006366 if (phone == null) {
6367 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6368 return;
6369 }
6370 try {
6371 phone.carrierActionSetMeteredApnsEnabled(enabled);
6372 } catch (Exception e) {
6373 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006374 } finally {
6375 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006376 }
6377 }
6378
6379 /**
6380 * Action set from carrier signalling broadcast receivers to enable/disable radio
6381 * @param subId the subscription ID that this action applies to.
6382 * @param enabled control enable or disable radio.
6383 * {@hide}
6384 */
6385 @Override
6386 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6387 enforceModifyPermission();
6388 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006391 if (phone == null) {
6392 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6393 return;
6394 }
6395 try {
6396 phone.carrierActionSetRadioEnabled(enabled);
6397 } catch (Exception e) {
6398 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 } finally {
6400 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006401 }
6402 }
6403
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006404 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006405 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6406 * network status based on which carrier apps could apply actions accordingly,
6407 * enable/disable default url handler for example.
6408 *
6409 * @param subId the subscription ID that this action applies to.
6410 * @param report control start/stop reporting the default network status.
6411 * {@hide}
6412 */
6413 @Override
6414 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6415 enforceModifyPermission();
6416 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417
6418 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006419 if (phone == null) {
6420 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6421 return;
6422 }
6423 try {
6424 phone.carrierActionReportDefaultNetworkStatus(report);
6425 } catch (Exception e) {
6426 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 } finally {
6428 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006429 }
6430 }
6431
6432 /**
fionaxud9622282017-07-17 17:51:30 -07006433 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6434 * @param subId the subscription ID that this action applies to.
6435 * {@hide}
6436 */
6437 @Override
6438 public void carrierActionResetAll(int subId) {
6439 enforceModifyPermission();
6440 final Phone phone = getPhone(subId);
6441 if (phone == null) {
6442 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6443 return;
6444 }
6445 try {
6446 phone.carrierActionResetAll();
6447 } catch (Exception e) {
6448 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6449 }
6450 }
6451
6452 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006453 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6454 * bug report is being generated.
6455 */
6456 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006457 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006458 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6459 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006460 writer.println("Permission Denial: can't dump Phone from pid="
6461 + Binder.getCallingPid()
6462 + ", uid=" + Binder.getCallingUid()
6463 + "without permission "
6464 + android.Manifest.permission.DUMP);
6465 return;
6466 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006467 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006468 }
Jack Yueb89b242016-06-22 13:27:47 -07006469
Brad Ebingerdac2f002018-04-03 15:17:52 -07006470 @Override
6471 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6472 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6473 throws RemoteException {
6474 (new TelephonyShellCommand(this)).exec(this, in, out, err, args, callback, resultReceiver);
6475 }
6476
Jack Yueb89b242016-06-22 13:27:47 -07006477 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006478 * Get aggregated video call data usage since boot.
6479 *
6480 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6481 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006482 * {@hide}
6483 */
6484 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006485 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006486 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6487 null);
6488
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 final long identity = Binder.clearCallingIdentity();
6490 try {
6491 // NetworkStatsService keeps tracking the active network interface and identity. It
6492 // records the delta with the corresponding network identity.
6493 // We just return the total video call data usage snapshot since boot.
6494 Phone phone = getPhone(subId);
6495 if (phone != null) {
6496 return phone.getVtDataUsage(perUidStats);
6497 }
6498 return null;
6499 } finally {
6500 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006501 }
Jack Yueb89b242016-06-22 13:27:47 -07006502 }
Jack Yu75ab2952016-07-08 14:29:33 -07006503
6504 /**
6505 * Policy control of data connection. Usually used when data limit is passed.
6506 * @param enabled True if enabling the data, otherwise disabling.
6507 * @param subId Subscription index
6508 * {@hide}
6509 */
6510 @Override
6511 public void setPolicyDataEnabled(boolean enabled, int subId) {
6512 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006513
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 Phone phone = getPhone(subId);
6517 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006518 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519 }
6520 } finally {
6521 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006522 }
6523 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006524
6525 /**
6526 * Get Client request stats
6527 * @return List of Client Request Stats
6528 * @hide
6529 */
6530 @Override
6531 public List<ClientRequestStats> getClientRequestStats(String callingPackage, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006532 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006533 mApp, subId, callingPackage, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006534 return null;
6535 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006536 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006538 final long identity = Binder.clearCallingIdentity();
6539 try {
6540 if (phone != null) {
6541 return phone.getClientRequestStats();
6542 }
6543
6544 return null;
6545 } finally {
6546 Binder.restoreCallingIdentity(identity);
6547 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006548 }
6549
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006550 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006551 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006552 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006553 }
Jack Yueb4124c2017-02-16 15:32:43 -08006554
6555 /**
Grace Chen70990072017-03-24 17:21:30 -07006556 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006557 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006558 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006559 * @param state State of SIM (power down, power up, pass through)
6560 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6561 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6562 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006563 *
6564 **/
6565 @Override
Grace Chen70990072017-03-24 17:21:30 -07006566 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006567 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006568 Phone phone = PhoneFactory.getPhone(slotIndex);
6569
vagdeviaf9a5b92018-08-15 16:01:53 -07006570 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6571
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006575 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006576 }
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006579 }
6580 }
Shuo Qiandd210312017-04-12 22:11:33 +00006581
Tyler Gunn65d45c22017-06-05 11:22:26 -07006582 private boolean isUssdApiAllowed(int subId) {
6583 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006584 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006585 if (configManager == null) {
6586 return false;
6587 }
6588 PersistableBundle pb = configManager.getConfigForSubId(subId);
6589 if (pb == null) {
6590 return false;
6591 }
6592 return pb.getBoolean(
6593 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6594 }
6595
Shuo Qiandd210312017-04-12 22:11:33 +00006596 /**
6597 * Check if phone is in emergency callback mode
6598 * @return true if phone is in emergency callback mode
6599 * @param subId sub id
6600 */
goneil9c5f4872017-12-05 14:07:56 -08006601 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006602 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006603 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006604 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605
6606 final long identity = Binder.clearCallingIdentity();
6607 try {
6608 if (phone != null) {
6609 return phone.isInEcm();
6610 } else {
6611 return false;
6612 }
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006615 }
6616 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006617
6618 /**
6619 * Get the current signal strength information for the given subscription.
6620 * Because this information is not updated when the device is in a low power state
6621 * it should not be relied-upon to be current.
6622 * @param subId Subscription index
6623 * @return the most recent cached signal strength info from the modem
6624 */
6625 @Override
6626 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 Phone p = getPhone(subId);
6630 if (p == null) {
6631 return null;
6632 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 return p.getSignalStrength();
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
6637 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006638 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006639
Pengquan Meng77b7f132018-08-22 14:49:57 -07006640 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006641 * Get the current modem radio state for the given slot.
6642 * @param slotIndex slot index.
6643 * @param callingPackage the name of the package making the call.
6644 * @return the current radio power state from the modem
6645 */
6646 @Override
6647 public int getRadioPowerState(int slotIndex, String callingPackage) {
6648 Phone phone = PhoneFactory.getPhone(slotIndex);
6649 if (phone != null) {
6650 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
6651 mApp, phone.getSubId(), callingPackage, "getRadioPowerState")) {
6652 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6653 }
6654
6655 final long identity = Binder.clearCallingIdentity();
6656 try {
6657 return phone.getRadioPowerState();
6658 } finally {
6659 Binder.restoreCallingIdentity(identity);
6660 }
6661 }
6662 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6663 }
6664
6665 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006666 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6667 *
6668 * <p>Requires one of the following permissions:
6669 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6670 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6671 * privileges.
6672 *
6673 * @param subId subscription id
6674 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6675 * {@code false}.
6676 */
6677 @Override
6678 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006679 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6680 null /* message */);
6681
Pengquan Menga1bb6272018-09-06 09:59:22 -07006682 boolean isEnabled = false;
6683 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006684 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006685 Phone phone = getPhone(subId);
6686 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006687 } catch (Exception e) {
6688 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6689 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006690 } finally {
6691 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006692 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006693 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006694 }
6695
6696
6697 /**
6698 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6699 *
6700 * <p> Requires permission:
6701 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6702 * privileges.
6703 *
6704 * @param subId subscription id
6705 * @param isEnabled {@code true} means enable, {@code false} means disable.
6706 */
6707 @Override
6708 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006709 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6710 mApp, subId, "setDataRoamingEnabled");
6711
Pengquan Menga1bb6272018-09-06 09:59:22 -07006712 final long identity = Binder.clearCallingIdentity();
6713 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006714 Phone phone = getPhone(subId);
6715 if (phone != null) {
6716 phone.setDataRoamingEnabled(isEnabled);
6717 }
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006720 }
6721 }
6722
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006723 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006724 public boolean isManualNetworkSelectionAllowed(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006725 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6726 mApp, subId, "isManualNetworkSelectionAllowed");
6727
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006728 boolean isAllowed = true;
6729 final long identity = Binder.clearCallingIdentity();
6730 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006731 Phone phone = getPhone(subId);
6732 if (phone != null) {
6733 isAllowed = phone.isCspPlmnEnabled();
6734 }
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
6738 return isAllowed;
6739 }
6740
6741 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006742 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006743 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006744 try {
6745 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006746 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006747 } catch (SecurityException e) {
6748 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6749 // has carrier privileges on an active UICC
6750 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6751 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006752 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006753 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006754 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006755
6756 final long identity = Binder.clearCallingIdentity();
6757 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006758 UiccController uiccController = UiccController.getInstance();
6759 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006760 if (hasReadPermission) {
6761 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006762 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006763
6764 // Remove private info if the caller doesn't have access
6765 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6766 for (UiccCardInfo cardInfo : cardInfos) {
6767 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6768 // is available
6769 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6770 if (card == null || card.getUiccProfile() == null) {
6771 // assume no access if the card or profile is unavailable
6772 filteredInfos.add(cardInfo.getUnprivileged());
6773 continue;
6774 }
6775 UiccProfile profile = card.getUiccProfile();
6776 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6777 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6778 filteredInfos.add(cardInfo);
6779 } else {
6780 filteredInfos.add(cardInfo.getUnprivileged());
6781 }
6782 }
6783 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006784 } finally {
6785 Binder.restoreCallingIdentity(identity);
6786 }
6787 }
6788
6789 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006790 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006791 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006792
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006793 final long identity = Binder.clearCallingIdentity();
6794 try {
6795 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6796 if (slots == null) {
6797 Rlog.i(LOG_TAG, "slots is null.");
6798 return null;
6799 }
6800
6801 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6802 for (int i = 0; i < slots.length; i++) {
6803 UiccSlot slot = slots[i];
6804 if (slot == null) {
6805 continue;
6806 }
6807
Jordan Liu7be7e652019-05-06 18:55:02 +00006808 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 UiccCard card = slot.getUiccCard();
6810 if (card != null) {
6811 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006812 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07006813 cardId = slot.getEid();
6814 if (TextUtils.isEmpty(cardId)) {
6815 cardId = slot.getIccId();
6816 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006817 }
6818
Jordan Liu857451f2019-05-09 16:35:35 -07006819 if (cardId != null) {
6820 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6821 // if cardId is an EID, it's all digits so this is fine
6822 cardId = IccUtils.stripTrailingFs(cardId);
6823 }
6824
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006825 int cardState = 0;
6826 switch (slot.getCardState()) {
6827 case CARDSTATE_ABSENT:
6828 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6829 break;
6830 case CARDSTATE_PRESENT:
6831 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6832 break;
6833 case CARDSTATE_ERROR:
6834 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6835 break;
6836 case CARDSTATE_RESTRICTED:
6837 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6838 break;
6839 default:
6840 break;
6841
6842 }
6843
6844 infos[i] = new UiccSlotInfo(
6845 slot.isActive(),
6846 slot.isEuicc(),
6847 cardId,
6848 cardState,
6849 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006850 slot.isExtendedApduSupported(),
6851 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 }
6853 return infos;
6854 } finally {
6855 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006856 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006857 }
6858
6859 @Override
6860 public boolean switchSlots(int[] physicalSlots) {
6861 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862
6863 final long identity = Binder.clearCallingIdentity();
6864 try {
6865 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006869 }
Jack Yu4c988042018-02-27 15:30:01 -08006870
6871 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08006872 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 return UiccController.getInstance().getCardIdForDefaultEuicc();
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
6879 }
6880
6881 @Override
Jack Yu4c988042018-02-27 15:30:01 -08006882 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
6883 enforceModifyPermission();
6884 final Phone phone = getPhone(subId);
6885 if (phone == null) {
6886 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
6887 return;
6888 }
6889
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006890 final long identity = Binder.clearCallingIdentity();
6891 try {
6892 phone.setRadioIndicationUpdateMode(filters, mode);
6893 } finally {
6894 Binder.restoreCallingIdentity(identity);
6895 }
Jack Yu4c988042018-02-27 15:30:01 -08006896 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07006897
6898 /**
goneil47ffb6e2018-04-06 15:40:58 -07006899 * A test API to reload the UICC profile.
6900 *
6901 * <p>Requires that the calling app has permission
6902 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6903 * @hide
6904 */
6905 @Override
6906 public void refreshUiccProfile(int subId) {
6907 enforceModifyPermission();
6908
6909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 Phone phone = getPhone(subId);
6912 if (phone == null) {
6913 return;
6914 }
6915 UiccCard uiccCard = phone.getUiccCard();
6916 if (uiccCard == null) {
6917 return;
6918 }
6919 UiccProfile uiccProfile = uiccCard.getUiccProfile();
6920 if (uiccProfile == null) {
6921 return;
6922 }
6923 uiccProfile.refresh();
6924 } finally {
6925 Binder.restoreCallingIdentity(identity);
6926 }
6927 }
6928
6929 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07006930 * Returns false if the mobile data is disabled by default, otherwise return true.
6931 */
6932 private boolean getDefaultDataEnabled() {
6933 return "true".equalsIgnoreCase(
6934 SystemProperties.get(DEFAULT_MOBILE_DATA_PROPERTY_NAME, "true"));
6935 }
6936
6937 /**
6938 * Returns true if the data roaming is enabled by default, i.e the system property
6939 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
6940 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
6941 */
6942 private boolean getDefaultDataRoamingEnabled(int subId) {
6943 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006945 boolean isDataRoamingEnabled = "true".equalsIgnoreCase(
6946 SystemProperties.get(DEFAULT_DATA_ROAMING_PROPERTY_NAME, "false"));
6947 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
6948 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
6949 return isDataRoamingEnabled;
6950 }
6951
6952 /**
6953 * Returns the default network type for the given {@code subId}, if the default network type is
6954 * not set, return {@link Phone#PREFERRED_NT_MODE}.
6955 */
6956 private int getDefaultNetworkType(int subId) {
6957 return Integer.parseInt(
6958 TelephonyManager.getTelephonyProperty(
6959 mSubscriptionController.getPhoneId(subId),
6960 DEFAULT_NETWORK_MODE_PROPERTY_NAME,
6961 String.valueOf(Phone.PREFERRED_NT_MODE)));
6962 }
fionaxua13278b2018-03-21 00:08:13 -07006963
6964 @Override
6965 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07006966 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07006967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
6971 final Phone phone = getPhone(subId);
6972 if (phone == null) {
6973 loge("setCarrierTestOverride fails with invalid subId: " + subId);
6974 return;
6975 }
chen xueaba88a2019-03-15 13:15:10 -07006976 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
6977 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 } finally {
6979 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006980 }
fionaxua13278b2018-03-21 00:08:13 -07006981 }
6982
6983 @Override
6984 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006985 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 final Phone phone = getPhone(subId);
6990 if (phone == null) {
6991 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
6992 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
6993 }
6994 return phone.getCarrierIdListVersion();
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07006997 }
fionaxua13278b2018-03-21 00:08:13 -07006998 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07006999
7000 @Override
7001 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage) {
7002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7003 mApp, subId, callingPackage, "getNumberOfModemsWithSimultaneousDataConnections")) {
7004 return -1;
7005 }
7006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7010 } finally {
7011 Binder.restoreCallingIdentity(identity);
7012 }
7013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007014
7015 @Override
7016 public int getCdmaRoamingMode(int subId) {
7017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7018 mApp, subId, "getCdmaRoamingMode");
7019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
7026 }
7027
7028 @Override
7029 public boolean setCdmaRoamingMode(int subId, int mode) {
7030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7031 mApp, subId, "setCdmaRoamingMode");
7032
7033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
7038 }
7039 }
7040
7041 @Override
7042 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7044 mApp, subId, "setCdmaSubscriptionMode");
7045
7046 final long identity = Binder.clearCallingIdentity();
7047 try {
7048 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
7051 }
7052 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007053
sqianc5eccab2018-10-19 18:46:41 -07007054 @Override
sqian8c685422019-02-22 15:55:18 -08007055 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
sqianc5eccab2018-10-19 18:46:41 -07007056 String callingPackage) {
sqian11b7a0e2018-12-05 18:48:28 -08007057 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
sqian8c685422019-02-22 15:55:18 -08007058 mApp, getDefaultSubscription(), callingPackage, "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007059 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7060 }
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
sqian854d44b2018-12-12 16:48:18 -08007063 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7064 for (Phone phone: PhoneFactory.getPhones()) {
7065 if (phone.getEmergencyNumberTracker() != null
7066 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7067 emergencyNumberListInternal.put(
7068 phone.getSubId(),
7069 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7070 }
sqian11b7a0e2018-12-05 18:48:28 -08007071 }
sqian854d44b2018-12-12 16:48:18 -08007072 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
sqianc5eccab2018-10-19 18:46:41 -07007076 }
7077
7078 @Override
sqian8c685422019-02-22 15:55:18 -08007079 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007080 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007081 if (!exactMatch) {
7082 TelephonyPermissions
7083 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007084 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007085 }
7086 final long identity = Binder.clearCallingIdentity();
7087 try {
sqian854d44b2018-12-12 16:48:18 -08007088 for (Phone phone: PhoneFactory.getPhones()) {
7089 if (phone.getEmergencyNumberTracker() != null
7090 && phone.getEmergencyNumberTracker() != null) {
7091 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7092 number, exactMatch)) {
7093 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007094 }
7095 }
sqian11b7a0e2018-12-05 18:48:28 -08007096 }
7097 return false;
7098 } finally {
7099 Binder.restoreCallingIdentity(identity);
7100 }
7101 }
7102
sqianf4ca7ed2019-01-15 18:32:07 -08007103 /**
7104 * Update emergency number list for test mode.
7105 */
7106 @Override
7107 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7109 "updateEmergencyNumberListTestMode");
7110
7111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 for (Phone phone: PhoneFactory.getPhones()) {
7114 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7115 if (tracker != null) {
7116 tracker.executeEmergencyNumberTestModeCommand(action, num);
7117 }
7118 }
7119 } finally {
7120 Binder.restoreCallingIdentity(identity);
7121 }
7122 }
7123
7124 /**
7125 * Get the full emergency number list for test mode.
7126 */
7127 @Override
7128 public List<String> getEmergencyNumberListTestMode() {
7129 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7130 "getEmergencyNumberListTestMode");
7131
7132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 Set<String> emergencyNumbers = new HashSet<>();
7135 for (Phone phone: PhoneFactory.getPhones()) {
7136 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7137 if (tracker != null) {
7138 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7139 emergencyNumbers.add(num.getNumber());
7140 }
7141 }
7142 }
7143 return new ArrayList<>(emergencyNumbers);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
chen xud6b45bd2018-10-30 22:27:10 -07007149 @Override
7150 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7151 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7152 Phone phone = getPhone(subId);
7153 if (phone == null) {
7154 return null;
7155 }
7156 final long identity = Binder.clearCallingIdentity();
7157 try {
7158 UiccProfile profile = UiccController.getInstance()
7159 .getUiccProfileForPhone(phone.getPhoneId());
7160 if (profile != null) {
7161 return profile.getCertsFromCarrierPrivilegeAccessRules();
7162 }
7163 } finally {
7164 Binder.restoreCallingIdentity(identity);
7165 }
7166 return null;
7167 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007168
7169 /**
7170 * Enable or disable a modem stack.
7171 */
7172 @Override
7173 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7174 enforceModifyPermission();
7175
7176 final long identity = Binder.clearCallingIdentity();
7177 try {
7178 Phone phone = PhoneFactory.getPhone(slotIndex);
7179 if (phone == null) {
7180 return false;
7181 } else {
7182 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7183 }
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
Michelecea4cf22018-12-21 15:00:11 -08007188
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007189 /**
7190 * Whether a modem stack is enabled or not.
7191 */
7192 @Override
7193 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage) {
7194 Phone phone = PhoneFactory.getPhone(slotIndex);
7195 if (phone == null) return false;
7196
7197 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7198 mApp, phone.getSubId(), callingPackage, "isModemEnabledForSlot")) {
7199 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7200 }
7201
7202 final long identity = Binder.clearCallingIdentity();
7203 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007204 try {
7205 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7206 } catch (NoSuchElementException ex) {
7207 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7208 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007209 } finally {
7210 Binder.restoreCallingIdentity(identity);
7211 }
7212 }
7213
Michelecea4cf22018-12-21 15:00:11 -08007214 @Override
Michele0ea7d782019-03-19 14:58:42 -07007215 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007216 enforceModifyPermission();
7217
7218 final long identity = Binder.clearCallingIdentity();
7219 try {
7220 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007221 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007222 .commit();
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
7225 }
7226 }
7227
7228 @Override
Michele0ea7d782019-03-19 14:58:42 -07007229 @TelephonyManager.IsMultiSimSupportedResult
7230 public int isMultiSimSupported(String callingPackage) {
Michele4245e952019-02-04 11:36:23 -08007231 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Michele0ea7d782019-03-19 14:58:42 -07007232 getDefaultPhone().getSubId(), callingPackage, "isMultiSimSupported")) {
7233 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007234 }
Michelecea4cf22018-12-21 15:00:11 -08007235
7236 final long identity = Binder.clearCallingIdentity();
7237 try {
Michele0ea7d782019-03-19 14:58:42 -07007238 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
7241 }
7242 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007243
Michele0ea7d782019-03-19 14:58:42 -07007244 @TelephonyManager.IsMultiSimSupportedResult
7245 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007246 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7247 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7248 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007249 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7250 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007251 }
7252 // Check if the hardware supports multisim functionality. If usage of multisim is not
7253 // supported by the modem, indicate that it is restricted.
7254 PhoneCapability staticCapability =
7255 mPhoneConfigurationManager.getStaticPhoneCapability();
7256 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007257 loge("isMultiSimSupportedInternal: no static configuration available");
7258 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007259 }
7260 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007261 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7262 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007263 }
7264 // Check if support of multiple SIMs is restricted by carrier
7265 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007266 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007267 }
7268
Michele0ea7d782019-03-19 14:58:42 -07007269 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007270 }
7271
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007272 /**
7273 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007274 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7275 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7276 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007277 * @param numOfSims number of active sims we want to switch to
7278 */
7279 @Override
7280 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007281 if (numOfSims == 1) {
7282 enforceModifyPermission();
7283 } else {
7284 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7285 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7286 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007287 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007288
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007289 try {
Michele30b57b22019-03-01 12:01:14 -08007290 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007291 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007292 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7293 return;
7294 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007295 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298 }
7299 }
7300
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007301 @Override
7302 public boolean isApplicationOnUicc(int subId, int appType) {
7303 enforceReadPrivilegedPermission("isApplicationOnUicc");
7304 Phone phone = getPhone(subId);
7305 if (phone == null) {
7306 return false;
7307 }
7308 final long identity = Binder.clearCallingIdentity();
7309 try {
7310 UiccCard uiccCard = phone.getUiccCard();
7311 if (uiccCard == null) {
7312 return false;
7313 }
7314 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7315 if (uiccProfile == null) {
7316 return false;
7317 }
7318 if (TelephonyManager.APPTYPE_SIM <= appType
7319 && appType <= TelephonyManager.APPTYPE_ISIM) {
7320 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7321 }
7322 return false;
7323 } finally {
7324 Binder.restoreCallingIdentity(identity);
7325 }
7326 }
7327
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007328 /**
chen xub4baa772019-04-03 10:23:41 -07007329 * Get whether making changes to modem configurations will trigger reboot.
7330 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007331 */
7332 @Override
chen xub4baa772019-04-03 10:23:41 -07007333 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage) {
7334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
7335 mApp, subId, callingPackage, "doesSwitchMultiSimConfigTriggerReboot")) {
7336 return false;
7337 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007338 final long identity = Binder.clearCallingIdentity();
7339 try {
7340 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7341 } finally {
7342 Binder.restoreCallingIdentity(identity);
7343 }
7344 }
7345
Nathan Harold29f5f052019-02-15 13:41:57 -08007346 private void updateModemStateMetrics() {
7347 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7348 // TODO: check the state for each modem if the api is ready.
7349 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7350 }
7351
Pengquan Meng3889a572019-01-23 11:16:29 -08007352 @Override
7353 public int[] getSlotsMapping() {
7354 enforceReadPrivilegedPermission("getSlotsMapping");
7355
7356 final long identity = Binder.clearCallingIdentity();
7357 try {
7358 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7359 // All logical slots should have a mapping to a physical slot.
7360 int[] logicalSlotsMapping = new int[phoneCount];
7361 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7362 for (int i = 0; i < slotInfos.length; i++) {
7363 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7364 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7365 }
7366 }
7367 return logicalSlotsMapping;
7368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
7371 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007372
7373 /**
7374 * Get the IRadio HAL Version
7375 */
7376 @Override
7377 public int getRadioHalVersion() {
7378 Phone phone = getDefaultPhone();
7379 if (phone == null) return -1;
7380 HalVersion hv = phone.getHalVersion();
7381 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7382 return hv.major * 100 + hv.minor;
7383 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007384
7385 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007386 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7387 * corresponding network requests on a subId.
7388 *
7389 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007390 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007391 * 2) APN is un-metered for this subscription, or
7392 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7393 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7394 *
7395 * @return whether data is allowed for a apn type.
7396 *
7397 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007398 */
7399 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007400 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07007401 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7402 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007403
7404 // Now that all security checks passes, perform the operation as ourselves.
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 Phone phone = getPhone(subId);
7408 if (phone == null) return false;
7409
Jack Yu41407ee2019-05-13 16:54:09 -07007410 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007411 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
7414 }
7415 }
7416
7417 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007418 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007419 enforceReadPrivilegedPermission("isApnMetered");
7420
7421 // Now that all security checks passes, perform the operation as ourselves.
7422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 Phone phone = getPhone(subId);
7425 if (phone == null) return true; // By default return true.
7426
Jack Yu41407ee2019-05-13 16:54:09 -07007427 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007432
7433 @Override
7434 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7435 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7436 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7437 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7438 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7439 }
7440 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7441 Intent intent = new Intent();
7442 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7443 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7444 // Bring up choose default SMS subscription dialog right now
7445 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7446 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7447 mApp.startActivity(intent);
7448 }
chen xud5ca2d52019-05-28 15:20:57 -07007449
7450 @Override
7451 public String getMmsUAProfUrl(int subId) {
7452 //TODO investigate if this API should require proper permission check in R b/133791609
7453 final long identity = Binder.clearCallingIdentity();
7454 try {
7455 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7456 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7457 } finally {
7458 Binder.restoreCallingIdentity(identity);
7459 }
7460 }
7461
7462 @Override
7463 public String getMmsUserAgent(int subId) {
7464 //TODO investigate if this API should require proper permission check in R b/133791609
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7468 .getString(com.android.internal.R.string.config_mms_user_agent);
7469 } finally {
7470 Binder.restoreCallingIdentity(identity);
7471 }
7472 }
Jack Yub07d4972019-05-28 16:12:25 -07007473
7474 @Override
7475 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7476 enforceModifyPermission();
7477
7478 // Now that all security checks passes, perform the operation as ourselves.
7479 final long identity = Binder.clearCallingIdentity();
7480 try {
7481 Phone phone = getPhone(subId);
7482 if (phone == null) return false;
7483
7484 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
7488 }
7489
7490 @Override
7491 public boolean isDataAllowedInVoiceCall(int subId) {
7492 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7493
7494 // Now that all security checks passes, perform the operation as ourselves.
7495 final long identity = Binder.clearCallingIdentity();
7496 try {
7497 Phone phone = getPhone(subId);
7498 if (phone == null) return false;
7499
7500 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7501 } finally {
7502 Binder.restoreCallingIdentity(identity);
7503 }
7504 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007505
7506 /**
7507 * Updates whether conference event pacakge handling is enabled.
7508 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7509 * otherwise.
7510 */
7511 @Override
7512 public void setCepEnabled(boolean isCepEnabled) {
7513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7514
7515 final long identity = Binder.clearCallingIdentity();
7516 try {
7517 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7518 for (Phone phone : PhoneFactory.getPhones()) {
7519 Phone defaultPhone = phone.getImsPhone();
7520 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7521 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7522 ImsPhoneCallTracker imsPhoneCallTracker =
7523 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7524 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7525 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7526 + imsPhone.getMsisdn());
7527 }
7528 }
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
7532 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007533}