blob: 13c5c618178b98444417e7a8aef52b47bdaef006 [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;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
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;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070055import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070078import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070079import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080080import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070081import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080082import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070083import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080084import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080085import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070086import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080087import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080089import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080090import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080091import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800119import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800120
Andrew Lee312e8172014-10-23 17:01:36 -0700121import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800122import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800123import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700124import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700125import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700126import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800127import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700128import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700129import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700131import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800132import com.android.internal.telephony.HalVersion;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800152import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700153import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800154import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700155import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800156import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700157import com.android.internal.telephony.imsphone.ImsPhone;
158import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800159import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900160import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700161import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800162import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700163import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800164import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700165import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800166import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000169import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800170import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700171import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800172import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700173import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700174import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800175import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700176import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700177import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800178import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800179
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700180import java.io.FileDescriptor;
181import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700182import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800183import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800184import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800185import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800186import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100187import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800188import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700189import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800190import java.util.Set;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700191
192/**
193 * Implementation of the ITelephony interface.
194 */
Santos Cordon117fee72014-05-16 17:56:12 -0700195public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196 private static final String LOG_TAG = "PhoneInterfaceManager";
197 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
198 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800199 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200
201 // Message codes used with mMainThreadHandler
202 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700203 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
204 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700205 private static final int CMD_OPEN_CHANNEL = 9;
206 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
207 private static final int CMD_CLOSE_CHANNEL = 11;
208 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800209 private static final int CMD_NV_READ_ITEM = 13;
210 private static final int EVENT_NV_READ_ITEM_DONE = 14;
211 private static final int CMD_NV_WRITE_ITEM = 15;
212 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
213 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
214 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700215 private static final int CMD_RESET_MODEM_CONFIG = 19;
216 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800217 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
218 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
219 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
220 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800221 private static final int CMD_SEND_ENVELOPE = 25;
222 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000223 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
224 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700225 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
226 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
227 private static final int CMD_EXCHANGE_SIM_IO = 31;
228 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800229 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
230 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700231 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
232 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700233 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
234 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700235 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
236 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
237 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
238 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700239 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
240 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
241 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
242 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700243 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800244 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
245 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000246 private static final int CMD_SWITCH_SLOTS = 50;
247 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700248 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
249 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
250 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
251 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
252 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
253 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
254 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
255 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700256 private static final int CMD_GET_ALL_CELL_INFO = 60;
257 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
258 private static final int CMD_GET_CELL_LOCATION = 62;
259 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700260 private static final int CMD_MODEM_REBOOT = 64;
261 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700262 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
263 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800264 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
265 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700266 private static final int CMD_GET_MODEM_STATUS = 70;
267 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700268 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
269 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700270 private static final int CMD_ERASE_MODEM_CONFIG = 74;
271 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800272 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
273 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
274 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
275 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
sqian80370722020-01-29 15:02:51 -0800276 private static final int CMD_GET_CALL_FORWARDING = 83;
277 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
278 private static final int CMD_SET_CALL_FORWARDING = 85;
279 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
280 private static final int CMD_GET_CALL_WAITING = 87;
281 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
282 private static final int CMD_SET_CALL_WAITING = 89;
283 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700284
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800285 // Parameters of select command.
286 private static final int SELECT_COMMAND = 0xA4;
287 private static final int SELECT_P1 = 0x04;
288 private static final int SELECT_P2 = 0;
289 private static final int SELECT_P3 = 0x10;
290
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291 /** The singleton instance. */
292 private static PhoneInterfaceManager sInstance;
293
Wink Saville3ab207e2014-11-20 13:07:20 -0800294 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800295 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800296 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700297 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800298 private AppOpsManager mAppOps;
299 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800300 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700302 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700303
Derek Tan97ebb422014-09-05 16:55:38 -0700304 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
305 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800306 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800307 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700308
Michelecea4cf22018-12-21 15:00:11 -0800309 // String to store multi SIM allowed
310 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
311
Derek Tan740e1672017-06-27 14:56:27 -0700312 // The AID of ISD-R.
313 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
314
yinxub1bed742017-04-17 11:45:04 -0700315 private NetworkScanRequestTracker mNetworkScanRequestTracker;
316
David Kelly5e06a7f2018-03-12 14:10:59 +0000317 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
318 private static final int MANUFACTURER_CODE_LENGTH = 8;
319
Derek Tan89e89d42014-07-08 17:00:10 -0700320 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700321 * Experiment flag to enable erase modem config on reset network, default value is false
322 */
323 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
324 "reset_network_erase_modem_config_enabled";
325
326 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700327 * A request object to use for transmitting data to an ICC.
328 */
329 private static final class IccAPDUArgument {
330 public int channel, cla, command, p1, p2, p3;
331 public String data;
332
333 public IccAPDUArgument(int channel, int cla, int command,
334 int p1, int p2, int p3, String data) {
335 this.channel = channel;
336 this.cla = cla;
337 this.command = command;
338 this.p1 = p1;
339 this.p2 = p2;
340 this.p3 = p3;
341 this.data = data;
342 }
343 }
344
345 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700346 * A request object to use for transmitting data to an ICC.
347 */
348 private static final class ManualNetworkSelectionArgument {
349 public OperatorInfo operatorInfo;
350 public boolean persistSelection;
351
352 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
353 this.operatorInfo = operatorInfo;
354 this.persistSelection = persistSelection;
355 }
356 }
357
358 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700359 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
360 * request after sending. The main thread will notify the request when it is complete.
361 */
362 private static final class MainThreadRequest {
363 /** The argument to use for the request */
364 public Object argument;
365 /** The result of the request that is run on the main thread */
366 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800367 // The subscriber id that this request applies to. Defaults to
368 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
369 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700370
Nathan Harold92bed182018-10-12 18:16:49 -0700371 // In cases where subId is unavailable, the caller needs to specify the phone.
372 public Phone phone;
373
vagdeviaf9a5b92018-08-15 16:01:53 -0700374 public WorkSource workSource;
375
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376 public MainThreadRequest(Object argument) {
377 this.argument = argument;
378 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800379
Nathan Harold92bed182018-10-12 18:16:49 -0700380 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
381 this.argument = argument;
382 if (phone != null) {
383 this.phone = phone;
384 }
385 this.workSource = workSource;
386 }
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800389 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800390 if (subId != null) {
391 this.subId = subId;
392 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700393 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700395 }
396
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800397 private static final class IncomingThirdPartyCallArgs {
398 public final ComponentName component;
399 public final String callId;
400 public final String callerDisplayName;
401
402 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
403 String callerDisplayName) {
404 this.component = component;
405 this.callId = callId;
406 this.callerDisplayName = callerDisplayName;
407 }
408 }
409
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 /**
411 * A handler that processes messages on the main thread in the phone process. Since many
412 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
413 * inbound binder threads to the main thread in the phone process. The Binder thread
414 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
415 * on, which will be notified when the operation completes and will contain the result of the
416 * request.
417 *
418 * <p>If a MainThreadRequest object is provided in the msg.obj field,
419 * note that request.result must be set to something non-null for the calling thread to
420 * unblock.
421 */
422 private final class MainThreadHandler extends Handler {
423 @Override
424 public void handleMessage(Message msg) {
425 MainThreadRequest request;
426 Message onCompleted;
427 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800428 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700429 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800430 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700431
432 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700433 case CMD_HANDLE_USSD_REQUEST: {
434 request = (MainThreadRequest) msg.obj;
435 final Phone phone = getPhoneFromRequest(request);
436 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
437 String ussdRequest = ussdObject.first;
438 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700439
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 if (!isUssdApiAllowed(request.subId)) {
441 // Carrier does not support use of this API, return failure.
442 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
443 UssdResponse response = new UssdResponse(ussdRequest, null);
444 Bundle returnData = new Bundle();
445 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
446 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700447
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 request.result = true;
449 notifyRequester(request);
450 return;
451 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700452
Pengquan Menga1bb6272018-09-06 09:59:22 -0700453 try {
454 request.result = phone != null
455 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
456 } catch (CallStateException cse) {
457 request.result = false;
458 }
459 // Wake up the requesting thread
460 notifyRequester(request);
461 break;
pkanwar32d516d2016-10-14 19:37:38 -0700462 }
463
Yorke Lee716f67e2015-06-17 15:39:16 -0700464 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700465 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700466 final Phone phone = getPhoneFromRequest(request);
467 request.result = phone != null ?
468 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
469 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700471 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700473 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700474
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700475 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700476 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700477 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700479 if (uiccCard == null) {
480 loge("iccTransmitApduLogicalChannel: No UICC");
481 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700482 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700483 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
485 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 iccArgument.channel, iccArgument.cla, iccArgument.command,
488 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700489 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 break;
492
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700494 ar = (AsyncResult) msg.obj;
495 request = (MainThreadRequest) ar.userObj;
496 if (ar.exception == null && ar.result != null) {
497 request.result = ar.result;
498 } else {
499 request.result = new IccIoResult(0x6F, 0, (byte[])null);
500 if (ar.result == null) {
501 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800502 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800504 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 } else {
506 loge("iccTransmitApduLogicalChannel: Unknown exception");
507 }
508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700509 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 break;
511
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700512 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
513 request = (MainThreadRequest) msg.obj;
514 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800515 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 if (uiccCard == null) {
517 loge("iccTransmitApduBasicChannel: No UICC");
518 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700520 } else {
521 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
522 request);
523 uiccCard.iccTransmitApduBasicChannel(
524 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
525 iccArgument.p3, iccArgument.data, onCompleted);
526 }
527 break;
528
529 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
530 ar = (AsyncResult) msg.obj;
531 request = (MainThreadRequest) ar.userObj;
532 if (ar.exception == null && ar.result != null) {
533 request.result = ar.result;
534 } else {
535 request.result = new IccIoResult(0x6F, 0, (byte[])null);
536 if (ar.result == null) {
537 loge("iccTransmitApduBasicChannel: Empty response");
538 } else if (ar.exception instanceof CommandException) {
539 loge("iccTransmitApduBasicChannel: CommandException: " +
540 ar.exception);
541 } else {
542 loge("iccTransmitApduBasicChannel: Unknown exception");
543 }
544 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700545 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700546 break;
547
548 case CMD_EXCHANGE_SIM_IO:
549 request = (MainThreadRequest) msg.obj;
550 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800551 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 if (uiccCard == null) {
553 loge("iccExchangeSimIO: No UICC");
554 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 } else {
557 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
558 request);
559 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
560 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
561 iccArgument.data, onCompleted);
562 }
563 break;
564
565 case EVENT_EXCHANGE_SIM_IO_DONE:
566 ar = (AsyncResult) msg.obj;
567 request = (MainThreadRequest) ar.userObj;
568 if (ar.exception == null && ar.result != null) {
569 request.result = ar.result;
570 } else {
571 request.result = new IccIoResult(0x6f, 0, (byte[])null);
572 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700573 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700574 break;
575
Derek Tan4d5e5c12014-02-04 11:54:58 -0800576 case CMD_SEND_ENVELOPE:
577 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800578 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700579 if (uiccCard == null) {
580 loge("sendEnvelopeWithStatus: No UICC");
581 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700582 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700583 } else {
584 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
585 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
586 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800587 break;
588
589 case EVENT_SEND_ENVELOPE_DONE:
590 ar = (AsyncResult) msg.obj;
591 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700592 if (ar.exception == null && ar.result != null) {
593 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
596 if (ar.result == null) {
597 loge("sendEnvelopeWithStatus: Empty response");
598 } else if (ar.exception instanceof CommandException) {
599 loge("sendEnvelopeWithStatus: CommandException: " +
600 ar.exception);
601 } else {
602 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
603 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800604 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 break;
607
Shishir Agrawal566b7612013-10-28 14:41:00 -0700608 case CMD_OPEN_CHANNEL:
609 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800610 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800611 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700612 if (uiccCard == null) {
613 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800614 request.result = new IccOpenLogicalChannelResponse(-1,
615 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700616 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700617 } else {
618 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800619 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
620 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700621 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 break;
623
624 case EVENT_OPEN_CHANNEL_DONE:
625 ar = (AsyncResult) msg.obj;
626 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700627 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700629 int[] result = (int[]) ar.result;
630 int channelId = result[0];
631 byte[] selectResponse = null;
632 if (result.length > 1) {
633 selectResponse = new byte[result.length - 1];
634 for (int i = 1; i < result.length; ++i) {
635 selectResponse[i - 1] = (byte) result[i];
636 }
637 }
638 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700639 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700641 if (ar.result == null) {
642 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 if (ar.exception != null) {
645 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
646 }
647
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700648 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700649 if (ar.exception instanceof CommandException) {
650 CommandException.Error error =
651 ((CommandException) (ar.exception)).getCommandError();
652 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700654 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 }
657 }
658 openChannelResp = new IccOpenLogicalChannelResponse(
659 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700660 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700661 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700662 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700663 break;
664
665 case CMD_CLOSE_CHANNEL:
666 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800667 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 if (uiccCard == null) {
669 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900670 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700671 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 } else {
673 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
674 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
675 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700676 break;
677
678 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800679 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
680 break;
681
682 case CMD_NV_READ_ITEM:
683 request = (MainThreadRequest) msg.obj;
684 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800685 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
686 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800687 break;
688
689 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 ar = (AsyncResult) msg.obj;
691 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800692 if (ar.exception == null && ar.result != null) {
693 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800695 request.result = "";
696 if (ar.result == null) {
697 loge("nvReadItem: Empty response");
698 } else if (ar.exception instanceof CommandException) {
699 loge("nvReadItem: CommandException: " +
700 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800702 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 }
704 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700705 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 break;
707
Jake Hambye994d462014-02-03 13:10:13 -0800708 case CMD_NV_WRITE_ITEM:
709 request = (MainThreadRequest) msg.obj;
710 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
711 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800712 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700713 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800714 break;
715
716 case EVENT_NV_WRITE_ITEM_DONE:
717 handleNullReturnEvent(msg, "nvWriteItem");
718 break;
719
720 case CMD_NV_WRITE_CDMA_PRL:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800723 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
726 case EVENT_NV_WRITE_CDMA_PRL_DONE:
727 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
728 break;
729
chen xu6dac5ab2018-10-26 17:39:23 -0700730 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800731 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700732 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case EVENT_RESET_MODEM_CONFIG_DONE:
737 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
Jake Hamby7c27be32014-03-03 13:25:59 -0800740 case CMD_GET_PREFERRED_NETWORK_TYPE:
741 request = (MainThreadRequest) msg.obj;
742 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700743 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800744 break;
745
746 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
747 ar = (AsyncResult) msg.obj;
748 request = (MainThreadRequest) ar.userObj;
749 if (ar.exception == null && ar.result != null) {
750 request.result = ar.result; // Integer
751 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800752 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800753 if (ar.result == null) {
754 loge("getPreferredNetworkType: Empty response");
755 } else if (ar.exception instanceof CommandException) {
756 loge("getPreferredNetworkType: CommandException: " +
757 ar.exception);
758 } else {
759 loge("getPreferredNetworkType: Unknown exception");
760 }
761 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700762 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800763 break;
764
765 case CMD_SET_PREFERRED_NETWORK_TYPE:
766 request = (MainThreadRequest) msg.obj;
767 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
768 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700769 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800770 break;
771
772 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
773 handleNullReturnEvent(msg, "setPreferredNetworkType");
774 break;
775
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000776 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
777 request = (MainThreadRequest)msg.obj;
778 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800779 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000780 break;
781
782 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
783 ar = (AsyncResult)msg.obj;
784 request = (MainThreadRequest)ar.userObj;
785 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700786 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000787 break;
788
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800789 case CMD_SET_VOICEMAIL_NUMBER:
790 request = (MainThreadRequest) msg.obj;
791 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
792 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800793 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
794 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800795 break;
796
797 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
798 handleNullReturnEvent(msg, "setVoicemailNumber");
799 break;
800
Stuart Scott54788802015-03-30 13:18:01 -0700801 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
804 request);
805 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
806 break;
807
808 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
809 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
810 break;
811
Shishir Agrawal302c8692015-06-19 13:49:39 -0700812 case CMD_PERFORM_NETWORK_SCAN:
813 request = (MainThreadRequest) msg.obj;
814 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
815 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
816 break;
817
sqian80370722020-01-29 15:02:51 -0800818 case CMD_GET_CALL_FORWARDING:
819 request = (MainThreadRequest) msg.obj;
820 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
821 int callForwardingReason = (Integer) request.argument;
822 getPhoneFromRequest(request).getCallForwardingOption(
823 callForwardingReason, onCompleted);
824 break;
825
826 case EVENT_GET_CALL_FORWARDING_DONE:
827 ar = (AsyncResult) msg.obj;
828 request = (MainThreadRequest) ar.userObj;
829 CallForwardingInfo callForwardingInfo = null;
830 if (ar.exception == null && ar.result != null) {
831 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
832 for (CallForwardInfo callForwardInfo : callForwardInfos) {
833 // Service Class is a bit mask per 3gpp 27.007. Search for
834 // any service for voice call.
835 if ((callForwardInfo.serviceClass
836 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
837 callForwardingInfo = new CallForwardingInfo(
838 callForwardInfo.serviceClass, callForwardInfo.reason,
839 callForwardInfo.number,
840 callForwardInfo.timeSeconds);
841 break;
842 }
843 }
844 // Didn't find a call forward info for voice call.
845 if (callForwardingInfo == null) {
846 callForwardingInfo = new CallForwardingInfo(
847 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
848 0 /* reason */, null /* number */, 0 /* timeout */);
849 }
850 } else {
851 if (ar.result == null) {
852 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
853 }
854 if (ar.exception != null) {
855 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
856 }
857 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
858 if (ar.exception instanceof CommandException) {
859 CommandException.Error error =
860 ((CommandException) (ar.exception)).getCommandError();
861 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
862 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
863 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
864 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
865 }
866 }
867 callForwardingInfo = new CallForwardingInfo(
868 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
869 }
870 request.result = callForwardingInfo;
871 notifyRequester(request);
872 break;
873
874 case CMD_SET_CALL_FORWARDING:
875 request = (MainThreadRequest) msg.obj;
876 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
877 CallForwardingInfo callForwardingInfoToSet =
878 (CallForwardingInfo) request.argument;
879 getPhoneFromRequest(request).setCallForwardingOption(
880 callForwardingInfoToSet.getStatus(),
881 callForwardingInfoToSet.getReason(),
882 callForwardingInfoToSet.getNumber(),
883 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
884 break;
885
886 case EVENT_SET_CALL_FORWARDING_DONE:
887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null) {
890 request.result = true;
891 } else {
892 request.result = false;
893 loge("setCallForwarding exception: " + ar.exception);
894 }
895 notifyRequester(request);
896 break;
897
898 case CMD_GET_CALL_WAITING:
899 request = (MainThreadRequest) msg.obj;
900 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
901 getPhoneFromRequest(request).getCallWaiting(onCompleted);
902 break;
903
904 case EVENT_GET_CALL_WAITING_DONE:
905 ar = (AsyncResult) msg.obj;
906 request = (MainThreadRequest) ar.userObj;
907 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
908 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800909 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800910 // Service Class is a bit mask per 3gpp 27.007.
911 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800912 if (callForwardResults.length > 1
913 && ((callForwardResults[1]
914 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
915 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800916 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
917 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
918 } else {
919 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
920 }
921 } else {
922 if (ar.result == null) {
923 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
924 }
925 if (ar.exception != null) {
926 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
927 }
928 if (ar.exception instanceof CommandException) {
929 CommandException.Error error =
930 ((CommandException) (ar.exception)).getCommandError();
931 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
932 callForwardingStatus =
933 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
934 }
935 }
936 }
937 request.result = callForwardingStatus;
938 notifyRequester(request);
939 break;
940
941 case CMD_SET_CALL_WAITING:
942 request = (MainThreadRequest) msg.obj;
943 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
944 boolean isEnable = (Boolean) request.argument;
945 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
946 break;
947
948 case EVENT_SET_CALL_WAITING_DONE:
949 ar = (AsyncResult) msg.obj;
950 request = (MainThreadRequest) ar.userObj;
951 if (ar.exception == null) {
952 request.result = true;
953 } else {
954 request.result = false;
955 loge("setCallWaiting exception: " + ar.exception);
956 }
957 notifyRequester(request);
958 break;
959
Shishir Agrawal302c8692015-06-19 13:49:39 -0700960 case EVENT_PERFORM_NETWORK_SCAN_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 CellNetworkScanResult cellScanResult;
964 if (ar.exception == null && ar.result != null) {
965 cellScanResult = new CellNetworkScanResult(
966 CellNetworkScanResult.STATUS_SUCCESS,
967 (List<OperatorInfo>) ar.result);
968 } else {
969 if (ar.result == null) {
970 loge("getCellNetworkScanResults: Empty response");
971 }
972 if (ar.exception != null) {
973 loge("getCellNetworkScanResults: Exception: " + ar.exception);
974 }
975 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
976 if (ar.exception instanceof CommandException) {
977 CommandException.Error error =
978 ((CommandException) (ar.exception)).getCommandError();
979 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
980 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
981 } else if (error == CommandException.Error.GENERIC_FAILURE) {
982 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
983 }
984 }
985 cellScanResult = new CellNetworkScanResult(errorCode, null);
986 }
987 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700988 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700989 break;
990
991 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
992 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700993 ManualNetworkSelectionArgument selArg =
994 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700995 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
996 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700997 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
998 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700999 break;
1000
1001 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001002 ar = (AsyncResult) msg.obj;
1003 request = (MainThreadRequest) ar.userObj;
1004 if (ar.exception == null) {
1005 request.result = true;
1006 } else {
1007 request.result = false;
1008 loge("setNetworkSelectionModeManual " + ar.exception);
1009 }
1010 notifyRequester(request);
1011 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001012 break;
1013
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001014 case CMD_GET_MODEM_ACTIVITY_INFO:
1015 request = (MainThreadRequest) msg.obj;
1016 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001017 if (defaultPhone != null) {
1018 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
1019 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001020 break;
1021
1022 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
1025 if (ar.exception == null && ar.result != null) {
1026 request.result = ar.result;
1027 } else {
1028 if (ar.result == null) {
1029 loge("queryModemActivityInfo: Empty response");
1030 } else if (ar.exception instanceof CommandException) {
1031 loge("queryModemActivityInfo: CommandException: " +
1032 ar.exception);
1033 } else {
1034 loge("queryModemActivityInfo: Unknown exception");
1035 }
1036 }
Amit Mahajand4766222016-01-28 15:28:28 -08001037 // Result cannot be null. Return ModemActivityInfo with all fields set to 0.
1038 if (request.result == null) {
Chen Xu13851032019-09-10 18:49:52 -07001039 request.result = new ModemActivityInfo(0, 0, 0, null, 0);
Amit Mahajand4766222016-01-28 15:28:28 -08001040 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001041 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001042 break;
1043
Meng Wang1a7c35a2016-05-05 20:56:15 -07001044 case CMD_SET_ALLOWED_CARRIERS:
1045 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001046 CarrierRestrictionRules argument =
1047 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001048 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001049 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001050 break;
1051
1052 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1053 ar = (AsyncResult) msg.obj;
1054 request = (MainThreadRequest) ar.userObj;
1055 if (ar.exception == null && ar.result != null) {
1056 request.result = ar.result;
1057 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001058 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1059 if (ar.exception instanceof CommandException) {
1060 loge("setAllowedCarriers: CommandException: " + ar.exception);
1061 CommandException.Error error =
1062 ((CommandException) (ar.exception)).getCommandError();
1063 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1064 request.result =
1065 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1066 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001067 } else {
1068 loge("setAllowedCarriers: Unknown exception");
1069 }
1070 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001071 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001072 break;
1073
1074 case CMD_GET_ALLOWED_CARRIERS:
1075 request = (MainThreadRequest) msg.obj;
1076 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001077 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001078 break;
1079
1080 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1081 ar = (AsyncResult) msg.obj;
1082 request = (MainThreadRequest) ar.userObj;
1083 if (ar.exception == null && ar.result != null) {
1084 request.result = ar.result;
1085 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001086 request.result = new IllegalStateException(
1087 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 if (ar.result == null) {
1089 loge("getAllowedCarriers: Empty response");
1090 } else if (ar.exception instanceof CommandException) {
1091 loge("getAllowedCarriers: CommandException: " +
1092 ar.exception);
1093 } else {
1094 loge("getAllowedCarriers: Unknown exception");
1095 }
1096 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001097 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001098 break;
1099
Nathan Haroldb3014052017-01-25 15:57:32 -08001100 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1101 ar = (AsyncResult) msg.obj;
1102 request = (MainThreadRequest) ar.userObj;
1103 if (ar.exception == null && ar.result != null) {
1104 request.result = ar.result;
1105 } else {
1106 request.result = new IllegalArgumentException(
1107 "Failed to retrieve Forbidden Plmns");
1108 if (ar.result == null) {
1109 loge("getForbiddenPlmns: Empty response");
1110 } else {
1111 loge("getForbiddenPlmns: Unknown exception");
1112 }
1113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001114 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001115 break;
1116
1117 case CMD_GET_FORBIDDEN_PLMNS:
1118 request = (MainThreadRequest) msg.obj;
1119 uiccCard = getUiccCardFromRequest(request);
1120 if (uiccCard == null) {
1121 loge("getForbiddenPlmns() UiccCard is null");
1122 request.result = new IllegalArgumentException(
1123 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001124 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001125 break;
1126 }
1127 Integer appType = (Integer) request.argument;
1128 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1129 if (uiccApp == null) {
1130 loge("getForbiddenPlmns() no app with specified type -- "
1131 + appType);
1132 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001133 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001134 break;
1135 } else {
1136 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1137 + " specified type -- " + appType);
1138 }
1139 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1140 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1141 onCompleted);
1142 break;
1143
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001144 case CMD_SWITCH_SLOTS:
1145 request = (MainThreadRequest) msg.obj;
1146 int[] physicalSlots = (int[]) request.argument;
1147 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1148 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1149 break;
1150
1151 case EVENT_SWITCH_SLOTS_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
1156 break;
1157 case CMD_GET_NETWORK_SELECTION_MODE:
1158 request = (MainThreadRequest) msg.obj;
1159 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1160 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1161 break;
1162
1163 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1164 ar = (AsyncResult) msg.obj;
1165 request = (MainThreadRequest) ar.userObj;
1166 if (ar.exception != null) {
1167 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1168 } else {
1169 int mode = ((int[]) ar.result)[0];
1170 if (mode == 0) {
1171 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1172 } else {
1173 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1174 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001175 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001176 notifyRequester(request);
1177 break;
1178 case CMD_GET_CDMA_ROAMING_MODE:
1179 request = (MainThreadRequest) msg.obj;
1180 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1181 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1182 break;
1183 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1184 ar = (AsyncResult) msg.obj;
1185 request = (MainThreadRequest) ar.userObj;
1186 if (ar.exception != null) {
1187 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1188 } else {
1189 request.result = ((int[]) ar.result)[0];
1190 }
1191 notifyRequester(request);
1192 break;
1193 case CMD_SET_CDMA_ROAMING_MODE:
1194 request = (MainThreadRequest) msg.obj;
1195 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1196 int mode = (int) request.argument;
1197 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1198 break;
1199 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
1202 request.result = ar.exception == null;
1203 notifyRequester(request);
1204 break;
1205 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1208 int subscriptionMode = (int) request.argument;
1209 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1210 break;
1211 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1212 ar = (AsyncResult) msg.obj;
1213 request = (MainThreadRequest) ar.userObj;
1214 request.result = ar.exception == null;
1215 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001216 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001217 case CMD_GET_ALL_CELL_INFO:
1218 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001219 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001220 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001221 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001222 case EVENT_GET_ALL_CELL_INFO_DONE:
1223 ar = (AsyncResult) msg.obj;
1224 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001225 // If a timeout occurs, the response will be null
1226 request.result = (ar.exception == null && ar.result != null)
1227 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001228 synchronized (request) {
1229 request.notifyAll();
1230 }
1231 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001232 case CMD_REQUEST_CELL_INFO_UPDATE:
1233 request = (MainThreadRequest) msg.obj;
1234 request.phone.requestCellInfoUpdate(request.workSource,
1235 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1236 break;
1237 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1238 ar = (AsyncResult) msg.obj;
1239 request = (MainThreadRequest) ar.userObj;
1240 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1241 try {
1242 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001243 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001244 cb.onError(
1245 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1246 ar.exception.getClass().getName(),
1247 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001248 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001249 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001250 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001251 } else {
1252 // use the result as returned
1253 cb.onCellInfo((List<CellInfo>) ar.result);
1254 }
1255 } catch (RemoteException re) {
1256 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1257 }
1258 break;
1259 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 request = (MainThreadRequest) msg.obj;
1261 WorkSource ws = (WorkSource) request.argument;
1262 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001263 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001265 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null) {
1269 request.result = ar.result;
1270 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001271 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001273 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 }
1275
1276 synchronized (request) {
1277 request.notifyAll();
1278 }
1279 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001280 case CMD_MODEM_REBOOT:
1281 request = (MainThreadRequest) msg.obj;
1282 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001283 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001284 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001285 case EVENT_CMD_MODEM_REBOOT_DONE:
1286 handleNullReturnEvent(msg, "rebootModem");
1287 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001288 case CMD_REQUEST_ENABLE_MODEM:
1289 request = (MainThreadRequest) msg.obj;
1290 boolean enable = (boolean) request.argument;
1291 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001292 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001293 PhoneConfigurationManager.getInstance()
1294 .enablePhone(request.phone, enable, onCompleted);
1295 break;
1296 case EVENT_ENABLE_MODEM_DONE:
1297 ar = (AsyncResult) msg.obj;
1298 request = (MainThreadRequest) ar.userObj;
1299 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001300 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001301 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001302 if ((boolean) request.result) {
1303 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1304 updateModemStateMetrics();
1305 } else {
1306 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1307 + ar.exception);
1308 }
1309 notifyRequester(request);
1310 break;
1311 case CMD_GET_MODEM_STATUS:
1312 request = (MainThreadRequest) msg.obj;
1313 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1314 PhoneConfigurationManager.getInstance()
1315 .getPhoneStatusFromModem(request.phone, onCompleted);
1316 break;
1317 case EVENT_GET_MODEM_STATUS_DONE:
1318 ar = (AsyncResult) msg.obj;
1319 request = (MainThreadRequest) ar.userObj;
1320 int id = request.phone.getPhoneId();
1321 if (ar.exception == null && ar.result != null) {
1322 request.result = ar.result;
1323 //update the cache as modem status has changed
1324 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1325 (boolean) request.result);
1326 } else {
1327 // Return true if modem status cannot be retrieved. For most cases,
1328 // modem status is on. And for older version modems, GET_MODEM_STATUS
1329 // and disable modem are not supported. Modem is always on.
1330 // TODO: this should be fixed in R to support a third
1331 // status UNKNOWN b/131631629
1332 request.result = true;
1333 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1334 + ar.exception);
1335 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001336 notifyRequester(request);
1337 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001338 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1339 ar = (AsyncResult) msg.obj;
1340 request = (MainThreadRequest) ar.userObj;
1341 if (ar.exception == null && ar.result != null) {
1342 request.result = ar.result;
1343 } else {
1344 request.result = -1;
1345 loge("Failed to set Forbidden Plmns");
1346 if (ar.result == null) {
1347 loge("setForbidenPlmns: Empty response");
1348 } else if (ar.exception != null) {
1349 loge("setForbiddenPlmns: Exception: " + ar.exception);
1350 request.result = -1;
1351 } else {
1352 loge("setForbiddenPlmns: Unknown exception");
1353 }
1354 }
1355 notifyRequester(request);
1356 break;
1357 case CMD_SET_FORBIDDEN_PLMNS:
1358 request = (MainThreadRequest) msg.obj;
1359 uiccCard = getUiccCardFromRequest(request);
1360 if (uiccCard == null) {
1361 loge("setForbiddenPlmns: UiccCard is null");
1362 request.result = -1;
1363 notifyRequester(request);
1364 break;
1365 }
1366 Pair<Integer, List<String>> setFplmnsArgs =
1367 (Pair<Integer, List<String>>) request.argument;
1368 appType = setFplmnsArgs.first;
1369 List<String> fplmns = setFplmnsArgs.second;
1370 uiccApp = uiccCard.getApplicationByType(appType);
1371 if (uiccApp == null) {
1372 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1373 request.result = -1;
1374 loge("Failed to get UICC App");
1375 notifyRequester(request);
1376 } else {
1377 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1378 ((SIMRecords) uiccApp.getIccRecords())
1379 .setForbiddenPlmns(onCompleted, fplmns);
1380 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001381 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001382 case CMD_ERASE_MODEM_CONFIG:
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1385 defaultPhone.eraseModemConfig(onCompleted);
1386 break;
1387 case EVENT_ERASE_MODEM_CONFIG_DONE:
1388 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001389 break;
zoey chenf95ca592019-12-30 16:11:23 +08001390
1391 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1394 Pair<String, String> changed = (Pair<String, String>) request.argument;
1395 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1396 changed.first, changed.second, onCompleted);
1397 break;
1398 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception == null) {
1402 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1403 } else {
1404 request.result = msg.arg1;
1405 }
1406 notifyRequester(request);
1407 break;
1408
1409 case CMD_SET_ICC_LOCK_ENABLED:
1410 request = (MainThreadRequest) msg.obj;
1411 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1412 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1413 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1414 enabled.first, enabled.second, onCompleted);
1415 break;
1416 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1417 ar = (AsyncResult) msg.obj;
1418 request = (MainThreadRequest) ar.userObj;
1419 if (ar.exception == null) {
1420 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1421 } else {
1422 request.result = msg.arg1;
1423 }
1424 notifyRequester(request);
1425 break;
1426
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001427 default:
1428 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1429 break;
1430 }
1431 }
Jake Hambye994d462014-02-03 13:10:13 -08001432
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 private void notifyRequester(MainThreadRequest request) {
1434 synchronized (request) {
1435 request.notifyAll();
1436 }
1437 }
1438
Jake Hambye994d462014-02-03 13:10:13 -08001439 private void handleNullReturnEvent(Message msg, String command) {
1440 AsyncResult ar = (AsyncResult) msg.obj;
1441 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1442 if (ar.exception == null) {
1443 request.result = true;
1444 } else {
1445 request.result = false;
1446 if (ar.exception instanceof CommandException) {
1447 loge(command + ": CommandException: " + ar.exception);
1448 } else {
1449 loge(command + ": Unknown exception");
1450 }
1451 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001452 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001453 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001454 }
1455
1456 /**
1457 * Posts the specified command to be executed on the main thread,
1458 * waits for the request to complete, and returns the result.
1459 * @see #sendRequestAsync
1460 */
1461 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001462 return sendRequest(
1463 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001464 }
1465
1466 /**
1467 * Posts the specified command to be executed on the main thread,
1468 * waits for the request to complete, and returns the result.
1469 * @see #sendRequestAsync
1470 */
1471 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1472 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001473 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001474 }
1475
1476 /**
1477 * Posts the specified command to be executed on the main thread,
1478 * waits for the request to complete, and returns the result.
1479 * @see #sendRequestAsync
1480 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001481 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001482 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001483 }
1484
1485 /**
1486 * Posts the specified command to be executed on the main thread,
1487 * waits for the request to complete, and returns the result.
1488 * @see #sendRequestAsync
1489 */
Nathan Harold92bed182018-10-12 18:16:49 -07001490 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1491 return sendRequest(command, argument, subId, null, workSource);
1492 }
1493
1494 /**
1495 * Posts the specified command to be executed on the main thread,
1496 * waits for the request to complete, and returns the result.
1497 * @see #sendRequestAsync
1498 */
1499 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1500 return sendRequest(
1501 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1502 }
1503
1504 /**
1505 * Posts the specified command to be executed on the main thread,
1506 * waits for the request to complete, and returns the result.
1507 * @see #sendRequestAsync
1508 */
1509 private Object sendRequest(
1510 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1512 throw new RuntimeException("This method will deadlock if called from the main thread.");
1513 }
1514
Nathan Harold92bed182018-10-12 18:16:49 -07001515 MainThreadRequest request = null;
1516 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1517 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1518 } else if (phone != null) {
1519 request = new MainThreadRequest(argument, phone, workSource);
1520 } else {
1521 request = new MainThreadRequest(argument, subId, workSource);
1522 }
1523
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 Message msg = mMainThreadHandler.obtainMessage(command, request);
1525 msg.sendToTarget();
1526
1527 // Wait for the request to complete
1528 synchronized (request) {
1529 while (request.result == null) {
1530 try {
1531 request.wait();
1532 } catch (InterruptedException e) {
1533 // Do nothing, go back and wait until the request is complete
1534 }
1535 }
1536 }
1537 return request.result;
1538 }
1539
1540 /**
1541 * Asynchronous ("fire and forget") version of sendRequest():
1542 * Posts the specified command to be executed on the main thread, and
1543 * returns immediately.
1544 * @see #sendRequest
1545 */
1546 private void sendRequestAsync(int command) {
1547 mMainThreadHandler.sendEmptyMessage(command);
1548 }
1549
1550 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001551 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001552 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001553 */
1554 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001555 sendRequestAsync(command, argument, null, null);
1556 }
1557
1558 /**
1559 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1560 * @see {@link #sendRequest(int,Object)}
1561 */
1562 private void sendRequestAsync(
1563 int command, Object argument, Phone phone, WorkSource workSource) {
1564 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001565 Message msg = mMainThreadHandler.obtainMessage(command, request);
1566 msg.sendToTarget();
1567 }
1568
1569 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001570 * Initialize the singleton PhoneInterfaceManager instance.
1571 * This is only done once, at startup, from PhoneApp.onCreate().
1572 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001573 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001574 synchronized (PhoneInterfaceManager.class) {
1575 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001576 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001577 } else {
1578 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1579 }
1580 return sInstance;
1581 }
1582 }
1583
1584 /** Private constructor; @see init() */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001585 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001586 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001587 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001588 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001589 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001590 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1591 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001592 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001593 mTelephonySharedPreferences =
1594 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001595 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001596 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001597
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001598 publish();
1599 }
1600
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001601 private Phone getDefaultPhone() {
1602 Phone thePhone = getPhone(getDefaultSubscription());
1603 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1604 }
1605
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001606 private void publish() {
1607 if (DBG) log("publish: " + this);
1608
1609 ServiceManager.addService("phone", this);
1610 }
1611
Stuart Scott584921c2015-01-15 17:10:34 -08001612 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001613 if (request.phone != null) {
1614 return request.phone;
1615 } else {
1616 return getPhoneFromSubId(request.subId);
1617 }
1618 }
1619
1620 private Phone getPhoneFromSubId(int subId) {
1621 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1622 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001623 }
1624
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001625 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1626 Phone phone = getPhoneFromRequest(request);
1627 return phone == null ? null :
1628 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1629 }
1630
Wink Saville36469e72014-06-11 15:17:00 -07001631 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001632 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001633 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001636 private void sendEraseModemConfig(Phone phone) {
1637 if (phone != null) {
1638 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1639 mApp, phone.getSubId(), "eraseModemConfig");
1640 final long identity = Binder.clearCallingIdentity();
1641 try {
1642 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1643 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1644 } finally {
1645 Binder.restoreCallingIdentity(identity);
1646 }
1647 }
1648 }
1649
Peter Wang050bb052020-01-13 23:33:09 -08001650 private boolean isImsAvailableOnDevice() {
1651 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1652 if (pm == null) {
1653 // For some reason package manger is not available.. This will fail internally anyway,
1654 // so do not throw error and allow.
1655 return true;
1656 }
1657 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1658 }
1659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001661 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001662 }
1663
Wink Savilleb564aae2014-10-23 10:18:09 -07001664 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 if (DBG) log("dial: " + number);
1666 // No permission check needed here: This is just a wrapper around the
1667 // ACTION_DIAL intent, which is available to any app since it puts up
1668 // the UI before it does anything.
1669
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001670 final long identity = Binder.clearCallingIdentity();
1671 try {
1672 String url = createTelUrl(number);
1673 if (url == null) {
1674 return;
1675 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001677 // PENDING: should we just silently fail if phone is offhook or ringing?
1678 PhoneConstants.State state = mCM.getState(subId);
1679 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1680 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1681 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1682 mApp.startActivity(intent);
1683 }
1684 } finally {
1685 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001686 }
1687 }
1688
1689 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001690 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001691 }
1692
Wink Savilleb564aae2014-10-23 10:18:09 -07001693 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694 if (DBG) log("call: " + number);
1695
1696 // This is just a wrapper around the ACTION_CALL intent, but we still
1697 // need to do a permission check since we're calling startActivity()
1698 // from the context of the phone app.
1699 enforceCallPermission();
1700
Jordan Liu1617b712019-07-10 15:06:26 -07001701 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001702 != AppOpsManager.MODE_ALLOWED) {
1703 return;
1704 }
1705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001706 final long identity = Binder.clearCallingIdentity();
1707 try {
1708 String url = createTelUrl(number);
1709 if (url == null) {
1710 return;
1711 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001713 boolean isValid = false;
1714 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1715 if (slist != null) {
1716 for (SubscriptionInfo subInfoRecord : slist) {
1717 if (subInfoRecord.getSubscriptionId() == subId) {
1718 isValid = true;
1719 break;
1720 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001721 }
Wink Saville08874612014-08-31 19:19:58 -07001722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001723 if (!isValid) {
1724 return;
1725 }
Wink Saville08874612014-08-31 19:19:58 -07001726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001727 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1728 intent.putExtra(SUBSCRIPTION_KEY, subId);
1729 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1730 mApp.startActivity(intent);
1731 } finally {
1732 Binder.restoreCallingIdentity(identity);
1733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 }
1735
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001737 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001738 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1739 }
1740
Wink Savilleb564aae2014-10-23 10:18:09 -07001741 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001742 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001743 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1744 }
1745
Wink Savilleb564aae2014-10-23 10:18:09 -07001746 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001747 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001748
1749 final long identity = Binder.clearCallingIdentity();
1750 try {
1751 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1752 checkSimPin.start();
1753 return checkSimPin.unlockSim(null, pin);
1754 } finally {
1755 Binder.restoreCallingIdentity(identity);
1756 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001757 }
1758
Wink Savilleb564aae2014-10-23 10:18:09 -07001759 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001761
1762 final long identity = Binder.clearCallingIdentity();
1763 try {
1764 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1765 checkSimPuk.start();
1766 return checkSimPuk.unlockSim(puk, pin);
1767 } finally {
1768 Binder.restoreCallingIdentity(identity);
1769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770 }
1771
1772 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001773 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 * a synchronous one.
1775 */
1776 private static class UnlockSim extends Thread {
1777
1778 private final IccCard mSimCard;
1779
1780 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001781 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1782 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001783
1784 // For replies from SimCard interface
1785 private Handler mHandler;
1786
1787 // For async handler to identify request type
1788 private static final int SUPPLY_PIN_COMPLETE = 100;
1789
1790 public UnlockSim(IccCard simCard) {
1791 mSimCard = simCard;
1792 }
1793
1794 @Override
1795 public void run() {
1796 Looper.prepare();
1797 synchronized (UnlockSim.this) {
1798 mHandler = new Handler() {
1799 @Override
1800 public void handleMessage(Message msg) {
1801 AsyncResult ar = (AsyncResult) msg.obj;
1802 switch (msg.what) {
1803 case SUPPLY_PIN_COMPLETE:
1804 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1805 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001806 mRetryCount = msg.arg1;
1807 if (ar.exception != null) {
1808 if (ar.exception instanceof CommandException &&
1809 ((CommandException)(ar.exception)).getCommandError()
1810 == CommandException.Error.PASSWORD_INCORRECT) {
1811 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1812 } else {
1813 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1814 }
1815 } else {
1816 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1817 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 mDone = true;
1819 UnlockSim.this.notifyAll();
1820 }
1821 break;
1822 }
1823 }
1824 };
1825 UnlockSim.this.notifyAll();
1826 }
1827 Looper.loop();
1828 }
1829
1830 /*
1831 * Use PIN or PUK to unlock SIM card
1832 *
1833 * If PUK is null, unlock SIM card with PIN
1834 *
1835 * If PUK is not null, unlock SIM card with PUK and set PIN code
1836 */
Wink Saville9de0f752013-10-22 19:04:03 -07001837 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001838
1839 while (mHandler == null) {
1840 try {
1841 wait();
1842 } catch (InterruptedException e) {
1843 Thread.currentThread().interrupt();
1844 }
1845 }
1846 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1847
1848 if (puk == null) {
1849 mSimCard.supplyPin(pin, callback);
1850 } else {
1851 mSimCard.supplyPuk(puk, pin, callback);
1852 }
1853
1854 while (!mDone) {
1855 try {
1856 Log.d(LOG_TAG, "wait for done");
1857 wait();
1858 } catch (InterruptedException e) {
1859 // Restore the interrupted status
1860 Thread.currentThread().interrupt();
1861 }
1862 }
1863 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001864 int[] resultArray = new int[2];
1865 resultArray[0] = mResult;
1866 resultArray[1] = mRetryCount;
1867 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001868 }
1869 }
1870
1871 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001872 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001873
1874 }
1875
Wink Savilleb564aae2014-10-23 10:18:09 -07001876 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001877 // No permission check needed here: this call is harmless, and it's
1878 // needed for the ServiceState.requestStateUpdate() call (which is
1879 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001880 final long identity = Binder.clearCallingIdentity();
1881 try {
1882 final Phone phone = getPhone(subId);
1883 if (phone != null) {
1884 phone.updateServiceLocation();
1885 }
1886 } finally {
1887 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001888 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001889 }
1890
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001891 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001892 @Override
1893 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001894 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001895 }
1896
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001897 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001898 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1899 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1900 callingFeatureId);
1901 }
1902
1903 @Deprecated
1904 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001905 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001906 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
1907 }
1908
1909 @Override
1910 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1911 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001912 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001913 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001914 return false;
1915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001916
1917 final long identity = Binder.clearCallingIdentity();
1918 try {
1919 return isRadioOnForSubscriber(subId);
1920 } finally {
1921 Binder.restoreCallingIdentity(identity);
1922 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001923 }
1924
1925 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001926 final long identity = Binder.clearCallingIdentity();
1927 try {
1928 final Phone phone = getPhone(subId);
1929 if (phone != null) {
1930 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
1931 } else {
1932 return false;
1933 }
1934 } finally {
1935 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001936 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001937 }
1938
1939 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001940 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001941 }
Wink Saville36469e72014-06-11 15:17:00 -07001942
Wink Savilleb564aae2014-10-23 10:18:09 -07001943 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001944 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001945
1946 final long identity = Binder.clearCallingIdentity();
1947 try {
1948 final Phone phone = getPhone(subId);
1949 if (phone != null) {
1950 phone.setRadioPower(!isRadioOnForSubscriber(subId));
1951 }
1952 } finally {
1953 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001954 }
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
1957 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001958 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07001959 }
1960
Wink Savilleb564aae2014-10-23 10:18:09 -07001961 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07001962 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001963
1964 final long identity = Binder.clearCallingIdentity();
1965 try {
1966 final Phone phone = getPhone(subId);
1967 if (phone == null) {
1968 return false;
1969 }
1970 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
1971 toggleRadioOnOffForSubscriber(subId);
1972 }
1973 return true;
1974 } finally {
1975 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001976 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001977 }
Wink Saville36469e72014-06-11 15:17:00 -07001978
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001979 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08001980 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001981 /*
1982 * If any of the Radios are available, it will need to be
1983 * shutdown. So return true if any Radio is available.
1984 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001985 final long identity = Binder.clearCallingIdentity();
1986 try {
1987 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
1988 Phone phone = PhoneFactory.getPhone(i);
1989 if (phone != null && phone.isRadioAvailable()) return true;
1990 }
1991 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
1992 return false;
1993 } finally {
1994 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001995 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001996 }
1997
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001998 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07001999 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002000 enforceModifyPermission();
2001
2002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2005 logv("Shutting down Phone " + i);
2006 shutdownRadioUsingPhoneId(i);
2007 }
2008 } finally {
2009 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002010 }
2011 }
2012
2013 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002014 Phone phone = PhoneFactory.getPhone(phoneId);
2015 if (phone != null && phone.isRadioAvailable()) {
2016 phone.shutdownRadio();
2017 }
2018 }
2019
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022
2023 final long identity = Binder.clearCallingIdentity();
2024 try {
2025 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2026 if (defaultPhone != null) {
2027 defaultPhone.setRadioPower(turnOn);
2028 return true;
2029 } else {
2030 loge("There's no default phone.");
2031 return false;
2032 }
2033 } finally {
2034 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002035 }
Wink Saville36469e72014-06-11 15:17:00 -07002036 }
2037
Wink Savilleb564aae2014-10-23 10:18:09 -07002038 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 final Phone phone = getPhone(subId);
2044 if (phone != null) {
2045 phone.setRadioPower(turnOn);
2046 return true;
2047 } else {
2048 return false;
2049 }
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
2054
Wink Saville36469e72014-06-11 15:17:00 -07002055 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 public boolean enableDataConnectivity() {
2058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 int subId = mSubscriptionController.getDefaultDataSubId();
2063 final Phone phone = getPhone(subId);
2064 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002065 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002066 return true;
2067 } else {
2068 return false;
2069 }
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
2074
Wink Saville36469e72014-06-11 15:17:00 -07002075 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002076 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002077 public boolean disableDataConnectivity() {
2078 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079
2080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 int subId = mSubscriptionController.getDefaultDataSubId();
2083 final Phone phone = getPhone(subId);
2084 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002085 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 return true;
2087 } else {
2088 return false;
2089 }
2090 } finally {
2091 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002092 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002093 }
2094
Sanket Padawe356d7632015-06-22 14:03:32 -07002095 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002096 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 final Phone phone = getPhone(subId);
2100 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002101 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102 } else {
2103 return false;
2104 }
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002107 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 }
2109
2110 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002111 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
pkanwarae03a6b2016-11-06 20:37:09 -08002114 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002115 enforceCallPermission();
2116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2120 return;
2121 }
2122 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2123 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2124 } finally {
2125 Binder.restoreCallingIdentity(identity);
2126 }
pkanwar32d516d2016-10-14 19:37:38 -07002127 };
2128
Wink Savilleb564aae2014-10-23 10:18:09 -07002129 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002131
2132 final long identity = Binder.clearCallingIdentity();
2133 try {
2134 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2135 return false;
2136 }
2137 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2138 } finally {
2139 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002140 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002141 }
2142
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002144 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002145 }
2146
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002147 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 Phone phone = PhoneFactory.getPhone(slotIndex);
2151 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2152 PhoneConstantConversions.convertCallState(phone.getState());
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
Sanket Padawe356d7632015-06-22 14:03:32 -07002158 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002159 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002160 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2161 }
2162
2163 @Override
2164 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002165 final long identity = Binder.clearCallingIdentity();
2166 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002167 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 if (phone != null) {
2169 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2170 } else {
2171 return PhoneConstantConversions.convertDataState(
2172 PhoneConstants.DataState.DISCONNECTED);
2173 }
2174 } finally {
2175 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177 }
2178
Sanket Padawe356d7632015-06-22 14:03:32 -07002179 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002180 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002181 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2182 }
2183
2184 @Override
2185 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002186 final long identity = Binder.clearCallingIdentity();
2187 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002188 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189 if (phone != null) {
2190 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2191 } else {
2192 return TelephonyManager.DATA_ACTIVITY_NONE;
2193 }
2194 } finally {
2195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002197 }
2198
2199 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002200 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002201 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002202 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002203
2204 LocationAccessPolicy.LocationPermissionResult locationResult =
2205 LocationAccessPolicy.checkLocationPermission(mApp,
2206 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2207 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002208 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002209 .setCallingPid(Binder.getCallingPid())
2210 .setCallingUid(Binder.getCallingUid())
2211 .setMethod("getCellLocation")
2212 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2213 .build());
2214 switch (locationResult) {
2215 case DENIED_HARD:
2216 throw new SecurityException("Not allowed to access cell location");
2217 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002218 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2219 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002222 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 final long identity = Binder.clearCallingIdentity();
2224 try {
2225 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002226 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002227 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 } finally {
2229 Binder.restoreCallingIdentity(identity);
2230 }
Svetoslav64fad262015-04-14 14:35:21 -07002231 }
2232
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002234 public String getNetworkCountryIsoForPhone(int phoneId, String callingPackage,
2235 String callingFeatureId) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002236 if (!TextUtils.isEmpty(callingPackage)) {
2237 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
2239 callingFeatureId, "getNetworkCountryIsoForPhone")) {
Jack Yu7c5d91a2019-09-26 11:48:33 -07002240 return "";
2241 }
2242 }
2243
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002244 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2245 // registered cell info, so return a NULL country instead.
2246 final long identity = Binder.clearCallingIdentity();
2247 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002248 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2249 // Get default phone in this case.
2250 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2251 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002252 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Jack Yu5f7092c2018-04-13 14:05:37 -07002253 // Todo: fix this when we can get the actual cellular network info when the device
2254 // is on IWLAN.
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002255 if (TelephonyManager.NETWORK_TYPE_IWLAN
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002256 == getVoiceNetworkTypeForSubscriber(subId, mApp.getPackageName(),
2257 null)) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002258 return "";
2259 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 Phone phone = PhoneFactory.getPhone(phoneId);
2261 if (phone != null) {
2262 ServiceStateTracker sst = phone.getServiceStateTracker();
sqianb9d961a2019-07-31 20:23:45 -07002263 EmergencyNumberTracker emergencyNumberTracker = phone.getEmergencyNumberTracker();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 if (sst != null) {
2265 LocaleTracker lt = sst.getLocaleTracker();
2266 if (lt != null) {
sqianb9d961a2019-07-31 20:23:45 -07002267 if (!TextUtils.isEmpty(lt.getCurrentCountry())) {
2268 return lt.getCurrentCountry();
2269 } else if (emergencyNumberTracker != null) {
2270 return emergencyNumberTracker.getEmergencyCountryIso();
2271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272 }
2273 }
2274 }
2275 return "";
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002276 } finally {
2277 Binder.restoreCallingIdentity(identity);
2278 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002279 }
2280
2281 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002283 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002284 }
2285
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002287 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002288 mApp.enforceCallingOrSelfPermission(
2289 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290
2291 final long identity = Binder.clearCallingIdentity();
2292 try {
2293 final Phone phone = getPhone(subId);
2294 if (phone != null) {
2295 phone.enableLocationUpdates();
2296 }
2297 } finally {
2298 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002299 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 }
2301
2302 @Override
2303 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002304 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Sanket Padawe356d7632015-06-22 14:03:32 -07002307 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002308 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 mApp.enforceCallingOrSelfPermission(
2310 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311
2312 final long identity = Binder.clearCallingIdentity();
2313 try {
2314 final Phone phone = getPhone(subId);
2315 if (phone != null) {
2316 phone.disableLocationUpdates();
2317 }
2318 } finally {
2319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002321 }
2322
Nathan Harold31d7ff32018-10-15 20:20:30 -07002323 /**
2324 * Returns the target SDK version number for a given package name.
2325 *
Nathan Haroldec184742019-07-10 17:04:16 -07002326 * This call MUST be invoked before clearing the calling UID.
2327 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002328 * @return target SDK if the package is found or INT_MAX.
2329 */
2330 private int getTargetSdk(String packageName) {
2331 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002332 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002333 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002334 if (ai != null) return ai.targetSdkVersion;
2335 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002336 loge("Failed to get package info for pkg="
2337 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002338 }
2339 return Integer.MAX_VALUE;
2340 }
2341
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 @Override
2343 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002344 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2345 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002346 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002347 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2348 throw new SecurityException(
2349 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2350 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002351
Jordan Liu1617b712019-07-10 15:06:26 -07002352 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002353 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2354 return null;
2355 }
Svetoslav64fad262015-04-14 14:35:21 -07002356
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002357 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002358
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002359 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002360 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361
Nathan Haroldf180aac2018-06-01 18:43:55 -07002362 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2363 for (CellInfo ci : info) {
2364 if (ci instanceof CellInfoGsm) {
2365 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2366 } else if (ci instanceof CellInfoWcdma) {
2367 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2368 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002370 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002371 }
2372
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002373 private List<CellInfo> getCachedCellInfo() {
2374 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2375 for (Phone phone : PhoneFactory.getPhones()) {
2376 List<CellInfo> info = phone.getAllCellInfo();
2377 if (info != null) cellInfos.addAll(info);
2378 }
2379 return cellInfos;
2380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381
2382 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002383 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002384 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002385 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002386
2387 LocationAccessPolicy.LocationPermissionResult locationResult =
2388 LocationAccessPolicy.checkLocationPermission(mApp,
2389 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2390 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002391 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002392 .setCallingPid(Binder.getCallingPid())
2393 .setCallingUid(Binder.getCallingUid())
2394 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002395 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002396 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2397 .build());
2398 switch (locationResult) {
2399 case DENIED_HARD:
2400 throw new SecurityException("Not allowed to access cell info");
2401 case DENIED_SOFT:
2402 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002403 }
2404
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002405 final int targetSdk = getTargetSdk(callingPackage);
2406 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2407 return getCachedCellInfo();
2408 }
2409
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002410 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002411 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2415 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002416 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002417 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002418 if (info != null) cellInfos.addAll(info);
2419 }
2420 return cellInfos;
2421 } finally {
2422 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
2424 }
2425
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002426 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002427 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2428 String callingFeatureId) {
2429 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2430 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 }
2432
2433 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002434 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2435 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002436 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002437 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002438 }
2439
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002440 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2441 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002442 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002443 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002444
2445 LocationAccessPolicy.LocationPermissionResult locationResult =
2446 LocationAccessPolicy.checkLocationPermission(mApp,
2447 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2448 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002450 .setCallingPid(Binder.getCallingPid())
2451 .setCallingUid(Binder.getCallingUid())
2452 .setMethod("requestCellInfoUpdate")
2453 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2454 .build());
2455 switch (locationResult) {
2456 case DENIED_HARD:
2457 throw new SecurityException("Not allowed to access cell info");
2458 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002459 try {
2460 cb.onCellInfo(new ArrayList<CellInfo>());
2461 } catch (RemoteException re) {
2462 // Drop without consequences
2463 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002464 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 }
2466
Nathan Harolda939a962019-05-09 10:13:47 -07002467
2468 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002469 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2470
2471 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2472 }
2473
2474 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002476 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002477 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478
2479 final long identity = Binder.clearCallingIdentity();
2480 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002481 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002482 } finally {
2483 Binder.restoreCallingIdentity(identity);
2484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Shishir Agrawala9f32182016-04-12 12:00:16 -07002487 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002488 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002489 Phone phone = PhoneFactory.getPhone(slotIndex);
2490 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002491 return null;
2492 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002493 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002494 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002495 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002496 return null;
2497 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498
2499 final long identity = Binder.clearCallingIdentity();
2500 try {
2501 return phone.getImei();
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
2504 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002505 }
2506
2507 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002508 public String getTypeAllocationCodeForSlot(int slotIndex) {
2509 Phone phone = PhoneFactory.getPhone(slotIndex);
2510 String tac = null;
2511 if (phone != null) {
2512 String imei = phone.getImei();
2513 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2514 }
2515 return tac;
2516 }
2517
2518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002519 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002520 Phone phone = PhoneFactory.getPhone(slotIndex);
2521 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002522 return null;
2523 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002524
Jeff Davidson913390f2018-02-23 17:11:49 -08002525 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002526 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002527 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002528 return null;
2529 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 return phone.getMeid();
2534 } finally {
2535 Binder.restoreCallingIdentity(identity);
2536 }
Jack Yu2af8d712017-03-15 17:14:14 -07002537 }
2538
2539 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002540 public String getManufacturerCodeForSlot(int slotIndex) {
2541 Phone phone = PhoneFactory.getPhone(slotIndex);
2542 String manufacturerCode = null;
2543 if (phone != null) {
2544 String meid = phone.getMeid();
2545 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2546 }
2547 return manufacturerCode;
2548 }
2549
2550 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002551 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2552 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 Phone phone = PhoneFactory.getPhone(slotIndex);
2554 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002555 return null;
2556 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002557 int subId = phone.getSubId();
2558 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002559 mApp, subId, callingPackage, callingFeatureId,
2560 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002561 return null;
2562 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563
2564 final long identity = Binder.clearCallingIdentity();
2565 try {
2566 return phone.getDeviceSvn();
2567 } finally {
2568 Binder.restoreCallingIdentity(identity);
2569 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 }
2571
fionaxu43304da2017-11-27 22:51:16 -08002572 @Override
2573 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 final Phone phone = getPhone(subId);
2577 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2578 } finally {
2579 Binder.restoreCallingIdentity(identity);
2580 }
fionaxu43304da2017-11-27 22:51:16 -08002581 }
2582
2583 @Override
2584 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002585 final long identity = Binder.clearCallingIdentity();
2586 try {
2587 final Phone phone = getPhone(subId);
2588 return phone == null ? null : phone.getCarrierName();
2589 } finally {
2590 Binder.restoreCallingIdentity(identity);
2591 }
fionaxu43304da2017-11-27 22:51:16 -08002592 }
2593
calvinpanffe225e2018-11-01 19:43:06 +08002594 @Override
chen xu0026ca62019-03-06 15:28:50 -08002595 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002596 final long identity = Binder.clearCallingIdentity();
2597 try {
2598 final Phone phone = getPhone(subId);
2599 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002600 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
2604 }
2605
2606 @Override
chen xu0026ca62019-03-06 15:28:50 -08002607 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002611 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002612 } finally {
2613 Binder.restoreCallingIdentity(identity);
2614 }
2615 }
2616
chen xu651eec72018-11-11 19:03:44 -08002617 @Override
chen xu864e11c2018-12-06 22:10:03 -08002618 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2619 if (!isSubscriptionMccMnc) {
2620 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2621 }
chen xu651eec72018-11-11 19:03:44 -08002622 final Phone phone = PhoneFactory.getPhone(slotIndex);
2623 if (phone == null) {
2624 return TelephonyManager.UNKNOWN_CARRIER_ID;
2625 }
2626 final long identity = Binder.clearCallingIdentity();
2627 try {
2628 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2629 } finally {
2630 Binder.restoreCallingIdentity(identity);
2631 }
2632 }
2633
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 //
2635 // Internal helper methods.
2636 //
2637
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002638 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002639 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2640 *
2641 * @throws SecurityException if the caller does not have the required permission
2642 */
2643 private void enforceModifyPermission() {
2644 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2645 }
2646
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002647 /**
2648 * Make sure the caller is system.
2649 *
2650 * @throws SecurityException if the caller is not system.
2651 */
2652 private void enforceSystemCaller() {
2653 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2654 throw new SecurityException("Caller must be system");
2655 }
2656 }
2657
Shuo Qianf2b2df42019-11-13 17:43:31 -08002658 private void enforceActiveEmergencySessionPermission() {
2659 mApp.enforceCallingOrSelfPermission(
2660 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2661 }
2662
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002663 /**
2664 * Make sure the caller has the CALL_PHONE permission.
2665 *
2666 * @throws SecurityException if the caller does not have the required permission
2667 */
2668 private void enforceCallPermission() {
2669 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2670 }
2671
paulhu423b5f22019-08-23 19:17:33 +08002672 private void enforceSettingsPermission() {
2673 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002674 }
2675
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002676 private String createTelUrl(String number) {
2677 if (TextUtils.isEmpty(number)) {
2678 return null;
2679 }
2680
Jake Hambye994d462014-02-03 13:10:13 -08002681 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Ihab Awadf9e92732013-12-05 18:02:52 -08002684 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002685 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2686 }
2687
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002688 private static void logv(String msg) {
2689 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2690 }
2691
Ihab Awadf9e92732013-12-05 18:02:52 -08002692 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2694 }
2695
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002696 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002698 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Sanket Padawe356d7632015-06-22 14:03:32 -07002701 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002702 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002703 final long identity = Binder.clearCallingIdentity();
2704 try {
2705 final Phone phone = PhoneFactory.getPhone(slotIndex);
2706 if (phone == null) {
2707 return PhoneConstants.PHONE_TYPE_NONE;
2708 } else {
2709 return phone.getPhoneType();
2710 }
2711 } finally {
2712 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002713 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002714 }
2715
2716 /**
2717 * Returns the CDMA ERI icon index to display
2718 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002719 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002720 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2721 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2722 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002723 }
2724
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002726 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2727 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002729 mApp, subId, callingPackage, callingFeatureId,
2730 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002731 return -1;
2732 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002733
2734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 final Phone phone = getPhone(subId);
2737 if (phone != null) {
2738 return phone.getCdmaEriIconIndex();
2739 } else {
2740 return -1;
2741 }
2742 } finally {
2743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
2747 /**
2748 * Returns the CDMA ERI icon mode,
2749 * 0 - ON
2750 * 1 - FLASHING
2751 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002752 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002753 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2754 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2755 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002759 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2760 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002761 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002762 mApp, subId, callingPackage, callingFeatureId,
2763 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002764 return -1;
2765 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766
2767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 final Phone phone = getPhone(subId);
2770 if (phone != null) {
2771 return phone.getCdmaEriIconMode();
2772 } else {
2773 return -1;
2774 }
2775 } finally {
2776 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002777 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
2780 /**
2781 * Returns the CDMA ERI text,
2782 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002783 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002784 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2785 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2786 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002787 }
2788
Sanket Padawe356d7632015-06-22 14:03:32 -07002789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002790 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002793 mApp, subId, callingPackage, callingFeatureId,
2794 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002795 return null;
2796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002797
2798 final long identity = Binder.clearCallingIdentity();
2799 try {
2800 final Phone phone = getPhone(subId);
2801 if (phone != null) {
2802 return phone.getCdmaEriText();
2803 } else {
2804 return null;
2805 }
2806 } finally {
2807 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002809 }
2810
2811 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002812 * Returns the CDMA MDN.
2813 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002814 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002815 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2817 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002818
2819 final long identity = Binder.clearCallingIdentity();
2820 try {
2821 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002822 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823 return phone.getLine1Number();
2824 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002825 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002826 return null;
2827 }
2828 } finally {
2829 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002830 }
2831 }
2832
2833 /**
2834 * Returns the CDMA MIN.
2835 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002836 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002837 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002838 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2839 mApp, subId, "getCdmaMin");
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 && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2845 return phone.getCdmaMin();
2846 } else {
2847 return null;
2848 }
2849 } finally {
2850 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002851 }
2852 }
2853
Hall Liud892bec2018-11-30 14:51:45 -08002854 @Override
2855 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2856 INumberVerificationCallback callback, String callingPackage) {
2857 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2858 != PERMISSION_GRANTED) {
2859 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2860 }
2861 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2862
2863 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2864 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2865 throw new SecurityException("Calling package must be configured in the device config");
2866 }
2867
2868 if (range == null) {
2869 throw new NullPointerException("Range must be non-null");
2870 }
2871
2872 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002873 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002874
2875 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2876 }
2877
Junda Liuca05d5d2014-08-14 22:36:34 -07002878 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002879 * Returns true if CDMA provisioning needs to run.
2880 */
2881 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882 final long identity = Binder.clearCallingIdentity();
2883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002884 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885 } finally {
2886 Binder.restoreCallingIdentity(identity);
2887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002888 }
2889
2890 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002891 * Sets the voice mail number of a given subId.
2892 */
2893 @Override
2894 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002895 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2896 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2901 new Pair<String, String>(alphaTag, number), new Integer(subId));
2902 return success;
2903 } finally {
2904 Binder.restoreCallingIdentity(identity);
2905 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002906 }
2907
Ta-wei Yen87c49842016-05-13 21:19:52 -07002908 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002909 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2910 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002911 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2912 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002913 if (!TextUtils.equals(callingPackage, systemDialer)) {
2914 throw new SecurityException("caller must be system dialer");
2915 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002916
2917 final long identity = Binder.clearCallingIdentity();
2918 try {
2919 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2920 if (phoneAccountHandle == null) {
2921 return null;
2922 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002923 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002924 } finally {
2925 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002926 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002927 }
2928
2929 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002930 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2931 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002933 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002934 mApp, subId, callingPackage, callingFeatureId,
2935 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002936 return null;
2937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002938
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08002945 }
2946
2947 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002948 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
2949 VisualVoicemailSmsFilterSettings settings) {
2950 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951
2952 final long identity = Binder.clearCallingIdentity();
2953 try {
2954 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002955 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002956 } finally {
2957 Binder.restoreCallingIdentity(identity);
2958 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002959 }
2960
2961 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002962 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
2963 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002968 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002972 }
2973
2974 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07002975 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
2976 String callingPackage, int subId) {
2977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002982 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983 } finally {
2984 Binder.restoreCallingIdentity(identity);
2985 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07002986 }
2987
2988 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002989 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07002990 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002995 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08002999 }
3000
3001 @Override
3002 public void sendVisualVoicemailSmsForSubscriber(String callingPackage, int subId,
3003 String number, int port, String text, PendingIntent sentIntent) {
3004 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003005 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003006 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003007 SmsController smsController = PhoneFactory.getSmsController();
3008 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, subId, number, port, text,
3009 sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003010 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003011
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003012 /**
fionaxu0152e512016-11-14 13:36:14 -08003013 * Sets the voice activation state of a given subId.
3014 */
3015 @Override
3016 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3018 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
3020 final long identity = Binder.clearCallingIdentity();
3021 try {
3022 final Phone phone = getPhone(subId);
3023 if (phone != null) {
3024 phone.setVoiceActivationState(activationState);
3025 } else {
3026 loge("setVoiceActivationState fails with invalid subId: " + subId);
3027 }
3028 } finally {
3029 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003030 }
3031 }
3032
3033 /**
3034 * Sets the data activation state of a given subId.
3035 */
3036 @Override
3037 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3039 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040
3041 final long identity = Binder.clearCallingIdentity();
3042 try {
3043 final Phone phone = getPhone(subId);
3044 if (phone != null) {
3045 phone.setDataActivationState(activationState);
3046 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003047 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048 }
3049 } finally {
3050 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003051 }
3052 }
3053
3054 /**
3055 * Returns the voice activation state of a given subId.
3056 */
3057 @Override
3058 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
fionaxu0152e512016-11-14 13:36:14 -08003061 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 if (phone != null) {
3065 return phone.getVoiceActivationState();
3066 } else {
3067 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3068 }
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003071 }
3072 }
3073
3074 /**
3075 * Returns the data activation state of a given subId.
3076 */
3077 @Override
3078 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003079 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003080
fionaxu0152e512016-11-14 13:36:14 -08003081 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 if (phone != null) {
3085 return phone.getDataActivationState();
3086 } else {
3087 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3088 }
3089 } finally {
3090 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003091 }
3092 }
3093
3094 /**
Wink Saville36469e72014-06-11 15:17:00 -07003095 * Returns the unread count of voicemails for a subId
3096 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003097 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003098 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3099 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003100 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003101 mApp, subId, callingPackage, callingFeatureId,
3102 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003103 return 0;
3104 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 if (phone != null) {
3109 return phone.getVoiceMessageCount();
3110 } else {
3111 return 0;
3112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003115 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003116 }
3117
3118 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003119 * returns true, if the device is in a state where both voice and data
3120 * are supported simultaneously. This can change based on location or network condition.
3121 */
3122 @Override
3123 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124 final long identity = Binder.clearCallingIdentity();
3125 try {
3126 final Phone phone = getPhone(subId);
3127 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3128 } finally {
3129 Binder.restoreCallingIdentity(identity);
3130 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003131 }
3132
3133 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003134 * Send the dialer code if called from the current default dialer or the caller has
3135 * carrier privilege.
3136 * @param inputCode The dialer code to send
3137 */
3138 @Override
3139 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003140 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003141 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003142 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3143 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003144 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003145 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003146 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
3149 final long identity = Binder.clearCallingIdentity();
3150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003151 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 } finally {
3153 Binder.restoreCallingIdentity(identity);
3154 }
fionaxu235cc5e2017-03-06 22:25:57 -08003155 }
3156
Pengquan Menga1bb6272018-09-06 09:59:22 -07003157 @Override
3158 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003159 TelephonyPermissions
3160 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3161 mApp, subId, "getNetworkSelectionMode");
3162 final long identity = Binder.clearCallingIdentity();
3163 try {
3164 if (!isActiveSubscription(subId)) {
3165 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3166 }
3167 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3168 } finally {
3169 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003170 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003171 }
3172
Brad Ebinger35c841c2018-10-01 10:40:55 -07003173 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003174 public boolean isInEmergencySmsMode() {
3175 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3176 final long identity = Binder.clearCallingIdentity();
3177 try {
3178 for (Phone phone : PhoneFactory.getPhones()) {
3179 if (phone.isInEmergencySmsMode()) {
3180 return true;
3181 }
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
3185 }
3186 return false;
3187 }
3188
shilu366312e2019-12-17 09:28:10 -08003189 /**
3190 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3191 * @param subId The subscription to use to check the configuration.
3192 * @param c The callback that will be used to send the result.
3193 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003194 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003195 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3196 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003197 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3198 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003199
Brad Ebinger77b832e2019-10-17 17:03:22 -07003200 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3201 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3202 "IMS not available on device.");
3203 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003204 final long token = Binder.clearCallingIdentity();
3205 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003206 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003207 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003208 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003209 } catch (ImsException e) {
3210 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003211 } finally {
3212 Binder.restoreCallingIdentity(token);
3213 }
3214 }
3215
shilu366312e2019-12-17 09:28:10 -08003216 /**
3217 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3218 * @param subId The subscription to use to check the configuration.
3219 * @param c The callback that will be used to send the result.
3220 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003221 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003222 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003223 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3224 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003225 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3226 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3227 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003228 final long token = Binder.clearCallingIdentity();
3229 try {
3230 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3231 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3232 .removeRegistrationCallbackForSubscription(c, subId);
3233 } catch (ImsException e) {
3234 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3235 + "is inactive, ignoring unregister.");
3236 // If the subscription is no longer active, just return, since the callback
3237 // will already have been removed internally.
3238 } finally {
3239 Binder.restoreCallingIdentity(token);
3240 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 }
3242
Brad Ebinger774ba362019-10-22 17:36:18 -07003243 /**
3244 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3245 */
3246 @Override
3247 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3248 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3249 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3250 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3251 "IMS not available on device.");
3252 }
3253 final long token = Binder.clearCallingIdentity();
3254 try {
3255 Phone phone = getPhone(subId);
3256 if (phone == null) {
3257 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3258 + subId + "'");
3259 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3260 }
3261 phone.getImsRegistrationState(regState -> {
3262 try {
3263 consumer.accept((regState == null)
3264 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3265 } catch (RemoteException e) {
3266 // Ignore if the remote process is no longer available to call back.
3267 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3268 }
3269 });
3270 } finally {
3271 Binder.restoreCallingIdentity(token);
3272 }
3273 }
3274
3275 /**
3276 * Get the transport type for the IMS service registration state.
3277 */
3278 @Override
3279 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003280 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3281 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003282 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3284 "IMS not available on device.");
3285 }
3286 final long token = Binder.clearCallingIdentity();
3287 try {
3288 Phone phone = getPhone(subId);
3289 if (phone == null) {
3290 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3291 + subId + "'");
3292 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3293 }
3294 phone.getImsRegistrationTech(regTech -> {
3295 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3296 int regTechConverted = (regTech == null)
3297 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3298 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3299 regTechConverted);
3300 try {
3301 consumer.accept(regTechConverted);
3302 } catch (RemoteException e) {
3303 // Ignore if the remote process is no longer available to call back.
3304 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3305 }
3306 });
3307 } finally {
3308 Binder.restoreCallingIdentity(token);
3309 }
3310 }
3311
shilu366312e2019-12-17 09:28:10 -08003312 /**
3313 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3314 * @param subId The subscription to use to check the configuration.
3315 * @param c The callback that will be used to send the result.
3316 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003317 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003318 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3319 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003320 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3321 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003322 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3323 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3324 "IMS not available on device.");
3325 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003326 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3327 final long token = Binder.clearCallingIdentity();
3328 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003330 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003331 } catch (ImsException e) {
3332 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003333 } finally {
3334 Binder.restoreCallingIdentity(token);
3335 }
3336 }
3337
shilu366312e2019-12-17 09:28:10 -08003338 /**
3339 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3340 * @param subId The subscription to use to check the configuration.
3341 * @param c The callback that will be used to send the result.
3342 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003343 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003344 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003345 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3346 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003347 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3348 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3349 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003350
3351 final long token = Binder.clearCallingIdentity();
3352 try {
3353 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3354 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003355 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003356 } catch (ImsException e) {
3357 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3358 + "is inactive, ignoring unregister.");
3359 // If the subscription is no longer active, just return, since the callback
3360 // will already have been removed internally.
3361 } finally {
3362 Binder.restoreCallingIdentity(token);
3363 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003364 }
3365
3366 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003367 public boolean isCapable(int subId, int capability, int regTech) {
3368 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003369 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3370 final long token = Binder.clearCallingIdentity();
3371 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003372 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003373 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003374 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3376 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003377 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003378 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3379 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003380 } finally {
3381 Binder.restoreCallingIdentity(token);
3382 }
3383 }
3384
3385 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003386 public boolean isAvailable(int subId, int capability, int regTech) {
3387 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 final long token = Binder.clearCallingIdentity();
3389 try {
3390 Phone phone = getPhone(subId);
3391 if (phone == null) return false;
3392 return phone.isImsCapabilityAvailable(capability, regTech);
3393 } finally {
3394 Binder.restoreCallingIdentity(token);
3395 }
3396 }
3397
Brad Ebinger77b832e2019-10-17 17:03:22 -07003398 /**
3399 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3400 * subscription.
3401 * @param subId The subscription to use to check the configuration.
3402 * @param callback The callback that will be used to send the result.
3403 * @param capability The MmTelFeature capability that will be used to send the result.
3404 * @param transportType The transport type of the MmTelFeature capability.
3405 */
3406 @Override
3407 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3408 int transportType) {
3409 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3410 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3411 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3412 "IMS not available on device.");
3413 }
3414 final long token = Binder.clearCallingIdentity();
3415 try {
3416 int slotId = getSlotIndex(subId);
3417 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3418 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3419 + subId + "'");
3420 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3421 }
3422 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3423 transportType, aBoolean -> {
3424 try {
3425 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3426 } catch (RemoteException e) {
3427 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3428 + "running. Ignore");
3429 }
3430 });
3431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
3434 }
3435
shilu366312e2019-12-17 09:28:10 -08003436 /**
3437 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3438 * @param subId The subscription to use to check the configuration.
3439 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 @Override
3441 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003442 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3443 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003444
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3446 final long token = Binder.clearCallingIdentity();
3447 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003448 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003449 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003450 } catch (ImsException e) {
3451 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 } finally {
3453 Binder.restoreCallingIdentity(token);
3454 }
3455 }
3456
3457 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003458 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003460 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003465 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003466 } catch (ImsException e) {
3467 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003468 } finally {
3469 Binder.restoreCallingIdentity(identity);
3470 }
3471 }
3472
shilu366312e2019-12-17 09:28:10 -08003473 /**
3474 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3475 * @param subId The subscription to use to check the configuration.
3476 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003477 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003478 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003479 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3480 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003481 final long identity = Binder.clearCallingIdentity();
3482 try {
3483 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003484 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3485 } catch (ImsException e) {
3486 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003487 } finally {
3488 Binder.restoreCallingIdentity(identity);
3489 }
3490 }
3491
3492 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003493 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003495 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003496 final long identity = Binder.clearCallingIdentity();
3497 try {
3498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003499 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003500 } catch (ImsException e) {
3501 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003502 } finally {
3503 Binder.restoreCallingIdentity(identity);
3504 }
3505 }
3506
shilu366312e2019-12-17 09:28:10 -08003507 /**
3508 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3509 * @param subId The subscription to use to check the configuration.
3510 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 @Override
3512 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003513 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3514 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003515 final long identity = Binder.clearCallingIdentity();
3516 try {
3517 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003520 } catch (ImsException e) {
3521 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 } finally {
3523 Binder.restoreCallingIdentity(identity);
3524 }
3525 }
3526
3527 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003528 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003530 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003534 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 } catch (ImsException e) {
3536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
3540 }
3541
shilu366312e2019-12-17 09:28:10 -08003542 /**
3543 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3544 * @param subId The subscription to use to check the configuration.
3545 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 @Override
3547 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003548 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3549 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003553 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003555 } catch (ImsException e) {
3556 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 } finally {
3558 Binder.restoreCallingIdentity(identity);
3559 }
3560 }
3561
3562 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003563 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003565 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003569 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 } catch (ImsException e) {
3572 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
3578 @Override
3579 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3580 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3581 "setVoWiFiNonPersistent");
3582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003586 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
shilu366312e2019-12-17 09:28:10 -08003594 /**
3595 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3596 * @param subId The subscription to use to check the configuration.
3597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 @Override
3599 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003600 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3601 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 } catch (ImsException e) {
3608 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
3612 }
3613
3614 @Override
3615 public void setVoWiFiModeSetting(int subId, int mode) {
3616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3617 "setVoWiFiModeSetting");
3618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003623 } catch (ImsException e) {
3624 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 } finally {
3626 Binder.restoreCallingIdentity(identity);
3627 }
3628 }
3629
3630 @Override
3631 public int getVoWiFiRoamingModeSetting(int subId) {
3632 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003638 } catch (ImsException e) {
3639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
3645 @Override
3646 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3648 "setVoWiFiRoamingModeSetting");
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003654 } catch (ImsException e) {
3655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
3659 }
3660
3661 @Override
3662 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3664 "setRttCapabilityEnabled");
3665 final long identity = Binder.clearCallingIdentity();
3666 try {
3667 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003668 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3669 } catch (ImsException e) {
3670 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 } finally {
3672 Binder.restoreCallingIdentity(identity);
3673 }
3674 }
3675
shilu366312e2019-12-17 09:28:10 -08003676 /**
3677 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3678 * @param subId The subscription to use to check the configuration.
3679 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 @Override
3681 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003682 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3683 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 final long identity = Binder.clearCallingIdentity();
3685 try {
3686 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003687 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003689 } catch (ImsException e) {
3690 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 } finally {
3692 Binder.restoreCallingIdentity(identity);
3693 }
3694 }
3695
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003696 @Override
3697 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3698 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3699 final long identity = Binder.clearCallingIdentity();
3700 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003701 if (!isImsAvailableOnDevice()) {
3702 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3703 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003704 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003707 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3717 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3718 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3720 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3721 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003722 try {
3723 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003724 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003725 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003726 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003727 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3728 + "is inactive, ignoring unregister.");
3729 // If the subscription is no longer active, just return, since the callback will already
3730 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003731 } finally {
3732 Binder.restoreCallingIdentity(identity);
3733 }
3734 }
3735
allenwtsu99c623b2020-01-03 18:24:23 +08003736
3737 private void checkModifyPhoneStatePermission(int subId, String message) {
3738 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3739 message);
3740 }
3741
3742 private boolean isImsProvisioningRequired(int subId, int capability,
3743 boolean isMmtelCapability) {
3744 Phone phone = getPhone(subId);
3745 if (phone == null) {
3746 loge("phone instance null for subid " + subId);
3747 return false;
3748 }
3749 if (isMmtelCapability) {
3750 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3751 return false;
3752 }
3753 } else {
3754 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3755 return false;
3756 }
3757 }
3758 return true;
3759 }
3760
3761 @Override
3762 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3763 boolean isProvisioned) {
3764 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3765
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
3768 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3769 if (!isImsProvisioningRequired(subId, capability, false)) {
3770 return;
3771 }
3772
3773 // this capability requires provisioning, route to the correct API.
3774 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3775 switch (capability) {
3776 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3777 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3778 ims.setEabProvisioned(isProvisioned);
3779 break;
3780 default: {
3781 throw new IllegalArgumentException("Tried to set provisioning for "
3782 + "rcs capability '" + capability + "', which does not require "
3783 + "provisioning.");
3784 }
3785 }
3786 } finally {
3787 Binder.restoreCallingIdentity(identity);
3788 }
3789
3790 }
3791
3792
3793 @Override
3794 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3795 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3796 final long identity = Binder.clearCallingIdentity();
3797 try {
3798 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3799 if (!isImsProvisioningRequired(subId, capability, false)) {
3800 return true;
3801 }
3802
3803 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3804 switch (capability) {
3805 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3806 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3807 return ims.isEabProvisionedOnDevice();
3808
3809 default: {
3810 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3811 + "capability '" + capability + "', which does not require "
3812 + "provisioning.");
3813 }
3814 }
3815
3816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
3819 }
3820
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003821 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003822 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3823 boolean isProvisioned) {
3824 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3825 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3826 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3827 }
allenwtsu99c623b2020-01-03 18:24:23 +08003828 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003829 final long identity = Binder.clearCallingIdentity();
3830 try {
3831 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003832 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003833 return;
3834 }
3835
3836 // this capability requires provisioning, route to the correct API.
3837 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3838 switch (capability) {
3839 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3840 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3841 ims.setVolteProvisioned(isProvisioned);
3842 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3843 ims.setWfcProvisioned(isProvisioned);
3844 }
3845 break;
3846 }
3847 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3848 // There is currently no difference in VT provisioning type.
3849 ims.setVtProvisioned(isProvisioned);
3850 break;
3851 }
3852 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3853 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3854 // change the capability of the feature instead if needed.
3855 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3856 == isProvisioned) {
3857 // No change in provisioning.
3858 return;
3859 }
3860 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3861 try {
3862 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003863 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003864 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3865 + ", Exception" + e.getMessage());
3866 }
3867 break;
3868 }
3869 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003870 throw new IllegalArgumentException("Tried to set provisioning for "
3871 + "MmTel capability '" + capability + "', which does not require "
3872 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003873 }
3874 }
3875
3876 } finally {
3877 Binder.restoreCallingIdentity(identity);
3878 }
3879 }
3880
3881 @Override
3882 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3883 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3884 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3885 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3886 }
3887 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3888 final long identity = Binder.clearCallingIdentity();
3889 try {
3890 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003891 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003892 return true;
3893 }
3894
3895 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3896 switch (capability) {
3897 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3898 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3899 return ims.isVolteProvisionedOnDevice();
3900 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3901 return ims.isWfcProvisionedOnDevice();
3902 }
3903 // This should never happen, since we are checking tech above to make sure it
3904 // is either LTE or IWLAN.
3905 throw new IllegalArgumentException("Invalid radio technology for voice "
3906 + "capability.");
3907 }
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3909 // There is currently no difference in VT provisioning type.
3910 return ims.isVtProvisionedOnDevice();
3911 }
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3913 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3914 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3915 }
3916 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003917 throw new IllegalArgumentException(
3918 "Tried to get provisioning for MmTel capability '" + capability
3919 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 }
3921 }
3922
3923 } finally {
3924 Binder.restoreCallingIdentity(identity);
3925 }
3926 }
3927
3928 @Override
3929 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3930 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3931 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3932 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3933 }
3934 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3935 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3936 return (provisionedBits & capability) > 0;
3937 }
3938
3939 @Override
3940 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
3941 boolean isProvisioned) {
3942 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3943 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3944 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3945 }
3946 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3947 "setProvisioningStatusForCapability");
3948 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3949 // If the current provisioning status for capability already matches isProvisioned,
3950 // do nothing.
3951 if (((provisionedBits & capability) > 0) == isProvisioned) {
3952 return;
3953 }
3954 if (isProvisioned) {
3955 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
3956 } else {
3957 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
3958 }
3959 }
3960
3961 /**
3962 * @return the bitfield containing the MmTel provisioning for the provided subscription and
3963 * technology. The bitfield should mirror the bitfield defined by
3964 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
3965 */
3966 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
3967 String key = getMmTelProvisioningKey(subId, tech);
3968 // Default is no capabilities are provisioned.
3969 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
3970 }
3971
3972 /**
3973 * Sets the MmTel capability provisioning bitfield (defined by
3974 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
3975 * technology specified.
3976 *
3977 * Note: This is a synchronous command and should not be called on UI thread.
3978 */
3979 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
3980 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
3981 String key = getMmTelProvisioningKey(subId, tech);
3982 editor.putInt(key, newField);
3983 editor.commit();
3984 }
3985
3986 private static String getMmTelProvisioningKey(int subId, int tech) {
3987 // resulting key is provision_ims_mmtel_{subId}_{tech}
3988 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
3989 }
3990
3991 /**
3992 * Query CarrierConfig to see if the specified capability requires provisioning for the
3993 * carrier associated with the subscription id.
3994 */
3995 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
3996 int capability) {
3997 CarrierConfigManager configManager = new CarrierConfigManager(context);
3998 PersistableBundle c = configManager.getConfigForSubId(subId);
3999 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004000 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004001 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4002 false);
4003 boolean requireVoiceVtProvisioning = c.getBoolean(
4004 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4005
4006 // First check to make sure that the capability requires provisioning.
4007 switch (capability) {
4008 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4009 // intentional fallthrough
4010 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4011 if (requireVoiceVtProvisioning) {
4012 // Voice and Video requires provisioning
4013 return true;
4014 }
4015 break;
4016 }
4017 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4018 if (requireUtProvisioning) {
4019 // UT requires provisioning
4020 return true;
4021 }
4022 break;
4023 }
4024 }
4025 return false;
4026 }
4027
allenwtsu99c623b2020-01-03 18:24:23 +08004028 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4029 int capability) {
4030 CarrierConfigManager configManager = new CarrierConfigManager(context);
4031 PersistableBundle c = configManager.getConfigForSubId(subId);
4032
4033 boolean requireRcsProvisioning = c.getBoolean(
4034 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4035
4036 // First check to make sure that the capability requires provisioning.
4037 switch (capability) {
4038 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4039 // intentional fallthrough
4040 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4041 if (requireRcsProvisioning) {
4042 // OPTION or PRESENCE requires provisioning
4043 return true;
4044 }
4045 break;
4046 }
4047 }
4048 return false;
4049 }
4050
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004051 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004052 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004053 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4054 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4055 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004056 enforceReadPrivilegedPermission("getImsProvisioningInt");
4057 final long identity = Binder.clearCallingIdentity();
4058 try {
4059 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004060 int slotId = getSlotIndex(subId);
4061 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4062 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4063 + subId + "' for key:" + key);
4064 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4065 }
4066 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004067 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4069 + subId + "' for key:" + key);
4070 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
4076 @Override
4077 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004078 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4079 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4080 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004081 enforceReadPrivilegedPermission("getImsProvisioningString");
4082 final long identity = Binder.clearCallingIdentity();
4083 try {
4084 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004085 int slotId = getSlotIndex(subId);
4086 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4087 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4088 + subId + "' for key:" + key);
4089 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4090 }
4091 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004092 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004093 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4094 + subId + "' for key:" + key);
4095 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004096 } finally {
4097 Binder.restoreCallingIdentity(identity);
4098 }
4099 }
4100
4101 @Override
4102 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004103 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4104 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4105 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4107 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004108 final long identity = Binder.clearCallingIdentity();
4109 try {
4110 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004111 int slotId = getSlotIndex(subId);
4112 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4113 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4114 + subId + "' for key:" + key);
4115 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4116 }
4117 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004118 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004119 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4120 + "' for key:" + key);
4121 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
4127 @Override
4128 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4130 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4131 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004132 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4133 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004134 final long identity = Binder.clearCallingIdentity();
4135 try {
4136 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004137 int slotId = getSlotIndex(subId);
4138 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4139 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4140 + subId + "' for key:" + key);
4141 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4142 }
4143 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004144 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004145 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4146 + "' for key:" + key);
4147 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004148 } finally {
4149 Binder.restoreCallingIdentity(identity);
4150 }
4151 }
4152
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 int slotId = SubscriptionManager.getSlotIndex(subId);
4155 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4157 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 }
4159 return slotId;
4160 }
4161
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004162 private int getSlotIndex(int subId) {
4163 int slotId = SubscriptionManager.getSlotIndex(subId);
4164 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4165 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4166 }
4167 return slotId;
4168 }
4169
Wink Saville36469e72014-06-11 15:17:00 -07004170 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004171 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004172 */
4173 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004174 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4175 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004176 final int targetSdk = getTargetSdk(callingPackage);
4177 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004178 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004179 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004180 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004181 mApp, subId, callingPackage, callingFeatureId,
4182 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004183 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4184 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004185
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004186 final long identity = Binder.clearCallingIdentity();
4187 try {
4188 final Phone phone = getPhone(subId);
4189 if (phone != null) {
4190 return phone.getServiceState().getDataNetworkType();
4191 } else {
4192 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4193 }
4194 } finally {
4195 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004196 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004197 }
4198
4199 /**
4200 * Returns the data network type
4201 */
4202 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004203 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4204 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4205 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004206 }
4207
4208 /**
4209 * Returns the data network type for a subId
4210 */
4211 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004212 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4213 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004215 mApp, subId, callingPackage, callingFeatureId,
4216 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004217 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4218 }
4219
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004220 final long identity = Binder.clearCallingIdentity();
4221 try {
4222 final Phone phone = getPhone(subId);
4223 if (phone != null) {
4224 return phone.getServiceState().getDataNetworkType();
4225 } else {
4226 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4227 }
4228 } finally {
4229 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004230 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004231 }
4232
4233 /**
Wink Saville36469e72014-06-11 15:17:00 -07004234 * Returns the Voice network type for a subId
4235 */
4236 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004237 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4238 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004239 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004240 mApp, subId, callingPackage, callingFeatureId,
4241 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004242 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4243 }
4244
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004245 final long identity = Binder.clearCallingIdentity();
4246 try {
4247 final Phone phone = getPhone(subId);
4248 if (phone != null) {
4249 return phone.getServiceState().getVoiceNetworkType();
4250 } else {
4251 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4252 }
4253 } finally {
4254 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004255 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004256 }
4257
4258 /**
4259 * @return true if a ICC card is present
4260 */
4261 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004262 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004263 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4264 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004265 }
4266
4267 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004268 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004269 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004270 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004271 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004272 final long identity = Binder.clearCallingIdentity();
4273 try {
4274 final Phone phone = PhoneFactory.getPhone(slotIndex);
4275 if (phone != null) {
4276 return phone.getIccCard().hasIccCard();
4277 } else {
4278 return false;
4279 }
4280 } finally {
4281 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004282 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004283 }
4284
4285 /**
4286 * Return if the current radio is LTE on CDMA. This
4287 * is a tri-state return value as for a period of time
4288 * the mode may be unknown.
4289 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004290 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004291 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004292 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004293 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004294 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004295 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4296 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4297 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004298 }
4299
Sanket Padawe356d7632015-06-22 14:03:32 -07004300 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004301 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4302 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004303 try {
4304 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4305 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004306 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4307 }
4308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 final Phone phone = getPhone(subId);
4312 if (phone == null) {
4313 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4314 } else {
4315 return phone.getLteOnCdmaMode();
4316 }
4317 } finally {
4318 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004319 }
Wink Saville36469e72014-06-11 15:17:00 -07004320 }
4321
Wink Saville36469e72014-06-11 15:17:00 -07004322 /**
4323 * {@hide}
4324 * Returns Default subId, 0 in the case of single standby.
4325 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004326 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004327 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004328 }
4329
Shishir Agrawala9f32182016-04-12 12:00:16 -07004330 private int getSlotForDefaultSubscription() {
4331 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4332 }
4333
Wink Savilleb564aae2014-10-23 10:18:09 -07004334 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004335 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004336 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004337
Pengquan Menge92a50d2018-09-21 15:54:48 -07004338 private boolean isActiveSubscription(int subId) {
4339 return mSubscriptionController.isActiveSubId(subId);
4340 }
4341
Ihab Awadf2177b72013-11-25 13:33:23 -08004342 /**
4343 * @see android.telephony.TelephonyManager.WifiCallingChoices
4344 */
4345 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004346 final long identity = Binder.clearCallingIdentity();
4347 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004348 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004349 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4350 getWhenToMakeWifiCallsDefaultPreference());
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004354 }
4355
4356 /**
4357 * @see android.telephony.TelephonyManager.WifiCallingChoices
4358 */
4359 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004360 final long identity = Binder.clearCallingIdentity();
4361 try {
4362 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004363 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004364 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
4367 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004368 }
4369
Sailesh Nepald1e68152013-12-12 19:08:02 -08004370 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004371 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004372 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004373 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004374
Jordan Liu4c733742019-02-28 12:03:40 -08004375 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4376 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4377 if (phoneId == -1) {
4378 throw new IllegalArgumentException("Given slot index: " + slotIndex
4379 + " does not correspond to an active phone");
4380 }
4381 return PhoneFactory.getPhone(phoneId);
4382 }
4383
Shishir Agrawal566b7612013-10-28 14:41:00 -07004384 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004385 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4386 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004387 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4388 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004390 if (DBG) {
4391 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4392 }
4393 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4394 p2);
4395 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004396
Jordan Liu4c733742019-02-28 12:03:40 -08004397
4398 @Override
4399 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4400 int slotIndex, String callingPackage, String aid, int p2) {
4401 enforceModifyPermission();
4402 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4403 if (DBG) {
4404 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4405 }
4406 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4407 callingPackage, aid, p2);
4408 }
4409
4410 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4411 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004412 final long identity = Binder.clearCallingIdentity();
4413 try {
4414 if (TextUtils.equals(ISDR_AID, aid)) {
4415 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004416 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4417 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 if (bestComponent == null
4419 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4420 loge("The calling package is not allowed to access ISD-R.");
4421 throw new SecurityException(
4422 "The calling package is not allowed to access ISD-R.");
4423 }
Derek Tan740e1672017-06-27 14:56:27 -07004424 }
Derek Tan740e1672017-06-27 14:56:27 -07004425
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004427 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4428 null /* workSource */);
4429 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004430 return response;
4431 } finally {
4432 Binder.restoreCallingIdentity(identity);
4433 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004434 }
4435
4436 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004437 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4439 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004440 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4441 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4442 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004443
Jordan Liu4c733742019-02-28 12:03:40 -08004444 @Override
4445 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4446 enforceModifyPermission();
4447 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4448 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4449 channel);
4450 }
4451
4452 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004453 final long identity = Binder.clearCallingIdentity();
4454 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004455 if (channel < 0) {
4456 return false;
4457 }
Jordan Liu4c733742019-02-28 12:03:40 -08004458 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4459 null /* workSource */);
4460 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 return success;
4462 } finally {
4463 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004464 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004465 }
4466
4467 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004468 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004469 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004470 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4471 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004472 if (DBG) {
4473 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4474 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4475 + p3 + " data=" + data);
4476 }
4477 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4478 command, p1, p2, p3, data);
4479 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004480
Jordan Liu4c733742019-02-28 12:03:40 -08004481 @Override
4482 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4483 int command, int p1, int p2, int p3, String data) {
4484 enforceModifyPermission();
4485 if (DBG) {
4486 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4487 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4488 + p3 + " data=" + data);
4489 }
4490 return iccTransmitApduLogicalChannelWithPermission(
4491 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4492 data);
4493 }
4494
4495 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4496 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 final long identity = Binder.clearCallingIdentity();
4498 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004499 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 return "";
4501 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004502
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004504 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4505 null /* workSource */);
4506 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004507
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004508 // Append the returned status code to the end of the response payload.
4509 String s = Integer.toHexString(
4510 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4511 if (response.payload != null) {
4512 s = IccUtils.bytesToHexString(response.payload) + s;
4513 }
4514 return s;
4515 } finally {
4516 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004517 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004518 }
Jake Hambye994d462014-02-03 13:10:13 -08004519
Evan Charltonc66da362014-05-16 14:06:40 -07004520 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004521 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4522 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4524 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) {
4527 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4528 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4529 }
4530 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4531 cla, command, p1, p2, p3, data);
4532 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004533
Jordan Liu4c733742019-02-28 12:03:40 -08004534 @Override
4535 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4536 int command, int p1, int p2, int p3, String data) {
4537 enforceModifyPermission();
4538 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4539 if (DBG) {
4540 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4541 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4542 + " data=" + data);
4543 }
4544
4545 return iccTransmitApduBasicChannelWithPermission(
4546 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4547 p2, p3, data);
4548 }
4549
4550 // open APDU basic channel assuming the caller has sufficient permissions
4551 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4552 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004553 final long identity = Binder.clearCallingIdentity();
4554 try {
4555 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4556 && TextUtils.equals(ISDR_AID, data)) {
4557 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004558 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4559 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004560 if (bestComponent == null
4561 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4562 loge("The calling package is not allowed to select ISD-R.");
4563 throw new SecurityException(
4564 "The calling package is not allowed to select ISD-R.");
4565 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004566 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004567
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004568 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004569 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4570 null /* workSource */);
4571 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 // Append the returned status code to the end of the response payload.
4574 String s = Integer.toHexString(
4575 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4576 if (response.payload != null) {
4577 s = IccUtils.bytesToHexString(response.payload) + s;
4578 }
4579 return s;
4580 } finally {
4581 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004582 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004583 }
4584
4585 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004586 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004587 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4589 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 final long identity = Binder.clearCallingIdentity();
4592 try {
4593 if (DBG) {
4594 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4595 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4596 }
4597
4598 IccIoResult response =
4599 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4600 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4601 subId);
4602
4603 if (DBG) {
4604 log("Exchange SIM_IO [R]" + response);
4605 }
4606
4607 byte[] result = null;
4608 int length = 2;
4609 if (response.payload != null) {
4610 length = 2 + response.payload.length;
4611 result = new byte[length];
4612 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4613 } else {
4614 result = new byte[length];
4615 }
4616
4617 result[length - 1] = (byte) response.sw2;
4618 result[length - 2] = (byte) response.sw1;
4619 return result;
4620 } finally {
4621 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004622 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004623 }
4624
Nathan Haroldb3014052017-01-25 15:57:32 -08004625 /**
4626 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4627 * on a particular subscription
4628 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004629 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4630 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004632 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004633 return null;
4634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635
4636 final long identity = Binder.clearCallingIdentity();
4637 try {
4638 if (appType != TelephonyManager.APPTYPE_USIM
4639 && appType != TelephonyManager.APPTYPE_SIM) {
4640 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4641 return null;
4642 }
4643 Object response = sendRequest(
4644 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4645 if (response instanceof String[]) {
4646 return (String[]) response;
4647 }
yincheng zhaod698b842019-09-06 17:06:54 -07004648 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004649 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004650 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004651 } finally {
4652 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004653 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004654 }
4655
yincheng zhaod698b842019-09-06 17:06:54 -07004656 /**
4657 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4658 * subscription.
4659 *
4660 * @param subId the id of the subscription.
4661 * @param appType the uicc app type, must be USIM or SIM.
4662 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4663 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004664 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004665 * @return number of fplmns that is successfully written to the SIM.
4666 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004667 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4668 String callingFeatureId) {
4669 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4670 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004671 if (DBG) logv("no permissions for setForbiddenplmns");
4672 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4673 }
4674 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4675 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4676 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4677 }
4678 if (fplmns == null) {
4679 throw new IllegalArgumentException("Fplmn List provided is null");
4680 }
4681 for (String fplmn : fplmns) {
4682 if (!CellIdentity.isValidPlmn(fplmn)) {
4683 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4684 }
4685 }
4686 final long identity = Binder.clearCallingIdentity();
4687 try {
4688 Object response = sendRequest(
4689 CMD_SET_FORBIDDEN_PLMNS,
4690 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4691 subId);
4692 return (int) response;
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
4695 }
4696 }
4697
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004698 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004699 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004700 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4701 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4706 if (response.payload == null) {
4707 return "";
4708 }
Evan Charltonc66da362014-05-16 14:06:40 -07004709
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004710 // Append the returned status code to the end of the response payload.
4711 String s = Integer.toHexString(
4712 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4713 s = IccUtils.bytesToHexString(response.payload) + s;
4714 return s;
4715 } finally {
4716 Binder.restoreCallingIdentity(identity);
4717 }
Evan Charltonc66da362014-05-16 14:06:40 -07004718 }
4719
Jake Hambye994d462014-02-03 13:10:13 -08004720 /**
4721 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4722 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4723 *
4724 * @param itemID the ID of the item to read
4725 * @return the NV item as a String, or null on error.
4726 */
4727 @Override
4728 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4731 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732
4733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004736 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4738 return value;
4739 } finally {
4740 Binder.restoreCallingIdentity(identity);
4741 }
Jake Hambye994d462014-02-03 13:10:13 -08004742 }
4743
4744 /**
4745 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4746 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4747 *
4748 * @param itemID the ID of the item to read
4749 * @param itemValue the value to write, as a String
4750 * @return true on success; false on any failure
4751 */
4752 @Override
4753 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004754 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004755 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4756 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757
4758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4761 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004762 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4764 return success;
4765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
Jake Hambye994d462014-02-03 13:10:13 -08004768 }
4769
4770 /**
4771 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4772 * Used for device configuration by some CDMA operators.
4773 *
4774 * @param preferredRoamingList byte array containing the new PRL
4775 * @return true on success; false on any failure
4776 */
4777 @Override
4778 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4780 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004781
4782 final long identity = Binder.clearCallingIdentity();
4783 try {
4784 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4785 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4786 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4787 return success;
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Jake Hambye994d462014-02-03 13:10:13 -08004791 }
4792
4793 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004794 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004795 * Used for device configuration by some CDMA operators.
4796 *
chen xu6dac5ab2018-10-26 17:39:23 -07004797 * @param slotIndex - device slot.
4798 *
Jake Hambye994d462014-02-03 13:10:13 -08004799 * @return true on success; false on any failure
4800 */
4801 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004802 public boolean resetModemConfig(int slotIndex) {
4803 Phone phone = PhoneFactory.getPhone(slotIndex);
4804 if (phone != null) {
4805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4806 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807
chen xu6dac5ab2018-10-26 17:39:23 -07004808 final long identity = Binder.clearCallingIdentity();
4809 try {
4810 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4811 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4812 return success;
4813 } finally {
4814 Binder.restoreCallingIdentity(identity);
4815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004816 }
chen xu6dac5ab2018-10-26 17:39:23 -07004817 return false;
4818 }
4819
4820 /**
4821 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4822 *
4823 * @param slotIndex - device slot.
4824 *
4825 * @return true on success; false on any failure
4826 */
4827 @Override
4828 public boolean rebootModem(int slotIndex) {
4829 Phone phone = PhoneFactory.getPhone(slotIndex);
4830 if (phone != null) {
4831 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4832 mApp, phone.getSubId(), "rebootModem");
4833
4834 final long identity = Binder.clearCallingIdentity();
4835 try {
4836 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4837 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4838 return success;
4839 } finally {
4840 Binder.restoreCallingIdentity(identity);
4841 }
4842 }
4843 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004844 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004845
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004846 public String[] getPcscfAddress(String apnType, String callingPackage,
4847 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004848 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4850 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004851 return new String[0];
4852 }
4853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854 final long identity = Binder.clearCallingIdentity();
4855 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004856 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004857 } finally {
4858 Binder.restoreCallingIdentity(identity);
4859 }
Wink Saville36469e72014-06-11 15:17:00 -07004860 }
4861
Brad Ebinger51f743a2017-01-23 13:50:20 -08004862 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004863 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4864 * {@link #disableIms(int)}.
4865 * @param slotIndex device slot.
4866 */
4867 public void resetIms(int slotIndex) {
4868 enforceModifyPermission();
4869
4870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 if (mImsResolver == null) {
4873 // may happen if the does not support IMS.
4874 return;
4875 }
4876 mImsResolver.disableIms(slotIndex);
4877 mImsResolver.enableIms(slotIndex);
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
4881 }
4882
4883 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004884 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4885 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004886 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004887 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004888 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889
4890 final long identity = Binder.clearCallingIdentity();
4891 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004892 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004893 // may happen if the device does not support IMS.
4894 return;
4895 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004896 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 } finally {
4898 Binder.restoreCallingIdentity(identity);
4899 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004900 }
4901
4902 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004903 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4904 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004905 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004906 public void disableIms(int slotId) {
4907 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908
4909 final long identity = Binder.clearCallingIdentity();
4910 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004911 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004912 // may happen if the device does not support IMS.
4913 return;
4914 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004915 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 } finally {
4917 Binder.restoreCallingIdentity(identity);
4918 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004919 }
4920
4921 /**
4922 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4923 * feature or {@link null} if the service is not available. If the feature is available, the
4924 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4925 */
4926 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004927 IImsServiceFeatureCallback callback) {
4928 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929
4930 final long identity = Binder.clearCallingIdentity();
4931 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004932 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004933 // may happen if the device does not support IMS.
4934 return null;
4935 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004936 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 } finally {
4938 Binder.restoreCallingIdentity(identity);
4939 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004940 }
4941
4942 /**
4943 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
4944 * feature during emergency calling or {@link null} if the service is not available. If the
4945 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
4946 * listener for feature updates.
4947 */
4948 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
4949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004950
4951 final long identity = Binder.clearCallingIdentity();
4952 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004953 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004954 // may happen if the device does not support IMS.
4955 return null;
4956 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004957 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004958 } finally {
4959 Binder.restoreCallingIdentity(identity);
4960 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08004961 }
4962
Brad Ebinger5f64b052017-12-14 14:26:15 -08004963 /**
4964 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004965 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08004966 */
4967 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
4968 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969
4970 final long identity = Binder.clearCallingIdentity();
4971 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004972 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004973 // may happen if the device does not support IMS.
4974 return null;
4975 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004976 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977 } finally {
4978 Binder.restoreCallingIdentity(identity);
4979 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08004980 }
4981
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004982 /**
4983 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004984 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004985 */
4986 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
4987 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988
4989 final long identity = Binder.clearCallingIdentity();
4990 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004991 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004992 // may happen if the device does not support IMS.
4993 return null;
4994 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004995 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 } finally {
4997 Binder.restoreCallingIdentity(identity);
4998 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004999 }
5000
Brad Ebinger884c07b2018-02-15 16:17:40 -08005001 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005002 * Sets the ImsService Package Name that Telephony will bind to.
5003 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005004 * @param slotIndex the slot ID that the ImsService should bind for.
5005 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005006 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005007 * @param featureTypes An integer array of feature types associated with a packageName.
5008 * @param packageName The name of the package that the current configuration will be replaced
5009 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005010 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005011 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005012 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5013 int[] featureTypes, String packageName) {
5014 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5015 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005016 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5017 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005018 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005022 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005023 // may happen if the device does not support IMS.
5024 return false;
5025 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005026 Map<Integer, String> featureConfig = new HashMap<>();
5027 for (int featureType : featureTypes) {
5028 featureConfig.put(featureType, packageName);
5029 }
5030 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5031 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005032 } finally {
5033 Binder.restoreCallingIdentity(identity);
5034 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005035 }
5036
5037 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005038 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005039 *
5040 * @param slotId The slot that the ImsService is associated with.
5041 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5042 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005043 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005044 * @return the package name of the ImsService configuration.
5045 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005046 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5047 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005048 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005049 TelephonyPermissions
5050 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5051 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5052 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005053
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005057 // may happen if the device does not support IMS.
5058 return "";
5059 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005060 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005061 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5062 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005063 } finally {
5064 Binder.restoreCallingIdentity(identity);
5065 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005066 }
5067
Brad Ebinger77b832e2019-10-17 17:03:22 -07005068 /**
5069 * Get the MmTelFeature state associated with the requested subscription id.
5070 * @param subId The subscription that the MmTelFeature is associated with.
5071 * @param callback A callback with an integer containing the
5072 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5073 */
5074 @Override
5075 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5076 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5077 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5078 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5079 "IMS not available on device.");
5080 }
5081 final long token = Binder.clearCallingIdentity();
5082 try {
5083 int slotId = getSlotIndex(subId);
5084 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5085 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5086 + subId + "'");
5087 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5088 }
5089 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5090 try {
5091 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5092 } catch (RemoteException e) {
5093 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5094 + "Ignore");
5095 }
5096 });
5097 } finally {
5098 Binder.restoreCallingIdentity(token);
5099 }
5100 }
5101
Wink Saville36469e72014-06-11 15:17:00 -07005102 public void setImsRegistrationState(boolean registered) {
5103 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104
5105 final long identity = Binder.clearCallingIdentity();
5106 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005107 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 } finally {
5109 Binder.restoreCallingIdentity(identity);
5110 }
Wink Saville36469e72014-06-11 15:17:00 -07005111 }
5112
5113 /**
Stuart Scott54788802015-03-30 13:18:01 -07005114 * Set the network selection mode to automatic.
5115 *
5116 */
5117 @Override
5118 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5120 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
shilufc958392020-01-20 11:36:01 -08005124 if (!isActiveSubscription(subId)) {
5125 return;
5126 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005127 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5128 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5129 } finally {
5130 Binder.restoreCallingIdentity(identity);
5131 }
Stuart Scott54788802015-03-30 13:18:01 -07005132 }
5133
Pengquan Mengea84e042018-09-20 14:57:26 -07005134 /**
5135 * Ask the radio to connect to the input network and change selection mode to manual.
5136 *
5137 * @param subId the id of the subscription.
5138 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5139 * the operator to attach to.
5140 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5141 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5142 * normal network selection next time.
5143 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005144 */
5145 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005146 public boolean setNetworkSelectionModeManual(
5147 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5149 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005150
5151 if (!isActiveSubscription(subId)) {
5152 return false;
5153 }
5154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005155 final long identity = Binder.clearCallingIdentity();
5156 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005157 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005159 if (DBG) {
5160 log("setNetworkSelectionModeManual: subId: " + subId
5161 + " operator: " + operatorInfo);
5162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005167 }
5168
5169 /**
5170 * Scans for available networks.
5171 */
5172 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005173 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5174 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5176 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005177 LocationAccessPolicy.LocationPermissionResult locationResult =
5178 LocationAccessPolicy.checkLocationPermission(mApp,
5179 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5180 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005181 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005182 .setCallingPid(Binder.getCallingPid())
5183 .setCallingUid(Binder.getCallingUid())
5184 .setMethod("getCellNetworkScanResults")
5185 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5186 .build());
5187 switch (locationResult) {
5188 case DENIED_HARD:
5189 throw new SecurityException("Not allowed to access scan results -- location");
5190 case DENIED_SOFT:
5191 return null;
5192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
Pengquan Menga1bb6272018-09-06 09:59:22 -07005194 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005195 try {
5196 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005197 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005198 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199 } finally {
5200 Binder.restoreCallingIdentity(identity);
5201 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005202 }
5203
5204 /**
sqian80370722020-01-29 15:02:51 -08005205 * Get the call forwarding info, given the call forwarding reason.
5206 */
5207 @Override
5208 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5209 enforceReadPrivilegedPermission("getCallForwarding");
5210 long identity = Binder.clearCallingIdentity();
5211 try {
5212 if (DBG) {
5213 log("getCallForwarding: subId " + subId
5214 + " callForwardingReason" + callForwardingReason);
5215 }
5216 return (CallForwardingInfo) sendRequest(
5217 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
5221 }
5222
5223 /**
5224 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5225 * reason, the number to forward, and the timeout before the forwarding is attempted.
5226 */
5227 @Override
5228 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5229 enforceModifyPermission();
5230 long identity = Binder.clearCallingIdentity();
5231 try {
5232 if (DBG) {
5233 log("setCallForwarding: subId " + subId
5234 + " callForwardingInfo" + callForwardingInfo);
5235 }
5236 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5237 } finally {
5238 Binder.restoreCallingIdentity(identity);
5239 }
5240 }
5241
5242 /**
5243 * Get the call forwarding info, given the call forwarding reason.
5244 */
5245 @Override
5246 public int getCallWaitingStatus(int subId) {
5247 enforceReadPrivilegedPermission("getCallForwarding");
5248 long identity = Binder.clearCallingIdentity();
5249 try {
5250 if (DBG) log("getCallWaitingStatus: subId " + subId);
5251 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
5255 }
5256
5257 /**
5258 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5259 * reason, the number to forward, and the timeout before the forwarding is attempted.
5260 */
5261 @Override
5262 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5263 enforceModifyPermission();
5264 long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5267 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
5271 }
5272
5273 /**
yinxub1bed742017-04-17 11:45:04 -07005274 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005275 *
yinxub1bed742017-04-17 11:45:04 -07005276 * @param subId id of the subscription
5277 * @param request contains the radio access networks with bands/channels to scan
5278 * @param messenger callback messenger for scan results or errors
5279 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005280 * @return the id of the requested scan which can be used to stop the scan.
5281 */
5282 @Override
5283 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005284 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5286 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005287 LocationAccessPolicy.LocationPermissionResult locationResult =
5288 LocationAccessPolicy.checkLocationPermission(mApp,
5289 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5290 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005291 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005292 .setCallingPid(Binder.getCallingPid())
5293 .setCallingUid(Binder.getCallingUid())
5294 .setMethod("requestNetworkScan")
5295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5296 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005297 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005298 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005299 if (e != null) {
5300 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5301 throw e;
5302 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005303 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005304 return TelephonyScanManager.INVALID_SCAN_ID;
5305 }
5306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 }
Hall Liu912dfd32019-04-25 14:02:26 -07005308 int callingUid = Binder.getCallingUid();
5309 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005310 final long identity = Binder.clearCallingIdentity();
5311 try {
5312 return mNetworkScanRequestTracker.startNetworkScan(
5313 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005314 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
yinxu504e1392017-04-12 16:03:22 -07005318 }
5319
Hall Liub2ac8ef2019-02-28 15:56:23 -08005320 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005321 NetworkScanRequest request, int subId) {
5322 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5323 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5324 boolean hasNetworkScanPermission =
5325 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5326 == PERMISSION_GRANTED;
5327
5328 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5329 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5330 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005331 }
5332
5333 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5334 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005335 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5336 return new SecurityException("Specific channels must not be"
5337 + " scanned without location access.");
5338 }
5339 }
5340 }
5341
Hall Liub2ac8ef2019-02-28 15:56:23 -08005342 return null;
5343 }
5344
yinxu504e1392017-04-12 16:03:22 -07005345 /**
5346 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005347 *
5348 * @param subId id of the subscription
5349 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005350 */
5351 @Override
5352 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005353 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5354 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005355
Hall Liu912dfd32019-04-25 14:02:26 -07005356 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357 final long identity = Binder.clearCallingIdentity();
5358 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005359 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
yinxu504e1392017-04-12 16:03:22 -07005363 }
5364
5365 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005366 * Get the calculated preferred network type.
5367 * Used for debugging incorrect network type.
5368 *
5369 * @return the preferred network type, defined in RILConstants.java.
5370 */
5371 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005372 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005373 final Phone defaultPhone = getDefaultPhone();
5374 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005375 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005376 return RILConstants.PREFERRED_NETWORK_MODE;
5377 }
5378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379 final long identity = Binder.clearCallingIdentity();
5380 try {
5381 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005382 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005383 } finally {
5384 Binder.restoreCallingIdentity(identity);
5385 }
Junda Liu84d15a22014-07-02 11:21:04 -07005386 }
5387
5388 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005389 * Get the preferred network type.
5390 * Used for device configuration by some CDMA operators.
5391 *
5392 * @return the preferred network type, defined in RILConstants.java.
5393 */
5394 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005395 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005396 TelephonyPermissions
5397 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5398 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
5400 final long identity = Binder.clearCallingIdentity();
5401 try {
5402 if (DBG) log("getPreferredNetworkType");
5403 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5404 int networkType = (result != null ? result[0] : -1);
5405 if (DBG) log("getPreferredNetworkType: " + networkType);
5406 return networkType;
5407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005410 }
5411
5412 /**
5413 * Set the preferred network type.
5414 * Used for device configuration by some CDMA operators.
5415 *
5416 * @param networkType the preferred network type, defined in RILConstants.java.
5417 * @return true on success; false on any failure.
5418 */
5419 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005420 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005421 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5422 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005426 Settings.Global.putInt(mApp.getContentResolver(),
5427 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5428 return setPreferredNetworkTypesInternal(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005431 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005432 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005433
5434 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005435 * Get the allowed network types that store in the telephony provider.
5436 *
5437 * @param subId the id of the subscription.
5438 * @return allowedNetworkTypes the allowed network types.
5439 */
5440 @Override
5441 public long getAllowedNetworkTypes(int subId) {
5442 TelephonyPermissions
5443 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5444 mApp, subId, "getAllowedNetworkTypes");
5445
5446 final long identity = Binder.clearCallingIdentity();
5447 try {
5448 return SubscriptionManager.getLongSubscriptionProperty(
5449 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5450 } finally {
5451 Binder.restoreCallingIdentity(identity);
5452 }
5453 }
5454
5455 /**
5456 * Set the allowed network types.
5457 *
5458 * @param subId the id of the subscription.
5459 * @param allowedNetworkTypes the allowed network types.
5460 * @return true on success; false on any failure.
5461 */
5462 @Override
5463 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5465 mApp, subId, "setAllowedNetworkTypes");
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 SubscriptionManager.setSubscriptionProperty(subId,
5469 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5470 String.valueOf(allowedNetworkTypes));
5471 return setPreferredNetworkTypesInternal(subId);
5472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
5475 }
5476
5477 private boolean setPreferredNetworkTypesInternal(int subId) {
5478 long networkTypeBitMask = RadioAccessFamily.getRafFromNetworkType(
5479 Settings.Global.getInt(mApp.getContentResolver(),
5480 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5481 RILConstants.PREFERRED_NETWORK_MODE));
5482 long allowedNetworkTypes = SubscriptionManager.getLongSubscriptionProperty(
5483 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5484 int networkMode = RadioAccessFamily.getNetworkTypeFromRaf(
5485 (int) (networkTypeBitMask & allowedNetworkTypes));
5486
5487 if (DBG) {
5488 log("setPreferredNetworkTypesInternal: subId " + subId
5489 + " networkTypes " + networkTypeBitMask
5490 + " allowedNetworkTypes " + allowedNetworkTypes
5491 + " networkMode " + networkMode);
5492 }
5493
5494 Boolean success = (Boolean) sendRequest(
5495 CMD_SET_PREFERRED_NETWORK_TYPE, networkMode, subId);
5496 if (DBG) log("setPreferredNetworkTypesInternal: " + (success ? "ok" : "fail"));
5497 return success;
5498 }
5499
5500 /**
Miaoa84611c2019-03-15 09:21:10 +08005501 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005502 *
Miaoa84611c2019-03-15 09:21:10 +08005503 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005504 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005505 * @hide
5506 */
5507 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005508 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005511 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005512 try {
Miaoa84611c2019-03-15 09:21:10 +08005513 if (phone != null) {
5514 return phone.hasMatchedTetherApnSetting();
5515 } else {
5516 return false;
5517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005518 } finally {
5519 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005520 }
Junda Liu475951f2014-11-07 16:45:03 -08005521 }
5522
5523 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005524 * Set mobile data enabled
5525 * Used by the user through settings etc to turn on/off mobile data
5526 *
5527 * @param enable {@code true} turn turn data on, else {@code false}
5528 */
5529 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005530 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 int phoneId = mSubscriptionController.getPhoneId(subId);
5537 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5538 Phone phone = PhoneFactory.getPhone(phoneId);
5539 if (phone != null) {
5540 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005541 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005542 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005543 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 }
5545 } finally {
5546 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005547 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005548 }
5549
5550 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005551 * Enable or disable always reporting signal strength changes from radio.
5552 *
5553 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5554 */
5555 @Override
5556 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5557 enforceModifyPermission();
5558 enforceSystemCaller();
5559
5560 final long identity = Binder.clearCallingIdentity();
5561 final Phone phone = getPhone(subId);
5562 try {
5563 if (phone != null) {
5564 if (DBG) {
5565 log("setAlwaysReportSignalStrength: subId=" + subId
5566 + " isEnable=" + isEnable);
5567 }
5568 phone.setAlwaysReportSignalStrength(isEnable);
5569 } else {
5570 loge("setAlwaysReportSignalStrength: no phone found for subId="
5571 + subId);
5572 }
5573 } finally {
5574 Binder.restoreCallingIdentity(identity);
5575 }
5576 }
5577
5578 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005579 * Get the user enabled state of Mobile Data.
5580 *
5581 * TODO: remove and use isUserDataEnabled.
5582 * This can't be removed now because some vendor codes
5583 * calls through ITelephony directly while they should
5584 * use TelephonyManager.
5585 *
5586 * @return true on enabled
5587 */
5588 @Override
5589 public boolean getDataEnabled(int subId) {
5590 return isUserDataEnabled(subId);
5591 }
5592
5593 /**
5594 * Get whether mobile data is enabled per user setting.
5595 *
5596 * There are other factors deciding whether mobile data is actually enabled, but they are
5597 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005598 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005599 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005600 *
5601 * @return {@code true} if data is enabled else {@code false}
5602 */
5603 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005604 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005605 try {
5606 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5607 null);
5608 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5610 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005612
5613 final long identity = Binder.clearCallingIdentity();
5614 try {
5615 int phoneId = mSubscriptionController.getPhoneId(subId);
5616 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5617 Phone phone = PhoneFactory.getPhone(phoneId);
5618 if (phone != null) {
5619 boolean retVal = phone.isUserDataEnabled();
5620 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5621 return retVal;
5622 } else {
5623 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5624 return false;
5625 }
5626 } finally {
5627 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005628 }
5629 }
5630
5631 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005632 * Checks if the device is capable of mobile data by considering whether whether the
5633 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5634 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005635 *
Shuo Qian985d1232020-01-08 14:30:06 -08005636 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005637 */
5638 @Override
5639 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005640 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641
5642 final long identity = Binder.clearCallingIdentity();
5643 try {
5644 int phoneId = mSubscriptionController.getPhoneId(subId);
5645 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5646 Phone phone = PhoneFactory.getPhone(phoneId);
5647 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005648 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5650 return retVal;
5651 } else {
5652 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5653 return false;
5654 }
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005657 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005658 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005659
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005660 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim,
5661 Phone phone) {
5662 //load access rules from carrier configs, and check those as well: b/139133814
5663 SubscriptionController subController = SubscriptionController.getInstance();
5664 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5665 || subController == null) return privilegeFromSim;
5666
5667 int uid = Binder.getCallingUid();
5668 PackageManager pkgMgr = phone.getContext().getPackageManager();
5669 String[] packages = pkgMgr.getPackagesForUid(uid);
5670
5671 final long identity = Binder.clearCallingIdentity();
5672 try {
5673 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5674 SubscriptionManager subManager = (SubscriptionManager)
5675 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5676 for (String pkg : packages) {
5677 if (subManager.canManageSubscription(subInfo, pkg)) {
5678 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5679 }
5680 }
5681 return privilegeFromSim;
5682 } finally {
5683 Binder.restoreCallingIdentity(identity);
5684 }
5685 }
5686
5687 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5688 String pkgName) {
5689 //load access rules from carrier configs, and check those as well: b/139133814
5690 SubscriptionController subController = SubscriptionController.getInstance();
5691 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5692 || subController == null) return privilegeFromSim;
5693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5697 SubscriptionManager subManager = (SubscriptionManager)
5698 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5699 return subManager.canManageSubscription(subInfo, pkgName)
5700 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5701 } finally {
5702 Binder.restoreCallingIdentity(identity);
5703 }
5704 }
5705
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005706 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005707 public int getCarrierPrivilegeStatus(int subId) {
5708 final Phone phone = getPhone(subId);
5709 if (phone == null) {
5710 loge("getCarrierPrivilegeStatus: Invalid subId");
5711 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5712 }
5713 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005714 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005715 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005716 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5717 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005718
5719 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5720 card.getCarrierPrivilegeStatusForCurrentTransaction(
5721 phone.getContext().getPackageManager()), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005722 }
Junda Liu29340342014-07-10 15:23:27 -07005723
5724 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005725 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005726 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005727 final Phone phone = getPhone(subId);
5728 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005729 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005730 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5731 }
5732 UiccProfile profile =
5733 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5734 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005735 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005736 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5737 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005738 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005739 profile.getCarrierPrivilegeStatusForUid(
5740 phone.getContext().getPackageManager(), uid), phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005741 }
5742
5743 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005744 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5745 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005746 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005747 }
5748
5749 int phoneId = SubscriptionManager.getPhoneId(subId);
5750 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005751 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005752 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005753 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5754 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005755 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5756 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5757 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005758 }
5759
5760 @Override
5761 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005762 if (TextUtils.isEmpty(pkgName))
5763 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005764 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5765 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5766 UiccCard card = UiccController.getInstance().getUiccCard(i);
5767 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005768 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005769 continue;
5770 }
5771
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005772 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5773 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5774 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005775 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5776 break;
5777 }
5778 }
5779
5780 return result;
Junda Liu29340342014-07-10 15:23:27 -07005781 }
Derek Tan89e89d42014-07-08 17:00:10 -07005782
5783 @Override
Junda Liue64de782015-04-16 17:19:16 -07005784 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5785 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5786 loge("phoneId " + phoneId + " is not valid.");
5787 return null;
5788 }
5789 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005790 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005791 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005792 return null ;
5793 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005794 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005795 }
5796
Amith Yamasani6e118872016-02-19 12:53:51 -08005797 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005798 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005799 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005800 List<String> privilegedPackages = new ArrayList<>();
5801 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005802 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5803 // has UICC in that slot.
5804 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005805 if (card.hasCarrierPrivilegeRules()) {
5806 if (packages == null) {
5807 // Only check packages in user 0 for now
5808 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005809 PackageManager.MATCH_DISABLED_COMPONENTS
5810 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005811 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005812 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005813 }
5814 for (int p = packages.size() - 1; p >= 0; p--) {
5815 PackageInfo pkgInfo = packages.get(p);
5816 if (pkgInfo != null && pkgInfo.packageName != null
5817 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005818 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005819 privilegedPackages.add(pkgInfo.packageName);
5820 }
5821 }
5822 }
5823 }
5824 return privilegedPackages;
5825 }
5826
chen xuf7e9fe82019-05-09 19:31:02 -07005827 @Override
5828 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005829 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5830
5831 final long identity = Binder.clearCallingIdentity();
5832
chen xuf7e9fe82019-05-09 19:31:02 -07005833 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005834 try {
5835 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5836 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5837 }
5838 } finally {
5839 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005840 }
5841 return privilegedPackages;
5842 }
5843
Wink Savilleb564aae2014-10-23 10:18:09 -07005844 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005845 final Phone phone = getPhone(subId);
5846 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005847 if (card == null) {
5848 loge("getIccId: No UICC");
5849 return null;
5850 }
5851 String iccId = card.getIccId();
5852 if (TextUtils.isEmpty(iccId)) {
5853 loge("getIccId: ICC ID is null or empty.");
5854 return null;
5855 }
5856 return iccId;
5857 }
5858
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005859 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005860 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5861 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005862 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005863 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005864
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005865 final long identity = Binder.clearCallingIdentity();
5866 try {
5867 final String iccId = getIccId(subId);
5868 final Phone phone = getPhone(subId);
5869 if (phone == null) {
5870 return false;
5871 }
5872 final String subscriberId = phone.getSubscriberId();
5873
5874 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005875 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005876 + subscriberId + " to " + number);
5877 }
5878
5879 if (TextUtils.isEmpty(iccId)) {
5880 return false;
5881 }
5882
5883 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
5884
5885 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5886 if (alphaTag == null) {
5887 editor.remove(alphaTagPrefKey);
5888 } else {
5889 editor.putString(alphaTagPrefKey, alphaTag);
5890 }
5891
5892 // Record both the line number and IMSI for this ICCID, since we need to
5893 // track all merged IMSIs based on line number
5894 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5895 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
5896 if (number == null) {
5897 editor.remove(numberPrefKey);
5898 editor.remove(subscriberPrefKey);
5899 } else {
5900 editor.putString(numberPrefKey, number);
5901 editor.putString(subscriberPrefKey, subscriberId);
5902 }
5903
5904 editor.commit();
5905 return true;
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07005908 }
Derek Tan7226c842014-07-02 17:42:23 -07005909 }
5910
5911 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005912 public String getLine1NumberForDisplay(int subId, String callingPackage,
5913 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07005914 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005916 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08005917 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07005918 return null;
5919 }
Derek Tan97ebb422014-09-05 16:55:38 -07005920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 final long identity = Binder.clearCallingIdentity();
5922 try {
5923 String iccId = getIccId(subId);
5924 if (iccId != null) {
5925 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5926 if (DBG_MERGE) {
5927 log("getLine1NumberForDisplay returning "
5928 + mTelephonySharedPreferences.getString(numberPrefKey, null));
5929 }
5930 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08005931 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005932 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
5933 return null;
5934 } finally {
5935 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005936 }
Derek Tan7226c842014-07-02 17:42:23 -07005937 }
5938
5939 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
5941 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005943 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005944 return null;
5945 }
Derek Tan97ebb422014-09-05 16:55:38 -07005946
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005947 final long identity = Binder.clearCallingIdentity();
5948 try {
5949 String iccId = getIccId(subId);
5950 if (iccId != null) {
5951 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
5952 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
5953 }
5954 return null;
5955 } finally {
5956 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07005957 }
Derek Tan7226c842014-07-02 17:42:23 -07005958 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07005959
5960 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005961 public String[] getMergedSubscriberIds(int subId, String callingPackage,
5962 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08005963 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
5964 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08005965 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08005966 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005967 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005968 return null;
5969 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08005970
Jordan Liub49b04b2019-05-06 14:45:15 -07005971 // Clear calling identity, when calling TelephonyManager, because callerUid must be
5972 // the process, where TelephonyManager was instantiated.
5973 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005974 final long identity = Binder.clearCallingIdentity();
5975 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005976 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005977 final TelephonyManager tele = TelephonyManager.from(context);
5978 final SubscriptionManager sub = SubscriptionManager.from(context);
5979
5980 // Figure out what subscribers are currently active
5981 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005982
Jordan Liub49b04b2019-05-06 14:45:15 -07005983 // Only consider subs which match the current subId
5984 // This logic can be simplified. See b/131189269 for progress.
5985 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07005986 activeSubscriberIds.add(tele.getSubscriberId(subId));
5987 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005988
5989 // First pass, find a number override for an active subscriber
5990 String mergeNumber = null;
5991 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
5992 for (String key : prefs.keySet()) {
5993 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
5994 final String subscriberId = (String) prefs.get(key);
5995 if (activeSubscriberIds.contains(subscriberId)) {
5996 final String iccId = key.substring(
5997 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
5998 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
5999 mergeNumber = (String) prefs.get(numberKey);
6000 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006001 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006002 + " for active subscriber " + subscriberId);
6003 }
6004 if (!TextUtils.isEmpty(mergeNumber)) {
6005 break;
6006 }
6007 }
6008 }
6009 }
6010
6011 // Shortcut when no active merged subscribers
6012 if (TextUtils.isEmpty(mergeNumber)) {
6013 return null;
6014 }
6015
6016 // Second pass, find all subscribers under that line override
6017 final ArraySet<String> result = new ArraySet<>();
6018 for (String key : prefs.keySet()) {
6019 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6020 final String number = (String) prefs.get(key);
6021 if (mergeNumber.equals(number)) {
6022 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6023 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6024 final String subscriberId = (String) prefs.get(subscriberKey);
6025 if (!TextUtils.isEmpty(subscriberId)) {
6026 result.add(subscriberId);
6027 }
6028 }
6029 }
6030 }
6031
6032 final String[] resultArray = result.toArray(new String[result.size()]);
6033 Arrays.sort(resultArray);
6034 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006035 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006036 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6037 }
6038 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006041 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006042 }
6043
6044 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006045 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6046 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6047
6048 final long identity = Binder.clearCallingIdentity();
6049 try {
6050 final TelephonyManager telephonyManager = mApp.getSystemService(
6051 TelephonyManager.class);
6052 String subscriberId = telephonyManager.getSubscriberId(subId);
6053 if (subscriberId == null) {
6054 if (DBG) {
6055 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6056 + subId);
6057 }
6058 return null;
6059 }
6060
6061 final SubscriptionInfo info = SubscriptionController.getInstance()
6062 .getSubscriptionInfo(subId);
6063 final ParcelUuid groupUuid = info.getGroupUuid();
6064 // If it doesn't belong to any group, return just subscriberId of itself.
6065 if (groupUuid == null) {
6066 return new String[]{subscriberId};
6067 }
6068
6069 // Get all subscriberIds from the group.
6070 final List<String> mergedSubscriberIds = new ArrayList<>();
6071 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006072 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6073 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006074 for (SubscriptionInfo subInfo : groupInfos) {
6075 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6076 if (subscriberId != null) {
6077 mergedSubscriberIds.add(subscriberId);
6078 }
6079 }
6080
6081 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
6084
6085 }
6086 }
6087
6088 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006089 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006090 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006091 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006092
6093 final long identity = Binder.clearCallingIdentity();
6094 try {
6095 final Phone phone = getPhone(subId);
6096 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6097 } finally {
6098 Binder.restoreCallingIdentity(identity);
6099 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006100 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006101
6102 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006103 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006104 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6105 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006106 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6107 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108
6109 final long identity = Binder.clearCallingIdentity();
6110 try {
6111 final Phone phone = getPhone(subId);
6112 if (phone == null) {
6113 return false;
6114 }
6115 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6116 cdmaNonRoamingList);
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006119 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006120 }
6121
6122 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006123 @Deprecated
6124 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6125 enforceModifyPermission();
6126
6127 int returnValue = 0;
6128 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006129 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006130 if(result.exception == null) {
6131 if (result.result != null) {
6132 byte[] responseData = (byte[])(result.result);
6133 if(responseData.length > oemResp.length) {
6134 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6135 responseData.length + "bytes. Buffer Size is " +
6136 oemResp.length + "bytes.");
6137 }
6138 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6139 returnValue = responseData.length;
6140 }
6141 } else {
6142 CommandException ex = (CommandException) result.exception;
6143 returnValue = ex.getCommandError().ordinal();
6144 if(returnValue > 0) returnValue *= -1;
6145 }
6146 } catch (RuntimeException e) {
6147 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6148 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6149 if(returnValue > 0) returnValue *= -1;
6150 }
6151
6152 return returnValue;
6153 }
6154
6155 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006156 public void setRadioCapability(RadioAccessFamily[] rafs) {
6157 try {
6158 ProxyController.getInstance().setRadioCapability(rafs);
6159 } catch (RuntimeException e) {
6160 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6161 }
6162 }
6163
6164 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006165 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006166 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006167 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006168 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006169 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006171 final long identity = Binder.clearCallingIdentity();
6172 try {
chen xub97461a2018-10-26 14:17:57 -07006173 TelephonyPermissions
6174 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6175 mApp, phone.getSubId(), "getRadioAccessFamily");
6176 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 } finally {
6178 Binder.restoreCallingIdentity(identity);
6179 }
chen xub97461a2018-10-26 14:17:57 -07006180 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006181 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006182
6183 @Override
6184 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006185 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006190 ImsManager.getInstance(defaultPhone.getContext(),
6191 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006192 } finally {
6193 Binder.restoreCallingIdentity(identity);
6194 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006195 }
6196
6197 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006198 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006199 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006200 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6201 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006202 return false;
6203 }
Svet Ganovb320e182015-04-16 12:30:10 -07006204
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006205 final long identity = Binder.clearCallingIdentity();
6206 try {
6207 // Check the user preference and the system-level IMS setting. Even if the user has
6208 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6209 // In the long run, we may instead need to check if there exists a connection service
6210 // which can support video calling.
6211 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006212 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006213 return imsManager.isVtEnabledByPlatform()
6214 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6215 && imsManager.isVtEnabledByUser();
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
6218 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006219 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006220
Andrew Leea1239f22015-03-02 17:44:07 -08006221 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006222 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6223 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006225 mApp, subId, callingPackage, callingFeatureId,
6226 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006227 return false;
6228 }
6229
6230 final long identity = Binder.clearCallingIdentity();
6231 try {
6232 CarrierConfigManager configManager =
6233 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006234 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006235 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6236 } finally {
6237 Binder.restoreCallingIdentity(identity);
6238 }
Andrew Leea1239f22015-03-02 17:44:07 -08006239 }
6240
6241 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006242 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006243 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006244 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006245 return false;
6246 }
6247
6248 final long identity = Binder.clearCallingIdentity();
6249 try {
6250 CarrierConfigManager configManager =
6251 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006252 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006253 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6254 } finally {
6255 Binder.restoreCallingIdentity(identity);
6256 }
Andrew Leea1239f22015-03-02 17:44:07 -08006257 }
6258
Andrew Lee9431b832015-03-09 18:46:45 -07006259 @Override
6260 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006261 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006262 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006263 }
6264
6265 @Override
6266 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267 final long identity = Binder.clearCallingIdentity();
6268 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006269 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270 } finally {
6271 Binder.restoreCallingIdentity(identity);
6272 }
Andrew Lee9431b832015-03-09 18:46:45 -07006273 }
6274
Hall Liuf6668912018-10-31 17:05:23 -07006275 /**
6276 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6277 * support for the feature and device firmware support.
6278 *
6279 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6280 */
6281 @Override
6282 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006284 final Phone phone = getPhone(subscriptionId);
6285 if (phone == null) {
6286 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6287 return false;
6288 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006289 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006290 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006291 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6292 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006293 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294 return isCarrierSupported && isDeviceSupported;
6295 } finally {
6296 Binder.restoreCallingIdentity(identity);
6297 }
Hall Liu98187582018-01-22 19:15:32 -08006298 }
6299
Hall Liuf6668912018-10-31 17:05:23 -07006300 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006301 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6302 * RTT setting, will return true if the device and carrier both support RTT.
6303 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006304 */
6305 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306 final long identity = Binder.clearCallingIdentity();
6307 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006308 boolean isRttSupported = isRttSupported(subscriptionId);
6309 boolean isUserRttSettingOn = Settings.Secure.getInt(
6310 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6311 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6312 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6313 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 } finally {
6315 Binder.restoreCallingIdentity(identity);
6316 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006317 }
6318
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006319 @Deprecated
6320 @Override
6321 public String getDeviceId(String callingPackage) {
6322 return getDeviceIdWithFeature(callingPackage, null);
6323 }
6324
Sanket Padawe7310cc72015-01-14 09:53:20 -08006325 /**
6326 * Returns the unique device ID of phone, for example, the IMEI for
6327 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6328 *
6329 * <p>Requires Permission:
6330 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6331 */
6332 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006333 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006334 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006335 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006336 return null;
6337 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006338 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006339 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006340 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006341 return null;
6342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343
6344 final long identity = Binder.clearCallingIdentity();
6345 try {
6346 return phone.getDeviceId();
6347 } finally {
6348 Binder.restoreCallingIdentity(identity);
6349 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006350 }
6351
Ping Sunc67b7c22016-03-02 19:16:45 +08006352 /**
6353 * {@hide}
6354 * Returns the IMS Registration Status on a particular subid
6355 *
6356 * @param subId
6357 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006358 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006359 Phone phone = getPhone(subId);
6360 if (phone != null) {
6361 return phone.isImsRegistered();
6362 } else {
6363 return false;
6364 }
6365 }
6366
Santos Cordon7a1885b2015-02-03 11:15:19 -08006367 @Override
6368 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006369 final long identity = Binder.clearCallingIdentity();
6370 try {
6371 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6372 } finally {
6373 Binder.restoreCallingIdentity(identity);
6374 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006375 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006376
Tyler Gunnf70ed162019-04-03 15:28:53 -07006377 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006378 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006379 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006380 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006381 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006382 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6383 }
6384 final long identity = Binder.clearCallingIdentity();
6385 try {
6386 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6387 } finally {
6388 Binder.restoreCallingIdentity(identity);
6389 }
6390 }
6391
6392 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006393 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6394 final long identity = Binder.clearCallingIdentity();
6395 try {
6396 Phone phone = getPhone(subscriptionId);
6397 if (phone == null) {
6398 return null;
6399 }
6400 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6401 } finally {
6402 Binder.restoreCallingIdentity(identity);
6403 }
6404 }
6405
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006406 /**
6407 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006408 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006409 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 final long identity = Binder.clearCallingIdentity();
6411 try {
6412 Phone phone = getPhone(subId);
6413 if (phone != null) {
6414 return phone.isWifiCallingEnabled();
6415 } else {
6416 return false;
6417 }
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006420 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006421 }
6422
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006423 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006424 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006425 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006426 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 final long identity = Binder.clearCallingIdentity();
6428 try {
6429 Phone phone = getPhone(subId);
6430 if (phone != null) {
6431 return phone.isVideoEnabled();
6432 } else {
6433 return false;
6434 }
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006437 }
6438 }
6439
6440 /**
6441 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6442 * defined in {@link ImsRegistrationImplBase}.
6443 */
6444 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 final long identity = Binder.clearCallingIdentity();
6446 try {
6447 Phone phone = getPhone(subId);
6448 if (phone != null) {
6449 return phone.getImsRegistrationTech();
6450 } else {
6451 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6452 }
6453 } finally {
6454 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006455 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006456 }
6457
Stuart Scott8eef64f2015-04-08 15:13:54 -07006458 @Override
6459 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006460 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006461 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6462 return;
6463 }
6464
Svet Ganovcc087f82015-05-12 20:35:54 -07006465 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006466
Svet Ganovcc087f82015-05-12 20:35:54 -07006467 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006468 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6469 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006470 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006471 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006472 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006473 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6474 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006475 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006476 // There has been issues when Sms raw table somehow stores orphan
6477 // fragments. They lead to garbled message when new fragments come
6478 // in and combined with those stale ones. In case this happens again,
6479 // user can reset all network settings which will clean up this table.
6480 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006481 // Clean up IMS settings as well here.
6482 int slotId = getSlotIndex(subId);
6483 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6484 ImsManager.getInstance(mApp, slotId).factoryReset();
6485 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006486
6487 // Erase modem config if erase modem on network setting is enabled.
6488 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6489 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6490 if (configValue != null && Boolean.parseBoolean(configValue)) {
6491 sendEraseModemConfig(getDefaultPhone());
6492 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006493 } finally {
6494 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006495 }
6496 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006497
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006498 private void cleanUpSmsRawTable(Context context) {
6499 ContentResolver resolver = context.getContentResolver();
6500 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6501 resolver.delete(uri, null, null);
6502 }
6503
Narayan Kamath1c496c22015-04-16 14:40:19 +01006504 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006505 public String getSimLocaleForSubscriber(int subId) {
6506 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6507 final Phone phone = getPhone(subId);
6508 if (phone == null) {
6509 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006510 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006511 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006512 final long identity = Binder.clearCallingIdentity();
6513 try {
chen xu5d3637b2019-01-21 23:31:38 -08006514 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006515 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006516 if (info == null) {
6517 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6518 return null;
6519 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006520 // Try and fetch the locale from the carrier properties or from the SIM language
6521 // preferences (EF-PL and EF-LI)...
6522 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006523 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006524 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6525 if (localeFromDefaultSim != null) {
6526 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6527 if (DBG) log("Using locale from subId: " + subId + " locale: "
6528 + localeFromDefaultSim);
6529 return localeFromDefaultSim.toLanguageTag();
6530 } else {
6531 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006532 }
6533 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006534
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 // The SIM language preferences only store a language (e.g. fr = French), not an
6536 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6537 // the SIM and carrier preferences does not include a country we add the country
6538 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006539 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006540 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006541 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 return mccLocale.toLanguageTag();
6543 }
6544
6545 if (DBG) log("No locale found - returning null");
6546 return null;
6547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006550 }
6551
6552 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006553 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6554 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006555 }
6556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006557 /**
6558 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6559 */
6560 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006561 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6562 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006563 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006564
Chenjie Yu1ba97252018-01-11 18:16:20 -08006565 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006566 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006567
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006568 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006569 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6570 * representing the state of the modem.
6571 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006572 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6573 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006574 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006575 */
6576 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006577 public void requestModemActivityInfo(ResultReceiver result) {
6578 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006579 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006580
6581 final long identity = Binder.clearCallingIdentity();
6582 try {
6583 ModemActivityInfo ret = null;
6584 synchronized (mLastModemActivityInfo) {
6585 ModemActivityInfo info = (ModemActivityInfo) sendRequest(
6586 CMD_GET_MODEM_ACTIVITY_INFO,
vagdeviaf9a5b92018-08-15 16:01:53 -07006587 null, workSource);
Siddharth Rayb8114062018-06-17 15:02:38 -07006588 if (isModemActivityInfoValid(info)) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
Chen Xu13851032019-09-10 18:49:52 -07006590 int[] txTimeMs = info.getTransmitTimeMillis();
6591 int[] lastModemTxTimeMs = mLastModemActivityInfo.getTransmitTimeMillis();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006592 for (int i = 0; i < mergedTxTimeMs.length; i++) {
Chen Xu13851032019-09-10 18:49:52 -07006593 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006594 }
6595 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006596 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
6597 + mLastModemActivityInfo.getSleepTimeMillis());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 mLastModemActivityInfo.setIdleTimeMillis(
6599 info.getIdleTimeMillis() + mLastModemActivityInfo.getIdleTimeMillis());
Chen Xu13851032019-09-10 18:49:52 -07006600 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
6601 mLastModemActivityInfo.setReceiveTimeMillis(
6602 info.getReceiveTimeMillis() + mLastModemActivityInfo
6603 .getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006604 }
Chen Xu13851032019-09-10 18:49:52 -07006605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006606 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
6607 mLastModemActivityInfo.getSleepTimeMillis(),
6608 mLastModemActivityInfo.getIdleTimeMillis(),
Chen Xu13851032019-09-10 18:49:52 -07006609 mLastModemActivityInfo.getTransmitTimeMillis(),
6610 mLastModemActivityInfo.getReceiveTimeMillis());
Chenjie Yu1ba97252018-01-11 18:16:20 -08006611 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 Bundle bundle = new Bundle();
6613 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
6614 result.send(0, bundle);
6615 } finally {
6616 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006617 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006618 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006619
Siddharth Rayb8114062018-06-17 15:02:38 -07006620 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6621 // less than total activity duration.
6622 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6623 if (info == null) {
6624 return false;
6625 }
6626 int activityDurationMs =
6627 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6628 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006629 int[] txTimeMs = info.getTransmitTimeMillis();
6630 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6631 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006632 }
6633 return (info.isValid()
6634 && (info.getSleepTimeMillis() <= activityDurationMs)
6635 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006636 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006637 && (totalTxTimeMs <= activityDurationMs));
6638 }
6639
Jack Yu85bd38a2015-11-09 11:34:32 -08006640 /**
6641 * {@hide}
6642 * Returns the service state information on specified subscription.
6643 */
6644 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006645 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6646 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006647 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006648 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006649 return null;
6650 }
6651
Hall Liuf19c44f2018-11-27 14:38:17 -08006652 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6653 LocationAccessPolicy.checkLocationPermission(mApp,
6654 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6655 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006656 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006657 .setCallingPid(Binder.getCallingPid())
6658 .setCallingUid(Binder.getCallingUid())
6659 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006660 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006661 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6662 .build());
6663
6664 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6665 LocationAccessPolicy.checkLocationPermission(mApp,
6666 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6667 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006668 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006669 .setCallingPid(Binder.getCallingPid())
6670 .setCallingUid(Binder.getCallingUid())
6671 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006672 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006673 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6674 .build());
6675 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6676 boolean hasFinePermission =
6677 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6678 boolean hasCoarsePermission =
6679 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 final Phone phone = getPhone(subId);
6684 if (phone == null) {
6685 return null;
6686 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006687
Hall Liuf19c44f2018-11-27 14:38:17 -08006688 ServiceState ss = phone.getServiceState();
6689
6690 // Scrub out the location info in ServiceState depending on what level of access
6691 // the caller has.
6692 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006693 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6694 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006695 } finally {
6696 Binder.restoreCallingIdentity(identity);
6697 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006698 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006699
6700 /**
6701 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6702 *
6703 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6704 * voicemail ringtone.
6705 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6706 * PhoneAccount.
6707 */
6708 @Override
6709 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 final long identity = Binder.clearCallingIdentity();
6711 try {
6712 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6713 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006714 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006716
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6718 } finally {
6719 Binder.restoreCallingIdentity(identity);
6720 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006721 }
6722
6723 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006724 * Sets the per-account voicemail ringtone.
6725 *
6726 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6727 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6728 *
6729 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6730 * voicemail ringtone.
6731 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6732 * PhoneAccount.
6733 */
6734 @Override
6735 public void setVoicemailRingtoneUri(String callingPackage,
6736 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006737 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006738 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006739 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6740 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006741 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6742 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6743 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006744 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745
6746 final long identity = Binder.clearCallingIdentity();
6747 try {
6748 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6749 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006750 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751 }
6752 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6753 } finally {
6754 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006755 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006756 }
6757
6758 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006759 * Returns whether vibration is set for voicemail notification in Phone settings.
6760 *
6761 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6762 * voicemail vibration setting.
6763 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6764 */
6765 @Override
6766 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6770 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006771 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006773
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006774 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
6777 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006778 }
6779
Youhan Wange64578a2016-05-02 15:32:42 -07006780 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006781 * Sets the per-account voicemail vibration.
6782 *
6783 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6784 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6785 *
6786 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6787 * voicemail vibration setting.
6788 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6789 * specific PhoneAccount.
6790 */
6791 @Override
6792 public void setVoicemailVibrationEnabled(String callingPackage,
6793 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006794 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006795 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006796 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6797 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006798 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6799 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6800 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006801 }
6802
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006803 final long identity = Binder.clearCallingIdentity();
6804 try {
6805 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6806 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006807 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808 }
6809 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6810 } finally {
6811 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006812 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006813 }
6814
6815 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006816 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6817 *
6818 * @throws SecurityException if the caller does not have the required permission
6819 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006820 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006821 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006822 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006823 }
6824
6825 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006826 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6827 * permission.
6828 *
6829 * @throws SecurityException if the caller does not have the required permission
6830 */
6831 private void enforceSendSmsPermission() {
6832 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6833 }
6834
6835 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006836 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006837 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006838 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006839 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006840 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 final long identity = Binder.clearCallingIdentity();
6842 try {
6843 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006844 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006845 if (componentName == null) {
6846 throw new SecurityException(
6847 "Caller not current active visual voicemail package[null]");
6848 }
6849 String vvmPackage = componentName.getPackageName();
6850 if (!callingPackage.equals(vvmPackage)) {
6851 throw new SecurityException("Caller not current active visual voicemail package["
6852 + vvmPackage + "]");
6853 }
6854 } finally {
6855 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006856 }
6857 }
6858
6859 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006860 * Return the application ID for the app type.
6861 *
6862 * @param subId the subscription ID that this request applies to.
6863 * @param appType the uicc app type.
6864 * @return Application ID for specificied app type, or null if no uicc.
6865 */
6866 @Override
6867 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006868 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006869 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006870
6871 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006872 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 if (phone == null) {
6874 return null;
6875 }
6876 String aid = null;
6877 try {
6878 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6879 .getApplicationByType(appType).getAid();
6880 } catch (Exception e) {
6881 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6882 }
6883 return aid;
6884 } finally {
6885 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006886 }
Youhan Wange64578a2016-05-02 15:32:42 -07006887 }
6888
Youhan Wang4001d252016-05-11 10:29:41 -07006889 /**
6890 * Return the Electronic Serial Number.
6891 *
6892 * @param subId the subscription ID that this request applies to.
6893 * @return ESN or null if error.
6894 */
6895 @Override
6896 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006897 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006898 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899
6900 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07006901 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902 if (phone == null) {
6903 return null;
6904 }
6905 String esn = null;
6906 try {
6907 esn = phone.getEsn();
6908 } catch (Exception e) {
6909 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
6910 }
6911 return esn;
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07006914 }
Youhan Wang4001d252016-05-11 10:29:41 -07006915 }
6916
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006917 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07006918 * Return the Preferred Roaming List Version.
6919 *
6920 * @param subId the subscription ID that this request applies to.
6921 * @return PRLVersion or null if error.
6922 */
6923 @Override
6924 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006925 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07006926 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927
6928 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07006929 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 if (phone == null) {
6931 return null;
6932 }
6933 String cdmaPrlVersion = null;
6934 try {
6935 cdmaPrlVersion = phone.getCdmaPrlVersion();
6936 } catch (Exception e) {
6937 Log.e(LOG_TAG, "Not getting PRLVersion", e);
6938 }
6939 return cdmaPrlVersion;
6940 } finally {
6941 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07006942 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07006943 }
6944
6945 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006946 * Get snapshot of Telephony histograms
6947 * @return List of Telephony histograms
6948 * @hide
6949 */
6950 @Override
6951 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6953 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 return RIL.getTelephonyRILTimingHistograms();
6958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07006961 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006962
6963 /**
6964 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006965 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
6966 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006967 * Require system privileges. In the future we may add this to carrier APIs.
6968 *
Michele Berionne482f8202018-11-27 18:57:59 -08006969 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006970 */
6971 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006972 @TelephonyManager.SetCarrierRestrictionResult
6973 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07006974 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006976
Michele Berionne482f8202018-11-27 18:57:59 -08006977 if (carrierRestrictionRules == null) {
6978 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08006979 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07006980
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 final long identity = Binder.clearCallingIdentity();
6982 try {
Michele Berionne482f8202018-11-27 18:57:59 -08006983 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07006984 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 } finally {
6986 Binder.restoreCallingIdentity(identity);
6987 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07006988 }
6989
6990 /**
6991 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08006992 * Get the allowed carrier list and the excluded carrier list, including the priority between
6993 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07006994 * Require system privileges. In the future we may add this to carrier APIs.
6995 *
Michele Berionne482f8202018-11-27 18:57:59 -08006996 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07006997 */
6998 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08006999 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007000 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007001 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002
7003 final long identity = Binder.clearCallingIdentity();
7004 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007005 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7006 if (response instanceof CarrierRestrictionRules) {
7007 return (CarrierRestrictionRules) response;
7008 }
7009 // Response is an Exception of some kind,
7010 // which is signalled to the user as a NULL retval
7011 return null;
7012 } catch (Exception e) {
7013 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7014 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 } finally {
7016 Binder.restoreCallingIdentity(identity);
7017 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007018 }
7019
fionaxu59545b42016-05-25 15:53:37 -07007020 /**
7021 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7022 * @param subId the subscription ID that this action applies to.
7023 * @param enabled control enable or disable metered apns.
7024 * {@hide}
7025 */
7026 @Override
7027 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7028 enforceModifyPermission();
7029 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030
7031 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007032 if (phone == null) {
7033 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7034 return;
7035 }
7036 try {
7037 phone.carrierActionSetMeteredApnsEnabled(enabled);
7038 } catch (Exception e) {
7039 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 } finally {
7041 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007042 }
7043 }
7044
7045 /**
7046 * Action set from carrier signalling broadcast receivers to enable/disable radio
7047 * @param subId the subscription ID that this action applies to.
7048 * @param enabled control enable or disable radio.
7049 * {@hide}
7050 */
7051 @Override
7052 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7053 enforceModifyPermission();
7054 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055
7056 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007057 if (phone == null) {
7058 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7059 return;
7060 }
7061 try {
7062 phone.carrierActionSetRadioEnabled(enabled);
7063 } catch (Exception e) {
7064 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 } finally {
7066 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007067 }
7068 }
7069
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007070 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007071 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7072 * network status based on which carrier apps could apply actions accordingly,
7073 * enable/disable default url handler for example.
7074 *
7075 * @param subId the subscription ID that this action applies to.
7076 * @param report control start/stop reporting the default network status.
7077 * {@hide}
7078 */
7079 @Override
7080 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7081 enforceModifyPermission();
7082 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007083
7084 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007085 if (phone == null) {
7086 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7087 return;
7088 }
7089 try {
7090 phone.carrierActionReportDefaultNetworkStatus(report);
7091 } catch (Exception e) {
7092 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007093 } finally {
7094 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007095 }
7096 }
7097
7098 /**
fionaxud9622282017-07-17 17:51:30 -07007099 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7100 * @param subId the subscription ID that this action applies to.
7101 * {@hide}
7102 */
7103 @Override
7104 public void carrierActionResetAll(int subId) {
7105 enforceModifyPermission();
7106 final Phone phone = getPhone(subId);
7107 if (phone == null) {
7108 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7109 return;
7110 }
7111 try {
7112 phone.carrierActionResetAll();
7113 } catch (Exception e) {
7114 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7115 }
7116 }
7117
7118 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007119 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7120 * bug report is being generated.
7121 */
7122 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007123 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007124 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7125 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007126 writer.println("Permission Denial: can't dump Phone from pid="
7127 + Binder.getCallingPid()
7128 + ", uid=" + Binder.getCallingUid()
7129 + "without permission "
7130 + android.Manifest.permission.DUMP);
7131 return;
7132 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007133 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007134 }
Jack Yueb89b242016-06-22 13:27:47 -07007135
Brad Ebingerdac2f002018-04-03 15:17:52 -07007136 @Override
7137 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7138 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7139 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007140 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7141 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007142 }
7143
Jack Yueb89b242016-06-22 13:27:47 -07007144 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007145 * Policy control of data connection. Usually used when data limit is passed.
7146 * @param enabled True if enabling the data, otherwise disabling.
7147 * @param subId Subscription index
7148 * {@hide}
7149 */
7150 @Override
7151 public void setPolicyDataEnabled(boolean enabled, int subId) {
7152 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007153
7154 final long identity = Binder.clearCallingIdentity();
7155 try {
7156 Phone phone = getPhone(subId);
7157 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007158 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 }
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007162 }
7163 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007164
7165 /**
7166 * Get Client request stats
7167 * @return List of Client Request Stats
7168 * @hide
7169 */
7170 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007171 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7172 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007173 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007174 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007175 return null;
7176 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007177 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007178
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 if (phone != null) {
7182 return phone.getClientRequestStats();
7183 }
7184
7185 return null;
7186 } finally {
7187 Binder.restoreCallingIdentity(identity);
7188 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007189 }
7190
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007191 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007192 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007193 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007194 }
Jack Yueb4124c2017-02-16 15:32:43 -08007195
7196 /**
Grace Chen70990072017-03-24 17:21:30 -07007197 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007198 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007199 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007200 * @param state State of SIM (power down, power up, pass through)
7201 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7202 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7203 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007204 *
7205 **/
7206 @Override
Grace Chen70990072017-03-24 17:21:30 -07007207 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007208 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007209 Phone phone = PhoneFactory.getPhone(slotIndex);
7210
vagdeviaf9a5b92018-08-15 16:01:53 -07007211 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007213 final long identity = Binder.clearCallingIdentity();
7214 try {
7215 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007216 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 }
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007220 }
7221 }
Shuo Qiandd210312017-04-12 22:11:33 +00007222
Tyler Gunn65d45c22017-06-05 11:22:26 -07007223 private boolean isUssdApiAllowed(int subId) {
7224 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007226 if (configManager == null) {
7227 return false;
7228 }
7229 PersistableBundle pb = configManager.getConfigForSubId(subId);
7230 if (pb == null) {
7231 return false;
7232 }
7233 return pb.getBoolean(
7234 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7235 }
7236
Shuo Qiandd210312017-04-12 22:11:33 +00007237 /**
7238 * Check if phone is in emergency callback mode
7239 * @return true if phone is in emergency callback mode
7240 * @param subId sub id
7241 */
goneil9c5f4872017-12-05 14:07:56 -08007242 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007243 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007244 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007245 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007246
7247 final long identity = Binder.clearCallingIdentity();
7248 try {
7249 if (phone != null) {
7250 return phone.isInEcm();
7251 } else {
7252 return false;
7253 }
7254 } finally {
7255 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007256 }
7257 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007258
7259 /**
7260 * Get the current signal strength information for the given subscription.
7261 * Because this information is not updated when the device is in a low power state
7262 * it should not be relied-upon to be current.
7263 * @param subId Subscription index
7264 * @return the most recent cached signal strength info from the modem
7265 */
7266 @Override
7267 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007268 final long identity = Binder.clearCallingIdentity();
7269 try {
7270 Phone p = getPhone(subId);
7271 if (p == null) {
7272 return null;
7273 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007274
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 return p.getSignalStrength();
7276 } finally {
7277 Binder.restoreCallingIdentity(identity);
7278 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007279 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007280
Pengquan Meng77b7f132018-08-22 14:49:57 -07007281 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007282 * Get the current modem radio state for the given slot.
7283 * @param slotIndex slot index.
7284 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007285 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007286 * @return the current radio power state from the modem
7287 */
7288 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007289 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007290 Phone phone = PhoneFactory.getPhone(slotIndex);
7291 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007292 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7293 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007294 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7295 }
7296
7297 final long identity = Binder.clearCallingIdentity();
7298 try {
7299 return phone.getRadioPowerState();
7300 } finally {
7301 Binder.restoreCallingIdentity(identity);
7302 }
7303 }
7304 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7305 }
7306
7307 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007308 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7309 *
7310 * <p>Requires one of the following permissions:
7311 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7312 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7313 * privileges.
7314 *
7315 * @param subId subscription id
7316 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7317 * {@code false}.
7318 */
7319 @Override
7320 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007321 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7322 null /* message */);
7323
Pengquan Menga1bb6272018-09-06 09:59:22 -07007324 boolean isEnabled = false;
7325 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007326 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007327 Phone phone = getPhone(subId);
7328 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007329 } catch (Exception e) {
7330 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7331 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007332 } finally {
7333 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007334 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007335 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007336 }
7337
7338
7339 /**
7340 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7341 *
7342 * <p> Requires permission:
7343 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7344 * privileges.
7345 *
7346 * @param subId subscription id
7347 * @param isEnabled {@code true} means enable, {@code false} means disable.
7348 */
7349 @Override
7350 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007351 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7352 mApp, subId, "setDataRoamingEnabled");
7353
Pengquan Menga1bb6272018-09-06 09:59:22 -07007354 final long identity = Binder.clearCallingIdentity();
7355 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007356 Phone phone = getPhone(subId);
7357 if (phone != null) {
7358 phone.setDataRoamingEnabled(isEnabled);
7359 }
7360 } finally {
7361 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007362 }
7363 }
7364
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007365 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007366 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007367 TelephonyPermissions
7368 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007369 mApp, subId, "isManualNetworkSelectionAllowed");
7370
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007371 boolean isAllowed = true;
7372 final long identity = Binder.clearCallingIdentity();
7373 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007374 Phone phone = getPhone(subId);
7375 if (phone != null) {
7376 isAllowed = phone.isCspPlmnEnabled();
7377 }
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
7381 return isAllowed;
7382 }
7383
7384 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007385 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007386 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007387 try {
7388 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007389 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007390 } catch (SecurityException e) {
7391 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7392 // has carrier privileges on an active UICC
7393 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7394 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007395 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007396 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007397 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007398
7399 final long identity = Binder.clearCallingIdentity();
7400 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007401 UiccController uiccController = UiccController.getInstance();
7402 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007403 if (hasReadPermission) {
7404 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007405 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007406
7407 // Remove private info if the caller doesn't have access
7408 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7409 for (UiccCardInfo cardInfo : cardInfos) {
7410 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7411 // is available
7412 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7413 if (card == null || card.getUiccProfile() == null) {
7414 // assume no access if the card or profile is unavailable
7415 filteredInfos.add(cardInfo.getUnprivileged());
7416 continue;
7417 }
7418 UiccProfile profile = card.getUiccProfile();
7419 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7420 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7421 filteredInfos.add(cardInfo);
7422 } else {
7423 filteredInfos.add(cardInfo.getUnprivileged());
7424 }
7425 }
7426 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007427 } finally {
7428 Binder.restoreCallingIdentity(identity);
7429 }
7430 }
7431
7432 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007433 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007434 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007435
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7439 if (slots == null) {
7440 Rlog.i(LOG_TAG, "slots is null.");
7441 return null;
7442 }
7443
7444 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7445 for (int i = 0; i < slots.length; i++) {
7446 UiccSlot slot = slots[i];
7447 if (slot == null) {
7448 continue;
7449 }
7450
Jordan Liu7be7e652019-05-06 18:55:02 +00007451 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007452 UiccCard card = slot.getUiccCard();
7453 if (card != null) {
7454 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007455 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007456 cardId = slot.getEid();
7457 if (TextUtils.isEmpty(cardId)) {
7458 cardId = slot.getIccId();
7459 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 }
7461
Jordan Liu857451f2019-05-09 16:35:35 -07007462 if (cardId != null) {
7463 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7464 // if cardId is an EID, it's all digits so this is fine
7465 cardId = IccUtils.stripTrailingFs(cardId);
7466 }
7467
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007468 int cardState = 0;
7469 switch (slot.getCardState()) {
7470 case CARDSTATE_ABSENT:
7471 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7472 break;
7473 case CARDSTATE_PRESENT:
7474 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7475 break;
7476 case CARDSTATE_ERROR:
7477 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7478 break;
7479 case CARDSTATE_RESTRICTED:
7480 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7481 break;
7482 default:
7483 break;
7484
7485 }
7486
7487 infos[i] = new UiccSlotInfo(
7488 slot.isActive(),
7489 slot.isEuicc(),
7490 cardId,
7491 cardState,
7492 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007493 slot.isExtendedApduSupported(),
7494 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 }
7496 return infos;
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007499 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007500 }
7501
7502 @Override
7503 public boolean switchSlots(int[] physicalSlots) {
7504 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505
7506 final long identity = Binder.clearCallingIdentity();
7507 try {
7508 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
7511 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007512 }
Jack Yu4c988042018-02-27 15:30:01 -08007513
7514 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007515 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007516 final long identity = Binder.clearCallingIdentity();
7517 try {
7518 return UiccController.getInstance().getCardIdForDefaultEuicc();
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
7522 }
7523
7524 @Override
Jack Yu4c988042018-02-27 15:30:01 -08007525 public void setRadioIndicationUpdateMode(int subId, int filters, int mode) {
7526 enforceModifyPermission();
7527 final Phone phone = getPhone(subId);
7528 if (phone == null) {
7529 loge("setRadioIndicationUpdateMode fails with invalid subId: " + subId);
7530 return;
7531 }
7532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007533 final long identity = Binder.clearCallingIdentity();
7534 try {
7535 phone.setRadioIndicationUpdateMode(filters, mode);
7536 } finally {
7537 Binder.restoreCallingIdentity(identity);
7538 }
Jack Yu4c988042018-02-27 15:30:01 -08007539 }
Pengquan Meng85728fb2018-03-12 16:31:21 -07007540
7541 /**
goneil47ffb6e2018-04-06 15:40:58 -07007542 * A test API to reload the UICC profile.
7543 *
7544 * <p>Requires that the calling app has permission
7545 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7546 * @hide
7547 */
7548 @Override
7549 public void refreshUiccProfile(int subId) {
7550 enforceModifyPermission();
7551
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
7554 Phone phone = getPhone(subId);
7555 if (phone == null) {
7556 return;
7557 }
7558 UiccCard uiccCard = phone.getUiccCard();
7559 if (uiccCard == null) {
7560 return;
7561 }
7562 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7563 if (uiccProfile == null) {
7564 return;
7565 }
7566 uiccProfile.refresh();
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
7569 }
7570 }
7571
7572 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007573 * Returns false if the mobile data is disabled by default, otherwise return true.
7574 */
7575 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007576 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007577 }
7578
7579 /**
7580 * Returns true if the data roaming is enabled by default, i.e the system property
7581 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7582 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7583 */
7584 private boolean getDefaultDataRoamingEnabled(int subId) {
7585 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007586 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim8d298d42018-12-13 17:11:34 +09007587 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007588 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7589 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7590 return isDataRoamingEnabled;
7591 }
7592
7593 /**
7594 * Returns the default network type for the given {@code subId}, if the default network type is
7595 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7596 */
7597 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007598 List<Integer> list = TelephonyProperties.default_network();
7599 int phoneId = mSubscriptionController.getPhoneId(subId);
7600 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7601 return list.get(phoneId);
7602 }
7603 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007604 }
fionaxua13278b2018-03-21 00:08:13 -07007605
7606 @Override
7607 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007608 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610
7611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 final Phone phone = getPhone(subId);
7614 if (phone == null) {
7615 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7616 return;
7617 }
chen xueaba88a2019-03-15 13:15:10 -07007618 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7619 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620 } finally {
7621 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007622 }
fionaxua13278b2018-03-21 00:08:13 -07007623 }
7624
7625 @Override
7626 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007627 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628
7629 final long identity = Binder.clearCallingIdentity();
7630 try {
7631 final Phone phone = getPhone(subId);
7632 if (phone == null) {
7633 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7634 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7635 }
7636 return phone.getCarrierIdListVersion();
7637 } finally {
7638 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007639 }
fionaxua13278b2018-03-21 00:08:13 -07007640 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007641
7642 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007643 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7644 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007645 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007646 mApp, subId, callingPackage, callingFeatureId,
7647 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007648 return -1;
7649 }
7650
7651 final long identity = Binder.clearCallingIdentity();
7652 try {
7653 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
7656 }
7657 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007658
7659 @Override
7660 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007661 TelephonyPermissions
7662 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007663 mApp, subId, "getCdmaRoamingMode");
7664
7665 final long identity = Binder.clearCallingIdentity();
7666 try {
7667 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7668 } finally {
7669 Binder.restoreCallingIdentity(identity);
7670 }
7671 }
7672
7673 @Override
7674 public boolean setCdmaRoamingMode(int subId, int mode) {
7675 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7676 mApp, subId, "setCdmaRoamingMode");
7677
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
7684 }
7685
7686 @Override
7687 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7688 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7689 mApp, subId, "setCdmaSubscriptionMode");
7690
7691 final long identity = Binder.clearCallingIdentity();
7692 try {
7693 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
7697 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007698
sqianc5eccab2018-10-19 18:46:41 -07007699 @Override
sqian8c685422019-02-22 15:55:18 -08007700 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007701 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007703 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7704 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007705 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7706 }
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
sqian854d44b2018-12-12 16:48:18 -08007709 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7710 for (Phone phone: PhoneFactory.getPhones()) {
7711 if (phone.getEmergencyNumberTracker() != null
7712 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7713 emergencyNumberListInternal.put(
7714 phone.getSubId(),
7715 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7716 }
sqian11b7a0e2018-12-05 18:48:28 -08007717 }
sqian854d44b2018-12-12 16:48:18 -08007718 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007719 } finally {
7720 Binder.restoreCallingIdentity(identity);
7721 }
sqianc5eccab2018-10-19 18:46:41 -07007722 }
7723
7724 @Override
sqian8c685422019-02-22 15:55:18 -08007725 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007727 if (!exactMatch) {
7728 TelephonyPermissions
7729 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007730 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007731 }
7732 final long identity = Binder.clearCallingIdentity();
7733 try {
sqian854d44b2018-12-12 16:48:18 -08007734 for (Phone phone: PhoneFactory.getPhones()) {
7735 if (phone.getEmergencyNumberTracker() != null
7736 && phone.getEmergencyNumberTracker() != null) {
7737 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7738 number, exactMatch)) {
7739 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007740 }
7741 }
sqian11b7a0e2018-12-05 18:48:28 -08007742 }
7743 return false;
7744 } finally {
7745 Binder.restoreCallingIdentity(identity);
7746 }
7747 }
7748
sqianf4ca7ed2019-01-15 18:32:07 -08007749 /**
7750 * Update emergency number list for test mode.
7751 */
7752 @Override
7753 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7754 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7755 "updateEmergencyNumberListTestMode");
7756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
7759 for (Phone phone: PhoneFactory.getPhones()) {
7760 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7761 if (tracker != null) {
7762 tracker.executeEmergencyNumberTestModeCommand(action, num);
7763 }
7764 }
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
7768 }
7769
7770 /**
7771 * Get the full emergency number list for test mode.
7772 */
7773 @Override
7774 public List<String> getEmergencyNumberListTestMode() {
7775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7776 "getEmergencyNumberListTestMode");
7777
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 Set<String> emergencyNumbers = new HashSet<>();
7781 for (Phone phone: PhoneFactory.getPhones()) {
7782 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7783 if (tracker != null) {
7784 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7785 emergencyNumbers.add(num.getNumber());
7786 }
7787 }
7788 }
7789 return new ArrayList<>(emergencyNumbers);
7790 } finally {
7791 Binder.restoreCallingIdentity(identity);
7792 }
7793 }
7794
chen xud6b45bd2018-10-30 22:27:10 -07007795 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007796 public int getEmergencyNumberDbVersion(int subId) {
7797 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7798
7799 final long identity = Binder.clearCallingIdentity();
7800 try {
7801 final Phone phone = getPhone(subId);
7802 if (phone == null) {
7803 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7804 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7805 }
7806 return phone.getEmergencyNumberDbVersion();
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
7810 }
7811
7812 @Override
7813 public void notifyOtaEmergencyNumberDbInstalled() {
7814 enforceModifyPermission();
7815
7816 final long identity = Binder.clearCallingIdentity();
7817 try {
7818 for (Phone phone: PhoneFactory.getPhones()) {
7819 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7820 if (tracker != null) {
7821 tracker.updateOtaEmergencyNumberDatabase();
7822 }
7823 }
7824 } finally {
7825 Binder.restoreCallingIdentity(identity);
7826 }
7827 }
7828
7829 @Override
7830 public void updateTestOtaEmergencyNumberDbFilePath(String otaFilePath) {
7831 enforceActiveEmergencySessionPermission();
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 for (Phone phone: PhoneFactory.getPhones()) {
7836 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7837 if (tracker != null) {
7838 tracker.updateTestOtaEmergencyNumberDbFilePath(otaFilePath);
7839 }
7840 }
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
7846 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007847 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7848 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7849 Phone phone = getPhone(subId);
7850 if (phone == null) {
7851 return null;
7852 }
7853 final long identity = Binder.clearCallingIdentity();
7854 try {
7855 UiccProfile profile = UiccController.getInstance()
7856 .getUiccProfileForPhone(phone.getPhoneId());
7857 if (profile != null) {
7858 return profile.getCertsFromCarrierPrivilegeAccessRules();
7859 }
7860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
7863 return null;
7864 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007865
7866 /**
7867 * Enable or disable a modem stack.
7868 */
7869 @Override
7870 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7871 enforceModifyPermission();
7872
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
7875 Phone phone = PhoneFactory.getPhone(slotIndex);
7876 if (phone == null) {
7877 return false;
7878 } else {
7879 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7880 }
7881 } finally {
7882 Binder.restoreCallingIdentity(identity);
7883 }
7884 }
Michelecea4cf22018-12-21 15:00:11 -08007885
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007886 /**
7887 * Whether a modem stack is enabled or not.
7888 */
7889 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007890 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7891 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007892 Phone phone = PhoneFactory.getPhone(slotIndex);
7893 if (phone == null) return false;
7894
7895 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007896 mApp, phone.getSubId(), callingPackage, callingFeatureId,
7897 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007898 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7899 }
7900
7901 final long identity = Binder.clearCallingIdentity();
7902 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07007903 try {
7904 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
7905 } catch (NoSuchElementException ex) {
7906 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
7907 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007908 } finally {
7909 Binder.restoreCallingIdentity(identity);
7910 }
7911 }
7912
Michelecea4cf22018-12-21 15:00:11 -08007913 @Override
Michele0ea7d782019-03-19 14:58:42 -07007914 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08007915 enforceModifyPermission();
7916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07007920 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08007921 .commit();
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
7925 }
7926
7927 @Override
Michele0ea7d782019-03-19 14:58:42 -07007928 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007929 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08007930 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007931 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
7932 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07007933 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08007934 }
Michelecea4cf22018-12-21 15:00:11 -08007935
7936 final long identity = Binder.clearCallingIdentity();
7937 try {
Michele0ea7d782019-03-19 14:58:42 -07007938 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08007939 } finally {
7940 Binder.restoreCallingIdentity(identity);
7941 }
7942 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007943
Michele0ea7d782019-03-19 14:58:42 -07007944 @TelephonyManager.IsMultiSimSupportedResult
7945 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08007946 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
7947 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
7948 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007949 loge("isMultiSimSupportedInternal: requires at least 2 cards");
7950 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007951 }
7952 // Check if the hardware supports multisim functionality. If usage of multisim is not
7953 // supported by the modem, indicate that it is restricted.
7954 PhoneCapability staticCapability =
7955 mPhoneConfigurationManager.getStaticPhoneCapability();
7956 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07007957 loge("isMultiSimSupportedInternal: no static configuration available");
7958 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007959 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00007960 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07007961 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
7962 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08007963 }
7964 // Check if support of multiple SIMs is restricted by carrier
7965 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07007966 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08007967 }
7968
Michele0ea7d782019-03-19 14:58:42 -07007969 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08007970 }
7971
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007972 /**
7973 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007974 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
7975 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
7976 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007977 * @param numOfSims number of active sims we want to switch to
7978 */
7979 @Override
7980 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08007981 if (numOfSims == 1) {
7982 enforceModifyPermission();
7983 } else {
7984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7985 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
7986 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007987 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08007988
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007989 try {
Michele30b57b22019-03-01 12:01:14 -08007990 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07007991 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08007992 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
7993 return;
7994 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08007995 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
7996 } finally {
7997 Binder.restoreCallingIdentity(identity);
7998 }
7999 }
8000
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008001 @Override
8002 public boolean isApplicationOnUicc(int subId, int appType) {
8003 enforceReadPrivilegedPermission("isApplicationOnUicc");
8004 Phone phone = getPhone(subId);
8005 if (phone == null) {
8006 return false;
8007 }
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 UiccCard uiccCard = phone.getUiccCard();
8011 if (uiccCard == null) {
8012 return false;
8013 }
8014 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8015 if (uiccProfile == null) {
8016 return false;
8017 }
8018 if (TelephonyManager.APPTYPE_SIM <= appType
8019 && appType <= TelephonyManager.APPTYPE_ISIM) {
8020 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8021 }
8022 return false;
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
8026 }
8027
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008028 /**
chen xub4baa772019-04-03 10:23:41 -07008029 * Get whether making changes to modem configurations will trigger reboot.
8030 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008031 */
8032 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008033 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8034 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008036 mApp, subId, callingPackage, callingFeatureId,
8037 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008038 return false;
8039 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8043 } finally {
8044 Binder.restoreCallingIdentity(identity);
8045 }
8046 }
8047
Nathan Harold29f5f052019-02-15 13:41:57 -08008048 private void updateModemStateMetrics() {
8049 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8050 // TODO: check the state for each modem if the api is ready.
8051 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8052 }
8053
Pengquan Meng3889a572019-01-23 11:16:29 -08008054 @Override
8055 public int[] getSlotsMapping() {
8056 enforceReadPrivilegedPermission("getSlotsMapping");
8057
8058 final long identity = Binder.clearCallingIdentity();
8059 try {
8060 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8061 // All logical slots should have a mapping to a physical slot.
8062 int[] logicalSlotsMapping = new int[phoneCount];
8063 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8064 for (int i = 0; i < slotInfos.length; i++) {
8065 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8066 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8067 }
8068 }
8069 return logicalSlotsMapping;
8070 } finally {
8071 Binder.restoreCallingIdentity(identity);
8072 }
8073 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008074
8075 /**
8076 * Get the IRadio HAL Version
8077 */
8078 @Override
8079 public int getRadioHalVersion() {
8080 Phone phone = getDefaultPhone();
8081 if (phone == null) return -1;
8082 HalVersion hv = phone.getHalVersion();
8083 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8084 return hv.major * 100 + hv.minor;
8085 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008086
8087 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008088 * Get the current calling package name.
8089 * @return the current calling package name
8090 */
8091 @Override
8092 public String getCurrentPackageName() {
8093 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8094 }
8095
8096 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008097 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8098 * corresponding network requests on a subId.
8099 *
8100 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008101 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008102 * 2) APN is un-metered for this subscription, or
8103 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008104 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008105 *
8106 * @return whether data is allowed for a apn type.
8107 *
8108 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008109 */
8110 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008111 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008112 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8113 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008114
8115 // Now that all security checks passes, perform the operation as ourselves.
8116 final long identity = Binder.clearCallingIdentity();
8117 try {
8118 Phone phone = getPhone(subId);
8119 if (phone == null) return false;
8120
Jack Yu41407ee2019-05-13 16:54:09 -07008121 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008122 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8123 } finally {
8124 Binder.restoreCallingIdentity(identity);
8125 }
8126 }
8127
8128 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008129 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008130 enforceReadPrivilegedPermission("isApnMetered");
8131
8132 // Now that all security checks passes, perform the operation as ourselves.
8133 final long identity = Binder.clearCallingIdentity();
8134 try {
8135 Phone phone = getPhone(subId);
8136 if (phone == null) return true; // By default return true.
8137
Jack Yu41407ee2019-05-13 16:54:09 -07008138 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008139 } finally {
8140 Binder.restoreCallingIdentity(identity);
8141 }
8142 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008143
8144 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008145 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8146 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8147 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8148 if (iccRecords == null) {
8149 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8150 return false;
8151 }
8152 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8153 }
8154
8155 @Override
Brad Ebingera63db5f2019-04-23 16:31:13 -07008156 public void enqueueSmsPickResult(String callingPackage, IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008157 if (callingPackage == null) {
8158 callingPackage = getCurrentPackageName();
8159 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008160 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8161 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
8162 if (!permissions.checkCallingCanSendSms(callingPackage, "Sending message")) {
8163 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8164 }
8165 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8166 Intent intent = new Intent();
8167 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8168 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8169 // Bring up choose default SMS subscription dialog right now
8170 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8171 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8172 mApp.startActivity(intent);
8173 }
chen xud5ca2d52019-05-28 15:20:57 -07008174
8175 @Override
8176 public String getMmsUAProfUrl(int subId) {
8177 //TODO investigate if this API should require proper permission check in R b/133791609
8178 final long identity = Binder.clearCallingIdentity();
8179 try {
8180 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8181 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8182 } finally {
8183 Binder.restoreCallingIdentity(identity);
8184 }
8185 }
8186
8187 @Override
8188 public String getMmsUserAgent(int subId) {
8189 //TODO investigate if this API should require proper permission check in R b/133791609
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8193 .getString(com.android.internal.R.string.config_mms_user_agent);
8194 } finally {
8195 Binder.restoreCallingIdentity(identity);
8196 }
8197 }
Jack Yub07d4972019-05-28 16:12:25 -07008198
8199 @Override
8200 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8201 enforceModifyPermission();
8202
8203 // Now that all security checks passes, perform the operation as ourselves.
8204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 Phone phone = getPhone(subId);
8207 if (phone == null) return false;
8208
8209 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
8214
8215 @Override
8216 public boolean isDataAllowedInVoiceCall(int subId) {
8217 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8218
8219 // Now that all security checks passes, perform the operation as ourselves.
8220 final long identity = Binder.clearCallingIdentity();
8221 try {
8222 Phone phone = getPhone(subId);
8223 if (phone == null) return false;
8224
8225 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
8229 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008230
changbetty97defcf2019-12-24 15:40:37 +08008231 @Override
8232 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8233 enforceModifyPermission();
8234
8235 // Now that all security checks passes, perform the operation as ourselves.
8236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 Phone phone = getPhone(subId);
8239 if (phone == null) return false;
8240
8241 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8242 } finally {
8243 Binder.restoreCallingIdentity(identity);
8244 }
8245 }
8246
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008247 /**
8248 * Updates whether conference event pacakge handling is enabled.
8249 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8250 * otherwise.
8251 */
8252 @Override
8253 public void setCepEnabled(boolean isCepEnabled) {
8254 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8255
8256 final long identity = Binder.clearCallingIdentity();
8257 try {
8258 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8259 for (Phone phone : PhoneFactory.getPhones()) {
8260 Phone defaultPhone = phone.getImsPhone();
8261 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8262 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8263 ImsPhoneCallTracker imsPhoneCallTracker =
8264 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8265 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8266 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8267 + imsPhone.getMsisdn());
8268 }
8269 }
8270 } finally {
8271 Binder.restoreCallingIdentity(identity);
8272 }
8273 }
allenwtsu46dcc572020-01-08 18:24:03 +08008274
8275 /**
8276 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8277 *
8278 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8279 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8280 * before being read.
8281 */
8282 @Override
8283 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8284 isCompressed) {
8285 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8286 mApp, subId, "notifyRcsAutoConfigurationReceived");
8287 try {
8288 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8289 if (configBinder == null) {
8290 Rlog.e(LOG_TAG, "null result for getImsConfig");
8291 } else {
8292 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8293 }
8294 } catch (RemoteException e) {
8295 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8296 }
8297 }
zoey chenf95ca592019-12-30 16:11:23 +08008298
8299 @Override
8300 public boolean isIccLockEnabled(int subId) {
8301 enforceReadPrivilegedPermission("isIccLockEnabled");
8302
8303 // Now that all security checks passes, perform the operation as ourselves.
8304 final long identity = Binder.clearCallingIdentity();
8305 try {
8306 Phone phone = getPhone(subId);
8307 if (phone != null && phone.getIccCard() != null) {
8308 return phone.getIccCard().getIccLockEnabled();
8309 } else {
8310 return false;
8311 }
8312 } finally {
8313 Binder.restoreCallingIdentity(identity);
8314 }
8315 }
8316
8317 /**
8318 * Set the ICC pin lock enabled or disabled..
8319 *
8320 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8321 * 0 or a positive integer as the attempts remaining value.
8322 *
8323 */
8324 @Override
8325 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8326 enforceModifyPermission();
8327
8328 Phone phone = getPhone(subId);
8329 if (phone == null) {
8330 return 0;
8331 }
8332 // Now that all security checks passes, perform the operation as ourselves.
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
8335 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8336 new Pair<Boolean, String>(enabled, password), phone, null);
8337 return attemptsRemaining;
8338
8339 } catch (Exception e) {
8340 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8341 } finally {
8342 Binder.restoreCallingIdentity(identity);
8343 }
8344 return 0;
8345 }
8346
8347 /**
8348 * Change the ICC password used in ICC pin lock.
8349 *
8350 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8351 * 0 or a positive integer as the attempts remaining value.
8352 *
8353 */
8354 @Override
8355 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8356 enforceModifyPermission();
8357
8358 Phone phone = getPhone(subId);
8359 if (phone == null) {
8360 return 0;
8361 }
8362 // Now that all security checks passes, perform the operation as ourselves.
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8366 new Pair<String, String>(oldPassword, newPassword), phone, null);
8367 return attemptsRemaining;
8368
8369 } catch (Exception e) {
8370 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8371 } finally {
8372 Binder.restoreCallingIdentity(identity);
8373 }
8374 return 0;
8375 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008376}