blob: e0c08fab475c6956991cf445cbea845599ff8aef [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Junda Liu12f7d802015-05-01 12:06:44 -070067import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080068import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070069import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080070import android.telephony.CellIdentityCdma;
71import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070072import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070073import android.telephony.CellInfoGsm;
74import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070075import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070076import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070077import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080078import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070079import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080080import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070081import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080082import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080083import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070084import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080085import android.telephony.RadioAccessSpecifier;
Tyler Gunn65d45c22017-06-05 11:22:26 -070086import android.telephony.Rlog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070091import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070092import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080093import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080094import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000095import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070096import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080098import android.telephony.data.ApnSetting;
99import android.telephony.emergency.EmergencyNumber;
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 Ebinger774ba362019-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 Ebinger77b832e2019-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;
yinxub1bed742017-04-17 11:45:04 -0700135import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700136import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700138import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800139import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700140import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700141import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700142import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700143import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700144import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700145import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700146import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800148import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800149import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700150import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800151import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700152import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800153import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700154import com.android.internal.telephony.imsphone.ImsPhone;
155import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800156import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900157import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700158import com.android.internal.telephony.uicc.IccIoResult;
159import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800160import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700161import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800162import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800164import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000165import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800166import com.android.internal.telephony.util.LocaleUtils;
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 zhaod698b842019-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;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700265 private static final int CMD_ERASE_MODEM_CONFIG = 74;
266 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700267
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800268 // Parameters of select command.
269 private static final int SELECT_COMMAND = 0xA4;
270 private static final int SELECT_P1 = 0x04;
271 private static final int SELECT_P2 = 0;
272 private static final int SELECT_P3 = 0x10;
273
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700274 /** The singleton instance. */
275 private static PhoneInterfaceManager sInstance;
276
Wink Saville3ab207e2014-11-20 13:07:20 -0800277 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800278 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800279 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700280 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800281 private AppOpsManager mAppOps;
282 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800283 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800284 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700285 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700286
Derek Tan97ebb422014-09-05 16:55:38 -0700287 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
288 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800289 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800290 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700291
Michelecea4cf22018-12-21 15:00:11 -0800292 // String to store multi SIM allowed
293 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
294
Derek Tan740e1672017-06-27 14:56:27 -0700295 // The AID of ISD-R.
296 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
297
yinxub1bed742017-04-17 11:45:04 -0700298 private NetworkScanRequestTracker mNetworkScanRequestTracker;
299
David Kelly5e06a7f2018-03-12 14:10:59 +0000300 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
301 private static final int MANUFACTURER_CODE_LENGTH = 8;
302
Derek Tan89e89d42014-07-08 17:00:10 -0700303 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700304 * Experiment flag to enable erase modem config on reset network, default value is false
305 */
306 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
307 "reset_network_erase_modem_config_enabled";
308
309 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700310 * A request object to use for transmitting data to an ICC.
311 */
312 private static final class IccAPDUArgument {
313 public int channel, cla, command, p1, p2, p3;
314 public String data;
315
316 public IccAPDUArgument(int channel, int cla, int command,
317 int p1, int p2, int p3, String data) {
318 this.channel = channel;
319 this.cla = cla;
320 this.command = command;
321 this.p1 = p1;
322 this.p2 = p2;
323 this.p3 = p3;
324 this.data = data;
325 }
326 }
327
328 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700329 * A request object to use for transmitting data to an ICC.
330 */
331 private static final class ManualNetworkSelectionArgument {
332 public OperatorInfo operatorInfo;
333 public boolean persistSelection;
334
335 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
336 this.operatorInfo = operatorInfo;
337 this.persistSelection = persistSelection;
338 }
339 }
340
341 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700342 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
343 * request after sending. The main thread will notify the request when it is complete.
344 */
345 private static final class MainThreadRequest {
346 /** The argument to use for the request */
347 public Object argument;
348 /** The result of the request that is run on the main thread */
349 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800350 // The subscriber id that this request applies to. Defaults to
351 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
352 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700353
Nathan Harold92bed182018-10-12 18:16:49 -0700354 // In cases where subId is unavailable, the caller needs to specify the phone.
355 public Phone phone;
356
vagdeviaf9a5b92018-08-15 16:01:53 -0700357 public WorkSource workSource;
358
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 public MainThreadRequest(Object argument) {
360 this.argument = argument;
361 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800362
Nathan Harold92bed182018-10-12 18:16:49 -0700363 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
364 this.argument = argument;
365 if (phone != null) {
366 this.phone = phone;
367 }
368 this.workSource = workSource;
369 }
370
vagdeviaf9a5b92018-08-15 16:01:53 -0700371 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800372 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 if (subId != null) {
374 this.subId = subId;
375 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700376 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800377 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700378 }
379
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800380 private static final class IncomingThirdPartyCallArgs {
381 public final ComponentName component;
382 public final String callId;
383 public final String callerDisplayName;
384
385 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
386 String callerDisplayName) {
387 this.component = component;
388 this.callId = callId;
389 this.callerDisplayName = callerDisplayName;
390 }
391 }
392
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700393 /**
394 * A handler that processes messages on the main thread in the phone process. Since many
395 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
396 * inbound binder threads to the main thread in the phone process. The Binder thread
397 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
398 * on, which will be notified when the operation completes and will contain the result of the
399 * request.
400 *
401 * <p>If a MainThreadRequest object is provided in the msg.obj field,
402 * note that request.result must be set to something non-null for the calling thread to
403 * unblock.
404 */
405 private final class MainThreadHandler extends Handler {
406 @Override
407 public void handleMessage(Message msg) {
408 MainThreadRequest request;
409 Message onCompleted;
410 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800411 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700412 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800413 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700414
415 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700416 case CMD_HANDLE_USSD_REQUEST: {
417 request = (MainThreadRequest) msg.obj;
418 final Phone phone = getPhoneFromRequest(request);
419 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
420 String ussdRequest = ussdObject.first;
421 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700422
Pengquan Menga1bb6272018-09-06 09:59:22 -0700423 if (!isUssdApiAllowed(request.subId)) {
424 // Carrier does not support use of this API, return failure.
425 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
426 UssdResponse response = new UssdResponse(ussdRequest, null);
427 Bundle returnData = new Bundle();
428 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
429 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700430
Pengquan Menga1bb6272018-09-06 09:59:22 -0700431 request.result = true;
432 notifyRequester(request);
433 return;
434 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700435
Pengquan Menga1bb6272018-09-06 09:59:22 -0700436 try {
437 request.result = phone != null
438 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
439 } catch (CallStateException cse) {
440 request.result = false;
441 }
442 // Wake up the requesting thread
443 notifyRequester(request);
444 break;
pkanwar32d516d2016-10-14 19:37:38 -0700445 }
446
Yorke Lee716f67e2015-06-17 15:39:16 -0700447 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700448 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700449 final Phone phone = getPhoneFromRequest(request);
450 request.result = phone != null ?
451 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
452 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700453 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700455 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700456 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700457
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700458 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700459 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700460 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800461 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700462 if (uiccCard == null) {
463 loge("iccTransmitApduLogicalChannel: No UICC");
464 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700466 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700467 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
468 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700469 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700470 iccArgument.channel, iccArgument.cla, iccArgument.command,
471 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700472 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700473 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700474 break;
475
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700476 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700477 ar = (AsyncResult) msg.obj;
478 request = (MainThreadRequest) ar.userObj;
479 if (ar.exception == null && ar.result != null) {
480 request.result = ar.result;
481 } else {
482 request.result = new IccIoResult(0x6F, 0, (byte[])null);
483 if (ar.result == null) {
484 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800485 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800487 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 } else {
489 loge("iccTransmitApduLogicalChannel: Unknown exception");
490 }
491 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700493 break;
494
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700495 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
496 request = (MainThreadRequest) msg.obj;
497 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800498 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 if (uiccCard == null) {
500 loge("iccTransmitApduBasicChannel: No UICC");
501 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700502 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 } else {
504 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
505 request);
506 uiccCard.iccTransmitApduBasicChannel(
507 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
508 iccArgument.p3, iccArgument.data, onCompleted);
509 }
510 break;
511
512 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
513 ar = (AsyncResult) msg.obj;
514 request = (MainThreadRequest) ar.userObj;
515 if (ar.exception == null && ar.result != null) {
516 request.result = ar.result;
517 } else {
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
519 if (ar.result == null) {
520 loge("iccTransmitApduBasicChannel: Empty response");
521 } else if (ar.exception instanceof CommandException) {
522 loge("iccTransmitApduBasicChannel: CommandException: " +
523 ar.exception);
524 } else {
525 loge("iccTransmitApduBasicChannel: Unknown exception");
526 }
527 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700528 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700529 break;
530
531 case CMD_EXCHANGE_SIM_IO:
532 request = (MainThreadRequest) msg.obj;
533 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800534 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 if (uiccCard == null) {
536 loge("iccExchangeSimIO: No UICC");
537 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700538 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700539 } else {
540 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
541 request);
542 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
543 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
544 iccArgument.data, onCompleted);
545 }
546 break;
547
548 case EVENT_EXCHANGE_SIM_IO_DONE:
549 ar = (AsyncResult) msg.obj;
550 request = (MainThreadRequest) ar.userObj;
551 if (ar.exception == null && ar.result != null) {
552 request.result = ar.result;
553 } else {
554 request.result = new IccIoResult(0x6f, 0, (byte[])null);
555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700556 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700557 break;
558
Derek Tan4d5e5c12014-02-04 11:54:58 -0800559 case CMD_SEND_ENVELOPE:
560 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700562 if (uiccCard == null) {
563 loge("sendEnvelopeWithStatus: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
568 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
569 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800570 break;
571
572 case EVENT_SEND_ENVELOPE_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800577 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700578 request.result = new IccIoResult(0x6F, 0, (byte[])null);
579 if (ar.result == null) {
580 loge("sendEnvelopeWithStatus: Empty response");
581 } else if (ar.exception instanceof CommandException) {
582 loge("sendEnvelopeWithStatus: CommandException: " +
583 ar.exception);
584 } else {
585 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800589 break;
590
Shishir Agrawal566b7612013-10-28 14:41:00 -0700591 case CMD_OPEN_CHANNEL:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800594 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 if (uiccCard == null) {
596 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800597 request.result = new IccOpenLogicalChannelResponse(-1,
598 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700599 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700600 } else {
601 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800602 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
603 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700604 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700605 break;
606
607 case EVENT_OPEN_CHANNEL_DONE:
608 ar = (AsyncResult) msg.obj;
609 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700610 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700611 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700612 int[] result = (int[]) ar.result;
613 int channelId = result[0];
614 byte[] selectResponse = null;
615 if (result.length > 1) {
616 selectResponse = new byte[result.length - 1];
617 for (int i = 1; i < result.length; ++i) {
618 selectResponse[i - 1] = (byte) result[i];
619 }
620 }
621 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700622 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700624 if (ar.result == null) {
625 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700626 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 if (ar.exception != null) {
628 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
629 }
630
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700631 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700632 if (ar.exception instanceof CommandException) {
633 CommandException.Error error =
634 ((CommandException) (ar.exception)).getCommandError();
635 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700636 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700637 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700638 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 }
640 }
641 openChannelResp = new IccOpenLogicalChannelResponse(
642 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700644 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 break;
647
648 case CMD_CLOSE_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900653 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700654 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700655 } else {
656 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
657 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
658 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 break;
660
661 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800662 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
663 break;
664
665 case CMD_NV_READ_ITEM:
666 request = (MainThreadRequest) msg.obj;
667 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800668 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
669 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800670 break;
671
672 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 ar = (AsyncResult) msg.obj;
674 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800675 if (ar.exception == null && ar.result != null) {
676 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800678 request.result = "";
679 if (ar.result == null) {
680 loge("nvReadItem: Empty response");
681 } else if (ar.exception instanceof CommandException) {
682 loge("nvReadItem: CommandException: " +
683 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700684 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800685 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 }
687 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700688 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700689 break;
690
Jake Hambye994d462014-02-03 13:10:13 -0800691 case CMD_NV_WRITE_ITEM:
692 request = (MainThreadRequest) msg.obj;
693 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
694 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_WRITE_ITEM_DONE:
700 handleNullReturnEvent(msg, "nvWriteItem");
701 break;
702
703 case CMD_NV_WRITE_CDMA_PRL:
704 request = (MainThreadRequest) msg.obj;
705 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800706 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800707 break;
708
709 case EVENT_NV_WRITE_CDMA_PRL_DONE:
710 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
711 break;
712
chen xu6dac5ab2018-10-26 17:39:23 -0700713 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800714 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700715 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800716 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800717 break;
718
chen xu6dac5ab2018-10-26 17:39:23 -0700719 case EVENT_RESET_MODEM_CONFIG_DONE:
720 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
Jake Hamby7c27be32014-03-03 13:25:59 -0800723 case CMD_GET_PREFERRED_NETWORK_TYPE:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700726 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800727 break;
728
729 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // Integer
734 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800735 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800736 if (ar.result == null) {
737 loge("getPreferredNetworkType: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("getPreferredNetworkType: CommandException: " +
740 ar.exception);
741 } else {
742 loge("getPreferredNetworkType: Unknown exception");
743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 break;
747
748 case CMD_SET_PREFERRED_NETWORK_TYPE:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
751 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700752 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 break;
754
755 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
756 handleNullReturnEvent(msg, "setPreferredNetworkType");
757 break;
758
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000759 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
760 request = (MainThreadRequest)msg.obj;
761 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000763 break;
764
765 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
766 ar = (AsyncResult)msg.obj;
767 request = (MainThreadRequest)ar.userObj;
768 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700769 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000770 break;
771
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800772 case CMD_SET_VOICEMAIL_NUMBER:
773 request = (MainThreadRequest) msg.obj;
774 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
775 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800776 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
777 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800778 break;
779
780 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
781 handleNullReturnEvent(msg, "setVoicemailNumber");
782 break;
783
Stuart Scott54788802015-03-30 13:18:01 -0700784 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
785 request = (MainThreadRequest) msg.obj;
786 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
787 request);
788 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
789 break;
790
791 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
792 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
793 break;
794
Shishir Agrawal302c8692015-06-19 13:49:39 -0700795 case CMD_PERFORM_NETWORK_SCAN:
796 request = (MainThreadRequest) msg.obj;
797 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
798 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
799 break;
800
801 case EVENT_PERFORM_NETWORK_SCAN_DONE:
802 ar = (AsyncResult) msg.obj;
803 request = (MainThreadRequest) ar.userObj;
804 CellNetworkScanResult cellScanResult;
805 if (ar.exception == null && ar.result != null) {
806 cellScanResult = new CellNetworkScanResult(
807 CellNetworkScanResult.STATUS_SUCCESS,
808 (List<OperatorInfo>) ar.result);
809 } else {
810 if (ar.result == null) {
811 loge("getCellNetworkScanResults: Empty response");
812 }
813 if (ar.exception != null) {
814 loge("getCellNetworkScanResults: Exception: " + ar.exception);
815 }
816 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
817 if (ar.exception instanceof CommandException) {
818 CommandException.Error error =
819 ((CommandException) (ar.exception)).getCommandError();
820 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
821 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
822 } else if (error == CommandException.Error.GENERIC_FAILURE) {
823 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
824 }
825 }
826 cellScanResult = new CellNetworkScanResult(errorCode, null);
827 }
828 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700829 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700830 break;
831
832 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
833 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700834 ManualNetworkSelectionArgument selArg =
835 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700836 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
837 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700838 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
839 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700840 break;
841
842 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -0700843 ar = (AsyncResult) msg.obj;
844 request = (MainThreadRequest) ar.userObj;
845 if (ar.exception == null) {
846 request.result = true;
847 } else {
848 request.result = false;
849 loge("setNetworkSelectionModeManual " + ar.exception);
850 }
851 notifyRequester(request);
852 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700853 break;
854
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700855 case CMD_GET_MODEM_ACTIVITY_INFO:
856 request = (MainThreadRequest) msg.obj;
857 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -0700858 if (defaultPhone != null) {
859 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
860 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700861 break;
862
863 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
864 ar = (AsyncResult) msg.obj;
865 request = (MainThreadRequest) ar.userObj;
866 if (ar.exception == null && ar.result != null) {
867 request.result = ar.result;
868 } else {
869 if (ar.result == null) {
870 loge("queryModemActivityInfo: Empty response");
871 } else if (ar.exception instanceof CommandException) {
872 loge("queryModemActivityInfo: CommandException: " +
873 ar.exception);
874 } else {
875 loge("queryModemActivityInfo: Unknown exception");
876 }
877 }
Amit Mahajand4766222016-01-28 15:28:28 -0800878 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
879 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -0700880 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -0800881 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700882 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700883 break;
884
Meng Wang1a7c35a2016-05-05 20:56:15 -0700885 case CMD_SET_ALLOWED_CARRIERS:
886 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -0800887 CarrierRestrictionRules argument =
888 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700889 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -0800890 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700891 break;
892
893 case EVENT_SET_ALLOWED_CARRIERS_DONE:
894 ar = (AsyncResult) msg.obj;
895 request = (MainThreadRequest) ar.userObj;
896 if (ar.exception == null && ar.result != null) {
897 request.result = ar.result;
898 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800899 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
900 if (ar.exception instanceof CommandException) {
901 loge("setAllowedCarriers: CommandException: " + ar.exception);
902 CommandException.Error error =
903 ((CommandException) (ar.exception)).getCommandError();
904 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
905 request.result =
906 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
907 }
Meng Wang1a7c35a2016-05-05 20:56:15 -0700908 } else {
909 loge("setAllowedCarriers: Unknown exception");
910 }
911 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700913 break;
914
915 case CMD_GET_ALLOWED_CARRIERS:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800918 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700919 break;
920
921 case EVENT_GET_ALLOWED_CARRIERS_DONE:
922 ar = (AsyncResult) msg.obj;
923 request = (MainThreadRequest) ar.userObj;
924 if (ar.exception == null && ar.result != null) {
925 request.result = ar.result;
926 } else {
Michele Berionne482f8202018-11-27 18:57:59 -0800927 request.result = new IllegalStateException(
928 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -0700929 if (ar.result == null) {
930 loge("getAllowedCarriers: Empty response");
931 } else if (ar.exception instanceof CommandException) {
932 loge("getAllowedCarriers: CommandException: " +
933 ar.exception);
934 } else {
935 loge("getAllowedCarriers: Unknown exception");
936 }
937 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700938 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -0700939 break;
940
Nathan Haroldb3014052017-01-25 15:57:32 -0800941 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
942 ar = (AsyncResult) msg.obj;
943 request = (MainThreadRequest) ar.userObj;
944 if (ar.exception == null && ar.result != null) {
945 request.result = ar.result;
946 } else {
947 request.result = new IllegalArgumentException(
948 "Failed to retrieve Forbidden Plmns");
949 if (ar.result == null) {
950 loge("getForbiddenPlmns: Empty response");
951 } else {
952 loge("getForbiddenPlmns: Unknown exception");
953 }
954 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700955 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800956 break;
957
958 case CMD_GET_FORBIDDEN_PLMNS:
959 request = (MainThreadRequest) msg.obj;
960 uiccCard = getUiccCardFromRequest(request);
961 if (uiccCard == null) {
962 loge("getForbiddenPlmns() UiccCard is null");
963 request.result = new IllegalArgumentException(
964 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700965 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800966 break;
967 }
968 Integer appType = (Integer) request.argument;
969 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
970 if (uiccApp == null) {
971 loge("getForbiddenPlmns() no app with specified type -- "
972 + appType);
973 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -0700974 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -0800975 break;
976 } else {
977 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
978 + " specified type -- " + appType);
979 }
980 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
981 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
982 onCompleted);
983 break;
984
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000985 case CMD_SWITCH_SLOTS:
986 request = (MainThreadRequest) msg.obj;
987 int[] physicalSlots = (int[]) request.argument;
988 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
989 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
990 break;
991
992 case EVENT_SWITCH_SLOTS_DONE:
993 ar = (AsyncResult) msg.obj;
994 request = (MainThreadRequest) ar.userObj;
995 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
997 break;
998 case CMD_GET_NETWORK_SELECTION_MODE:
999 request = (MainThreadRequest) msg.obj;
1000 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1001 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1002 break;
1003
1004 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1005 ar = (AsyncResult) msg.obj;
1006 request = (MainThreadRequest) ar.userObj;
1007 if (ar.exception != null) {
1008 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1009 } else {
1010 int mode = ((int[]) ar.result)[0];
1011 if (mode == 0) {
1012 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1013 } else {
1014 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1015 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001016 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001017 notifyRequester(request);
1018 break;
1019 case CMD_GET_CDMA_ROAMING_MODE:
1020 request = (MainThreadRequest) msg.obj;
1021 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1022 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1023 break;
1024 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1025 ar = (AsyncResult) msg.obj;
1026 request = (MainThreadRequest) ar.userObj;
1027 if (ar.exception != null) {
1028 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1029 } else {
1030 request.result = ((int[]) ar.result)[0];
1031 }
1032 notifyRequester(request);
1033 break;
1034 case CMD_SET_CDMA_ROAMING_MODE:
1035 request = (MainThreadRequest) msg.obj;
1036 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1037 int mode = (int) request.argument;
1038 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1039 break;
1040 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
1043 request.result = ar.exception == null;
1044 notifyRequester(request);
1045 break;
1046 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1047 request = (MainThreadRequest) msg.obj;
1048 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1049 int subscriptionMode = (int) request.argument;
1050 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1051 break;
1052 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 request.result = ar.exception == null;
1056 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001057 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001058 case CMD_GET_ALL_CELL_INFO:
1059 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001060 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001061 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001062 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001063 case EVENT_GET_ALL_CELL_INFO_DONE:
1064 ar = (AsyncResult) msg.obj;
1065 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001066 // If a timeout occurs, the response will be null
1067 request.result = (ar.exception == null && ar.result != null)
1068 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001069 synchronized (request) {
1070 request.notifyAll();
1071 }
1072 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001073 case CMD_REQUEST_CELL_INFO_UPDATE:
1074 request = (MainThreadRequest) msg.obj;
1075 request.phone.requestCellInfoUpdate(request.workSource,
1076 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1077 break;
1078 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1079 ar = (AsyncResult) msg.obj;
1080 request = (MainThreadRequest) ar.userObj;
1081 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1082 try {
1083 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001084 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001085 cb.onError(
1086 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1087 ar.exception.getClass().getName(),
1088 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001089 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001090 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001091 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001092 } else {
1093 // use the result as returned
1094 cb.onCellInfo((List<CellInfo>) ar.result);
1095 }
1096 } catch (RemoteException re) {
1097 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1098 }
1099 break;
1100 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001101 request = (MainThreadRequest) msg.obj;
1102 WorkSource ws = (WorkSource) request.argument;
1103 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001104 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001105 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001106 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001107 ar = (AsyncResult) msg.obj;
1108 request = (MainThreadRequest) ar.userObj;
1109 if (ar.exception == null) {
1110 request.result = ar.result;
1111 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001112 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001113 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001114 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001115 }
1116
1117 synchronized (request) {
1118 request.notifyAll();
1119 }
1120 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001121 case CMD_MODEM_REBOOT:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001125 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001126 case EVENT_CMD_MODEM_REBOOT_DONE:
1127 handleNullReturnEvent(msg, "rebootModem");
1128 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001129 case CMD_REQUEST_ENABLE_MODEM:
1130 request = (MainThreadRequest) msg.obj;
1131 boolean enable = (boolean) request.argument;
1132 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001133 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001134 PhoneConfigurationManager.getInstance()
1135 .enablePhone(request.phone, enable, onCompleted);
1136 break;
1137 case EVENT_ENABLE_MODEM_DONE:
1138 ar = (AsyncResult) msg.obj;
1139 request = (MainThreadRequest) ar.userObj;
1140 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001141 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001142 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001143 if ((boolean) request.result) {
1144 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1145 updateModemStateMetrics();
1146 } else {
1147 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1148 + ar.exception);
1149 }
1150 notifyRequester(request);
1151 break;
1152 case CMD_GET_MODEM_STATUS:
1153 request = (MainThreadRequest) msg.obj;
1154 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1155 PhoneConfigurationManager.getInstance()
1156 .getPhoneStatusFromModem(request.phone, onCompleted);
1157 break;
1158 case EVENT_GET_MODEM_STATUS_DONE:
1159 ar = (AsyncResult) msg.obj;
1160 request = (MainThreadRequest) ar.userObj;
1161 int id = request.phone.getPhoneId();
1162 if (ar.exception == null && ar.result != null) {
1163 request.result = ar.result;
1164 //update the cache as modem status has changed
1165 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1166 (boolean) request.result);
1167 } else {
1168 // Return true if modem status cannot be retrieved. For most cases,
1169 // modem status is on. And for older version modems, GET_MODEM_STATUS
1170 // and disable modem are not supported. Modem is always on.
1171 // TODO: this should be fixed in R to support a third
1172 // status UNKNOWN b/131631629
1173 request.result = true;
1174 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1175 + ar.exception);
1176 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001177 notifyRequester(request);
1178 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001179 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1180 ar = (AsyncResult) msg.obj;
1181 request = (MainThreadRequest) ar.userObj;
1182 if (ar.exception == null && ar.result != null) {
1183 request.result = ar.result;
1184 } else {
1185 request.result = -1;
1186 loge("Failed to set Forbidden Plmns");
1187 if (ar.result == null) {
1188 loge("setForbidenPlmns: Empty response");
1189 } else if (ar.exception != null) {
1190 loge("setForbiddenPlmns: Exception: " + ar.exception);
1191 request.result = -1;
1192 } else {
1193 loge("setForbiddenPlmns: Unknown exception");
1194 }
1195 }
1196 notifyRequester(request);
1197 break;
1198 case CMD_SET_FORBIDDEN_PLMNS:
1199 request = (MainThreadRequest) msg.obj;
1200 uiccCard = getUiccCardFromRequest(request);
1201 if (uiccCard == null) {
1202 loge("setForbiddenPlmns: UiccCard is null");
1203 request.result = -1;
1204 notifyRequester(request);
1205 break;
1206 }
1207 Pair<Integer, List<String>> setFplmnsArgs =
1208 (Pair<Integer, List<String>>) request.argument;
1209 appType = setFplmnsArgs.first;
1210 List<String> fplmns = setFplmnsArgs.second;
1211 uiccApp = uiccCard.getApplicationByType(appType);
1212 if (uiccApp == null) {
1213 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1214 request.result = -1;
1215 loge("Failed to get UICC App");
1216 notifyRequester(request);
1217 } else {
1218 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1219 ((SIMRecords) uiccApp.getIccRecords())
1220 .setForbiddenPlmns(onCompleted, fplmns);
1221 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001222 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001223 case CMD_ERASE_MODEM_CONFIG:
1224 request = (MainThreadRequest) msg.obj;
1225 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1226 defaultPhone.eraseModemConfig(onCompleted);
1227 break;
1228 case EVENT_ERASE_MODEM_CONFIG_DONE:
1229 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001230 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001231 default:
1232 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1233 break;
1234 }
1235 }
Jake Hambye994d462014-02-03 13:10:13 -08001236
Pengquan Menga1bb6272018-09-06 09:59:22 -07001237 private void notifyRequester(MainThreadRequest request) {
1238 synchronized (request) {
1239 request.notifyAll();
1240 }
1241 }
1242
Jake Hambye994d462014-02-03 13:10:13 -08001243 private void handleNullReturnEvent(Message msg, String command) {
1244 AsyncResult ar = (AsyncResult) msg.obj;
1245 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1246 if (ar.exception == null) {
1247 request.result = true;
1248 } else {
1249 request.result = false;
1250 if (ar.exception instanceof CommandException) {
1251 loge(command + ": CommandException: " + ar.exception);
1252 } else {
1253 loge(command + ": Unknown exception");
1254 }
1255 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001256 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001258 }
1259
1260 /**
1261 * Posts the specified command to be executed on the main thread,
1262 * waits for the request to complete, and returns the result.
1263 * @see #sendRequestAsync
1264 */
1265 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001266 return sendRequest(
1267 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001268 }
1269
1270 /**
1271 * Posts the specified command to be executed on the main thread,
1272 * waits for the request to complete, and returns the result.
1273 * @see #sendRequestAsync
1274 */
1275 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1276 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001277 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001278 }
1279
1280 /**
1281 * Posts the specified command to be executed on the main thread,
1282 * waits for the request to complete, and returns the result.
1283 * @see #sendRequestAsync
1284 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001285 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001286 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001287 }
1288
1289 /**
1290 * Posts the specified command to be executed on the main thread,
1291 * waits for the request to complete, and returns the result.
1292 * @see #sendRequestAsync
1293 */
Nathan Harold92bed182018-10-12 18:16:49 -07001294 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1295 return sendRequest(command, argument, subId, null, workSource);
1296 }
1297
1298 /**
1299 * Posts the specified command to be executed on the main thread,
1300 * waits for the request to complete, and returns the result.
1301 * @see #sendRequestAsync
1302 */
1303 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1304 return sendRequest(
1305 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1306 }
1307
1308 /**
1309 * Posts the specified command to be executed on the main thread,
1310 * waits for the request to complete, and returns the result.
1311 * @see #sendRequestAsync
1312 */
1313 private Object sendRequest(
1314 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001315 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1316 throw new RuntimeException("This method will deadlock if called from the main thread.");
1317 }
1318
Nathan Harold92bed182018-10-12 18:16:49 -07001319 MainThreadRequest request = null;
1320 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1321 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1322 } else if (phone != null) {
1323 request = new MainThreadRequest(argument, phone, workSource);
1324 } else {
1325 request = new MainThreadRequest(argument, subId, workSource);
1326 }
1327
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001328 Message msg = mMainThreadHandler.obtainMessage(command, request);
1329 msg.sendToTarget();
1330
1331 // Wait for the request to complete
1332 synchronized (request) {
1333 while (request.result == null) {
1334 try {
1335 request.wait();
1336 } catch (InterruptedException e) {
1337 // Do nothing, go back and wait until the request is complete
1338 }
1339 }
1340 }
1341 return request.result;
1342 }
1343
1344 /**
1345 * Asynchronous ("fire and forget") version of sendRequest():
1346 * Posts the specified command to be executed on the main thread, and
1347 * returns immediately.
1348 * @see #sendRequest
1349 */
1350 private void sendRequestAsync(int command) {
1351 mMainThreadHandler.sendEmptyMessage(command);
1352 }
1353
1354 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001355 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001356 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001357 */
1358 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001359 sendRequestAsync(command, argument, null, null);
1360 }
1361
1362 /**
1363 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1364 * @see {@link #sendRequest(int,Object)}
1365 */
1366 private void sendRequestAsync(
1367 int command, Object argument, Phone phone, WorkSource workSource) {
1368 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001369 Message msg = mMainThreadHandler.obtainMessage(command, request);
1370 msg.sendToTarget();
1371 }
1372
1373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001374 * Initialize the singleton PhoneInterfaceManager instance.
1375 * This is only done once, at startup, from PhoneApp.onCreate().
1376 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001377 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001378 synchronized (PhoneInterfaceManager.class) {
1379 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001380 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001381 } else {
1382 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1383 }
1384 return sInstance;
1385 }
1386 }
1387
1388 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001389 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001390 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001391 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001392 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001393 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001394 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1395 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001396 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001397 mTelephonySharedPreferences =
1398 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001399 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001400 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001402 publish();
1403 }
1404
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001405 private Phone getDefaultPhone() {
1406 Phone thePhone = getPhone(getDefaultSubscription());
1407 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1408 }
1409
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001410 private void publish() {
1411 if (DBG) log("publish: " + this);
1412
1413 ServiceManager.addService("phone", this);
1414 }
1415
Stuart Scott584921c2015-01-15 17:10:34 -08001416 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001417 if (request.phone != null) {
1418 return request.phone;
1419 } else {
1420 return getPhoneFromSubId(request.subId);
1421 }
1422 }
1423
1424 private Phone getPhoneFromSubId(int subId) {
1425 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1426 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001427 }
1428
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001429 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1430 Phone phone = getPhoneFromRequest(request);
1431 return phone == null ? null :
1432 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1433 }
1434
Wink Saville36469e72014-06-11 15:17:00 -07001435 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001436 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001437 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001439
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001440 private void sendEraseModemConfig(Phone phone) {
1441 if (phone != null) {
1442 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1443 mApp, phone.getSubId(), "eraseModemConfig");
1444 final long identity = Binder.clearCallingIdentity();
1445 try {
1446 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1447 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1448 } finally {
1449 Binder.restoreCallingIdentity(identity);
1450 }
1451 }
1452 }
1453
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001455 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001456 }
1457
Wink Savilleb564aae2014-10-23 10:18:09 -07001458 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001459 if (DBG) log("dial: " + number);
1460 // No permission check needed here: This is just a wrapper around the
1461 // ACTION_DIAL intent, which is available to any app since it puts up
1462 // the UI before it does anything.
1463
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001464 final long identity = Binder.clearCallingIdentity();
1465 try {
1466 String url = createTelUrl(number);
1467 if (url == null) {
1468 return;
1469 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001471 // PENDING: should we just silently fail if phone is offhook or ringing?
1472 PhoneConstants.State state = mCM.getState(subId);
1473 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1474 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1475 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1476 mApp.startActivity(intent);
1477 }
1478 } finally {
1479 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001480 }
1481 }
1482
1483 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001484 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001485 }
1486
Wink Savilleb564aae2014-10-23 10:18:09 -07001487 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001488 if (DBG) log("call: " + number);
1489
1490 // This is just a wrapper around the ACTION_CALL intent, but we still
1491 // need to do a permission check since we're calling startActivity()
1492 // from the context of the phone app.
1493 enforceCallPermission();
1494
Jordan Liu1617b712019-07-10 15:06:26 -07001495 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001496 != AppOpsManager.MODE_ALLOWED) {
1497 return;
1498 }
1499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001500 final long identity = Binder.clearCallingIdentity();
1501 try {
1502 String url = createTelUrl(number);
1503 if (url == null) {
1504 return;
1505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001506
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001507 boolean isValid = false;
1508 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1509 if (slist != null) {
1510 for (SubscriptionInfo subInfoRecord : slist) {
1511 if (subInfoRecord.getSubscriptionId() == subId) {
1512 isValid = true;
1513 break;
1514 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001515 }
Wink Saville08874612014-08-31 19:19:58 -07001516 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001517 if (!isValid) {
1518 return;
1519 }
Wink Saville08874612014-08-31 19:19:58 -07001520
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001521 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1522 intent.putExtra(SUBSCRIPTION_KEY, subId);
1523 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1524 mApp.startActivity(intent);
1525 } finally {
1526 Binder.restoreCallingIdentity(identity);
1527 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001528 }
1529
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001530 public boolean supplyPin(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001531 return supplyPinForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001532 }
1533
Wink Savilleb564aae2014-10-23 10:18:09 -07001534 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001535 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001536 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1537 }
1538
1539 public boolean supplyPuk(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001540 return supplyPukForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001541 }
1542
Wink Savilleb564aae2014-10-23 10:18:09 -07001543 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001544 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001545 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1546 }
1547
1548 /** {@hide} */
1549 public int[] supplyPinReportResult(String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001550 return supplyPinReportResultForSubscriber(getDefaultSubscription(), pin);
Wink Saville36469e72014-06-11 15:17:00 -07001551 }
1552
Wink Savilleb564aae2014-10-23 10:18:09 -07001553 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001554 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001555
1556 final long identity = Binder.clearCallingIdentity();
1557 try {
1558 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1559 checkSimPin.start();
1560 return checkSimPin.unlockSim(null, pin);
1561 } finally {
1562 Binder.restoreCallingIdentity(identity);
1563 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001564 }
1565
Wink Saville9de0f752013-10-22 19:04:03 -07001566 /** {@hide} */
1567 public int[] supplyPukReportResult(String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001568 return supplyPukReportResultForSubscriber(getDefaultSubscription(), puk, pin);
Wink Saville36469e72014-06-11 15:17:00 -07001569 }
1570
Wink Savilleb564aae2014-10-23 10:18:09 -07001571 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001572 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001573
1574 final long identity = Binder.clearCallingIdentity();
1575 try {
1576 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1577 checkSimPuk.start();
1578 return checkSimPuk.unlockSim(puk, pin);
1579 } finally {
1580 Binder.restoreCallingIdentity(identity);
1581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 }
1583
1584 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001585 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 * a synchronous one.
1587 */
1588 private static class UnlockSim extends Thread {
1589
1590 private final IccCard mSimCard;
1591
1592 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001593 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1594 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595
1596 // For replies from SimCard interface
1597 private Handler mHandler;
1598
1599 // For async handler to identify request type
1600 private static final int SUPPLY_PIN_COMPLETE = 100;
1601
1602 public UnlockSim(IccCard simCard) {
1603 mSimCard = simCard;
1604 }
1605
1606 @Override
1607 public void run() {
1608 Looper.prepare();
1609 synchronized (UnlockSim.this) {
1610 mHandler = new Handler() {
1611 @Override
1612 public void handleMessage(Message msg) {
1613 AsyncResult ar = (AsyncResult) msg.obj;
1614 switch (msg.what) {
1615 case SUPPLY_PIN_COMPLETE:
1616 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1617 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001618 mRetryCount = msg.arg1;
1619 if (ar.exception != null) {
1620 if (ar.exception instanceof CommandException &&
1621 ((CommandException)(ar.exception)).getCommandError()
1622 == CommandException.Error.PASSWORD_INCORRECT) {
1623 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1624 } else {
1625 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1626 }
1627 } else {
1628 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1629 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001630 mDone = true;
1631 UnlockSim.this.notifyAll();
1632 }
1633 break;
1634 }
1635 }
1636 };
1637 UnlockSim.this.notifyAll();
1638 }
1639 Looper.loop();
1640 }
1641
1642 /*
1643 * Use PIN or PUK to unlock SIM card
1644 *
1645 * If PUK is null, unlock SIM card with PIN
1646 *
1647 * If PUK is not null, unlock SIM card with PUK and set PIN code
1648 */
Wink Saville9de0f752013-10-22 19:04:03 -07001649 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001650
1651 while (mHandler == null) {
1652 try {
1653 wait();
1654 } catch (InterruptedException e) {
1655 Thread.currentThread().interrupt();
1656 }
1657 }
1658 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1659
1660 if (puk == null) {
1661 mSimCard.supplyPin(pin, callback);
1662 } else {
1663 mSimCard.supplyPuk(puk, pin, callback);
1664 }
1665
1666 while (!mDone) {
1667 try {
1668 Log.d(LOG_TAG, "wait for done");
1669 wait();
1670 } catch (InterruptedException e) {
1671 // Restore the interrupted status
1672 Thread.currentThread().interrupt();
1673 }
1674 }
1675 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001676 int[] resultArray = new int[2];
1677 resultArray[0] = mResult;
1678 resultArray[1] = mRetryCount;
1679 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001680 }
1681 }
1682
1683 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001684 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001685
1686 }
1687
Wink Savilleb564aae2014-10-23 10:18:09 -07001688 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001689 // No permission check needed here: this call is harmless, and it's
1690 // needed for the ServiceState.requestStateUpdate() call (which is
1691 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001692 final long identity = Binder.clearCallingIdentity();
1693 try {
1694 final Phone phone = getPhone(subId);
1695 if (phone != null) {
1696 phone.updateServiceLocation();
1697 }
1698 } finally {
1699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001701 }
1702
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001703 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001704 @Override
1705 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001706 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001707 }
1708
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001709 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001710 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1711 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1712 callingFeatureId);
1713 }
1714
1715 @Deprecated
1716 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001717 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001718 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1719 }
1720
1721 @Override
1722 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1723 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001725 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001726 return false;
1727 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728
1729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 return isRadioOnForSubscriber(subId);
1732 } finally {
1733 Binder.restoreCallingIdentity(identity);
1734 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001735 }
1736
1737 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001738 final long identity = Binder.clearCallingIdentity();
1739 try {
1740 final Phone phone = getPhone(subId);
1741 if (phone != null) {
1742 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1743 } else {
1744 return false;
1745 }
1746 } finally {
1747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001749 }
1750
1751 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001752 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 }
Wink Saville36469e72014-06-11 15:17:00 -07001754
Wink Savilleb564aae2014-10-23 10:18:09 -07001755 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001757
1758 final long identity = Binder.clearCallingIdentity();
1759 try {
1760 final Phone phone = getPhone(subId);
1761 if (phone != null) {
1762 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1763 }
1764 } finally {
1765 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001766 }
Wink Saville36469e72014-06-11 15:17:00 -07001767 }
1768
1769 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001770 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001771 }
1772
Wink Savilleb564aae2014-10-23 10:18:09 -07001773 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001774 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001775
1776 final long identity = Binder.clearCallingIdentity();
1777 try {
1778 final Phone phone = getPhone(subId);
1779 if (phone == null) {
1780 return false;
1781 }
1782 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1783 toggleRadioOnOffForSubscriber(subId);
1784 }
1785 return true;
1786 } finally {
1787 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001788 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001789 }
Wink Saville36469e72014-06-11 15:17:00 -07001790
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001791 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001792 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001793 /*
1794 * If any of the Radios are available, it will need to be
1795 * shutdown. So return true if any Radio is available.
1796 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 final long identity = Binder.clearCallingIdentity();
1798 try {
1799 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1800 Phone phone = PhoneFactory.getPhone(i);
1801 if (phone != null && phone.isRadioAvailable()) return true;
1802 }
1803 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1804 return false;
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001807 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001808 }
1809
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001810 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001811 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001812 enforceModifyPermission();
1813
1814 final long identity = Binder.clearCallingIdentity();
1815 try {
1816 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1817 logv("Shutting down Phone " + i);
1818 shutdownRadioUsingPhoneId(i);
1819 }
1820 } finally {
1821 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001822 }
1823 }
1824
1825 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001826 Phone phone = PhoneFactory.getPhone(phoneId);
1827 if (phone != null && phone.isRadioAvailable()) {
1828 phone.shutdownRadio();
1829 }
1830 }
1831
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07001833 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001834
1835 final long identity = Binder.clearCallingIdentity();
1836 try {
1837 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
1838 if (defaultPhone != null) {
1839 defaultPhone.setRadioPower(turnOn);
1840 return true;
1841 } else {
1842 loge("There's no default phone.");
1843 return false;
1844 }
1845 } finally {
1846 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07001847 }
Wink Saville36469e72014-06-11 15:17:00 -07001848 }
1849
Wink Savilleb564aae2014-10-23 10:18:09 -07001850 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001851 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001852
1853 final long identity = Binder.clearCallingIdentity();
1854 try {
1855 final Phone phone = getPhone(subId);
1856 if (phone != null) {
1857 phone.setRadioPower(turnOn);
1858 return true;
1859 } else {
1860 return false;
1861 }
1862 } finally {
1863 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001865 }
1866
Wink Saville36469e72014-06-11 15:17:00 -07001867 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001868 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001869 public boolean enableDataConnectivity() {
1870 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001871
1872 final long identity = Binder.clearCallingIdentity();
1873 try {
1874 int subId = mSubscriptionController.getDefaultDataSubId();
1875 final Phone phone = getPhone(subId);
1876 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001877 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001878 return true;
1879 } else {
1880 return false;
1881 }
1882 } finally {
1883 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001884 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001885 }
1886
Wink Saville36469e72014-06-11 15:17:00 -07001887 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 public boolean disableDataConnectivity() {
1890 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001891
1892 final long identity = Binder.clearCallingIdentity();
1893 try {
1894 int subId = mSubscriptionController.getDefaultDataSubId();
1895 final Phone phone = getPhone(subId);
1896 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08001897 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001898 return true;
1899 } else {
1900 return false;
1901 }
1902 } finally {
1903 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001904 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001905 }
1906
Sanket Padawe356d7632015-06-22 14:03:32 -07001907 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07001908 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001909 final long identity = Binder.clearCallingIdentity();
1910 try {
1911 final Phone phone = getPhone(subId);
1912 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08001913 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001914 } else {
1915 return false;
1916 }
1917 } finally {
1918 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001919 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001920 }
1921
1922 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001923 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07001924 }
1925
pkanwarae03a6b2016-11-06 20:37:09 -08001926 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001927 enforceCallPermission();
1928
1929 final long identity = Binder.clearCallingIdentity();
1930 try {
1931 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1932 return;
1933 }
1934 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
1935 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
1936 } finally {
1937 Binder.restoreCallingIdentity(identity);
1938 }
pkanwar32d516d2016-10-14 19:37:38 -07001939 };
1940
Wink Savilleb564aae2014-10-23 10:18:09 -07001941 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001943
1944 final long identity = Binder.clearCallingIdentity();
1945 try {
1946 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1947 return false;
1948 }
1949 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
1950 } finally {
1951 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001952 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001953 }
1954
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07001956 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Sanket Padawe13bac7b2017-03-20 15:04:47 -07001959 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001960 final long identity = Binder.clearCallingIdentity();
1961 try {
1962 Phone phone = PhoneFactory.getPhone(slotIndex);
1963 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
1964 PhoneConstantConversions.convertCallState(phone.getState());
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
1967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Sanket Padawe356d7632015-06-22 14:03:32 -07001970 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001971 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001972 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
1973 }
1974
1975 @Override
1976 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001977 final long identity = Binder.clearCallingIdentity();
1978 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001979 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 if (phone != null) {
1981 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
1982 } else {
1983 return PhoneConstantConversions.convertDataState(
1984 PhoneConstants.DataState.DISCONNECTED);
1985 }
1986 } finally {
1987 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 }
1990
Sanket Padawe356d7632015-06-22 14:03:32 -07001991 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00001992 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07001993 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
1994 }
1995
1996 @Override
1997 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 final long identity = Binder.clearCallingIdentity();
1999 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002001 if (phone != null) {
2002 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2003 } else {
2004 return TelephonyManager.DATA_ACTIVITY_NONE;
2005 }
2006 } finally {
2007 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002008 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 }
2010
2011 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002012 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002013 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002014 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002015
2016 LocationAccessPolicy.LocationPermissionResult locationResult =
2017 LocationAccessPolicy.checkLocationPermission(mApp,
2018 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2019 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002020 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002021 .setCallingPid(Binder.getCallingPid())
2022 .setCallingUid(Binder.getCallingUid())
2023 .setMethod("getCellLocation")
2024 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2025 .build());
2026 switch (locationResult) {
2027 case DENIED_HARD:
2028 throw new SecurityException("Not allowed to access cell location");
2029 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002030 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2031 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002035 final long identity = Binder.clearCallingIdentity();
2036 try {
2037 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002038 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002039 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040 } finally {
2041 Binder.restoreCallingIdentity(identity);
2042 }
Svetoslav64fad262015-04-14 14:35:21 -07002043 }
2044
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002045 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002046 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2047 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002048 if (!TextUtils.isEmpty(callingPackage)) {
2049 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002050 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2051 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002052 return "";
2053 }
2054 }
2055
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002056 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2057 // registered cell info, so return a NULL country instead.
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002060 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2061 // Get default phone in this case.
2062 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2063 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002064 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002065 // Todo: fix this when we can get the actual cellular network info when the device
2066 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002067 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002068 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2069 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002070 return "";
2071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002072 Phone phone = PhoneFactory.getPhone(phoneId);
2073 if (phone != null) {
2074 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002075 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 if (sst != null) {
2077 LocaleTracker lt = sst.getLocaleTracker();
2078 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002079 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2080 return lt.getCurrentCountry();
2081 } else if (emergencyNumberTracker != null) {
2082 return emergencyNumberTracker.getEmergencyCountryIso();
2083 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002084 }
2085 }
2086 }
2087 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002088 } finally {
2089 Binder.restoreCallingIdentity(identity);
2090 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002091 }
2092
2093 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002094 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002095 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002096 }
2097
Sanket Padawe356d7632015-06-22 14:03:32 -07002098 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002099 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 mApp.enforceCallingOrSelfPermission(
2101 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone phone = getPhone(subId);
2106 if (phone != null) {
2107 phone.enableLocationUpdates();
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002111 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002112 }
2113
2114 @Override
2115 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002116 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002117 }
2118
Sanket Padawe356d7632015-06-22 14:03:32 -07002119 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002120 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002121 mApp.enforceCallingOrSelfPermission(
2122 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002123
2124 final long identity = Binder.clearCallingIdentity();
2125 try {
2126 final Phone phone = getPhone(subId);
2127 if (phone != null) {
2128 phone.disableLocationUpdates();
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Nathan Harold31d7ff32018-10-15 20:20:30 -07002135 /**
2136 * Returns the target SDK version number for a given package name.
2137 *
Nathan Haroldec184742019-07-10 17:04:16 -07002138 * This call MUST be invoked before clearing the calling UID.
2139 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002140 * @return target SDK if the package is found or INT_MAX.
2141 */
2142 private int getTargetSdk(String packageName) {
2143 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002144 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002145 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002146 if (ai != null) return ai.targetSdkVersion;
2147 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002148 loge("Failed to get package info for pkg="
2149 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002150 }
2151 return Integer.MAX_VALUE;
2152 }
2153
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 @Override
2155 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002156 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2157 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002158 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002159 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2160 throw new SecurityException(
2161 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2162 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002163
Jordan Liu1617b712019-07-10 15:06:26 -07002164 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2166 return null;
2167 }
Svetoslav64fad262015-04-14 14:35:21 -07002168
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002169 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002171 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002172 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173
Nathan Haroldf180aac2018-06-01 18:43:55 -07002174 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2175 for (CellInfo ci : info) {
2176 if (ci instanceof CellInfoGsm) {
2177 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2178 } else if (ci instanceof CellInfoWcdma) {
2179 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002182 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002185 private List<CellInfo> getCachedCellInfo() {
2186 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2187 for (Phone phone : PhoneFactory.getPhones()) {
2188 List<CellInfo> info = phone.getAllCellInfo();
2189 if (info != null) cellInfos.addAll(info);
2190 }
2191 return cellInfos;
2192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002193
2194 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002195 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002196 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002197 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002198
2199 LocationAccessPolicy.LocationPermissionResult locationResult =
2200 LocationAccessPolicy.checkLocationPermission(mApp,
2201 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2202 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002203 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002204 .setCallingPid(Binder.getCallingPid())
2205 .setCallingUid(Binder.getCallingUid())
2206 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002207 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002208 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2209 .build());
2210 switch (locationResult) {
2211 case DENIED_HARD:
2212 throw new SecurityException("Not allowed to access cell info");
2213 case DENIED_SOFT:
2214 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215 }
2216
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002217 final int targetSdk = getTargetSdk(callingPackage);
2218 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2219 return getCachedCellInfo();
2220 }
2221
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002222 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002223 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2227 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002228 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002229 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 if (info != null) cellInfos.addAll(info);
2231 }
2232 return cellInfos;
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236 }
2237
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002238 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002239 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2240 String callingFeatureId) {
2241 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2242 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002243 }
2244
2245 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002246 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2247 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002248 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002249 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002250 }
2251
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002252 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2253 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002254 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002255 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002256
2257 LocationAccessPolicy.LocationPermissionResult locationResult =
2258 LocationAccessPolicy.checkLocationPermission(mApp,
2259 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2260 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002261 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002262 .setCallingPid(Binder.getCallingPid())
2263 .setCallingUid(Binder.getCallingUid())
2264 .setMethod("requestCellInfoUpdate")
2265 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2266 .build());
2267 switch (locationResult) {
2268 case DENIED_HARD:
2269 throw new SecurityException("Not allowed to access cell info");
2270 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002271 try {
2272 cb.onCellInfo(new ArrayList<CellInfo>());
2273 } catch (RemoteException re) {
2274 // Drop without consequences
2275 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002276 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002277 }
2278
Nathan Harolda939a962019-05-09 10:13:47 -07002279
2280 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002281 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2282
2283 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2284 }
2285
2286 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002288 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002293 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 } finally {
2295 Binder.restoreCallingIdentity(identity);
2296 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Shishir Agrawala9f32182016-04-12 12:00:16 -07002299 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002300 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002301 Phone phone = PhoneFactory.getPhone(slotIndex);
2302 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002303 return null;
2304 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002305 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002306 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002307 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002308 return null;
2309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002310
2311 final long identity = Binder.clearCallingIdentity();
2312 try {
2313 return phone.getImei();
2314 } finally {
2315 Binder.restoreCallingIdentity(identity);
2316 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002317 }
2318
2319 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002320 public String getTypeAllocationCodeForSlot(int slotIndex) {
2321 Phone phone = PhoneFactory.getPhone(slotIndex);
2322 String tac = null;
2323 if (phone != null) {
2324 String imei = phone.getImei();
2325 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2326 }
2327 return tac;
2328 }
2329
2330 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002331 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002332 Phone phone = PhoneFactory.getPhone(slotIndex);
2333 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002334 return null;
2335 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002336
Jeff Davidson913390f2018-02-23 17:11:49 -08002337 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002338 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002339 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002340 return null;
2341 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002342
2343 final long identity = Binder.clearCallingIdentity();
2344 try {
2345 return phone.getMeid();
2346 } finally {
2347 Binder.restoreCallingIdentity(identity);
2348 }
Jack Yu2af8d712017-03-15 17:14:14 -07002349 }
2350
2351 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002352 public String getManufacturerCodeForSlot(int slotIndex) {
2353 Phone phone = PhoneFactory.getPhone(slotIndex);
2354 String manufacturerCode = null;
2355 if (phone != null) {
2356 String meid = phone.getMeid();
2357 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2358 }
2359 return manufacturerCode;
2360 }
2361
2362 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002363 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2364 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002365 Phone phone = PhoneFactory.getPhone(slotIndex);
2366 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002367 return null;
2368 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002369 int subId = phone.getSubId();
2370 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002371 mApp, subId, callingPackage, callingFeatureId,
2372 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002373 return null;
2374 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002375
2376 final long identity = Binder.clearCallingIdentity();
2377 try {
2378 return phone.getDeviceSvn();
2379 } finally {
2380 Binder.restoreCallingIdentity(identity);
2381 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002382 }
2383
fionaxu43304da2017-11-27 22:51:16 -08002384 @Override
2385 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002386 final long identity = Binder.clearCallingIdentity();
2387 try {
2388 final Phone phone = getPhone(subId);
2389 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2390 } finally {
2391 Binder.restoreCallingIdentity(identity);
2392 }
fionaxu43304da2017-11-27 22:51:16 -08002393 }
2394
2395 @Override
2396 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002397 final long identity = Binder.clearCallingIdentity();
2398 try {
2399 final Phone phone = getPhone(subId);
2400 return phone == null ? null : phone.getCarrierName();
2401 } finally {
2402 Binder.restoreCallingIdentity(identity);
2403 }
fionaxu43304da2017-11-27 22:51:16 -08002404 }
2405
calvinpanffe225e2018-11-01 19:43:06 +08002406 @Override
chen xu0026ca62019-03-06 15:28:50 -08002407 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002408 final long identity = Binder.clearCallingIdentity();
2409 try {
2410 final Phone phone = getPhone(subId);
2411 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002412 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002413 } finally {
2414 Binder.restoreCallingIdentity(identity);
2415 }
2416 }
2417
2418 @Override
chen xu0026ca62019-03-06 15:28:50 -08002419 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002420 final long identity = Binder.clearCallingIdentity();
2421 try {
2422 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002423 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002424 } finally {
2425 Binder.restoreCallingIdentity(identity);
2426 }
2427 }
2428
chen xu651eec72018-11-11 19:03:44 -08002429 @Override
chen xu864e11c2018-12-06 22:10:03 -08002430 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2431 if (!isSubscriptionMccMnc) {
2432 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2433 }
chen xu651eec72018-11-11 19:03:44 -08002434 final Phone phone = PhoneFactory.getPhone(slotIndex);
2435 if (phone == null) {
2436 return TelephonyManager.UNKNOWN_CARRIER_ID;
2437 }
2438 final long identity = Binder.clearCallingIdentity();
2439 try {
2440 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2441 } finally {
2442 Binder.restoreCallingIdentity(identity);
2443 }
2444 }
2445
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002446 //
2447 // Internal helper methods.
2448 //
2449
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002450 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002451 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2452 *
2453 * @throws SecurityException if the caller does not have the required permission
2454 */
2455 private void enforceModifyPermission() {
2456 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2457 }
2458
Shuo Qianf2b2df42019-11-13 17:43:31 -08002459 private void enforceActiveEmergencySessionPermission() {
2460 mApp.enforceCallingOrSelfPermission(
2461 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2462 }
2463
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 /**
2465 * Make sure the caller has the CALL_PHONE permission.
2466 *
2467 * @throws SecurityException if the caller does not have the required permission
2468 */
2469 private void enforceCallPermission() {
2470 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2471 }
2472
paulhu423b5f22019-08-23 19:17:33 +08002473 private void enforceSettingsPermission() {
2474 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002475 }
2476
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 private String createTelUrl(String number) {
2478 if (TextUtils.isEmpty(number)) {
2479 return null;
2480 }
2481
Jake Hambye994d462014-02-03 13:10:13 -08002482 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484
Ihab Awadf9e92732013-12-05 18:02:52 -08002485 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002486 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2487 }
2488
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002489 private static void logv(String msg) {
2490 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2491 }
2492
Ihab Awadf9e92732013-12-05 18:02:52 -08002493 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002494 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2495 }
2496
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002497 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002499 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002500 }
2501
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002503 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504 final long identity = Binder.clearCallingIdentity();
2505 try {
2506 final Phone phone = PhoneFactory.getPhone(slotIndex);
2507 if (phone == null) {
2508 return PhoneConstants.PHONE_TYPE_NONE;
2509 } else {
2510 return phone.getPhoneType();
2511 }
2512 } finally {
2513 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002514 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002515 }
2516
2517 /**
2518 * Returns the CDMA ERI icon index to display
2519 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002520 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002521 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2522 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2523 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
2525
Sanket Padawe356d7632015-06-22 14:03:32 -07002526 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2528 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002529 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002530 mApp, subId, callingPackage, callingFeatureId,
2531 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002532 return -1;
2533 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002534
2535 final long identity = Binder.clearCallingIdentity();
2536 try {
2537 final Phone phone = getPhone(subId);
2538 if (phone != null) {
2539 return phone.getCdmaEriIconIndex();
2540 } else {
2541 return -1;
2542 }
2543 } finally {
2544 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002545 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002546 }
2547
2548 /**
2549 * Returns the CDMA ERI icon mode,
2550 * 0 - ON
2551 * 1 - FLASHING
2552 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002553 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002554 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2555 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2556 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002557 }
2558
Sanket Padawe356d7632015-06-22 14:03:32 -07002559 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002560 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2561 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002562 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002563 mApp, subId, callingPackage, callingFeatureId,
2564 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002565 return -1;
2566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 final Phone phone = getPhone(subId);
2571 if (phone != null) {
2572 return phone.getCdmaEriIconMode();
2573 } else {
2574 return -1;
2575 }
2576 } finally {
2577 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002578 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002579 }
2580
2581 /**
2582 * Returns the CDMA ERI text,
2583 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002584 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002585 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2586 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2587 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Sanket Padawe356d7632015-06-22 14:03:32 -07002590 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002591 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2592 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002593 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002594 mApp, subId, callingPackage, callingFeatureId,
2595 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002596 return null;
2597 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598
2599 final long identity = Binder.clearCallingIdentity();
2600 try {
2601 final Phone phone = getPhone(subId);
2602 if (phone != null) {
2603 return phone.getCdmaEriText();
2604 } else {
2605 return null;
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
2612 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002613 * Returns the CDMA MDN.
2614 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002615 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002616 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2618 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619
2620 final long identity = Binder.clearCallingIdentity();
2621 try {
2622 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002623 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002624 return phone.getLine1Number();
2625 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002626 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627 return null;
2628 }
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002631 }
2632 }
2633
2634 /**
2635 * Returns the CDMA MIN.
2636 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002637 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002638 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002639 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2640 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2646 return phone.getCdmaMin();
2647 } else {
2648 return null;
2649 }
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002652 }
2653 }
2654
Hall Liud892bec2018-11-30 14:51:45 -08002655 @Override
2656 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2657 INumberVerificationCallback callback, String callingPackage) {
2658 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2659 != PERMISSION_GRANTED) {
2660 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2661 }
2662 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2663
2664 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2665 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2666 throw new SecurityException("Calling package must be configured in the device config");
2667 }
2668
2669 if (range == null) {
2670 throw new NullPointerException("Range must be non-null");
2671 }
2672
2673 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002674 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002675
2676 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2677 }
2678
Junda Liuca05d5d2014-08-14 22:36:34 -07002679 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 * Returns true if CDMA provisioning needs to run.
2681 */
2682 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002683 final long identity = Binder.clearCallingIdentity();
2684 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002685 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002689 }
2690
2691 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002692 * Sets the voice mail number of a given subId.
2693 */
2694 @Override
2695 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002696 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697
2698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2701 new Pair<String, String>(alphaTag, number), new Integer(subId));
2702 return success;
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002706 }
2707
Ta-wei Yen87c49842016-05-13 21:19:52 -07002708 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002709 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2710 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002711 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2712 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002713 if (!TextUtils.equals(callingPackage, systemDialer)) {
2714 throw new SecurityException("caller must be system dialer");
2715 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002716
2717 final long identity = Binder.clearCallingIdentity();
2718 try {
2719 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2720 if (phoneAccountHandle == null) {
2721 return null;
2722 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002723 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002726 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002727 }
2728
2729 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002730 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2731 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002732 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002734 mApp, subId, callingPackage, callingFeatureId,
2735 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002736 return null;
2737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002739 final long identity = Binder.clearCallingIdentity();
2740 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002741 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002742 } finally {
2743 Binder.restoreCallingIdentity(identity);
2744 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002745 }
2746
2747 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002748 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2749 VisualVoicemailSmsFilterSettings settings) {
2750 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002751
2752 final long identity = Binder.clearCallingIdentity();
2753 try {
2754 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002756 } finally {
2757 Binder.restoreCallingIdentity(identity);
2758 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002759 }
2760
2761 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002762 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2763 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002764
2765 final long identity = Binder.clearCallingIdentity();
2766 try {
2767 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002768 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002769 } finally {
2770 Binder.restoreCallingIdentity(identity);
2771 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002772 }
2773
2774 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002775 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2776 String callingPackage, int subId) {
2777 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778
2779 final long identity = Binder.clearCallingIdentity();
2780 try {
2781 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002782 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002786 }
2787
2788 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002789 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002790 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002791
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
2794 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002795 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796 } finally {
2797 Binder.restoreCallingIdentity(identity);
2798 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002799 }
2800
2801 @Override
2802 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
2803 String number, int port, String text, PendingIntent sentIntent) {
2804 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08002805 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002806 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07002807 SmsController smsController = PhoneFactory.getSmsController();
2808 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
2809 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07002810 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07002811
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002812 /**
fionaxu0152e512016-11-14 13:36:14 -08002813 * Sets the voice activation state of a given subId.
2814 */
2815 @Override
2816 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2818 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002819
2820 final long identity = Binder.clearCallingIdentity();
2821 try {
2822 final Phone phone = getPhone(subId);
2823 if (phone != null) {
2824 phone.setVoiceActivationState(activationState);
2825 } else {
2826 loge("setVoiceActivationState fails with invalid subId: " + subId);
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002830 }
2831 }
2832
2833 /**
2834 * Sets the data activation state of a given subId.
2835 */
2836 @Override
2837 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002840
2841 final long identity = Binder.clearCallingIdentity();
2842 try {
2843 final Phone phone = getPhone(subId);
2844 if (phone != null) {
2845 phone.setDataActivationState(activationState);
2846 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09002847 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002851 }
2852 }
2853
2854 /**
2855 * Returns the voice activation state of a given subId.
2856 */
2857 @Override
2858 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002859 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
fionaxu0152e512016-11-14 13:36:14 -08002861 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 final long identity = Binder.clearCallingIdentity();
2863 try {
2864 if (phone != null) {
2865 return phone.getVoiceActivationState();
2866 } else {
2867 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002871 }
2872 }
2873
2874 /**
2875 * Returns the data activation state of a given subId.
2876 */
2877 @Override
2878 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002879 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
fionaxu0152e512016-11-14 13:36:14 -08002881 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 if (phone != null) {
2885 return phone.getDataActivationState();
2886 } else {
2887 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08002891 }
2892 }
2893
2894 /**
Wink Saville36469e72014-06-11 15:17:00 -07002895 * Returns the unread count of voicemails for a subId
2896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002898 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
2899 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002901 mApp, subId, callingPackage, callingFeatureId,
2902 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08002903 return 0;
2904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 final Phone phone = getPhone(subId);
2908 if (phone != null) {
2909 return phone.getVoiceMessageCount();
2910 } else {
2911 return 0;
2912 }
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002915 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917
2918 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08002919 * returns true, if the device is in a state where both voice and data
2920 * are supported simultaneously. This can change based on location or network condition.
2921 */
2922 @Override
2923 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
2928 } finally {
2929 Binder.restoreCallingIdentity(identity);
2930 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08002931 }
2932
2933 /**
fionaxu235cc5e2017-03-06 22:25:57 -08002934 * Send the dialer code if called from the current default dialer or the caller has
2935 * carrier privilege.
2936 * @param inputCode The dialer code to send
2937 */
2938 @Override
2939 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002940 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08002941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002942 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
2943 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08002944 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002945 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2946 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08002947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948
2949 final long identity = Binder.clearCallingIdentity();
2950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
fionaxu235cc5e2017-03-06 22:25:57 -08002955 }
2956
Pengquan Menga1bb6272018-09-06 09:59:22 -07002957 @Override
2958 public int getNetworkSelectionMode(int subId) {
Pengquan Menge92a50d2018-09-21 15:54:48 -07002959 if (!isActiveSubscription(subId)) {
2960 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
2961 }
2962
Pengquan Menga1bb6272018-09-06 09:59:22 -07002963 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
2964 }
2965
Brad Ebinger35c841c2018-10-01 10:40:55 -07002966 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07002967 public boolean isInEmergencySmsMode() {
2968 enforceReadPrivilegedPermission("isInEmergencySmsMode");
2969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 for (Phone phone : PhoneFactory.getPhones()) {
2972 if (phone.isInEmergencySmsMode()) {
2973 return true;
2974 }
2975 }
2976 } finally {
2977 Binder.restoreCallingIdentity(identity);
2978 }
2979 return false;
2980 }
2981
2982 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08002983 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
2984 throws RemoteException {
2985 enforceReadPrivilegedPermission("registerImsRegistrationCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07002986 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
2987 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
2988 "IMS not available on device.");
2989 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 final long token = Binder.clearCallingIdentity();
2991 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08002992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002993 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07002994 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07002995 } catch (ImsException e) {
2996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07002997 } finally {
2998 Binder.restoreCallingIdentity(token);
2999 }
3000 }
3001
3002 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003003 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
3004 enforceReadPrivilegedPermission("unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003005 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3006 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3007 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003008 final long token = Binder.clearCallingIdentity();
3009 try {
3010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3012 .removeRegistrationCallbackForSubscription(c, subId);
3013 } catch (ImsException e) {
3014 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3015 + "is inactive, ignoring unregister.");
3016 // If the subscription is no longer active, just return, since the callback
3017 // will already have been removed internally.
3018 } finally {
3019 Binder.restoreCallingIdentity(token);
3020 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003021 }
3022
Brad Ebinger774ba362019-10-22 17:36:18 -07003023 /**
3024 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3025 */
3026 @Override
3027 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3028 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3029 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3030 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3031 "IMS not available on device.");
3032 }
3033 final long token = Binder.clearCallingIdentity();
3034 try {
3035 Phone phone = getPhone(subId);
3036 if (phone == null) {
3037 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3038 + subId + "'");
3039 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3040 }
3041 phone.getImsRegistrationState(regState -> {
3042 try {
3043 consumer.accept((regState == null)
3044 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3045 } catch (RemoteException e) {
3046 // Ignore if the remote process is no longer available to call back.
3047 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3048 }
3049 });
3050 } finally {
3051 Binder.restoreCallingIdentity(token);
3052 }
3053 }
3054
3055 /**
3056 * Get the transport type for the IMS service registration state.
3057 */
3058 @Override
3059 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
3060 enforceReadPrivilegedPermission("getImsMmTelRegistrationTransportType");
3061 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3062 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3063 "IMS not available on device.");
3064 }
3065 final long token = Binder.clearCallingIdentity();
3066 try {
3067 Phone phone = getPhone(subId);
3068 if (phone == null) {
3069 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3070 + subId + "'");
3071 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3072 }
3073 phone.getImsRegistrationTech(regTech -> {
3074 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3075 int regTechConverted = (regTech == null)
3076 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3077 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3078 regTechConverted);
3079 try {
3080 consumer.accept(regTechConverted);
3081 } catch (RemoteException e) {
3082 // Ignore if the remote process is no longer available to call back.
3083 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3084 }
3085 });
3086 } finally {
3087 Binder.restoreCallingIdentity(token);
3088 }
3089 }
3090
Brad Ebinger35c841c2018-10-01 10:40:55 -07003091 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003092 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3093 throws RemoteException {
3094 enforceReadPrivilegedPermission("registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003095 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3096 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3097 "IMS not available on device.");
3098 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003099 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3100 final long token = Binder.clearCallingIdentity();
3101 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003102 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003103 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003104 } catch (ImsException e) {
3105 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003106 } finally {
3107 Binder.restoreCallingIdentity(token);
3108 }
3109 }
3110
3111 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003112 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
3113 enforceReadPrivilegedPermission("unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3115 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3116 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003117
3118 final long token = Binder.clearCallingIdentity();
3119 try {
3120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3121 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003122 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003123 } catch (ImsException e) {
3124 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3125 + "is inactive, ignoring unregister.");
3126 // If the subscription is no longer active, just return, since the callback
3127 // will already have been removed internally.
3128 } finally {
3129 Binder.restoreCallingIdentity(token);
3130 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003131 }
3132
3133 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003134 public boolean isCapable(int subId, int capability, int regTech) {
3135 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3137 final long token = Binder.clearCallingIdentity();
3138 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003139 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003140 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003141 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003142 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3143 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003144 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003145 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3146 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 } finally {
3148 Binder.restoreCallingIdentity(token);
3149 }
3150 }
3151
3152 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003153 public boolean isAvailable(int subId, int capability, int regTech) {
3154 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003155 final long token = Binder.clearCallingIdentity();
3156 try {
3157 Phone phone = getPhone(subId);
3158 if (phone == null) return false;
3159 return phone.isImsCapabilityAvailable(capability, regTech);
3160 } finally {
3161 Binder.restoreCallingIdentity(token);
3162 }
3163 }
3164
Brad Ebinger77b832e2019-10-17 17:03:22 -07003165 /**
3166 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3167 * subscription.
3168 * @param subId The subscription to use to check the configuration.
3169 * @param callback The callback that will be used to send the result.
3170 * @param capability The MmTelFeature capability that will be used to send the result.
3171 * @param transportType The transport type of the MmTelFeature capability.
3172 */
3173 @Override
3174 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3175 int transportType) {
3176 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3177 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3178 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3179 "IMS not available on device.");
3180 }
3181 final long token = Binder.clearCallingIdentity();
3182 try {
3183 int slotId = getSlotIndex(subId);
3184 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3185 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3186 + subId + "'");
3187 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3188 }
3189 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3190 transportType, aBoolean -> {
3191 try {
3192 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3193 } catch (RemoteException e) {
3194 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3195 + "running. Ignore");
3196 }
3197 });
3198 } finally {
3199 Binder.restoreCallingIdentity(token);
3200 }
3201 }
3202
Brad Ebinger35c841c2018-10-01 10:40:55 -07003203 @Override
3204 public boolean isAdvancedCallingSettingEnabled(int subId) {
3205 enforceReadPrivilegedPermission("enforceReadPrivilegedPermission");
3206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3207 final long token = Binder.clearCallingIdentity();
3208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003210 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003211 } catch (ImsException e) {
3212 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003213 } finally {
3214 Binder.restoreCallingIdentity(token);
3215 }
3216 }
3217
3218 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003219 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003221 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003222 final long identity = Binder.clearCallingIdentity();
3223 try {
3224 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003225 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003226 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003227 } catch (ImsException e) {
3228 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003229 } finally {
3230 Binder.restoreCallingIdentity(identity);
3231 }
3232 }
3233
3234 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003235 public boolean isVtSettingEnabled(int subId) {
3236 enforceReadPrivilegedPermission("isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 final long identity = Binder.clearCallingIdentity();
3238 try {
3239 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003240 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3241 } catch (ImsException e) {
3242 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 } finally {
3244 Binder.restoreCallingIdentity(identity);
3245 }
3246 }
3247
3248 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003249 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003251 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003252 final long identity = Binder.clearCallingIdentity();
3253 try {
3254 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003255 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003256 } catch (ImsException e) {
3257 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003258 } finally {
3259 Binder.restoreCallingIdentity(identity);
3260 }
3261 }
3262
3263 @Override
3264 public boolean isVoWiFiSettingEnabled(int subId) {
3265 enforceReadPrivilegedPermission("isVoWiFiSettingEnabled");
3266 final long identity = Binder.clearCallingIdentity();
3267 try {
3268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003269 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003270 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003271 } catch (ImsException e) {
3272 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003273 } finally {
3274 Binder.restoreCallingIdentity(identity);
3275 }
3276 }
3277
3278 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003279 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003281 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003285 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003286 } catch (ImsException e) {
3287 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 } finally {
3289 Binder.restoreCallingIdentity(identity);
3290 }
3291 }
3292
3293 @Override
3294 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
3295 enforceReadPrivilegedPermission("isVoWiFiRoamingSettingEnabled");
3296 final long identity = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003299 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003300 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003301 } catch (ImsException e) {
3302 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 } finally {
3304 Binder.restoreCallingIdentity(identity);
3305 }
3306 }
3307
3308 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003309 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003310 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003311 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003312 final long identity = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003315 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003316 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003317 } catch (ImsException e) {
3318 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003319 } finally {
3320 Binder.restoreCallingIdentity(identity);
3321 }
3322 }
3323
3324 @Override
3325 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3326 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3327 "setVoWiFiNonPersistent");
3328 final long identity = Binder.clearCallingIdentity();
3329 try {
3330 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003332 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003333 } catch (ImsException e) {
3334 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
3338 }
3339
3340 @Override
3341 public int getVoWiFiModeSetting(int subId) {
3342 enforceReadPrivilegedPermission("getVoWiFiModeSetting");
3343 final long identity = Binder.clearCallingIdentity();
3344 try {
3345 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003346 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003347 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003348 } catch (ImsException e) {
3349 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003350 } finally {
3351 Binder.restoreCallingIdentity(identity);
3352 }
3353 }
3354
3355 @Override
3356 public void setVoWiFiModeSetting(int subId, int mode) {
3357 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3358 "setVoWiFiModeSetting");
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003363 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003364 } catch (ImsException e) {
3365 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003366 } finally {
3367 Binder.restoreCallingIdentity(identity);
3368 }
3369 }
3370
3371 @Override
3372 public int getVoWiFiRoamingModeSetting(int subId) {
3373 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3374 final long identity = Binder.clearCallingIdentity();
3375 try {
3376 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003377 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003378 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003379 } catch (ImsException e) {
3380 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 } finally {
3382 Binder.restoreCallingIdentity(identity);
3383 }
3384 }
3385
3386 @Override
3387 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3388 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3389 "setVoWiFiRoamingModeSetting");
3390 final long identity = Binder.clearCallingIdentity();
3391 try {
3392 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 } catch (ImsException e) {
3396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(identity);
3399 }
3400 }
3401
3402 @Override
3403 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3404 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3405 "setRttCapabilityEnabled");
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003409 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3410 } catch (ImsException e) {
3411 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
3415 }
3416
3417 @Override
3418 public boolean isTtyOverVolteEnabled(int subId) {
3419 enforceReadPrivilegedPermission("isTtyOverVolteEnabled");
3420 final long identity = Binder.clearCallingIdentity();
3421 try {
3422 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003423 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003424 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003425 } catch (ImsException e) {
3426 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 } finally {
3428 Binder.restoreCallingIdentity(identity);
3429 }
3430 }
3431
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003432 @Override
3433 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3434 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3435 final long identity = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003439 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003440 } catch (ImsException e) {
3441 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003442 } finally {
3443 Binder.restoreCallingIdentity(identity);
3444 }
3445 }
3446
3447 @Override
3448 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3449 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3450 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003451 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3452 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3453 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003454 try {
3455 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003457 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003458 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003459 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3460 + "is inactive, ignoring unregister.");
3461 // If the subscription is no longer active, just return, since the callback will already
3462 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003463 } finally {
3464 Binder.restoreCallingIdentity(identity);
3465 }
3466 }
3467
3468 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003469 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3470 boolean isProvisioned) {
3471 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3472 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3473 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3474 }
3475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3476 "setProvisioningStatusForCapability");
3477 final long identity = Binder.clearCallingIdentity();
3478 try {
3479 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3480 Phone phone = getPhone(subId);
3481 if (phone == null) {
3482 loge("setImsProvisioningStatusForCapability: phone instance null for subid "
3483 + subId);
3484 return;
3485 }
3486 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3487 return;
3488 }
3489
3490 // this capability requires provisioning, route to the correct API.
3491 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3492 switch (capability) {
3493 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3494 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3495 ims.setVolteProvisioned(isProvisioned);
3496 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3497 ims.setWfcProvisioned(isProvisioned);
3498 }
3499 break;
3500 }
3501 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3502 // There is currently no difference in VT provisioning type.
3503 ims.setVtProvisioned(isProvisioned);
3504 break;
3505 }
3506 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3507 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3508 // change the capability of the feature instead if needed.
3509 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3510 == isProvisioned) {
3511 // No change in provisioning.
3512 return;
3513 }
3514 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3515 try {
3516 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003517 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003518 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3519 + ", Exception" + e.getMessage());
3520 }
3521 break;
3522 }
3523 default: {
3524 throw new IllegalArgumentException("Tried to set provisioning for capability '"
3525 + capability + "', which does not require provisioning.");
3526 }
3527 }
3528
3529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
3534 @Override
3535 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3536 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3537 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3538 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3539 }
3540 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3541 final long identity = Binder.clearCallingIdentity();
3542 try {
3543 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3544 Phone phone = getPhone(subId);
3545 if (phone == null) {
3546 loge("getImsProvisioningStatusForCapability: phone instance null for subid "
3547 + subId);
3548 // We will fail with "true" as the provisioning status because this is the default
3549 // if we do not require provisioning.
3550 return true;
3551 }
3552
3553 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3554 return true;
3555 }
3556
3557 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3558 switch (capability) {
3559 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3560 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3561 return ims.isVolteProvisionedOnDevice();
3562 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3563 return ims.isWfcProvisionedOnDevice();
3564 }
3565 // This should never happen, since we are checking tech above to make sure it
3566 // is either LTE or IWLAN.
3567 throw new IllegalArgumentException("Invalid radio technology for voice "
3568 + "capability.");
3569 }
3570 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3571 // There is currently no difference in VT provisioning type.
3572 return ims.isVtProvisionedOnDevice();
3573 }
3574 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3575 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3576 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3577 }
3578 default: {
3579 throw new IllegalArgumentException("Tried to get provisioning for capability '"
3580 + capability + "', which does not require provisioning.");
3581 }
3582 }
3583
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
3586 }
3587 }
3588
3589 @Override
3590 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3591 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3592 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3593 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3594 }
3595 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3596 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3597 return (provisionedBits & capability) > 0;
3598 }
3599
3600 @Override
3601 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3602 boolean isProvisioned) {
3603 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3604 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3605 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3606 }
3607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3608 "setProvisioningStatusForCapability");
3609 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3610 // If the current provisioning status for capability already matches isProvisioned,
3611 // do nothing.
3612 if (((provisionedBits & capability) > 0) == isProvisioned) {
3613 return;
3614 }
3615 if (isProvisioned) {
3616 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3617 } else {
3618 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3619 }
3620 }
3621
3622 /**
3623 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3624 * technology. The bitfield should mirror the bitfield defined by
3625 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3626 */
3627 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3628 String key = getMmTelProvisioningKey(subId, tech);
3629 // Default is no capabilities are provisioned.
3630 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3631 }
3632
3633 /**
3634 * Sets the MmTel capability provisioning bitfield (defined by
3635 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3636 * technology specified.
3637 *
3638 * Note: This is a synchronous command and should not be called on UI thread.
3639 */
3640 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3641 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3642 String key = getMmTelProvisioningKey(subId, tech);
3643 editor.putInt(key, newField);
3644 editor.commit();
3645 }
3646
3647 private static String getMmTelProvisioningKey(int subId, int tech) {
3648 // resulting key is provision_ims_mmtel_{subId}_{tech}
3649 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3650 }
3651
3652 /**
3653 * Query CarrierConfig to see if the specified capability requires provisioning for the
3654 * carrier associated with the subscription id.
3655 */
3656 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3657 int capability) {
3658 CarrierConfigManager configManager = new CarrierConfigManager(context);
3659 PersistableBundle c = configManager.getConfigForSubId(subId);
3660 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07003661 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003662 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
3663 false);
3664 boolean requireVoiceVtProvisioning = c.getBoolean(
3665 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
3666
3667 // First check to make sure that the capability requires provisioning.
3668 switch (capability) {
3669 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
3670 // intentional fallthrough
3671 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3672 if (requireVoiceVtProvisioning) {
3673 // Voice and Video requires provisioning
3674 return true;
3675 }
3676 break;
3677 }
3678 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3679 if (requireUtProvisioning) {
3680 // UT requires provisioning
3681 return true;
3682 }
3683 break;
3684 }
3685 }
3686 return false;
3687 }
3688
3689 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003690 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003691 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3692 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3693 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003694 enforceReadPrivilegedPermission("getImsProvisioningInt");
3695 final long identity = Binder.clearCallingIdentity();
3696 try {
3697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003698 int slotId = getSlotIndex(subId);
3699 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3700 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
3701 + subId + "' for key:" + key);
3702 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
3703 }
3704 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003706 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
3707 + subId + "' for key:" + key);
3708 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003709 } finally {
3710 Binder.restoreCallingIdentity(identity);
3711 }
3712 }
3713
3714 @Override
3715 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3717 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3718 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003719 enforceReadPrivilegedPermission("getImsProvisioningString");
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003723 int slotId = getSlotIndex(subId);
3724 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3725 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
3726 + subId + "' for key:" + key);
3727 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
3728 }
3729 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003730 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003731 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
3732 + subId + "' for key:" + key);
3733 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003734 } finally {
3735 Binder.restoreCallingIdentity(identity);
3736 }
3737 }
3738
3739 @Override
3740 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003741 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3742 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3743 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003744 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3745 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003746 final long identity = Binder.clearCallingIdentity();
3747 try {
3748 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003749 int slotId = getSlotIndex(subId);
3750 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3751 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
3752 + subId + "' for key:" + key);
3753 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3754 }
3755 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003756 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003757 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
3758 + "' for key:" + key);
3759 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003760 } finally {
3761 Binder.restoreCallingIdentity(identity);
3762 }
3763 }
3764
3765 @Override
3766 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003767 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3768 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
3769 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08003770 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3771 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 final long identity = Binder.clearCallingIdentity();
3773 try {
3774 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003775 int slotId = getSlotIndex(subId);
3776 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3777 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
3778 + subId + "' for key:" + key);
3779 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
3780 }
3781 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003782 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003783 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
3784 + "' for key:" + key);
3785 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
3789 }
3790
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003791 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003792 int slotId = SubscriptionManager.getSlotIndex(subId);
3793 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003794 throw new ImsException("Invalid Subscription Id, subId=" + subId,
3795 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07003796 }
3797 return slotId;
3798 }
3799
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003800 private int getSlotIndex(int subId) {
3801 int slotId = SubscriptionManager.getSlotIndex(subId);
3802 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
3803 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
3804 }
3805 return slotId;
3806 }
3807
Wink Saville36469e72014-06-11 15:17:00 -07003808 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07003809 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07003810 */
3811 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003812 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
3813 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07003814 final int targetSdk = getTargetSdk(callingPackage);
3815 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003816 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07003817 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07003818 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003819 mApp, subId, callingPackage, callingFeatureId,
3820 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003821 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3822 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003823
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003824 final long identity = Binder.clearCallingIdentity();
3825 try {
3826 final Phone phone = getPhone(subId);
3827 if (phone != null) {
3828 return phone.getServiceState().getDataNetworkType();
3829 } else {
3830 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3831 }
3832 } finally {
3833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003835 }
3836
3837 /**
3838 * Returns the data network type
3839 */
3840 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003841 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
3842 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
3843 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003844 }
3845
3846 /**
3847 * Returns the data network type for a subId
3848 */
3849 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003850 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
3851 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003852 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003853 mApp, subId, callingPackage, callingFeatureId,
3854 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003855 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3856 }
3857
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003858 final long identity = Binder.clearCallingIdentity();
3859 try {
3860 final Phone phone = getPhone(subId);
3861 if (phone != null) {
3862 return phone.getServiceState().getDataNetworkType();
3863 } else {
3864 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3865 }
3866 } finally {
3867 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003869 }
3870
3871 /**
Wink Saville36469e72014-06-11 15:17:00 -07003872 * Returns the Voice network type for a subId
3873 */
3874 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003875 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
3876 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003877 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003878 mApp, subId, callingPackage, callingFeatureId,
3879 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07003880 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3881 }
3882
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 final Phone phone = getPhone(subId);
3886 if (phone != null) {
3887 return phone.getServiceState().getVoiceNetworkType();
3888 } else {
3889 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
3890 }
3891 } finally {
3892 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003893 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003894 }
3895
3896 /**
3897 * @return true if a ICC card is present
3898 */
3899 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07003900 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003901 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
3902 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07003903 }
3904
3905 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003906 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07003907 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003908 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003909 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003910 final long identity = Binder.clearCallingIdentity();
3911 try {
3912 final Phone phone = PhoneFactory.getPhone(slotIndex);
3913 if (phone != null) {
3914 return phone.getIccCard().hasIccCard();
3915 } else {
3916 return false;
3917 }
3918 } finally {
3919 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08003920 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003921 }
3922
3923 /**
3924 * Return if the current radio is LTE on CDMA. This
3925 * is a tri-state return value as for a period of time
3926 * the mode may be unknown.
3927 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003928 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003929 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08003930 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003931 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003932 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003933 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
3934 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
3935 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003936 }
3937
Sanket Padawe356d7632015-06-22 14:03:32 -07003938 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003939 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
3940 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003941 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003942 mApp, subId, callingPackage, callingFeatureId,
3943 "getLteOnCdmaModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003944 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3945 }
3946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003947 final long identity = Binder.clearCallingIdentity();
3948 try {
3949 final Phone phone = getPhone(subId);
3950 if (phone == null) {
3951 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
3952 } else {
3953 return phone.getLteOnCdmaMode();
3954 }
3955 } finally {
3956 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003957 }
Wink Saville36469e72014-06-11 15:17:00 -07003958 }
3959
Wink Saville36469e72014-06-11 15:17:00 -07003960 /**
3961 * {@hide}
3962 * Returns Default subId, 0 in the case of single standby.
3963 */
Wink Savilleb564aae2014-10-23 10:18:09 -07003964 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003965 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07003966 }
3967
Shishir Agrawala9f32182016-04-12 12:00:16 -07003968 private int getSlotForDefaultSubscription() {
3969 return mSubscriptionController.getPhoneId(getDefaultSubscription());
3970 }
3971
Wink Savilleb564aae2014-10-23 10:18:09 -07003972 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08003973 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003974 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003975
Pengquan Menge92a50d2018-09-21 15:54:48 -07003976 private boolean isActiveSubscription(int subId) {
3977 return mSubscriptionController.isActiveSubId(subId);
3978 }
3979
Ihab Awadf2177b72013-11-25 13:33:23 -08003980 /**
3981 * @see android.telephony.TelephonyManager.WifiCallingChoices
3982 */
3983 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003984 final long identity = Binder.clearCallingIdentity();
3985 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003986 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003987 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
3988 getWhenToMakeWifiCallsDefaultPreference());
3989 } finally {
3990 Binder.restoreCallingIdentity(identity);
3991 }
Ihab Awadf2177b72013-11-25 13:33:23 -08003992 }
3993
3994 /**
3995 * @see android.telephony.TelephonyManager.WifiCallingChoices
3996 */
3997 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003998 final long identity = Binder.clearCallingIdentity();
3999 try {
4000 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004001 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004002 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4003 } finally {
4004 Binder.restoreCallingIdentity(identity);
4005 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004006 }
4007
Sailesh Nepald1e68152013-12-12 19:08:02 -08004008 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004009 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004010 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004011 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004012
Jordan Liu4c733742019-02-28 12:03:40 -08004013 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4014 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4015 if (phoneId == -1) {
4016 throw new IllegalArgumentException("Given slot index: " + slotIndex
4017 + " does not correspond to an active phone");
4018 }
4019 return PhoneFactory.getPhone(phoneId);
4020 }
4021
Shishir Agrawal566b7612013-10-28 14:41:00 -07004022 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004023 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4024 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004025 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4026 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004027 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004028 if (DBG) {
4029 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4030 }
4031 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4032 p2);
4033 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004034
Jordan Liu4c733742019-02-28 12:03:40 -08004035
4036 @Override
4037 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4038 int slotIndex, String callingPackage, String aid, int p2) {
4039 enforceModifyPermission();
4040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4041 if (DBG) {
4042 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4043 }
4044 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4045 callingPackage, aid, p2);
4046 }
4047
4048 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4049 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004050 final long identity = Binder.clearCallingIdentity();
4051 try {
4052 if (TextUtils.equals(ISDR_AID, aid)) {
4053 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004054 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4055 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004056 if (bestComponent == null
4057 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4058 loge("The calling package is not allowed to access ISD-R.");
4059 throw new SecurityException(
4060 "The calling package is not allowed to access ISD-R.");
4061 }
Derek Tan740e1672017-06-27 14:56:27 -07004062 }
Derek Tan740e1672017-06-27 14:56:27 -07004063
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004064 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004065 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4066 null /* workSource */);
4067 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004068 return response;
4069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004072 }
4073
4074 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004075 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4077 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004078 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4079 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4080 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004081
Jordan Liu4c733742019-02-28 12:03:40 -08004082 @Override
4083 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4084 enforceModifyPermission();
4085 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4086 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4087 channel);
4088 }
4089
4090 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004091 final long identity = Binder.clearCallingIdentity();
4092 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004093 if (channel < 0) {
4094 return false;
4095 }
Jordan Liu4c733742019-02-28 12:03:40 -08004096 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4097 null /* workSource */);
4098 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004099 return success;
4100 } finally {
4101 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004102 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004103 }
4104
4105 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004106 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004107 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4109 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004110 if (DBG) {
4111 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4112 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4113 + p3 + " data=" + data);
4114 }
4115 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4116 command, p1, p2, p3, data);
4117 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004118
Jordan Liu4c733742019-02-28 12:03:40 -08004119 @Override
4120 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4121 int command, int p1, int p2, int p3, String data) {
4122 enforceModifyPermission();
4123 if (DBG) {
4124 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4125 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4126 + p3 + " data=" + data);
4127 }
4128 return iccTransmitApduLogicalChannelWithPermission(
4129 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4130 data);
4131 }
4132
4133 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4134 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004135 final long identity = Binder.clearCallingIdentity();
4136 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004137 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004138 return "";
4139 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004140
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004141 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004142 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4143 null /* workSource */);
4144 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004145
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004146 // Append the returned status code to the end of the response payload.
4147 String s = Integer.toHexString(
4148 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4149 if (response.payload != null) {
4150 s = IccUtils.bytesToHexString(response.payload) + s;
4151 }
4152 return s;
4153 } finally {
4154 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004155 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004156 }
Jake Hambye994d462014-02-03 13:10:13 -08004157
Evan Charltonc66da362014-05-16 14:06:40 -07004158 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004159 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4160 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4162 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004163 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004164 if (DBG) {
4165 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4166 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4167 }
4168 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4169 cla, command, p1, p2, p3, data);
4170 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004171
Jordan Liu4c733742019-02-28 12:03:40 -08004172 @Override
4173 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4174 int command, int p1, int p2, int p3, String data) {
4175 enforceModifyPermission();
4176 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4177 if (DBG) {
4178 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4179 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4180 + " data=" + data);
4181 }
4182
4183 return iccTransmitApduBasicChannelWithPermission(
4184 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4185 p2, p3, data);
4186 }
4187
4188 // open APDU basic channel assuming the caller has sufficient permissions
4189 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4190 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004191 final long identity = Binder.clearCallingIdentity();
4192 try {
4193 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4194 && TextUtils.equals(ISDR_AID, data)) {
4195 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004196 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4197 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004198 if (bestComponent == null
4199 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4200 loge("The calling package is not allowed to select ISD-R.");
4201 throw new SecurityException(
4202 "The calling package is not allowed to select ISD-R.");
4203 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004204 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004206 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004207 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4208 null /* workSource */);
4209 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004211 // Append the returned status code to the end of the response payload.
4212 String s = Integer.toHexString(
4213 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4214 if (response.payload != null) {
4215 s = IccUtils.bytesToHexString(response.payload) + s;
4216 }
4217 return s;
4218 } finally {
4219 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004220 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004221 }
4222
4223 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004224 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004225 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4227 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004229 final long identity = Binder.clearCallingIdentity();
4230 try {
4231 if (DBG) {
4232 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4233 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4234 }
4235
4236 IccIoResult response =
4237 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4238 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4239 subId);
4240
4241 if (DBG) {
4242 log("Exchange SIM_IO [R]" + response);
4243 }
4244
4245 byte[] result = null;
4246 int length = 2;
4247 if (response.payload != null) {
4248 length = 2 + response.payload.length;
4249 result = new byte[length];
4250 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4251 } else {
4252 result = new byte[length];
4253 }
4254
4255 result[length - 1] = (byte) response.sw2;
4256 result[length - 2] = (byte) response.sw1;
4257 return result;
4258 } finally {
4259 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004260 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004261 }
4262
Nathan Haroldb3014052017-01-25 15:57:32 -08004263 /**
4264 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4265 * on a particular subscription
4266 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004267 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4268 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004270 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004271 return null;
4272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273
4274 final long identity = Binder.clearCallingIdentity();
4275 try {
4276 if (appType != TelephonyManager.APPTYPE_USIM
4277 && appType != TelephonyManager.APPTYPE_SIM) {
4278 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4279 return null;
4280 }
4281 Object response = sendRequest(
4282 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4283 if (response instanceof String[]) {
4284 return (String[]) response;
4285 }
yincheng zhaod698b842019-09-06 17:06:54 -07004286 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004288 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004289 } finally {
4290 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004291 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004292 }
4293
yincheng zhaod698b842019-09-06 17:06:54 -07004294 /**
4295 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4296 * subscription.
4297 *
4298 * @param subId the id of the subscription.
4299 * @param appType the uicc app type, must be USIM or SIM.
4300 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4301 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004302 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004303 * @return number of fplmns that is successfully written to the SIM.
4304 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004305 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4306 String callingFeatureId) {
4307 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4308 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004309 if (DBG) logv("no permissions for setForbiddenplmns");
4310 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4311 }
4312 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4313 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4314 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4315 }
4316 if (fplmns == null) {
4317 throw new IllegalArgumentException("Fplmn List provided is null");
4318 }
4319 for (String fplmn : fplmns) {
4320 if (!CellIdentity.isValidPlmn(fplmn)) {
4321 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4322 }
4323 }
4324 final long identity = Binder.clearCallingIdentity();
4325 try {
4326 Object response = sendRequest(
4327 CMD_SET_FORBIDDEN_PLMNS,
4328 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4329 subId);
4330 return (int) response;
4331 } finally {
4332 Binder.restoreCallingIdentity(identity);
4333 }
4334 }
4335
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004336 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004337 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004338 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4339 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4344 if (response.payload == null) {
4345 return "";
4346 }
Evan Charltonc66da362014-05-16 14:06:40 -07004347
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004348 // Append the returned status code to the end of the response payload.
4349 String s = Integer.toHexString(
4350 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4351 s = IccUtils.bytesToHexString(response.payload) + s;
4352 return s;
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
4355 }
Evan Charltonc66da362014-05-16 14:06:40 -07004356 }
4357
Jake Hambye994d462014-02-03 13:10:13 -08004358 /**
4359 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4360 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4361 *
4362 * @param itemID the ID of the item to read
4363 * @return the NV item as a String, or null on error.
4364 */
4365 @Override
4366 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004367 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004368 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4369 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370
4371 final long identity = Binder.clearCallingIdentity();
4372 try {
4373 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004374 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004375 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4376 return value;
4377 } finally {
4378 Binder.restoreCallingIdentity(identity);
4379 }
Jake Hambye994d462014-02-03 13:10:13 -08004380 }
4381
4382 /**
4383 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4384 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4385 *
4386 * @param itemID the ID of the item to read
4387 * @param itemValue the value to write, as a String
4388 * @return true on success; false on any failure
4389 */
4390 @Override
4391 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004392 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004393 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4394 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004395
4396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4399 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004400 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004401 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4402 return success;
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
4405 }
Jake Hambye994d462014-02-03 13:10:13 -08004406 }
4407
4408 /**
4409 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4410 * Used for device configuration by some CDMA operators.
4411 *
4412 * @param preferredRoamingList byte array containing the new PRL
4413 * @return true on success; false on any failure
4414 */
4415 @Override
4416 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004417 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4418 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419
4420 final long identity = Binder.clearCallingIdentity();
4421 try {
4422 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4423 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4424 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4425 return success;
4426 } finally {
4427 Binder.restoreCallingIdentity(identity);
4428 }
Jake Hambye994d462014-02-03 13:10:13 -08004429 }
4430
4431 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004432 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004433 * Used for device configuration by some CDMA operators.
4434 *
chen xu6dac5ab2018-10-26 17:39:23 -07004435 * @param slotIndex - device slot.
4436 *
Jake Hambye994d462014-02-03 13:10:13 -08004437 * @return true on success; false on any failure
4438 */
4439 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004440 public boolean resetModemConfig(int slotIndex) {
4441 Phone phone = PhoneFactory.getPhone(slotIndex);
4442 if (phone != null) {
4443 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4444 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004445
chen xu6dac5ab2018-10-26 17:39:23 -07004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4449 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4450 return success;
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004454 }
chen xu6dac5ab2018-10-26 17:39:23 -07004455 return false;
4456 }
4457
4458 /**
4459 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4460 *
4461 * @param slotIndex - device slot.
4462 *
4463 * @return true on success; false on any failure
4464 */
4465 @Override
4466 public boolean rebootModem(int slotIndex) {
4467 Phone phone = PhoneFactory.getPhone(slotIndex);
4468 if (phone != null) {
4469 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4470 mApp, phone.getSubId(), "rebootModem");
4471
4472 final long identity = Binder.clearCallingIdentity();
4473 try {
4474 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4475 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4476 return success;
4477 } finally {
4478 Binder.restoreCallingIdentity(identity);
4479 }
4480 }
4481 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004482 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004483
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004484 public String[] getPcscfAddress(String apnType, String callingPackage,
4485 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004486 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4488 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004489 return new String[0];
4490 }
4491
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 final long identity = Binder.clearCallingIdentity();
4493 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004494 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004495 } finally {
4496 Binder.restoreCallingIdentity(identity);
4497 }
Wink Saville36469e72014-06-11 15:17:00 -07004498 }
4499
Brad Ebinger51f743a2017-01-23 13:50:20 -08004500 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004501 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4502 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004503 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004504 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004505 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506
4507 final long identity = Binder.clearCallingIdentity();
4508 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004509 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004510 // may happen if the device does not support IMS.
4511 return;
4512 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004513 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 } finally {
4515 Binder.restoreCallingIdentity(identity);
4516 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004517 }
4518
4519 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004520 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4521 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004522 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004523 public void disableIms(int slotId) {
4524 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525
4526 final long identity = Binder.clearCallingIdentity();
4527 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004529 // may happen if the device does not support IMS.
4530 return;
4531 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004532 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 } finally {
4534 Binder.restoreCallingIdentity(identity);
4535 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004536 }
4537
4538 /**
4539 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4540 * feature or {@link null} if the service is not available. If the feature is available, the
4541 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4542 */
4543 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004544 IImsServiceFeatureCallback callback) {
4545 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004546
4547 final long identity = Binder.clearCallingIdentity();
4548 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004549 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004550 // may happen if the device does not support IMS.
4551 return null;
4552 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004553 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004554 } finally {
4555 Binder.restoreCallingIdentity(identity);
4556 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004557 }
4558
4559 /**
4560 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4561 * feature during emergency calling or {@link null} if the service is not available. If the
4562 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4563 * listener for feature updates.
4564 */
4565 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567
4568 final long identity = Binder.clearCallingIdentity();
4569 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004570 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004571 // may happen if the device does not support IMS.
4572 return null;
4573 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004574 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 } finally {
4576 Binder.restoreCallingIdentity(identity);
4577 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004578 }
4579
Brad Ebinger5f64b052017-12-14 14:26:15 -08004580 /**
4581 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004582 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004583 */
4584 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4585 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586
4587 final long identity = Binder.clearCallingIdentity();
4588 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004589 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004590 // may happen if the device does not support IMS.
4591 return null;
4592 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004593 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 } finally {
4595 Binder.restoreCallingIdentity(identity);
4596 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004597 }
4598
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004599 /**
4600 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004601 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004602 */
4603 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4604 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004605
4606 final long identity = Binder.clearCallingIdentity();
4607 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004608 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004609 // may happen if the device does not support IMS.
4610 return null;
4611 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004612 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 } finally {
4614 Binder.restoreCallingIdentity(identity);
4615 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004616 }
4617
Brad Ebinger884c07b2018-02-15 16:17:40 -08004618 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07004619 * Sets the ImsService Package Name that Telephony will bind to.
4620 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08004621 * @param slotIndex the slot ID that the ImsService should bind for.
4622 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07004623 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004624 * @param featureTypes An integer array of feature types associated with a packageName.
4625 * @param packageName The name of the package that the current configuration will be replaced
4626 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004627 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004628 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004629 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
4630 int[] featureTypes, String packageName) {
4631 int[] subIds = SubscriptionManager.getSubId(slotIndex);
4632 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004633 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
4634 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08004635 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07004636
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004637 final long identity = Binder.clearCallingIdentity();
4638 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004639 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004640 // may happen if the device does not support IMS.
4641 return false;
4642 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004643 Map<Integer, String> featureConfig = new HashMap<>();
4644 for (int featureType : featureTypes) {
4645 featureConfig.put(featureType, packageName);
4646 }
4647 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
4648 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 } finally {
4650 Binder.restoreCallingIdentity(identity);
4651 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004652 }
4653
4654 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08004655 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004656 *
4657 * @param slotId The slot that the ImsService is associated with.
4658 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
4659 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004660 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07004661 * @return the package name of the ImsService configuration.
4662 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08004663 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
4664 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07004665 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08004666 TelephonyPermissions
4667 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4668 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
4669 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07004670
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004671 final long identity = Binder.clearCallingIdentity();
4672 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004673 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004674 // may happen if the device does not support IMS.
4675 return "";
4676 }
Brad Ebingera80c3312019-12-02 10:59:39 -08004677 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08004678 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
4679 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004680 } finally {
4681 Binder.restoreCallingIdentity(identity);
4682 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07004683 }
4684
Brad Ebinger77b832e2019-10-17 17:03:22 -07004685 /**
4686 * Get the MmTelFeature state associated with the requested subscription id.
4687 * @param subId The subscription that the MmTelFeature is associated with.
4688 * @param callback A callback with an integer containing the
4689 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
4690 */
4691 @Override
4692 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
4693 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
4694 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
4695 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4696 "IMS not available on device.");
4697 }
4698 final long token = Binder.clearCallingIdentity();
4699 try {
4700 int slotId = getSlotIndex(subId);
4701 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4702 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
4703 + subId + "'");
4704 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
4705 }
4706 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
4707 try {
4708 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
4709 } catch (RemoteException e) {
4710 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
4711 + "Ignore");
4712 }
4713 });
4714 } finally {
4715 Binder.restoreCallingIdentity(token);
4716 }
4717 }
4718
Wink Saville36469e72014-06-11 15:17:00 -07004719 public void setImsRegistrationState(boolean registered) {
4720 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004724 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004725 } finally {
4726 Binder.restoreCallingIdentity(identity);
4727 }
Wink Saville36469e72014-06-11 15:17:00 -07004728 }
4729
4730 /**
Stuart Scott54788802015-03-30 13:18:01 -07004731 * Set the network selection mode to automatic.
4732 *
4733 */
4734 @Override
4735 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4737 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738
Pengquan Menge92a50d2018-09-21 15:54:48 -07004739 if (!isActiveSubscription(subId)) {
4740 return;
4741 }
4742
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004743 final long identity = Binder.clearCallingIdentity();
4744 try {
4745 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
4746 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
4747 } finally {
4748 Binder.restoreCallingIdentity(identity);
4749 }
Stuart Scott54788802015-03-30 13:18:01 -07004750 }
4751
Pengquan Mengea84e042018-09-20 14:57:26 -07004752 /**
4753 * Ask the radio to connect to the input network and change selection mode to manual.
4754 *
4755 * @param subId the id of the subscription.
4756 * @param operatorInfo the operator information, included the PLMN, long name and short name of
4757 * the operator to attach to.
4758 * @param persistSelection whether the selection will persist until reboot. If true, only allows
4759 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
4760 * normal network selection next time.
4761 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07004762 */
4763 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07004764 public boolean setNetworkSelectionModeManual(
4765 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004766 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4767 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07004768
4769 if (!isActiveSubscription(subId)) {
4770 return false;
4771 }
4772
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004773 final long identity = Binder.clearCallingIdentity();
4774 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07004775 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07004777 if (DBG) {
4778 log("setNetworkSelectionModeManual: subId: " + subId
4779 + " operator: " + operatorInfo);
4780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004785 }
4786
4787 /**
4788 * Scans for available networks.
4789 */
4790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004791 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
4792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4794 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08004795 LocationAccessPolicy.LocationPermissionResult locationResult =
4796 LocationAccessPolicy.checkLocationPermission(mApp,
4797 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4798 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004799 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004800 .setCallingPid(Binder.getCallingPid())
4801 .setCallingUid(Binder.getCallingUid())
4802 .setMethod("getCellNetworkScanResults")
4803 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4804 .build());
4805 switch (locationResult) {
4806 case DENIED_HARD:
4807 throw new SecurityException("Not allowed to access scan results -- location");
4808 case DENIED_SOFT:
4809 return null;
4810 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004811
Pengquan Menga1bb6272018-09-06 09:59:22 -07004812 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004813 try {
4814 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07004815 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 } finally {
4818 Binder.restoreCallingIdentity(identity);
4819 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07004820 }
4821
4822 /**
yinxub1bed742017-04-17 11:45:04 -07004823 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07004824 *
yinxub1bed742017-04-17 11:45:04 -07004825 * @param subId id of the subscription
4826 * @param request contains the radio access networks with bands/channels to scan
4827 * @param messenger callback messenger for scan results or errors
4828 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07004829 * @return the id of the requested scan which can be used to stop the scan.
4830 */
4831 @Override
4832 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004833 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004834 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4835 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08004836 LocationAccessPolicy.LocationPermissionResult locationResult =
4837 LocationAccessPolicy.checkLocationPermission(mApp,
4838 new LocationAccessPolicy.LocationPermissionQuery.Builder()
4839 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004840 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08004841 .setCallingPid(Binder.getCallingPid())
4842 .setCallingUid(Binder.getCallingUid())
4843 .setMethod("requestNetworkScan")
4844 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
4845 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004846 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07004847 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08004848 if (e != null) {
4849 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
4850 throw e;
4851 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07004852 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08004853 return TelephonyScanManager.INVALID_SCAN_ID;
4854 }
4855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004856 }
Hall Liu912dfd32019-04-25 14:02:26 -07004857 int callingUid = Binder.getCallingUid();
4858 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07004859 final long identity = Binder.clearCallingIdentity();
4860 try {
4861 return mNetworkScanRequestTracker.startNetworkScan(
4862 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07004863 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07004864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
yinxu504e1392017-04-12 16:03:22 -07004867 }
4868
Hall Liub2ac8ef2019-02-28 15:56:23 -08004869 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07004870 NetworkScanRequest request, int subId) {
4871 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
4872 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
4873 boolean hasNetworkScanPermission =
4874 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
4875 == PERMISSION_GRANTED;
4876
4877 if (!hasCarrierPriv && !hasNetworkScanPermission) {
4878 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
4879 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08004880 }
4881
4882 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
4883 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08004884 if (ras.getChannels() != null && ras.getChannels().length > 0) {
4885 return new SecurityException("Specific channels must not be"
4886 + " scanned without location access.");
4887 }
4888 }
4889 }
4890
Hall Liub2ac8ef2019-02-28 15:56:23 -08004891 return null;
4892 }
4893
yinxu504e1392017-04-12 16:03:22 -07004894 /**
4895 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07004896 *
4897 * @param subId id of the subscription
4898 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07004899 */
4900 @Override
4901 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4903 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904
Hall Liu912dfd32019-04-25 14:02:26 -07004905 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004906 final long identity = Binder.clearCallingIdentity();
4907 try {
Hall Liu912dfd32019-04-25 14:02:26 -07004908 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004909 } finally {
4910 Binder.restoreCallingIdentity(identity);
4911 }
yinxu504e1392017-04-12 16:03:22 -07004912 }
4913
4914 /**
Junda Liu84d15a22014-07-02 11:21:04 -07004915 * Get the calculated preferred network type.
4916 * Used for debugging incorrect network type.
4917 *
4918 * @return the preferred network type, defined in RILConstants.java.
4919 */
4920 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004921 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004922 final Phone defaultPhone = getDefaultPhone();
4923 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004924 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004925 return RILConstants.PREFERRED_NETWORK_MODE;
4926 }
4927
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004928 final long identity = Binder.clearCallingIdentity();
4929 try {
4930 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 } finally {
4933 Binder.restoreCallingIdentity(identity);
4934 }
Junda Liu84d15a22014-07-02 11:21:04 -07004935 }
4936
4937 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08004938 * Get the preferred network type.
4939 * Used for device configuration by some CDMA operators.
4940 *
4941 * @return the preferred network type, defined in RILConstants.java.
4942 */
4943 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004944 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08004945 TelephonyPermissions
4946 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
4947 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004948
4949 final long identity = Binder.clearCallingIdentity();
4950 try {
4951 if (DBG) log("getPreferredNetworkType");
4952 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
4953 int networkType = (result != null ? result[0] : -1);
4954 if (DBG) log("getPreferredNetworkType: " + networkType);
4955 return networkType;
4956 } finally {
4957 Binder.restoreCallingIdentity(identity);
4958 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004959 }
4960
4961 /**
4962 * Set the preferred network type.
4963 * Used for device configuration by some CDMA operators.
4964 *
4965 * @param networkType the preferred network type, defined in RILConstants.java.
4966 * @return true on success; false on any failure.
4967 */
4968 @Override
Stuart Scott54788802015-03-30 13:18:01 -07004969 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004970 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4971 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972
4973 final long identity = Binder.clearCallingIdentity();
4974 try {
4975 if (DBG) log("setPreferredNetworkType: subId " + subId + " type " + networkType);
4976 Boolean success = (Boolean) sendRequest(
4977 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
4978 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
4979 if (success) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004980 Settings.Global.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
4982 }
4983 return success;
4984 } finally {
4985 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07004986 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004987 }
Robert Greenwalted86e582014-05-21 20:03:20 -07004988
4989 /**
Miaoa84611c2019-03-15 09:21:10 +08004990 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08004991 *
Miaoa84611c2019-03-15 09:21:10 +08004992 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07004993 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08004994 * @hide
4995 */
4996 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08004997 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004998 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005000 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001 try {
Miaoa84611c2019-03-15 09:21:10 +08005002 if (phone != null) {
5003 return phone.hasMatchedTetherApnSetting();
5004 } else {
5005 return false;
5006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005007 } finally {
5008 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005009 }
Junda Liu475951f2014-11-07 16:45:03 -08005010 }
5011
5012 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005013 * Set mobile data enabled
5014 * Used by the user through settings etc to turn on/off mobile data
5015 *
5016 * @param enable {@code true} turn turn data on, else {@code false}
5017 */
5018 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005019 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005020 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5021 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
5025 int phoneId = mSubscriptionController.getPhoneId(subId);
5026 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5027 Phone phone = PhoneFactory.getPhone(phoneId);
5028 if (phone != null) {
5029 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005030 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005032 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005033 }
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005036 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005037 }
5038
5039 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005040 * Get the user enabled state of Mobile Data.
5041 *
5042 * TODO: remove and use isUserDataEnabled.
5043 * This can't be removed now because some vendor codes
5044 * calls through ITelephony directly while they should
5045 * use TelephonyManager.
5046 *
5047 * @return true on enabled
5048 */
5049 @Override
5050 public boolean getDataEnabled(int subId) {
5051 return isUserDataEnabled(subId);
5052 }
5053
5054 /**
5055 * Get whether mobile data is enabled per user setting.
5056 *
5057 * There are other factors deciding whether mobile data is actually enabled, but they are
5058 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005059 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005060 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005061 *
5062 * @return {@code true} if data is enabled else {@code false}
5063 */
5064 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005065 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005066 try {
5067 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5068 null);
5069 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005070 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5071 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005072 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073
5074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 int phoneId = mSubscriptionController.getPhoneId(subId);
5077 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5078 Phone phone = PhoneFactory.getPhone(phoneId);
5079 if (phone != null) {
5080 boolean retVal = phone.isUserDataEnabled();
5081 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5082 return retVal;
5083 } else {
5084 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5085 return false;
5086 }
5087 } finally {
5088 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005089 }
5090 }
5091
5092 /**
5093 * Get whether mobile data is enabled.
5094 *
5095 * Comparable to {@link #isUserDataEnabled(int)}, this considers all factors deciding
5096 * whether mobile data is actually enabled.
5097 *
5098 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
5099 *
5100 * @return {@code true} if data is enabled else {@code false}
5101 */
5102 @Override
5103 public boolean isDataEnabled(int subId) {
5104 try {
5105 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5106 null);
5107 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5109 mApp, subId, "isDataEnabled");
Malcolm Chen964682d2017-11-28 16:20:07 -08005110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005111
5112 final long identity = Binder.clearCallingIdentity();
5113 try {
5114 int phoneId = mSubscriptionController.getPhoneId(subId);
5115 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5116 Phone phone = PhoneFactory.getPhone(phoneId);
5117 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005118 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005119 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5120 return retVal;
5121 } else {
5122 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5123 return false;
5124 }
5125 } finally {
5126 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005127 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005128 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005129
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005130 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5131 Phone phone) {
5132 //load access rules from carrier configs, and check those as well: b/139133814
5133 SubscriptionController subController = SubscriptionController.getInstance();
5134 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5135 || subController == null) return privilegeFromSim;
5136
5137 int uid = Binder.getCallingUid();
5138 PackageManager pkgMgr = phone.getContext().getPackageManager();
5139 String[] packages = pkgMgr.getPackagesForUid(uid);
5140
5141 final long identity = Binder.clearCallingIdentity();
5142 try {
5143 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5144 SubscriptionManager subManager = (SubscriptionManager)
5145 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5146 for (String pkg : packages) {
5147 if (subManager.canManageSubscription(subInfo, pkg)) {
5148 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5149 }
5150 }
5151 return privilegeFromSim;
5152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
5155 }
5156
5157 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5158 String pkgName) {
5159 //load access rules from carrier configs, and check those as well: b/139133814
5160 SubscriptionController subController = SubscriptionController.getInstance();
5161 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5162 || subController == null) return privilegeFromSim;
5163
5164 final long identity = Binder.clearCallingIdentity();
5165 try {
5166 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5167 SubscriptionManager subManager = (SubscriptionManager)
5168 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5169 return subManager.canManageSubscription(subInfo, pkgName)
5170 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5171 } finally {
5172 Binder.restoreCallingIdentity(identity);
5173 }
5174 }
5175
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005176 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005177 public int getCarrierPrivilegeStatus(int subId) {
5178 final Phone phone = getPhone(subId);
5179 if (phone == null) {
5180 loge("getCarrierPrivilegeStatus: Invalid subId");
5181 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5182 }
5183 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005184 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005185 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005186 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5187 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005188
5189 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5190 card.getCarrierPrivilegeStatusForCurrentTransaction(
5191 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005192 }
Junda Liu29340342014-07-10 15:23:27 -07005193
5194 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005195 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
5196 final Phone phone = getPhone(subId);
5197 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005198 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005199 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5200 }
5201 UiccProfile profile =
5202 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5203 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005204 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005205 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5206 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005207 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5208 profile.getCarrierPrivilegeStatusForUid(
5209 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005210 }
5211
5212 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005213 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5214 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005215 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005216 }
5217
5218 int phoneId = SubscriptionManager.getPhoneId(subId);
5219 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005220 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005221 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005222 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5223 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005224 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5225 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5226 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005227 }
5228
5229 @Override
5230 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005231 if (TextUtils.isEmpty(pkgName))
5232 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005233 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5234 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5235 UiccCard card = UiccController.getInstance().getUiccCard(i);
5236 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005237 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005238 continue;
5239 }
5240
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005241 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5242 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5243 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005244 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5245 break;
5246 }
5247 }
5248
5249 return result;
Junda Liu29340342014-07-10 15:23:27 -07005250 }
Derek Tan89e89d42014-07-08 17:00:10 -07005251
5252 @Override
Junda Liue64de782015-04-16 17:19:16 -07005253 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5254 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5255 loge("phoneId " + phoneId + " is not valid.");
5256 return null;
5257 }
5258 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005259 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005260 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005261 return null ;
5262 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005263 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005264 }
5265
Amith Yamasani6e118872016-02-19 12:53:51 -08005266 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005267 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005268 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005269 List<String> privilegedPackages = new ArrayList<>();
5270 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005271 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5272 // has UICC in that slot.
5273 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005274 if (card.hasCarrierPrivilegeRules()) {
5275 if (packages == null) {
5276 // Only check packages in user 0 for now
5277 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005278 PackageManager.MATCH_DISABLED_COMPONENTS
5279 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005280 | PackageManager.GET_SIGNING_CERTIFICATES,
5281 UserHandle.USER_SYSTEM);
Amith Yamasani6e118872016-02-19 12:53:51 -08005282 }
5283 for (int p = packages.size() - 1; p >= 0; p--) {
5284 PackageInfo pkgInfo = packages.get(p);
5285 if (pkgInfo != null && pkgInfo.packageName != null
5286 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005287 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005288 privilegedPackages.add(pkgInfo.packageName);
5289 }
5290 }
5291 }
5292 }
5293 return privilegedPackages;
5294 }
5295
chen xuf7e9fe82019-05-09 19:31:02 -07005296 @Override
5297 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005298 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5299
5300 final long identity = Binder.clearCallingIdentity();
5301
chen xuf7e9fe82019-05-09 19:31:02 -07005302 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005303 try {
5304 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5305 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5306 }
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005309 }
5310 return privilegedPackages;
5311 }
5312
Wink Savilleb564aae2014-10-23 10:18:09 -07005313 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005314 final Phone phone = getPhone(subId);
5315 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005316 if (card == null) {
5317 loge("getIccId: No UICC");
5318 return null;
5319 }
5320 String iccId = card.getIccId();
5321 if (TextUtils.isEmpty(iccId)) {
5322 loge("getIccId: ICC ID is null or empty.");
5323 return null;
5324 }
5325 return iccId;
5326 }
5327
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005328 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005329 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5330 String number) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005331 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5332 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005333
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005334 final long identity = Binder.clearCallingIdentity();
5335 try {
5336 final String iccId = getIccId(subId);
5337 final Phone phone = getPhone(subId);
5338 if (phone == null) {
5339 return false;
5340 }
5341 final String subscriberId = phone.getSubscriberId();
5342
5343 if (DBG_MERGE) {
5344 Slog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
5345 + subscriberId + " to " + number);
5346 }
5347
5348 if (TextUtils.isEmpty(iccId)) {
5349 return false;
5350 }
5351
5352 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5353
5354 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5355 if (alphaTag == null) {
5356 editor.remove(alphaTagPrefKey);
5357 } else {
5358 editor.putString(alphaTagPrefKey, alphaTag);
5359 }
5360
5361 // Record both the line number and IMSI for this ICCID, since we need to
5362 // track all merged IMSIs based on line number
5363 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5364 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5365 if (number == null) {
5366 editor.remove(numberPrefKey);
5367 editor.remove(subscriberPrefKey);
5368 } else {
5369 editor.putString(numberPrefKey, number);
5370 editor.putString(subscriberPrefKey, subscriberId);
5371 }
5372
5373 editor.commit();
5374 return true;
5375 } finally {
5376 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005377 }
Derek Tan7226c842014-07-02 17:42:23 -07005378 }
5379
5380 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005381 public String getLine1NumberForDisplay(int subId, String callingPackage,
5382 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005383 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005385 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005386 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005387 return null;
5388 }
Derek Tan97ebb422014-09-05 16:55:38 -07005389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005390 final long identity = Binder.clearCallingIdentity();
5391 try {
5392 String iccId = getIccId(subId);
5393 if (iccId != null) {
5394 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5395 if (DBG_MERGE) {
5396 log("getLine1NumberForDisplay returning "
5397 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5398 }
5399 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005400 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005401 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5402 return null;
5403 } finally {
5404 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005405 }
Derek Tan7226c842014-07-02 17:42:23 -07005406 }
5407
5408 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005409 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5410 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005412 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005413 return null;
5414 }
Derek Tan97ebb422014-09-05 16:55:38 -07005415
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 final long identity = Binder.clearCallingIdentity();
5417 try {
5418 String iccId = getIccId(subId);
5419 if (iccId != null) {
5420 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5421 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5422 }
5423 return null;
5424 } finally {
5425 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005426 }
Derek Tan7226c842014-07-02 17:42:23 -07005427 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005428
5429 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005430 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5431 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005432 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5433 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005434 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005435 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005436 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005437 return null;
5438 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005439
Jordan Liub49b04b2019-05-06 14:45:15 -07005440 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5441 // the process, where TelephonyManager was instantiated.
5442 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005443 final long identity = Binder.clearCallingIdentity();
5444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005445 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005446 final TelephonyManager tele = TelephonyManager.from(context);
5447 final SubscriptionManager sub = SubscriptionManager.from(context);
5448
5449 // Figure out what subscribers are currently active
5450 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451
Jordan Liub49b04b2019-05-06 14:45:15 -07005452 // Only consider subs which match the current subId
5453 // This logic can be simplified. See b/131189269 for progress.
5454 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005455 activeSubscriberIds.add(tele.getSubscriberId(subId));
5456 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457
5458 // First pass, find a number override for an active subscriber
5459 String mergeNumber = null;
5460 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5461 for (String key : prefs.keySet()) {
5462 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5463 final String subscriberId = (String) prefs.get(key);
5464 if (activeSubscriberIds.contains(subscriberId)) {
5465 final String iccId = key.substring(
5466 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5467 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5468 mergeNumber = (String) prefs.get(numberKey);
5469 if (DBG_MERGE) {
5470 Slog.d(LOG_TAG, "Found line number " + mergeNumber
5471 + " for active subscriber " + subscriberId);
5472 }
5473 if (!TextUtils.isEmpty(mergeNumber)) {
5474 break;
5475 }
5476 }
5477 }
5478 }
5479
5480 // Shortcut when no active merged subscribers
5481 if (TextUtils.isEmpty(mergeNumber)) {
5482 return null;
5483 }
5484
5485 // Second pass, find all subscribers under that line override
5486 final ArraySet<String> result = new ArraySet<>();
5487 for (String key : prefs.keySet()) {
5488 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
5489 final String number = (String) prefs.get(key);
5490 if (mergeNumber.equals(number)) {
5491 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
5492 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5493 final String subscriberId = (String) prefs.get(subscriberKey);
5494 if (!TextUtils.isEmpty(subscriberId)) {
5495 result.add(subscriberId);
5496 }
5497 }
5498 }
5499 }
5500
5501 final String[] resultArray = result.toArray(new String[result.size()]);
5502 Arrays.sort(resultArray);
5503 if (DBG_MERGE) {
5504 Slog.d(LOG_TAG,
5505 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
5506 }
5507 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08005510 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005511 }
5512
5513 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07005514 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
5515 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
5516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
5519 final TelephonyManager telephonyManager = mApp.getSystemService(
5520 TelephonyManager.class);
5521 String subscriberId = telephonyManager.getSubscriberId(subId);
5522 if (subscriberId == null) {
5523 if (DBG) {
5524 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
5525 + subId);
5526 }
5527 return null;
5528 }
5529
5530 final SubscriptionInfo info = SubscriptionController.getInstance()
5531 .getSubscriptionInfo(subId);
5532 final ParcelUuid groupUuid = info.getGroupUuid();
5533 // If it doesn't belong to any group, return just subscriberId of itself.
5534 if (groupUuid == null) {
5535 return new String[]{subscriberId};
5536 }
5537
5538 // Get all subscriberIds from the group.
5539 final List<String> mergedSubscriberIds = new ArrayList<>();
5540 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005541 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
5542 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07005543 for (SubscriptionInfo subInfo : groupInfos) {
5544 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
5545 if (subscriberId != null) {
5546 mergedSubscriberIds.add(subscriberId);
5547 }
5548 }
5549
5550 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
5551 } finally {
5552 Binder.restoreCallingIdentity(identity);
5553
5554 }
5555 }
5556
5557 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005558 public boolean setOperatorBrandOverride(int subId, String brand) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005559 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
5560 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 final Phone phone = getPhone(subId);
5565 return phone == null ? false : phone.setOperatorBrandOverride(brand);
5566 } finally {
5567 Binder.restoreCallingIdentity(identity);
5568 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005569 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05005570
5571 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005572 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005573 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
5574 List<String> cdmaNonRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005575 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005576
5577 final long identity = Binder.clearCallingIdentity();
5578 try {
5579 final Phone phone = getPhone(subId);
5580 if (phone == null) {
5581 return false;
5582 }
5583 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
5584 cdmaNonRoamingList);
5585 } finally {
5586 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005587 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08005588 }
5589
5590 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005591 @Deprecated
5592 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
5593 enforceModifyPermission();
5594
5595 int returnValue = 0;
5596 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07005597 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00005598 if(result.exception == null) {
5599 if (result.result != null) {
5600 byte[] responseData = (byte[])(result.result);
5601 if(responseData.length > oemResp.length) {
5602 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
5603 responseData.length + "bytes. Buffer Size is " +
5604 oemResp.length + "bytes.");
5605 }
5606 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
5607 returnValue = responseData.length;
5608 }
5609 } else {
5610 CommandException ex = (CommandException) result.exception;
5611 returnValue = ex.getCommandError().ordinal();
5612 if(returnValue > 0) returnValue *= -1;
5613 }
5614 } catch (RuntimeException e) {
5615 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
5616 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
5617 if(returnValue > 0) returnValue *= -1;
5618 }
5619
5620 return returnValue;
5621 }
5622
5623 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07005624 public void setRadioCapability(RadioAccessFamily[] rafs) {
5625 try {
5626 ProxyController.getInstance().setRadioCapability(rafs);
5627 } catch (RuntimeException e) {
5628 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
5629 }
5630 }
5631
5632 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07005633 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005634 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07005635 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08005636 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07005637 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08005638 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005639 final long identity = Binder.clearCallingIdentity();
5640 try {
chen xub97461a2018-10-26 14:17:57 -07005641 TelephonyPermissions
5642 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5643 mApp, phone.getSubId(), "getRadioAccessFamily");
5644 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645 } finally {
5646 Binder.restoreCallingIdentity(identity);
5647 }
chen xub97461a2018-10-26 14:17:57 -07005648 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07005649 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005650
5651 @Override
5652 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005653 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07005654 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005655
5656 final long identity = Binder.clearCallingIdentity();
5657 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005658 ImsManager.getInstance(defaultPhone.getContext(),
5659 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005660 } finally {
5661 Binder.restoreCallingIdentity(identity);
5662 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005663 }
5664
5665 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005666 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005667 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005668 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5669 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00005670 return false;
5671 }
Svet Ganovb320e182015-04-16 12:30:10 -07005672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 final long identity = Binder.clearCallingIdentity();
5674 try {
5675 // Check the user preference and the system-level IMS setting. Even if the user has
5676 // enabled video calling, if IMS is disabled we aren't able to support video calling.
5677 // In the long run, we may instead need to check if there exists a connection service
5678 // which can support video calling.
5679 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005680 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 return imsManager.isVtEnabledByPlatform()
5682 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
5683 && imsManager.isVtEnabledByUser();
5684 } finally {
5685 Binder.restoreCallingIdentity(identity);
5686 }
Andrew Leedf14ead2014-10-17 14:22:52 -07005687 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06005688
Andrew Leea1239f22015-03-02 17:44:07 -08005689 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005690 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
5691 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005693 mApp, subId, callingPackage, callingFeatureId,
5694 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695 return false;
5696 }
5697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 CarrierConfigManager configManager =
5701 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
5706 }
Andrew Leea1239f22015-03-02 17:44:07 -08005707 }
5708
5709 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005710 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005712 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005713 return false;
5714 }
5715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 CarrierConfigManager configManager =
5719 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005720 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005721 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
5722 } finally {
5723 Binder.restoreCallingIdentity(identity);
5724 }
Andrew Leea1239f22015-03-02 17:44:07 -08005725 }
5726
Andrew Lee9431b832015-03-09 18:46:45 -07005727 @Override
5728 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07005729 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08005730 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07005731 }
5732
5733 @Override
5734 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005735 final long identity = Binder.clearCallingIdentity();
5736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005737 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738 } finally {
5739 Binder.restoreCallingIdentity(identity);
5740 }
Andrew Lee9431b832015-03-09 18:46:45 -07005741 }
5742
Hall Liuf6668912018-10-31 17:05:23 -07005743 /**
5744 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
5745 * support for the feature and device firmware support.
5746 *
5747 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
5748 */
5749 @Override
5750 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005751 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005752 final Phone phone = getPhone(subscriptionId);
5753 if (phone == null) {
5754 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
5755 return false;
5756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005757 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005758 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005759 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
5760 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005761 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005762 return isCarrierSupported && isDeviceSupported;
5763 } finally {
5764 Binder.restoreCallingIdentity(identity);
5765 }
Hall Liu98187582018-01-22 19:15:32 -08005766 }
5767
Hall Liuf6668912018-10-31 17:05:23 -07005768 /**
Hall Liu6a06be62019-07-23 18:39:00 -07005769 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
5770 * RTT setting, will return true if the device and carrier both support RTT.
5771 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07005772 */
5773 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 final long identity = Binder.clearCallingIdentity();
5775 try {
Hall Liu81eb08c2019-10-29 16:50:20 -07005776 return isRttSupported(subscriptionId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777 } finally {
5778 Binder.restoreCallingIdentity(identity);
5779 }
Hall Liu3ad5f012018-04-06 16:23:39 -07005780 }
5781
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005782 @Deprecated
5783 @Override
5784 public String getDeviceId(String callingPackage) {
5785 return getDeviceIdWithFeature(callingPackage, null);
5786 }
5787
Sanket Padawe7310cc72015-01-14 09:53:20 -08005788 /**
5789 * Returns the unique device ID of phone, for example, the IMEI for
5790 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
5791 *
5792 * <p>Requires Permission:
5793 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
5794 */
5795 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005796 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005797 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08005798 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08005799 return null;
5800 }
Jeff Davidson913390f2018-02-23 17:11:49 -08005801 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07005802 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005803 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005804 return null;
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806
5807 final long identity = Binder.clearCallingIdentity();
5808 try {
5809 return phone.getDeviceId();
5810 } finally {
5811 Binder.restoreCallingIdentity(identity);
5812 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08005813 }
5814
Ping Sunc67b7c22016-03-02 19:16:45 +08005815 /**
5816 * {@hide}
5817 * Returns the IMS Registration Status on a particular subid
5818 *
5819 * @param subId
5820 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005821 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08005822 Phone phone = getPhone(subId);
5823 if (phone != null) {
5824 return phone.isImsRegistered();
5825 } else {
5826 return false;
5827 }
5828 }
5829
Santos Cordon7a1885b2015-02-03 11:15:19 -08005830 @Override
5831 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005832 final long identity = Binder.clearCallingIdentity();
5833 try {
5834 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
5835 } finally {
5836 Binder.restoreCallingIdentity(identity);
5837 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08005838 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07005839
Tyler Gunnf70ed162019-04-03 15:28:53 -07005840 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07005841 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005842 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07005843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005844 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07005845 throw new SecurityException("Requires READ_PHONE_STATE permission.");
5846 }
5847 final long identity = Binder.clearCallingIdentity();
5848 try {
5849 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
5855 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07005856 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 Phone phone = getPhone(subscriptionId);
5860 if (phone == null) {
5861 return null;
5862 }
5863 return PhoneUtils.makePstnPhoneAccountHandle(phone);
5864 } finally {
5865 Binder.restoreCallingIdentity(identity);
5866 }
5867 }
5868
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005869 /**
5870 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07005871 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005872 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005873 final long identity = Binder.clearCallingIdentity();
5874 try {
5875 Phone phone = getPhone(subId);
5876 if (phone != null) {
5877 return phone.isWifiCallingEnabled();
5878 } else {
5879 return false;
5880 }
5881 } finally {
5882 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005883 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07005884 }
5885
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005886 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005887 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005888 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005889 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005890 final long identity = Binder.clearCallingIdentity();
5891 try {
5892 Phone phone = getPhone(subId);
5893 if (phone != null) {
5894 return phone.isVideoEnabled();
5895 } else {
5896 return false;
5897 }
5898 } finally {
5899 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005900 }
5901 }
5902
5903 /**
5904 * @return the IMS registration technology for the MMTEL feature. Valid return values are
5905 * defined in {@link ImsRegistrationImplBase}.
5906 */
5907 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005908 final long identity = Binder.clearCallingIdentity();
5909 try {
5910 Phone phone = getPhone(subId);
5911 if (phone != null) {
5912 return phone.getImsRegistrationTech();
5913 } else {
5914 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
5915 }
5916 } finally {
5917 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08005918 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07005919 }
5920
Stuart Scott8eef64f2015-04-08 15:13:54 -07005921 @Override
5922 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08005923 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07005924 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
5925 return;
5926 }
5927
Svet Ganovcc087f82015-05-12 20:35:54 -07005928 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929
Svet Ganovcc087f82015-05-12 20:35:54 -07005930 try {
Stuart Scott981d8582015-04-21 14:09:50 -07005931 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
5932 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07005933 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07005934 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07005935 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005936 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
5937 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07005938 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005939 // There has been issues when Sms raw table somehow stores orphan
5940 // fragments. They lead to garbled message when new fragments come
5941 // in and combined with those stale ones. In case this happens again,
5942 // user can reset all network settings which will clean up this table.
5943 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07005944 // Clean up IMS settings as well here.
5945 int slotId = getSlotIndex(subId);
5946 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5947 ImsManager.getInstance(mApp, slotId).factoryReset();
5948 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07005949
5950 // Erase modem config if erase modem on network setting is enabled.
5951 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
5952 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
5953 if (configValue != null && Boolean.parseBoolean(configValue)) {
5954 sendEraseModemConfig(getDefaultPhone());
5955 }
Svet Ganovcc087f82015-05-12 20:35:54 -07005956 } finally {
5957 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07005958 }
5959 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005960
Amit Mahajan7dbbd822019-03-13 17:33:47 -07005961 private void cleanUpSmsRawTable(Context context) {
5962 ContentResolver resolver = context.getContentResolver();
5963 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
5964 resolver.delete(uri, null, null);
5965 }
5966
Narayan Kamath1c496c22015-04-16 14:40:19 +01005967 @Override
chen xu5d3637b2019-01-21 23:31:38 -08005968 public String getSimLocaleForSubscriber(int subId) {
5969 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
5970 final Phone phone = getPhone(subId);
5971 if (phone == null) {
5972 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08005973 return null;
chen xu5d3637b2019-01-21 23:31:38 -08005974 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005975 final long identity = Binder.clearCallingIdentity();
5976 try {
chen xu5d3637b2019-01-21 23:31:38 -08005977 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005978 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08005979 if (info == null) {
5980 log("getSimLocaleForSubscriber, inactive subId: " + subId);
5981 return null;
5982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983 // Try and fetch the locale from the carrier properties or from the SIM language
5984 // preferences (EF-PL and EF-LI)...
5985 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005986 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08005987 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
5988 if (localeFromDefaultSim != null) {
5989 if (!localeFromDefaultSim.getCountry().isEmpty()) {
5990 if (DBG) log("Using locale from subId: " + subId + " locale: "
5991 + localeFromDefaultSim);
5992 return localeFromDefaultSim.toLanguageTag();
5993 } else {
5994 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 }
5996 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01005997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005998 // The SIM language preferences only store a language (e.g. fr = French), not an
5999 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6000 // the SIM and carrier preferences does not include a country we add the country
6001 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006002 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006003 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006004 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 return mccLocale.toLanguageTag();
6006 }
6007
6008 if (DBG) log("No locale found - returning null");
6009 return null;
6010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006013 }
6014
6015 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006016 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6017 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006018 }
6019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006020 /**
6021 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6022 */
6023 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006024 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6025 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006026 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006027
Chenjie Yu1ba97252018-01-11 18:16:20 -08006028 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006029 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006030
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006031 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006032 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6033 * representing the state of the modem.
6034 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006035 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6036 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006037 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006038 */
6039 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006040 public void requestModemActivityInfo(ResultReceiver result) {
6041 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006043
6044 final long identity = Binder.clearCallingIdentity();
6045 try {
6046 ModemActivityInfo ret = null;
6047 synchronized (mLastModemActivityInfo) {
6048 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6049 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006050 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006051 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006053 int[] txTimeMs = info.getTransmitTimeMillis();
6054 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006055 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006056 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006057 }
6058 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006059 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6060 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 mLastModemActivityInfo.setIdleTimeMillis(
6062 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006063 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6064 mLastModemActivityInfo.setReceiveTimeMillis(
6065 info.getReceiveTimeMillis() + mLastModemActivityInfo
6066 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006067 }
Chen Xu13851032019-09-10 18:49:52 -07006068
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006069 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6070 mLastModemActivityInfo.getSleepTimeMillis(),
6071 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006072 mLastModemActivityInfo.getTransmitTimeMillis(),
6073 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006074 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006075 Bundle bundle = new Bundle();
6076 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6077 result.send(0, bundle);
6078 } finally {
6079 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006080 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006081 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006082
Siddharth Rayb8114062018-06-17 15:02:38 -07006083 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6084 // less than total activity duration.
6085 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6086 if (info == null) {
6087 return false;
6088 }
6089 int activityDurationMs =
6090 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6091 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006092 int[] txTimeMs = info.getTransmitTimeMillis();
6093 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6094 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006095 }
6096 return (info.isValid()
6097 && (info.getSleepTimeMillis() <= activityDurationMs)
6098 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006099 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006100 && (totalTxTimeMs <= activityDurationMs));
6101 }
6102
Jack Yu85bd38a2015-11-09 11:34:32 -08006103 /**
6104 * {@hide}
6105 * Returns the service state information on specified subscription.
6106 */
6107 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006108 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006111 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006112 return null;
6113 }
6114
Hall Liuf19c44f2018-11-27 14:38:17 -08006115 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6116 LocationAccessPolicy.checkLocationPermission(mApp,
6117 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6118 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006119 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006120 .setCallingPid(Binder.getCallingPid())
6121 .setCallingUid(Binder.getCallingUid())
6122 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006123 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006124 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6125 .build());
6126
6127 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6128 LocationAccessPolicy.checkLocationPermission(mApp,
6129 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6130 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006131 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006132 .setCallingPid(Binder.getCallingPid())
6133 .setCallingUid(Binder.getCallingUid())
6134 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006135 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006136 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6137 .build());
6138 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6139 boolean hasFinePermission =
6140 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6141 boolean hasCoarsePermission =
6142 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6143
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006144 final long identity = Binder.clearCallingIdentity();
6145 try {
6146 final Phone phone = getPhone(subId);
6147 if (phone == null) {
6148 return null;
6149 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006150
Hall Liuf19c44f2018-11-27 14:38:17 -08006151 ServiceState ss = phone.getServiceState();
6152
6153 // Scrub out the location info in ServiceState depending on what level of access
6154 // the caller has.
6155 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006156 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6157 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006161 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006162
6163 /**
6164 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6165 *
6166 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6167 * voicemail ringtone.
6168 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6169 * PhoneAccount.
6170 */
6171 @Override
6172 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6176 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006177 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006179
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6181 } finally {
6182 Binder.restoreCallingIdentity(identity);
6183 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006184 }
6185
6186 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006187 * Sets the per-account voicemail ringtone.
6188 *
6189 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6190 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6191 *
6192 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6193 * voicemail ringtone.
6194 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6195 * PhoneAccount.
6196 */
6197 @Override
6198 public void setVoicemailRingtoneUri(String callingPackage,
6199 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006200 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006201 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006202 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6203 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6205 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6206 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6212 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006213 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006214 }
6215 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006218 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006219 }
6220
6221 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006222 * Returns whether vibration is set for voicemail notification in Phone settings.
6223 *
6224 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6225 * voicemail vibration setting.
6226 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6227 */
6228 @Override
6229 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006230 final long identity = Binder.clearCallingIdentity();
6231 try {
6232 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6233 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006234 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006236
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006237 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6238 } finally {
6239 Binder.restoreCallingIdentity(identity);
6240 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006241 }
6242
Youhan Wange64578a2016-05-02 15:32:42 -07006243 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006244 * Sets the per-account voicemail vibration.
6245 *
6246 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6247 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6248 *
6249 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6250 * voicemail vibration setting.
6251 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6252 * specific PhoneAccount.
6253 */
6254 @Override
6255 public void setVoicemailVibrationEnabled(String callingPackage,
6256 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006257 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006258 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006259 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6260 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006261 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6262 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6263 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006264 }
6265
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266 final long identity = Binder.clearCallingIdentity();
6267 try {
6268 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6269 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006270 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006271 }
6272 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006275 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006276 }
6277
6278 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006279 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6280 *
6281 * @throws SecurityException if the caller does not have the required permission
6282 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006283 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006284 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006285 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006286 }
6287
6288 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006289 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6290 * permission.
6291 *
6292 * @throws SecurityException if the caller does not have the required permission
6293 */
6294 private void enforceSendSmsPermission() {
6295 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6296 }
6297
6298 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006299 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006300 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006301 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006302 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006303 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 final long identity = Binder.clearCallingIdentity();
6305 try {
6306 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006307 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308 if (componentName == null) {
6309 throw new SecurityException(
6310 "Caller not current active visual voicemail package[null]");
6311 }
6312 String vvmPackage = componentName.getPackageName();
6313 if (!callingPackage.equals(vvmPackage)) {
6314 throw new SecurityException("Caller not current active visual voicemail package["
6315 + vvmPackage + "]");
6316 }
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006319 }
6320 }
6321
6322 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006323 * Return the application ID for the app type.
6324 *
6325 * @param subId the subscription ID that this request applies to.
6326 * @param appType the uicc app type.
6327 * @return Application ID for specificied app type, or null if no uicc.
6328 */
6329 @Override
6330 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006331 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006332 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006333
6334 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006335 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006336 if (phone == null) {
6337 return null;
6338 }
6339 String aid = null;
6340 try {
6341 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6342 .getApplicationByType(appType).getAid();
6343 } catch (Exception e) {
6344 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6345 }
6346 return aid;
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006349 }
Youhan Wange64578a2016-05-02 15:32:42 -07006350 }
6351
Youhan Wang4001d252016-05-11 10:29:41 -07006352 /**
6353 * Return the Electronic Serial Number.
6354 *
6355 * @param subId the subscription ID that this request applies to.
6356 * @return ESN or null if error.
6357 */
6358 @Override
6359 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006360 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006361 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
6363 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006364 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 if (phone == null) {
6366 return null;
6367 }
6368 String esn = null;
6369 try {
6370 esn = phone.getEsn();
6371 } catch (Exception e) {
6372 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6373 }
6374 return esn;
6375 } finally {
6376 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006377 }
Youhan Wang4001d252016-05-11 10:29:41 -07006378 }
6379
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006380 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006381 * Return the Preferred Roaming List Version.
6382 *
6383 * @param subId the subscription ID that this request applies to.
6384 * @return PRLVersion or null if error.
6385 */
6386 @Override
6387 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006388 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006389 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390
6391 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006392 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 if (phone == null) {
6394 return null;
6395 }
6396 String cdmaPrlVersion = null;
6397 try {
6398 cdmaPrlVersion = phone.getCdmaPrlVersion();
6399 } catch (Exception e) {
6400 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6401 }
6402 return cdmaPrlVersion;
6403 } finally {
6404 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006405 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006406 }
6407
6408 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006409 * Get snapshot of Telephony histograms
6410 * @return List of Telephony histograms
6411 * @hide
6412 */
6413 @Override
6414 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6416 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006417
6418 final long identity = Binder.clearCallingIdentity();
6419 try {
6420 return RIL.getTelephonyRILTimingHistograms();
6421 } finally {
6422 Binder.restoreCallingIdentity(identity);
6423 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006424 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006425
6426 /**
6427 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006428 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6429 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006430 * Require system privileges. In the future we may add this to carrier APIs.
6431 *
Michele Berionne482f8202018-11-27 18:57:59 -08006432 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006433 */
6434 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006435 @TelephonyManager.SetCarrierRestrictionResult
6436 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006437 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006438 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006439
Michele Berionne482f8202018-11-27 18:57:59 -08006440 if (carrierRestrictionRules == null) {
6441 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006442 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006443
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 final long identity = Binder.clearCallingIdentity();
6445 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006446 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006447 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006448 } finally {
6449 Binder.restoreCallingIdentity(identity);
6450 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006451 }
6452
6453 /**
6454 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006455 * Get the allowed carrier list and the excluded carrier list, including the priority between
6456 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006457 * Require system privileges. In the future we may add this to carrier APIs.
6458 *
Michele Berionne482f8202018-11-27 18:57:59 -08006459 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006460 */
6461 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006462 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006463 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07006464 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465
6466 final long identity = Binder.clearCallingIdentity();
6467 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006468 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
6469 if (response instanceof CarrierRestrictionRules) {
6470 return (CarrierRestrictionRules) response;
6471 }
6472 // Response is an Exception of some kind,
6473 // which is signalled to the user as a NULL retval
6474 return null;
6475 } catch (Exception e) {
6476 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
6477 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006478 } finally {
6479 Binder.restoreCallingIdentity(identity);
6480 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006481 }
6482
fionaxu59545b42016-05-25 15:53:37 -07006483 /**
6484 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
6485 * @param subId the subscription ID that this action applies to.
6486 * @param enabled control enable or disable metered apns.
6487 * {@hide}
6488 */
6489 @Override
6490 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
6491 enforceModifyPermission();
6492 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493
6494 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006495 if (phone == null) {
6496 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
6497 return;
6498 }
6499 try {
6500 phone.carrierActionSetMeteredApnsEnabled(enabled);
6501 } catch (Exception e) {
6502 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006503 } finally {
6504 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006505 }
6506 }
6507
6508 /**
6509 * Action set from carrier signalling broadcast receivers to enable/disable radio
6510 * @param subId the subscription ID that this action applies to.
6511 * @param enabled control enable or disable radio.
6512 * {@hide}
6513 */
6514 @Override
6515 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
6516 enforceModifyPermission();
6517 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518
6519 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07006520 if (phone == null) {
6521 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
6522 return;
6523 }
6524 try {
6525 phone.carrierActionSetRadioEnabled(enabled);
6526 } catch (Exception e) {
6527 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006528 } finally {
6529 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07006530 }
6531 }
6532
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006533 /**
fionaxu8da9cb12017-05-23 15:02:46 -07006534 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
6535 * network status based on which carrier apps could apply actions accordingly,
6536 * enable/disable default url handler for example.
6537 *
6538 * @param subId the subscription ID that this action applies to.
6539 * @param report control start/stop reporting the default network status.
6540 * {@hide}
6541 */
6542 @Override
6543 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
6544 enforceModifyPermission();
6545 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006546
6547 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07006548 if (phone == null) {
6549 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
6550 return;
6551 }
6552 try {
6553 phone.carrierActionReportDefaultNetworkStatus(report);
6554 } catch (Exception e) {
6555 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006556 } finally {
6557 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07006558 }
6559 }
6560
6561 /**
fionaxud9622282017-07-17 17:51:30 -07006562 * Action set from carrier signalling broadcast receivers to reset all carrier actions
6563 * @param subId the subscription ID that this action applies to.
6564 * {@hide}
6565 */
6566 @Override
6567 public void carrierActionResetAll(int subId) {
6568 enforceModifyPermission();
6569 final Phone phone = getPhone(subId);
6570 if (phone == null) {
6571 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
6572 return;
6573 }
6574 try {
6575 phone.carrierActionResetAll();
6576 } catch (Exception e) {
6577 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
6578 }
6579 }
6580
6581 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006582 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
6583 * bug report is being generated.
6584 */
6585 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07006586 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006587 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
6588 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07006589 writer.println("Permission Denial: can't dump Phone from pid="
6590 + Binder.getCallingPid()
6591 + ", uid=" + Binder.getCallingUid()
6592 + "without permission "
6593 + android.Manifest.permission.DUMP);
6594 return;
6595 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07006597 }
Jack Yueb89b242016-06-22 13:27:47 -07006598
Brad Ebingerdac2f002018-04-03 15:17:52 -07006599 @Override
6600 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
6601 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
6602 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01006603 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
6604 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07006605 }
6606
Jack Yueb89b242016-06-22 13:27:47 -07006607 /**
Jack Yu84291ec2017-05-26 16:07:50 -07006608 * Get aggregated video call data usage since boot.
6609 *
6610 * @param perUidStats True if requesting data usage per uid, otherwise overall usage.
6611 * @return Snapshot of video call data usage
Jack Yueb89b242016-06-22 13:27:47 -07006612 * {@hide}
6613 */
6614 @Override
Jack Yu84291ec2017-05-26 16:07:50 -07006615 public NetworkStats getVtDataUsage(int subId, boolean perUidStats) {
Jack Yueb89b242016-06-22 13:27:47 -07006616 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_NETWORK_USAGE_HISTORY,
6617 null);
6618
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006619 final long identity = Binder.clearCallingIdentity();
6620 try {
6621 // NetworkStatsService keeps tracking the active network interface and identity. It
6622 // records the delta with the corresponding network identity.
6623 // We just return the total video call data usage snapshot since boot.
6624 Phone phone = getPhone(subId);
6625 if (phone != null) {
6626 return phone.getVtDataUsage(perUidStats);
6627 }
6628 return null;
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
Jack Yueb89b242016-06-22 13:27:47 -07006631 }
Jack Yueb89b242016-06-22 13:27:47 -07006632 }
Jack Yu75ab2952016-07-08 14:29:33 -07006633
6634 /**
6635 * Policy control of data connection. Usually used when data limit is passed.
6636 * @param enabled True if enabling the data, otherwise disabling.
6637 * @param subId Subscription index
6638 * {@hide}
6639 */
6640 @Override
6641 public void setPolicyDataEnabled(boolean enabled, int subId) {
6642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006643
6644 final long identity = Binder.clearCallingIdentity();
6645 try {
6646 Phone phone = getPhone(subId);
6647 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006648 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 }
6650 } finally {
6651 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07006652 }
6653 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006654
6655 /**
6656 * Get Client request stats
6657 * @return List of Client Request Stats
6658 * @hide
6659 */
6660 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006661 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
6662 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006663 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006664 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006665 return null;
6666 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006667 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006668
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006669 final long identity = Binder.clearCallingIdentity();
6670 try {
6671 if (phone != null) {
6672 return phone.getClientRequestStats();
6673 }
6674
6675 return null;
6676 } finally {
6677 Binder.restoreCallingIdentity(identity);
6678 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006679 }
6680
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006681 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006682 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00006683 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07006684 }
Jack Yueb4124c2017-02-16 15:32:43 -08006685
6686 /**
Grace Chen70990072017-03-24 17:21:30 -07006687 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08006688 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006689 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07006690 * @param state State of SIM (power down, power up, pass through)
6691 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
6692 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
6693 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08006694 *
6695 **/
6696 @Override
Grace Chen70990072017-03-24 17:21:30 -07006697 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08006698 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006699 Phone phone = PhoneFactory.getPhone(slotIndex);
6700
vagdeviaf9a5b92018-08-15 16:01:53 -07006701 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 final long identity = Binder.clearCallingIdentity();
6704 try {
6705 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07006706 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 }
6708 } finally {
6709 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08006710 }
6711 }
Shuo Qiandd210312017-04-12 22:11:33 +00006712
Tyler Gunn65d45c22017-06-05 11:22:26 -07006713 private boolean isUssdApiAllowed(int subId) {
6714 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006715 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07006716 if (configManager == null) {
6717 return false;
6718 }
6719 PersistableBundle pb = configManager.getConfigForSubId(subId);
6720 if (pb == null) {
6721 return false;
6722 }
6723 return pb.getBoolean(
6724 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
6725 }
6726
Shuo Qiandd210312017-04-12 22:11:33 +00006727 /**
6728 * Check if phone is in emergency callback mode
6729 * @return true if phone is in emergency callback mode
6730 * @param subId sub id
6731 */
goneil9c5f4872017-12-05 14:07:56 -08006732 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00006733 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006734 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00006735 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736
6737 final long identity = Binder.clearCallingIdentity();
6738 try {
6739 if (phone != null) {
6740 return phone.isInEcm();
6741 } else {
6742 return false;
6743 }
6744 } finally {
6745 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00006746 }
6747 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006748
6749 /**
6750 * Get the current signal strength information for the given subscription.
6751 * Because this information is not updated when the device is in a low power state
6752 * it should not be relied-upon to be current.
6753 * @param subId Subscription index
6754 * @return the most recent cached signal strength info from the modem
6755 */
6756 @Override
6757 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 final long identity = Binder.clearCallingIdentity();
6759 try {
6760 Phone p = getPhone(subId);
6761 if (p == null) {
6762 return null;
6763 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006765 return p.getSignalStrength();
6766 } finally {
6767 Binder.restoreCallingIdentity(identity);
6768 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08006769 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006770
Pengquan Meng77b7f132018-08-22 14:49:57 -07006771 /**
Chen Xuf792fd62018-10-17 17:54:36 +00006772 * Get the current modem radio state for the given slot.
6773 * @param slotIndex slot index.
6774 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006775 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00006776 * @return the current radio power state from the modem
6777 */
6778 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006779 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00006780 Phone phone = PhoneFactory.getPhone(slotIndex);
6781 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
6783 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00006784 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6785 }
6786
6787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 return phone.getRadioPowerState();
6790 } finally {
6791 Binder.restoreCallingIdentity(identity);
6792 }
6793 }
6794 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
6795 }
6796
6797 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07006798 * Checks if data roaming is enabled on the subscription with id {@code subId}.
6799 *
6800 * <p>Requires one of the following permissions:
6801 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
6802 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
6803 * privileges.
6804 *
6805 * @param subId subscription id
6806 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
6807 * {@code false}.
6808 */
6809 @Override
6810 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006811 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6812 null /* message */);
6813
Pengquan Menga1bb6272018-09-06 09:59:22 -07006814 boolean isEnabled = false;
6815 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07006816 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006817 Phone phone = getPhone(subId);
6818 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006819 } catch (Exception e) {
6820 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
6821 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07006822 } finally {
6823 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006824 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07006825 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07006826 }
6827
6828
6829 /**
6830 * Enables/Disables the data roaming on the subscription with id {@code subId}.
6831 *
6832 * <p> Requires permission:
6833 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
6834 * privileges.
6835 *
6836 * @param subId subscription id
6837 * @param isEnabled {@code true} means enable, {@code false} means disable.
6838 */
6839 @Override
6840 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07006841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6842 mApp, subId, "setDataRoamingEnabled");
6843
Pengquan Menga1bb6272018-09-06 09:59:22 -07006844 final long identity = Binder.clearCallingIdentity();
6845 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07006846 Phone phone = getPhone(subId);
6847 if (phone != null) {
6848 phone.setDataRoamingEnabled(isEnabled);
6849 }
6850 } finally {
6851 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07006852 }
6853 }
6854
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006855 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006856 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08006857 TelephonyPermissions
6858 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07006859 mApp, subId, "isManualNetworkSelectionAllowed");
6860
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006861 boolean isAllowed = true;
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07006864 Phone phone = getPhone(subId);
6865 if (phone != null) {
6866 isAllowed = phone.isCspPlmnEnabled();
6867 }
6868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
6871 return isAllowed;
6872 }
6873
6874 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08006875 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006876 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08006877 try {
6878 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07006879 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08006880 } catch (SecurityException e) {
6881 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
6882 // has carrier privileges on an active UICC
6883 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
6884 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07006885 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08006886 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08006887 }
Jordan Liu5aa07002018-12-18 15:44:48 -08006888
6889 final long identity = Binder.clearCallingIdentity();
6890 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08006891 UiccController uiccController = UiccController.getInstance();
6892 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07006893 if (hasReadPermission) {
6894 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08006895 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07006896
6897 // Remove private info if the caller doesn't have access
6898 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
6899 for (UiccCardInfo cardInfo : cardInfos) {
6900 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
6901 // is available
6902 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
6903 if (card == null || card.getUiccProfile() == null) {
6904 // assume no access if the card or profile is unavailable
6905 filteredInfos.add(cardInfo.getUnprivileged());
6906 continue;
6907 }
6908 UiccProfile profile = card.getUiccProfile();
6909 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
6910 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6911 filteredInfos.add(cardInfo);
6912 } else {
6913 filteredInfos.add(cardInfo.getUnprivileged());
6914 }
6915 }
6916 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08006917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
6920 }
6921
6922 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006923 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006924 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 final long identity = Binder.clearCallingIdentity();
6927 try {
6928 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
6929 if (slots == null) {
6930 Rlog.i(LOG_TAG, "slots is null.");
6931 return null;
6932 }
6933
6934 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
6935 for (int i = 0; i < slots.length; i++) {
6936 UiccSlot slot = slots[i];
6937 if (slot == null) {
6938 continue;
6939 }
6940
Jordan Liu7be7e652019-05-06 18:55:02 +00006941 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 UiccCard card = slot.getUiccCard();
6943 if (card != null) {
6944 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00006945 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07006946 cardId = slot.getEid();
6947 if (TextUtils.isEmpty(cardId)) {
6948 cardId = slot.getIccId();
6949 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 }
6951
Jordan Liu857451f2019-05-09 16:35:35 -07006952 if (cardId != null) {
6953 // if cardId is an ICCID, strip off trailing Fs before exposing to user
6954 // if cardId is an EID, it's all digits so this is fine
6955 cardId = IccUtils.stripTrailingFs(cardId);
6956 }
6957
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 int cardState = 0;
6959 switch (slot.getCardState()) {
6960 case CARDSTATE_ABSENT:
6961 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
6962 break;
6963 case CARDSTATE_PRESENT:
6964 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
6965 break;
6966 case CARDSTATE_ERROR:
6967 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
6968 break;
6969 case CARDSTATE_RESTRICTED:
6970 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
6971 break;
6972 default:
6973 break;
6974
6975 }
6976
6977 infos[i] = new UiccSlotInfo(
6978 slot.isActive(),
6979 slot.isEuicc(),
6980 cardId,
6981 cardState,
6982 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08006983 slot.isExtendedApduSupported(),
6984 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 }
6986 return infos;
6987 } finally {
6988 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07006989 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00006990 }
6991
6992 @Override
6993 public boolean switchSlots(int[] physicalSlots) {
6994 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995
6996 final long identity = Binder.clearCallingIdentity();
6997 try {
6998 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007002 }
Jack Yu4c988042018-02-27 15:30:01 -08007003
7004 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007005 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007006 final long identity = Binder.clearCallingIdentity();
7007 try {
7008 return UiccController.getInstance().getCardIdForDefaultEuicc();
7009 } finally {
7010 Binder.restoreCallingIdentity(identity);
7011 }
7012 }
7013
7014 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007015 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7016 enforceModifyPermission();
7017 final Phone phone = getPhone(subId);
7018 if (phone == null) {
7019 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7020 return;
7021 }
7022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007023 final long identity = Binder.clearCallingIdentity();
7024 try {
7025 phone.setRadioIndicationUpdateMode(filters, mode);
7026 } finally {
7027 Binder.restoreCallingIdentity(identity);
7028 }
Jack Yu4c988042018-02-27 15:30:01 -08007029 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007030
7031 /**
goneil47ffb6e2018-04-06 15:40:58 -07007032 * A test API to reload the UICC profile.
7033 *
7034 * <p>Requires that the calling app has permission
7035 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7036 * @hide
7037 */
7038 @Override
7039 public void refreshUiccProfile(int subId) {
7040 enforceModifyPermission();
7041
7042 final long identity = Binder.clearCallingIdentity();
7043 try {
7044 Phone phone = getPhone(subId);
7045 if (phone == null) {
7046 return;
7047 }
7048 UiccCard uiccCard = phone.getUiccCard();
7049 if (uiccCard == null) {
7050 return;
7051 }
7052 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7053 if (uiccProfile == null) {
7054 return;
7055 }
7056 uiccProfile.refresh();
7057 } finally {
7058 Binder.restoreCallingIdentity(identity);
7059 }
7060 }
7061
7062 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007063 * Returns false if the mobile data is disabled by default, otherwise return true.
7064 */
7065 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007066 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007067 }
7068
7069 /**
7070 * Returns true if the data roaming is enabled by default, i.e the system property
7071 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7072 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7073 */
7074 private boolean getDefaultDataRoamingEnabled(int subId) {
7075 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007076 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007077 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007078 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7079 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7080 return isDataRoamingEnabled;
7081 }
7082
7083 /**
7084 * Returns the default network type for the given {@code subId}, if the default network type is
7085 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7086 */
7087 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007088 List<Integer> list = TelephonyProperties.default_network();
7089 int phoneId = mSubscriptionController.getPhoneId(subId);
7090 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7091 return list.get(phoneId);
7092 }
7093 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007094 }
fionaxua13278b2018-03-21 00:08:13 -07007095
7096 @Override
7097 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007098 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007099 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 final Phone phone = getPhone(subId);
7104 if (phone == null) {
7105 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7106 return;
7107 }
chen xueaba88a2019-03-15 13:15:10 -07007108 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7109 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110 } finally {
7111 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007112 }
fionaxua13278b2018-03-21 00:08:13 -07007113 }
7114
7115 @Override
7116 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007117 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118
7119 final long identity = Binder.clearCallingIdentity();
7120 try {
7121 final Phone phone = getPhone(subId);
7122 if (phone == null) {
7123 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7124 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7125 }
7126 return phone.getCarrierIdListVersion();
7127 } finally {
7128 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007129 }
fionaxua13278b2018-03-21 00:08:13 -07007130 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007131
7132 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007133 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7134 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007135 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007136 mApp, subId, callingPackage, callingFeatureId,
7137 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007138 return -1;
7139 }
7140
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007148
7149 @Override
7150 public int getCdmaRoamingMode(int subId) {
7151 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7152 mApp, subId, "getCdmaRoamingMode");
7153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7157 } finally {
7158 Binder.restoreCallingIdentity(identity);
7159 }
7160 }
7161
7162 @Override
7163 public boolean setCdmaRoamingMode(int subId, int mode) {
7164 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7165 mApp, subId, "setCdmaRoamingMode");
7166
7167 final long identity = Binder.clearCallingIdentity();
7168 try {
7169 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
7173 }
7174
7175 @Override
7176 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7178 mApp, subId, "setCdmaSubscriptionMode");
7179
7180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
7185 }
7186 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007187
sqianc5eccab2018-10-19 18:46:41 -07007188 @Override
sqian8c685422019-02-22 15:55:18 -08007189 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007190 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007192 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7193 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007194 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7195 }
7196 final long identity = Binder.clearCallingIdentity();
7197 try {
sqian854d44b2018-12-12 16:48:18 -08007198 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7199 for (Phone phone: PhoneFactory.getPhones()) {
7200 if (phone.getEmergencyNumberTracker() != null
7201 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7202 emergencyNumberListInternal.put(
7203 phone.getSubId(),
7204 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7205 }
sqian11b7a0e2018-12-05 18:48:28 -08007206 }
sqian854d44b2018-12-12 16:48:18 -08007207 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007208 } finally {
7209 Binder.restoreCallingIdentity(identity);
7210 }
sqianc5eccab2018-10-19 18:46:41 -07007211 }
7212
7213 @Override
sqian8c685422019-02-22 15:55:18 -08007214 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007215 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007216 if (!exactMatch) {
7217 TelephonyPermissions
7218 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007219 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007220 }
7221 final long identity = Binder.clearCallingIdentity();
7222 try {
sqian854d44b2018-12-12 16:48:18 -08007223 for (Phone phone: PhoneFactory.getPhones()) {
7224 if (phone.getEmergencyNumberTracker() != null
7225 && phone.getEmergencyNumberTracker() != null) {
7226 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7227 number, exactMatch)) {
7228 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007229 }
7230 }
sqian11b7a0e2018-12-05 18:48:28 -08007231 }
7232 return false;
7233 } finally {
7234 Binder.restoreCallingIdentity(identity);
7235 }
7236 }
7237
sqianf4ca7ed2019-01-15 18:32:07 -08007238 /**
7239 * Update emergency number list for test mode.
7240 */
7241 @Override
7242 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7243 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7244 "updateEmergencyNumberListTestMode");
7245
7246 final long identity = Binder.clearCallingIdentity();
7247 try {
7248 for (Phone phone: PhoneFactory.getPhones()) {
7249 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7250 if (tracker != null) {
7251 tracker.executeEmergencyNumberTestModeCommand(action, num);
7252 }
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
7256 }
7257 }
7258
7259 /**
7260 * Get the full emergency number list for test mode.
7261 */
7262 @Override
7263 public List<String> getEmergencyNumberListTestMode() {
7264 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7265 "getEmergencyNumberListTestMode");
7266
7267 final long identity = Binder.clearCallingIdentity();
7268 try {
7269 Set<String> emergencyNumbers = new HashSet<>();
7270 for (Phone phone: PhoneFactory.getPhones()) {
7271 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7272 if (tracker != null) {
7273 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7274 emergencyNumbers.add(num.getNumber());
7275 }
7276 }
7277 }
7278 return new ArrayList<>(emergencyNumbers);
7279 } finally {
7280 Binder.restoreCallingIdentity(identity);
7281 }
7282 }
7283
chen xud6b45bd2018-10-30 22:27:10 -07007284 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007285 public int getEmergencyNumberDbVersion(int subId) {
7286 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7287
7288 final long identity = Binder.clearCallingIdentity();
7289 try {
7290 final Phone phone = getPhone(subId);
7291 if (phone == null) {
7292 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7293 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7294 }
7295 return phone.getEmergencyNumberDbVersion();
7296 } finally {
7297 Binder.restoreCallingIdentity(identity);
7298 }
7299 }
7300
7301 @Override
7302 public void notifyOtaEmergencyNumberDbInstalled() {
7303 enforceModifyPermission();
7304
7305 final long identity = Binder.clearCallingIdentity();
7306 try {
7307 for (Phone phone: PhoneFactory.getPhones()) {
7308 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7309 if (tracker != null) {
7310 tracker.updateOtaEmergencyNumberDatabase();
7311 }
7312 }
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
7315 }
7316 }
7317
7318 @Override
7319 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7320 enforceActiveEmergencySessionPermission();
7321
7322 final long identity = Binder.clearCallingIdentity();
7323 try {
7324 for (Phone phone: PhoneFactory.getPhones()) {
7325 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7326 if (tracker != null) {
7327 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7328 }
7329 }
7330 } finally {
7331 Binder.restoreCallingIdentity(identity);
7332 }
7333 }
7334
7335 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007336 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7337 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7338 Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 return null;
7341 }
7342 final long identity = Binder.clearCallingIdentity();
7343 try {
7344 UiccProfile profile = UiccController.getInstance()
7345 .getUiccProfileForPhone(phone.getPhoneId());
7346 if (profile != null) {
7347 return profile.getCertsFromCarrierPrivilegeAccessRules();
7348 }
7349 } finally {
7350 Binder.restoreCallingIdentity(identity);
7351 }
7352 return null;
7353 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007354
7355 /**
7356 * Enable or disable a modem stack.
7357 */
7358 @Override
7359 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7360 enforceModifyPermission();
7361
7362 final long identity = Binder.clearCallingIdentity();
7363 try {
7364 Phone phone = PhoneFactory.getPhone(slotIndex);
7365 if (phone == null) {
7366 return false;
7367 } else {
7368 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7369 }
7370 } finally {
7371 Binder.restoreCallingIdentity(identity);
7372 }
7373 }
Michelecea4cf22018-12-21 15:00:11 -08007374
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007375 /**
7376 * Whether a modem stack is enabled or not.
7377 */
7378 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007379 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7380 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007381 Phone phone = PhoneFactory.getPhone(slotIndex);
7382 if (phone == null) return false;
7383
7384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007385 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7386 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007387 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7388 }
7389
7390 final long identity = Binder.clearCallingIdentity();
7391 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007392 try {
7393 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7394 } catch (NoSuchElementException ex) {
7395 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7396 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007397 } finally {
7398 Binder.restoreCallingIdentity(identity);
7399 }
7400 }
7401
Michelecea4cf22018-12-21 15:00:11 -08007402 @Override
Michele0ea7d782019-03-19 14:58:42 -07007403 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007404 enforceModifyPermission();
7405
7406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007409 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007410 .commit();
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415
7416 @Override
Michele0ea7d782019-03-19 14:58:42 -07007417 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007418 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007420 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7421 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007422 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007423 }
Michelecea4cf22018-12-21 15:00:11 -08007424
7425 final long identity = Binder.clearCallingIdentity();
7426 try {
Michele0ea7d782019-03-19 14:58:42 -07007427 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007428 } finally {
7429 Binder.restoreCallingIdentity(identity);
7430 }
7431 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007432
Michele0ea7d782019-03-19 14:58:42 -07007433 @TelephonyManager.IsMultiSimSupportedResult
7434 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007435 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7436 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7437 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007438 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7439 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007440 }
7441 // Check if the hardware supports multisim functionality. If usage of multisim is not
7442 // supported by the modem, indicate that it is restricted.
7443 PhoneCapability staticCapability =
7444 mPhoneConfigurationManager.getStaticPhoneCapability();
7445 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007446 loge("isMultiSimSupportedInternal: no static configuration available");
7447 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007448 }
7449 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007450 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7451 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007452 }
7453 // Check if support of multiple SIMs is restricted by carrier
7454 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007455 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007456 }
7457
Michele0ea7d782019-03-19 14:58:42 -07007458 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007459 }
7460
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007461 /**
7462 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007463 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7464 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7465 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007466 * @param numOfSims number of active sims we want to switch to
7467 */
7468 @Override
7469 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007470 if (numOfSims == 1) {
7471 enforceModifyPermission();
7472 } else {
7473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7474 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7475 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007476 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007477
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007478 try {
Michele30b57b22019-03-01 12:01:14 -08007479 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007480 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007481 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7482 return;
7483 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007484 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7485 } finally {
7486 Binder.restoreCallingIdentity(identity);
7487 }
7488 }
7489
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09007490 @Override
7491 public boolean isApplicationOnUicc(int subId, int appType) {
7492 enforceReadPrivilegedPermission("isApplicationOnUicc");
7493 Phone phone = getPhone(subId);
7494 if (phone == null) {
7495 return false;
7496 }
7497 final long identity = Binder.clearCallingIdentity();
7498 try {
7499 UiccCard uiccCard = phone.getUiccCard();
7500 if (uiccCard == null) {
7501 return false;
7502 }
7503 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7504 if (uiccProfile == null) {
7505 return false;
7506 }
7507 if (TelephonyManager.APPTYPE_SIM <= appType
7508 && appType <= TelephonyManager.APPTYPE_ISIM) {
7509 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
7510 }
7511 return false;
7512 } finally {
7513 Binder.restoreCallingIdentity(identity);
7514 }
7515 }
7516
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007517 /**
chen xub4baa772019-04-03 10:23:41 -07007518 * Get whether making changes to modem configurations will trigger reboot.
7519 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007520 */
7521 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007522 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
7523 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07007524 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007525 mApp, subId, callingPackage, callingFeatureId,
7526 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07007527 return false;
7528 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08007529 final long identity = Binder.clearCallingIdentity();
7530 try {
7531 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
7532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
Nathan Harold29f5f052019-02-15 13:41:57 -08007537 private void updateModemStateMetrics() {
7538 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
7539 // TODO: check the state for each modem if the api is ready.
7540 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
7541 }
7542
Pengquan Meng3889a572019-01-23 11:16:29 -08007543 @Override
7544 public int[] getSlotsMapping() {
7545 enforceReadPrivilegedPermission("getSlotsMapping");
7546
7547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
7550 // All logical slots should have a mapping to a physical slot.
7551 int[] logicalSlotsMapping = new int[phoneCount];
7552 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
7553 for (int i = 0; i < slotInfos.length; i++) {
7554 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
7555 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
7556 }
7557 }
7558 return logicalSlotsMapping;
7559 } finally {
7560 Binder.restoreCallingIdentity(identity);
7561 }
7562 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08007563
7564 /**
7565 * Get the IRadio HAL Version
7566 */
7567 @Override
7568 public int getRadioHalVersion() {
7569 Phone phone = getDefaultPhone();
7570 if (phone == null) return -1;
7571 HalVersion hv = phone.getHalVersion();
7572 if (hv.equals(HalVersion.UNKNOWN)) return -1;
7573 return hv.major * 100 + hv.minor;
7574 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007575
7576 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07007577 * Return whether data is enabled for certain APN type. This will tell if framework will accept
7578 * corresponding network requests on a subId.
7579 *
7580 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007581 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07007582 * 2) APN is un-metered for this subscription, or
7583 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
7584 * {@link SubscriptionManager#setAlwaysAllowMmsData} is turned on.
7585 *
7586 * @return whether data is allowed for a apn type.
7587 *
7588 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007589 */
7590 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07007591 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07007592 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
7593 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007594
7595 // Now that all security checks passes, perform the operation as ourselves.
7596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 Phone phone = getPhone(subId);
7599 if (phone == null) return false;
7600
Jack Yu41407ee2019-05-13 16:54:09 -07007601 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07007602 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
7603 } finally {
7604 Binder.restoreCallingIdentity(identity);
7605 }
7606 }
7607
7608 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07007609 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07007610 enforceReadPrivilegedPermission("isApnMetered");
7611
7612 // Now that all security checks passes, perform the operation as ourselves.
7613 final long identity = Binder.clearCallingIdentity();
7614 try {
7615 Phone phone = getPhone(subId);
7616 if (phone == null) return true; // By default return true.
7617
Jack Yu41407ee2019-05-13 16:54:09 -07007618 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07007619 } finally {
7620 Binder.restoreCallingIdentity(identity);
7621 }
7622 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07007623
7624 @Override
7625 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
7626 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
7627 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
7628 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
7629 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
7630 }
7631 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
7632 Intent intent = new Intent();
7633 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
7634 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
7635 // Bring up choose default SMS subscription dialog right now
7636 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
7637 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
7638 mApp.startActivity(intent);
7639 }
chen xud5ca2d52019-05-28 15:20:57 -07007640
7641 @Override
7642 public String getMmsUAProfUrl(int subId) {
7643 //TODO investigate if this API should require proper permission check in R b/133791609
7644 final long identity = Binder.clearCallingIdentity();
7645 try {
7646 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7647 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
7650 }
7651 }
7652
7653 @Override
7654 public String getMmsUserAgent(int subId) {
7655 //TODO investigate if this API should require proper permission check in R b/133791609
7656 final long identity = Binder.clearCallingIdentity();
7657 try {
7658 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
7659 .getString(com.android.internal.R.string.config_mms_user_agent);
7660 } finally {
7661 Binder.restoreCallingIdentity(identity);
7662 }
7663 }
Jack Yub07d4972019-05-28 16:12:25 -07007664
7665 @Override
7666 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
7667 enforceModifyPermission();
7668
7669 // Now that all security checks passes, perform the operation as ourselves.
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 Phone phone = getPhone(subId);
7673 if (phone == null) return false;
7674
7675 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
7679 }
7680
7681 @Override
7682 public boolean isDataAllowedInVoiceCall(int subId) {
7683 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
7684
7685 // Now that all security checks passes, perform the operation as ourselves.
7686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 Phone phone = getPhone(subId);
7689 if (phone == null) return false;
7690
7691 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
7692 } finally {
7693 Binder.restoreCallingIdentity(identity);
7694 }
7695 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07007696
7697 /**
7698 * Updates whether conference event pacakge handling is enabled.
7699 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
7700 * otherwise.
7701 */
7702 @Override
7703 public void setCepEnabled(boolean isCepEnabled) {
7704 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
7705
7706 final long identity = Binder.clearCallingIdentity();
7707 try {
7708 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
7709 for (Phone phone : PhoneFactory.getPhones()) {
7710 Phone defaultPhone = phone.getImsPhone();
7711 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
7712 ImsPhone imsPhone = (ImsPhone) defaultPhone;
7713 ImsPhoneCallTracker imsPhoneCallTracker =
7714 (ImsPhoneCallTracker) imsPhone.getCallTracker();
7715 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
7716 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
7717 + imsPhone.getMsisdn());
7718 }
7719 }
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
7722 }
7723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07007724}