blob: 9e9714540d4905b444bfe38943d7f72de1938d7b [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;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
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.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
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;
Peter Wang59571be2020-01-27 12:35:15 +0800152import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700154import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800155import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700156import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800157import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700158import com.android.internal.telephony.imsphone.ImsPhone;
159import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800160import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900161import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800163import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700166import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800169import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000170import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800171import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700172import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800173import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800176import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700178import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800179import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800180
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700181import java.io.FileDescriptor;
182import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800185import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800187import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100188import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700190import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800192import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800193import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195/**
196 * Implementation of the ITelephony interface.
197 */
Santos Cordon117fee72014-05-16 17:56:12 -0700198public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 private static final String LOG_TAG = "PhoneInterfaceManager";
200 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
201 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
204 // Message codes used with mMainThreadHandler
205 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700206 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
207 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208 private static final int CMD_OPEN_CHANNEL = 9;
209 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
210 private static final int CMD_CLOSE_CHANNEL = 11;
211 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800212 private static final int CMD_NV_READ_ITEM = 13;
213 private static final int EVENT_NV_READ_ITEM_DONE = 14;
214 private static final int CMD_NV_WRITE_ITEM = 15;
215 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
216 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
217 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_RESET_MODEM_CONFIG = 19;
219 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800220 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
221 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
222 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
223 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800224 private static final int CMD_SEND_ENVELOPE = 25;
225 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000226 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
227 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700228 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
229 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
230 private static final int CMD_EXCHANGE_SIM_IO = 31;
231 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
233 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700234 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700236 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
237 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700238 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
239 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
240 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
241 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700242 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
243 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
244 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
245 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700246 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800247 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
248 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000249 private static final int CMD_SWITCH_SLOTS = 50;
250 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700251 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
252 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
253 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
254 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
255 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
256 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
257 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
258 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700259 private static final int CMD_GET_ALL_CELL_INFO = 60;
260 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
261 private static final int CMD_GET_CELL_LOCATION = 62;
262 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_MODEM_REBOOT = 64;
264 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700265 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
266 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800267 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
268 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700269 private static final int CMD_GET_MODEM_STATUS = 70;
270 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700271 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
272 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700273 private static final int CMD_ERASE_MODEM_CONFIG = 74;
274 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800275 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
276 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
277 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
278 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800279 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
280 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800281 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800282 private static final int CMD_GET_CALL_FORWARDING = 83;
283 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
284 private static final int CMD_SET_CALL_FORWARDING = 85;
285 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
286 private static final int CMD_GET_CALL_WAITING = 87;
287 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
288 private static final int CMD_SET_CALL_WAITING = 89;
289 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800291 // Parameters of select command.
292 private static final int SELECT_COMMAND = 0xA4;
293 private static final int SELECT_P1 = 0x04;
294 private static final int SELECT_P2 = 0;
295 private static final int SELECT_P3 = 0x10;
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 /** The singleton instance. */
298 private static PhoneInterfaceManager sInstance;
299
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800302 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700303 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private AppOpsManager mAppOps;
305 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800306 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700308 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Peter Wangdafb9ac2020-01-15 14:13:38 -0800310 /** User Activity */
311 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
313
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700314 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
315
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530764 // request.result must be set to something non-null
765 // for the calling thread to unblock
766 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800767 if (ar.result == null) {
768 loge("getPreferredNetworkType: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("getPreferredNetworkType: CommandException: " +
771 ar.exception);
772 } else {
773 loge("getPreferredNetworkType: Unknown exception");
774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800777 break;
778
779 case CMD_SET_PREFERRED_NETWORK_TYPE:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
782 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700783 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800784 break;
785
786 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
787 handleNullReturnEvent(msg, "setPreferredNetworkType");
788 break;
789
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
791 request = (MainThreadRequest)msg.obj;
792 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000794 break;
795
796 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
797 ar = (AsyncResult)msg.obj;
798 request = (MainThreadRequest)ar.userObj;
799 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000801 break;
802
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800803 case CMD_SET_VOICEMAIL_NUMBER:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
806 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800807 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
808 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800809 break;
810
811 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
812 handleNullReturnEvent(msg, "setVoicemailNumber");
813 break;
814
Stuart Scott54788802015-03-30 13:18:01 -0700815 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
818 request);
819 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
823 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
824 break;
825
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 case CMD_PERFORM_NETWORK_SCAN:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
829 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
830 break;
831
sqian80370722020-01-29 15:02:51 -0800832 case CMD_GET_CALL_FORWARDING:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
835 int callForwardingReason = (Integer) request.argument;
836 getPhoneFromRequest(request).getCallForwardingOption(
837 callForwardingReason, onCompleted);
838 break;
839
840 case EVENT_GET_CALL_FORWARDING_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 CallForwardingInfo callForwardingInfo = null;
844 if (ar.exception == null && ar.result != null) {
845 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
846 for (CallForwardInfo callForwardInfo : callForwardInfos) {
847 // Service Class is a bit mask per 3gpp 27.007. Search for
848 // any service for voice call.
849 if ((callForwardInfo.serviceClass
850 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
851 callForwardingInfo = new CallForwardingInfo(
852 callForwardInfo.serviceClass, callForwardInfo.reason,
853 callForwardInfo.number,
854 callForwardInfo.timeSeconds);
855 break;
856 }
857 }
858 // Didn't find a call forward info for voice call.
859 if (callForwardingInfo == null) {
860 callForwardingInfo = new CallForwardingInfo(
861 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
862 0 /* reason */, null /* number */, 0 /* timeout */);
863 }
864 } else {
865 if (ar.result == null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
867 }
868 if (ar.exception != null) {
869 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
870 }
871 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
872 if (ar.exception instanceof CommandException) {
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
876 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
879 }
880 }
881 callForwardingInfo = new CallForwardingInfo(
882 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
883 }
884 request.result = callForwardingInfo;
885 notifyRequester(request);
886 break;
887
888 case CMD_SET_CALL_FORWARDING:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
891 CallForwardingInfo callForwardingInfoToSet =
892 (CallForwardingInfo) request.argument;
893 getPhoneFromRequest(request).setCallForwardingOption(
894 callForwardingInfoToSet.getStatus(),
895 callForwardingInfoToSet.getReason(),
896 callForwardingInfoToSet.getNumber(),
897 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
898 break;
899
900 case EVENT_SET_CALL_FORWARDING_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null) {
904 request.result = true;
905 } else {
906 request.result = false;
907 loge("setCallForwarding exception: " + ar.exception);
908 }
909 notifyRequester(request);
910 break;
911
912 case CMD_GET_CALL_WAITING:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
915 getPhoneFromRequest(request).getCallWaiting(onCompleted);
916 break;
917
918 case EVENT_GET_CALL_WAITING_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
922 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800924 // Service Class is a bit mask per 3gpp 27.007.
925 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800926 if (callForwardResults.length > 1
927 && ((callForwardResults[1]
928 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
929 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800930 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
931 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
932 } else {
933 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
934 }
935 } else {
936 if (ar.result == null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
938 }
939 if (ar.exception != null) {
940 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
941 }
942 if (ar.exception instanceof CommandException) {
943 CommandException.Error error =
944 ((CommandException) (ar.exception)).getCommandError();
945 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
946 callForwardingStatus =
947 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
948 }
949 }
950 }
951 request.result = callForwardingStatus;
952 notifyRequester(request);
953 break;
954
955 case CMD_SET_CALL_WAITING:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
958 boolean isEnable = (Boolean) request.argument;
959 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
960 break;
961
962 case EVENT_SET_CALL_WAITING_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = true;
967 } else {
968 request.result = false;
969 loge("setCallWaiting exception: " + ar.exception);
970 }
971 notifyRequester(request);
972 break;
973
Shishir Agrawal302c8692015-06-19 13:49:39 -0700974 case EVENT_PERFORM_NETWORK_SCAN_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 CellNetworkScanResult cellScanResult;
978 if (ar.exception == null && ar.result != null) {
979 cellScanResult = new CellNetworkScanResult(
980 CellNetworkScanResult.STATUS_SUCCESS,
981 (List<OperatorInfo>) ar.result);
982 } else {
983 if (ar.result == null) {
984 loge("getCellNetworkScanResults: Empty response");
985 }
986 if (ar.exception != null) {
987 loge("getCellNetworkScanResults: Exception: " + ar.exception);
988 }
989 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.GENERIC_FAILURE) {
996 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
997 }
998 }
999 cellScanResult = new CellNetworkScanResult(errorCode, null);
1000 }
1001 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001002 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001003 break;
1004
1005 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1006 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001007 ManualNetworkSelectionArgument selArg =
1008 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001009 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1010 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001011 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1012 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001013 break;
1014
1015 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null) {
1019 request.result = true;
1020 } else {
1021 request.result = false;
1022 loge("setNetworkSelectionModeManual " + ar.exception);
1023 }
1024 notifyRequester(request);
1025 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001026 break;
1027
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001028 case CMD_GET_MODEM_ACTIVITY_INFO:
1029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001031 if (defaultPhone != null) {
1032 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001033 } else {
1034 ResultReceiver result = (ResultReceiver) request.argument;
1035 Bundle bundle = new Bundle();
1036 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1037 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1038 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001039 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001040 break;
1041
1042 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001045 ResultReceiver result = (ResultReceiver) request.argument;
1046
1047 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001048 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001049 // Update the last modem activity info and the result of the request.
1050 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1051 if (isModemActivityInfoValid(info)) {
1052 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1053 int[] txTimeMs = info.getTransmitTimeMillis();
1054 int[] lastModemTxTimeMs = mLastModemActivityInfo
1055 .getTransmitTimeMillis();
1056 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1057 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1058 }
1059 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1060 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1061 + mLastModemActivityInfo.getSleepTimeMillis());
1062 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1063 + mLastModemActivityInfo.getIdleTimeMillis());
1064 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1065 mLastModemActivityInfo.setReceiveTimeMillis(
1066 info.getReceiveTimeMillis()
1067 + mLastModemActivityInfo.getReceiveTimeMillis());
1068 }
1069 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1070 mLastModemActivityInfo.getSleepTimeMillis(),
1071 mLastModemActivityInfo.getIdleTimeMillis(),
1072 mLastModemActivityInfo.getTransmitTimeMillis(),
1073 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 } else {
1075 if (ar.result == null) {
1076 loge("queryModemActivityInfo: Empty response");
1077 } else if (ar.exception instanceof CommandException) {
1078 loge("queryModemActivityInfo: CommandException: " +
1079 ar.exception);
1080 } else {
1081 loge("queryModemActivityInfo: Unknown exception");
1082 }
1083 }
sqian1a1be542020-03-05 11:37:28 -08001084 Bundle bundle = new Bundle();
1085 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1086 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001087 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001088 break;
1089
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 case CMD_SET_ALLOWED_CARRIERS:
1091 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001092 CarrierRestrictionRules argument =
1093 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001095 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001096 break;
1097
1098 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null && ar.result != null) {
1102 request.result = ar.result;
1103 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001104 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1105 if (ar.exception instanceof CommandException) {
1106 loge("setAllowedCarriers: CommandException: " + ar.exception);
1107 CommandException.Error error =
1108 ((CommandException) (ar.exception)).getCommandError();
1109 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1110 request.result =
1111 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1112 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001113 } else {
1114 loge("setAllowedCarriers: Unknown exception");
1115 }
1116 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001117 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001118 break;
1119
1120 case CMD_GET_ALLOWED_CARRIERS:
1121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001123 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001124 break;
1125
1126 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null && ar.result != null) {
1130 request.result = ar.result;
1131 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001132 request.result = new IllegalStateException(
1133 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001134 if (ar.result == null) {
1135 loge("getAllowedCarriers: Empty response");
1136 } else if (ar.exception instanceof CommandException) {
1137 loge("getAllowedCarriers: CommandException: " +
1138 ar.exception);
1139 } else {
1140 loge("getAllowedCarriers: Unknown exception");
1141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001144 break;
1145
Nathan Haroldb3014052017-01-25 15:57:32 -08001146 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 } else {
1152 request.result = new IllegalArgumentException(
1153 "Failed to retrieve Forbidden Plmns");
1154 if (ar.result == null) {
1155 loge("getForbiddenPlmns: Empty response");
1156 } else {
1157 loge("getForbiddenPlmns: Unknown exception");
1158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001161 break;
1162
1163 case CMD_GET_FORBIDDEN_PLMNS:
1164 request = (MainThreadRequest) msg.obj;
1165 uiccCard = getUiccCardFromRequest(request);
1166 if (uiccCard == null) {
1167 loge("getForbiddenPlmns() UiccCard is null");
1168 request.result = new IllegalArgumentException(
1169 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001171 break;
1172 }
1173 Integer appType = (Integer) request.argument;
1174 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1175 if (uiccApp == null) {
1176 loge("getForbiddenPlmns() no app with specified type -- "
1177 + appType);
1178 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001180 break;
1181 } else {
1182 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1183 + " specified type -- " + appType);
1184 }
1185 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1186 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1187 onCompleted);
1188 break;
1189
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001190 case CMD_SWITCH_SLOTS:
1191 request = (MainThreadRequest) msg.obj;
1192 int[] physicalSlots = (int[]) request.argument;
1193 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1194 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1195 break;
1196
1197 case EVENT_SWITCH_SLOTS_DONE:
1198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
1200 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
1202 break;
1203 case CMD_GET_NETWORK_SELECTION_MODE:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1206 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1207 break;
1208
1209 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
1212 if (ar.exception != null) {
1213 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1214 } else {
1215 int mode = ((int[]) ar.result)[0];
1216 if (mode == 0) {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1218 } else {
1219 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 notifyRequester(request);
1223 break;
1224 case CMD_GET_CDMA_ROAMING_MODE:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1227 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1228 break;
1229 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception != null) {
1233 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1234 } else {
1235 request.result = ((int[]) ar.result)[0];
1236 }
1237 notifyRequester(request);
1238 break;
1239 case CMD_SET_CDMA_ROAMING_MODE:
1240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1242 int mode = (int) request.argument;
1243 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1244 break;
1245 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1246 ar = (AsyncResult) msg.obj;
1247 request = (MainThreadRequest) ar.userObj;
1248 request.result = ar.exception == null;
1249 notifyRequester(request);
1250 break;
1251 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1254 int subscriptionMode = (int) request.argument;
1255 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1256 break;
1257 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
1260 request.result = ar.exception == null;
1261 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001262 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 case CMD_GET_ALL_CELL_INFO:
1264 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001266 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 case EVENT_GET_ALL_CELL_INFO_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001271 // If a timeout occurs, the response will be null
1272 request.result = (ar.exception == null && ar.result != null)
1273 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 synchronized (request) {
1275 request.notifyAll();
1276 }
1277 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001278 case CMD_REQUEST_CELL_INFO_UPDATE:
1279 request = (MainThreadRequest) msg.obj;
1280 request.phone.requestCellInfoUpdate(request.workSource,
1281 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1282 break;
1283 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1287 try {
1288 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001290 cb.onError(
1291 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1292 ar.exception.getClass().getName(),
1293 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001296 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 } else {
1298 // use the result as returned
1299 cb.onCellInfo((List<CellInfo>) ar.result);
1300 }
1301 } catch (RemoteException re) {
1302 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1303 }
1304 break;
1305 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001306 request = (MainThreadRequest) msg.obj;
1307 WorkSource ws = (WorkSource) request.argument;
1308 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001309 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001311 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null) {
1315 request.result = ar.result;
1316 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001317 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001319 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 }
1321
1322 synchronized (request) {
1323 request.notifyAll();
1324 }
1325 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001326 case CMD_MODEM_REBOOT:
1327 request = (MainThreadRequest) msg.obj;
1328 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001329 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001330 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001331 case EVENT_CMD_MODEM_REBOOT_DONE:
1332 handleNullReturnEvent(msg, "rebootModem");
1333 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001334 case CMD_REQUEST_ENABLE_MODEM:
1335 request = (MainThreadRequest) msg.obj;
1336 boolean enable = (boolean) request.argument;
1337 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001338 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001339 PhoneConfigurationManager.getInstance()
1340 .enablePhone(request.phone, enable, onCompleted);
1341 break;
1342 case EVENT_ENABLE_MODEM_DONE:
1343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
1345 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001347 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001348 if ((boolean) request.result) {
1349 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1350 updateModemStateMetrics();
1351 } else {
1352 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1353 + ar.exception);
1354 }
1355 notifyRequester(request);
1356 break;
1357 case CMD_GET_MODEM_STATUS:
1358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1360 PhoneConfigurationManager.getInstance()
1361 .getPhoneStatusFromModem(request.phone, onCompleted);
1362 break;
1363 case EVENT_GET_MODEM_STATUS_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 int id = request.phone.getPhoneId();
1367 if (ar.exception == null && ar.result != null) {
1368 request.result = ar.result;
1369 //update the cache as modem status has changed
1370 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1371 (boolean) request.result);
1372 } else {
1373 // Return true if modem status cannot be retrieved. For most cases,
1374 // modem status is on. And for older version modems, GET_MODEM_STATUS
1375 // and disable modem are not supported. Modem is always on.
1376 // TODO: this should be fixed in R to support a third
1377 // status UNKNOWN b/131631629
1378 request.result = true;
1379 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1380 + ar.exception);
1381 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001382 notifyRequester(request);
1383 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001384 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1385 request = (MainThreadRequest) msg.obj;
1386 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1388 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1389 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1390 break;
1391 }
1392 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1396 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1397 args.second.accept(ar.exception == null);
1398 notifyRequester(request);
1399 break;
1400 }
yincheng zhaod698b842019-09-06 17:06:54 -07001401 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception == null && ar.result != null) {
1405 request.result = ar.result;
1406 } else {
1407 request.result = -1;
1408 loge("Failed to set Forbidden Plmns");
1409 if (ar.result == null) {
1410 loge("setForbidenPlmns: Empty response");
1411 } else if (ar.exception != null) {
1412 loge("setForbiddenPlmns: Exception: " + ar.exception);
1413 request.result = -1;
1414 } else {
1415 loge("setForbiddenPlmns: Unknown exception");
1416 }
1417 }
1418 notifyRequester(request);
1419 break;
1420 case CMD_SET_FORBIDDEN_PLMNS:
1421 request = (MainThreadRequest) msg.obj;
1422 uiccCard = getUiccCardFromRequest(request);
1423 if (uiccCard == null) {
1424 loge("setForbiddenPlmns: UiccCard is null");
1425 request.result = -1;
1426 notifyRequester(request);
1427 break;
1428 }
1429 Pair<Integer, List<String>> setFplmnsArgs =
1430 (Pair<Integer, List<String>>) request.argument;
1431 appType = setFplmnsArgs.first;
1432 List<String> fplmns = setFplmnsArgs.second;
1433 uiccApp = uiccCard.getApplicationByType(appType);
1434 if (uiccApp == null) {
1435 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1436 request.result = -1;
1437 loge("Failed to get UICC App");
1438 notifyRequester(request);
1439 } else {
1440 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1441 ((SIMRecords) uiccApp.getIccRecords())
1442 .setForbiddenPlmns(onCompleted, fplmns);
1443 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001444 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001445 case CMD_ERASE_MODEM_CONFIG:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1448 defaultPhone.eraseModemConfig(onCompleted);
1449 break;
1450 case EVENT_ERASE_MODEM_CONFIG_DONE:
1451 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001452 break;
zoey chenf95ca592019-12-30 16:11:23 +08001453
1454 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1457 Pair<String, String> changed = (Pair<String, String>) request.argument;
1458 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1459 changed.first, changed.second, onCompleted);
1460 break;
1461 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 if (ar.exception == null) {
1465 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1466 } else {
1467 request.result = msg.arg1;
1468 }
1469 notifyRequester(request);
1470 break;
1471
1472 case CMD_SET_ICC_LOCK_ENABLED:
1473 request = (MainThreadRequest) msg.obj;
1474 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1475 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1476 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1477 enabled.first, enabled.second, onCompleted);
1478 break;
1479 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null) {
1483 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1484 } else {
1485 request.result = msg.arg1;
1486 }
1487 notifyRequester(request);
1488 break;
1489
Peter Wangdafb9ac2020-01-15 14:13:38 -08001490 case MSG_NOTIFY_USER_ACTIVITY:
1491 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001492 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001493 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1494 getDefaultPhone().getContext().sendBroadcastAsUser(
1495 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1496 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 default:
1498 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1499 break;
1500 }
1501 }
Jake Hambye994d462014-02-03 13:10:13 -08001502
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 private void notifyRequester(MainThreadRequest request) {
1504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 }
1508
Jake Hambye994d462014-02-03 13:10:13 -08001509 private void handleNullReturnEvent(Message msg, String command) {
1510 AsyncResult ar = (AsyncResult) msg.obj;
1511 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception == null) {
1513 request.result = true;
1514 } else {
1515 request.result = false;
1516 if (ar.exception instanceof CommandException) {
1517 loge(command + ": CommandException: " + ar.exception);
1518 } else {
1519 loge(command + ": Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525
1526 /**
1527 * Posts the specified command to be executed on the main thread,
1528 * waits for the request to complete, and returns the result.
1529 * @see #sendRequestAsync
1530 */
1531 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001532 return sendRequest(
1533 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001534 }
1535
1536 /**
1537 * Posts the specified command to be executed on the main thread,
1538 * waits for the request to complete, and returns the result.
1539 * @see #sendRequestAsync
1540 */
1541 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1542 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001543 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
1546 /**
1547 * Posts the specified command to be executed on the main thread,
1548 * waits for the request to complete, and returns the result.
1549 * @see #sendRequestAsync
1550 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001551 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001552 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001553 }
1554
1555 /**
1556 * Posts the specified command to be executed on the main thread,
1557 * waits for the request to complete, and returns the result.
1558 * @see #sendRequestAsync
1559 */
Nathan Harold92bed182018-10-12 18:16:49 -07001560 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1561 return sendRequest(command, argument, subId, null, workSource);
1562 }
1563
1564 /**
1565 * Posts the specified command to be executed on the main thread,
1566 * waits for the request to complete, and returns the result.
1567 * @see #sendRequestAsync
1568 */
1569 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1570 return sendRequest(
1571 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1572 }
1573
1574 /**
1575 * Posts the specified command to be executed on the main thread,
1576 * waits for the request to complete, and returns the result.
1577 * @see #sendRequestAsync
1578 */
1579 private Object sendRequest(
1580 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1582 throw new RuntimeException("This method will deadlock if called from the main thread.");
1583 }
1584
Nathan Harold92bed182018-10-12 18:16:49 -07001585 MainThreadRequest request = null;
1586 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1587 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1588 } else if (phone != null) {
1589 request = new MainThreadRequest(argument, phone, workSource);
1590 } else {
1591 request = new MainThreadRequest(argument, subId, workSource);
1592 }
1593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 Message msg = mMainThreadHandler.obtainMessage(command, request);
1595 msg.sendToTarget();
1596
1597 // Wait for the request to complete
1598 synchronized (request) {
1599 while (request.result == null) {
1600 try {
1601 request.wait();
1602 } catch (InterruptedException e) {
1603 // Do nothing, go back and wait until the request is complete
1604 }
1605 }
1606 }
1607 return request.result;
1608 }
1609
1610 /**
1611 * Asynchronous ("fire and forget") version of sendRequest():
1612 * Posts the specified command to be executed on the main thread, and
1613 * returns immediately.
1614 * @see #sendRequest
1615 */
1616 private void sendRequestAsync(int command) {
1617 mMainThreadHandler.sendEmptyMessage(command);
1618 }
1619
1620 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001622 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001623 */
1624 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 sendRequestAsync(command, argument, null, null);
1626 }
1627
1628 /**
1629 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1630 * @see {@link #sendRequest(int,Object)}
1631 */
1632 private void sendRequestAsync(
1633 int command, Object argument, Phone phone, WorkSource workSource) {
1634 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001635 Message msg = mMainThreadHandler.obtainMessage(command, request);
1636 msg.sendToTarget();
1637 }
1638
1639 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 * Initialize the singleton PhoneInterfaceManager instance.
1641 * This is only done once, at startup, from PhoneApp.onCreate().
1642 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001643 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 synchronized (PhoneInterfaceManager.class) {
1645 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 } else {
1648 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1649 }
1650 return sInstance;
1651 }
1652 }
1653
1654 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001655 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001658 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001659 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1661 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001662 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001663 mTelephonySharedPreferences =
1664 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001665 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001666 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001667 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001668
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 publish();
1670 }
1671
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001672 private Phone getDefaultPhone() {
1673 Phone thePhone = getPhone(getDefaultSubscription());
1674 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1675 }
1676
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 private void publish() {
1678 if (DBG) log("publish: " + this);
1679
Peter Wangc035ce42020-01-08 21:00:22 -08001680 TelephonyFrameworkInitializer
1681 .getTelephonyServiceManager()
1682 .getTelephonyServiceRegisterer()
1683 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Stuart Scott584921c2015-01-15 17:10:34 -08001686 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001687 if (request.phone != null) {
1688 return request.phone;
1689 } else {
1690 return getPhoneFromSubId(request.subId);
1691 }
1692 }
1693
1694 private Phone getPhoneFromSubId(int subId) {
1695 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1696 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001697 }
1698
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001699 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1700 Phone phone = getPhoneFromRequest(request);
1701 return phone == null ? null :
1702 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1703 }
1704
Wink Saville36469e72014-06-11 15:17:00 -07001705 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001707 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001710 private void sendEraseModemConfig(Phone phone) {
1711 if (phone != null) {
1712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1713 mApp, phone.getSubId(), "eraseModemConfig");
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1717 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
1720 }
1721 }
1722 }
1723
Peter Wang050bb052020-01-13 23:33:09 -08001724 private boolean isImsAvailableOnDevice() {
1725 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1726 if (pm == null) {
1727 // For some reason package manger is not available.. This will fail internally anyway,
1728 // so do not throw error and allow.
1729 return true;
1730 }
1731 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1732 }
1733
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001735 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001736 }
1737
Wink Savilleb564aae2014-10-23 10:18:09 -07001738 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 if (DBG) log("dial: " + number);
1740 // No permission check needed here: This is just a wrapper around the
1741 // ACTION_DIAL intent, which is available to any app since it puts up
1742 // the UI before it does anything.
1743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 String url = createTelUrl(number);
1747 if (url == null) {
1748 return;
1749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001751 // PENDING: should we just silently fail if phone is offhook or ringing?
1752 PhoneConstants.State state = mCM.getState(subId);
1753 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1754 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1755 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1756 mApp.startActivity(intent);
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761 }
1762
1763 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
Wink Savilleb564aae2014-10-23 10:18:09 -07001767 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 if (DBG) log("call: " + number);
1769
1770 // This is just a wrapper around the ACTION_CALL intent, but we still
1771 // need to do a permission check since we're calling startActivity()
1772 // from the context of the phone app.
1773 enforceCallPermission();
1774
Jordan Liu1617b712019-07-10 15:06:26 -07001775 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 != AppOpsManager.MODE_ALLOWED) {
1777 return;
1778 }
1779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 String url = createTelUrl(number);
1783 if (url == null) {
1784 return;
1785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787 boolean isValid = false;
1788 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1789 if (slist != null) {
1790 for (SubscriptionInfo subInfoRecord : slist) {
1791 if (subInfoRecord.getSubscriptionId() == subId) {
1792 isValid = true;
1793 break;
1794 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001795 }
Wink Saville08874612014-08-31 19:19:58 -07001796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 if (!isValid) {
1798 return;
1799 }
Wink Saville08874612014-08-31 19:19:58 -07001800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1802 intent.putExtra(SUBSCRIPTION_KEY, subId);
1803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1804 mApp.startActivity(intent);
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Wink Savilleb564aae2014-10-23 10:18:09 -07001810 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001811 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001812 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001816 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001817 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1818 }
1819
Wink Savilleb564aae2014-10-23 10:18:09 -07001820 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1826 checkSimPin.start();
1827 return checkSimPin.unlockSim(null, pin);
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
1830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Wink Savilleb564aae2014-10-23 10:18:09 -07001833 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1839 checkSimPuk.start();
1840 return checkSimPuk.unlockSim(puk, pin);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 }
1845
1846 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001847 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 * a synchronous one.
1849 */
1850 private static class UnlockSim extends Thread {
1851
1852 private final IccCard mSimCard;
1853
1854 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001855 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1856 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857
1858 // For replies from SimCard interface
1859 private Handler mHandler;
1860
1861 // For async handler to identify request type
1862 private static final int SUPPLY_PIN_COMPLETE = 100;
1863
1864 public UnlockSim(IccCard simCard) {
1865 mSimCard = simCard;
1866 }
1867
1868 @Override
1869 public void run() {
1870 Looper.prepare();
1871 synchronized (UnlockSim.this) {
1872 mHandler = new Handler() {
1873 @Override
1874 public void handleMessage(Message msg) {
1875 AsyncResult ar = (AsyncResult) msg.obj;
1876 switch (msg.what) {
1877 case SUPPLY_PIN_COMPLETE:
1878 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1879 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001880 mRetryCount = msg.arg1;
1881 if (ar.exception != null) {
1882 if (ar.exception instanceof CommandException &&
1883 ((CommandException)(ar.exception)).getCommandError()
1884 == CommandException.Error.PASSWORD_INCORRECT) {
1885 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001886 } //When UiccCardApp dispose,handle message and return exception
1887 else if (ar.exception instanceof CommandException &&
1888 ((CommandException) (ar.exception)).getCommandError()
1889 == CommandException.Error.ABORTED) {
1890 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001891 } else {
1892 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1893 }
1894 } else {
1895 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 mDone = true;
1898 UnlockSim.this.notifyAll();
1899 }
1900 break;
1901 }
1902 }
1903 };
1904 UnlockSim.this.notifyAll();
1905 }
1906 Looper.loop();
1907 }
1908
1909 /*
1910 * Use PIN or PUK to unlock SIM card
1911 *
1912 * If PUK is null, unlock SIM card with PIN
1913 *
1914 * If PUK is not null, unlock SIM card with PUK and set PIN code
1915 */
Wink Saville9de0f752013-10-22 19:04:03 -07001916 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917
1918 while (mHandler == null) {
1919 try {
1920 wait();
1921 } catch (InterruptedException e) {
1922 Thread.currentThread().interrupt();
1923 }
1924 }
1925 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1926
1927 if (puk == null) {
1928 mSimCard.supplyPin(pin, callback);
1929 } else {
1930 mSimCard.supplyPuk(puk, pin, callback);
1931 }
1932
1933 while (!mDone) {
1934 try {
1935 Log.d(LOG_TAG, "wait for done");
1936 wait();
1937 } catch (InterruptedException e) {
1938 // Restore the interrupted status
1939 Thread.currentThread().interrupt();
1940 }
1941 }
1942 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001943 int[] resultArray = new int[2];
1944 resultArray[0] = mResult;
1945 resultArray[1] = mRetryCount;
1946 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948 }
1949
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001950 /**
1951 * This method has been removed due to privacy and stability concerns.
1952 */
1953 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001955 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1956 return;
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Nathan Harold1f889d82020-06-04 17:05:26 -07001959 @Override
1960 public void updateServiceLocationWithPackageName(String callingPackage) {
1961 mApp.getSystemService(AppOpsManager.class)
1962 .checkPackage(Binder.getCallingUid(), callingPackage);
1963
1964 final int targetSdk = getTargetSdk(callingPackage);
1965 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1966 // Callers targeting S have no business invoking this method.
1967 return;
1968 }
1969
1970 LocationAccessPolicy.LocationPermissionResult locationResult =
1971 LocationAccessPolicy.checkLocationPermission(mApp,
1972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1973 .setCallingPackage(callingPackage)
1974 .setCallingFeatureId(null)
1975 .setCallingPid(Binder.getCallingPid())
1976 .setCallingUid(Binder.getCallingUid())
1977 .setMethod("updateServiceLocation")
1978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1979 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1980 .build());
1981 // Apps that lack location permission have no business calling this method;
1982 // however, because no permission was declared in the public API, denials must
1983 // all be "soft".
1984 switch (locationResult) {
1985 case DENIED_HARD: /* fall through */
1986 case DENIED_SOFT:
1987 return;
1988 }
1989
1990 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 final long identity = Binder.clearCallingIdentity();
1992 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001993 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001995 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 }
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002002 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002003 @Override
2004 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002005 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
2007
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002008
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002009 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002010 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2011 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2012 callingFeatureId);
2013 }
2014
2015 @Deprecated
2016 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002017 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002018 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2019 }
2020
2021 @Override
2022 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2023 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002025 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002026 return false;
2027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 return isRadioOnForSubscriber(subId);
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002035 }
2036
2037 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 if (phone != null) {
2042 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2043 } else {
2044 return false;
2045 }
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050
2051 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002052 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
Wink Saville36469e72014-06-11 15:17:00 -07002054
Wink Savilleb564aae2014-10-23 10:18:09 -07002055 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 final Phone phone = getPhone(subId);
2061 if (phone != null) {
2062 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2063 }
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002066 }
Wink Saville36469e72014-06-11 15:17:00 -07002067 }
2068
2069 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002070 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002071 }
2072
Wink Savilleb564aae2014-10-23 10:18:09 -07002073 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 final Phone phone = getPhone(subId);
2079 if (phone == null) {
2080 return false;
2081 }
2082 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2083 toggleRadioOnOffForSubscriber(subId);
2084 }
2085 return true;
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
Wink Saville36469e72014-06-11 15:17:00 -07002090
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002091 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002092 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002093 /*
2094 * If any of the Radios are available, it will need to be
2095 * shutdown. So return true if any Radio is available.
2096 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2100 Phone phone = PhoneFactory.getPhone(i);
2101 if (phone != null && phone.isRadioAvailable()) return true;
2102 }
2103 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2104 return false;
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002107 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002108 }
2109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002111 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 enforceModifyPermission();
2113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2117 logv("Shutting down Phone " + i);
2118 shutdownRadioUsingPhoneId(i);
2119 }
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002122 }
2123 }
2124
2125 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002126 Phone phone = PhoneFactory.getPhone(phoneId);
2127 if (phone != null && phone.isRadioAvailable()) {
2128 phone.shutdownRadio();
2129 }
2130 }
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2138 if (defaultPhone != null) {
2139 defaultPhone.setRadioPower(turnOn);
2140 return true;
2141 } else {
2142 loge("There's no default phone.");
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002147 }
Wink Saville36469e72014-06-11 15:17:00 -07002148 }
2149
Wink Savilleb564aae2014-10-23 10:18:09 -07002150 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = getPhone(subId);
2156 if (phone != null) {
2157 phone.setRadioPower(turnOn);
2158 return true;
2159 } else {
2160 return false;
2161 }
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Wink Saville36469e72014-06-11 15:17:00 -07002167 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public boolean enableDataConnectivity() {
2170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 int subId = mSubscriptionController.getDefaultDataSubId();
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002177 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 return true;
2179 } else {
2180 return false;
2181 }
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Wink Saville36469e72014-06-11 15:17:00 -07002187 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 public boolean disableDataConnectivity() {
2190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 int subId = mSubscriptionController.getDefaultDataSubId();
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002197 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198 return true;
2199 } else {
2200 return false;
2201 }
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206
Sanket Padawe356d7632015-06-22 14:03:32 -07002207 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002208 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 final Phone phone = getPhone(subId);
2212 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002213 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 } else {
2215 return false;
2216 }
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
2222 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002223 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
pkanwarae03a6b2016-11-06 20:37:09 -08002226 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 enforceCallPermission();
2228
2229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2232 return;
2233 }
2234 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2235 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
pkanwar32d516d2016-10-14 19:37:38 -07002239 };
2240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2247 return false;
2248 }
2249 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002256 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002259 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 Phone phone = PhoneFactory.getPhone(slotIndex);
2263 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2264 PhoneConstantConversions.convertCallState(phone.getState());
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002271 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002272 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2273 }
2274
2275 @Override
2276 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002279 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280 if (phone != null) {
2281 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2282 } else {
2283 return PhoneConstantConversions.convertDataState(
2284 PhoneConstants.DataState.DISCONNECTED);
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002292 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002293 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2294 }
2295
2296 @Override
2297 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002300 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 if (phone != null) {
2302 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2303 } else {
2304 return TelephonyManager.DATA_ACTIVITY_NONE;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002312 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002313 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002314 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002315
2316 LocationAccessPolicy.LocationPermissionResult locationResult =
2317 LocationAccessPolicy.checkLocationPermission(mApp,
2318 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2319 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002320 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002321 .setCallingPid(Binder.getCallingPid())
2322 .setCallingUid(Binder.getCallingUid())
2323 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002324 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002325 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2326 .build());
2327 switch (locationResult) {
2328 case DENIED_HARD:
2329 throw new SecurityException("Not allowed to access cell location");
2330 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002331 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2332 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002339 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002340 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Svetoslav64fad262015-04-14 14:35:21 -07002344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 @Override
Jack Yu01425032020-02-22 19:38:58 -08002347 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002348 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2349 // registered cell info, so return a NULL country instead.
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002352 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2353 // Get default phone in this case.
2354 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2355 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002356 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002358 if (phone == null) return "";
2359 ServiceStateTracker sst = phone.getServiceStateTracker();
2360 if (sst == null) return "";
2361 LocaleTracker lt = sst.getLocaleTracker();
2362 if (lt == null) return "";
2363 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2364 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2365 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002369 }
2370
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002371 /**
2372 * This method was removed due to potential issues caused by performing partial
2373 * updates of service state, and lack of a credible use case.
2374 *
2375 * This has the ability to break the telephony implementation by disabling notification of
2376 * changes in device connectivity. DO NOT USE THIS!
2377 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002378 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 public void enableLocationUpdates() {
2380 mApp.enforceCallingOrSelfPermission(
2381 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002384 /**
2385 * This method was removed due to potential issues caused by performing partial
2386 * updates of service state, and lack of a credible use case.
2387 *
2388 * This has the ability to break the telephony implementation by disabling notification of
2389 * changes in device connectivity. DO NOT USE THIS!
2390 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 @Override
2392 public void disableLocationUpdates() {
2393 mApp.enforceCallingOrSelfPermission(
2394 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 }
2396
Nathan Harold31d7ff32018-10-15 20:20:30 -07002397 /**
2398 * Returns the target SDK version number for a given package name.
2399 *
Nathan Haroldec184742019-07-10 17:04:16 -07002400 * This call MUST be invoked before clearing the calling UID.
2401 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002402 * @return target SDK if the package is found or INT_MAX.
2403 */
2404 private int getTargetSdk(String packageName) {
2405 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002406 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002407 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002408 if (ai != null) return ai.targetSdkVersion;
2409 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002410 loge("Failed to get package info for pkg="
2411 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 }
2413 return Integer.MAX_VALUE;
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 @Override
2417 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002418 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2419 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002420 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002421 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2422 throw new SecurityException(
2423 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2424 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002425
Jordan Liu1617b712019-07-10 15:06:26 -07002426 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2428 return null;
2429 }
Svetoslav64fad262015-04-14 14:35:21 -07002430
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002431 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002433 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002434 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
Nathan Haroldf180aac2018-06-01 18:43:55 -07002436 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2437 for (CellInfo ci : info) {
2438 if (ci instanceof CellInfoGsm) {
2439 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2440 } else if (ci instanceof CellInfoWcdma) {
2441 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002444 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002447 private List<CellInfo> getCachedCellInfo() {
2448 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2449 for (Phone phone : PhoneFactory.getPhones()) {
2450 List<CellInfo> info = phone.getAllCellInfo();
2451 if (info != null) cellInfos.addAll(info);
2452 }
2453 return cellInfos;
2454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002458 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002459 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002460
2461 LocationAccessPolicy.LocationPermissionResult locationResult =
2462 LocationAccessPolicy.checkLocationPermission(mApp,
2463 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2464 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002465 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002466 .setCallingPid(Binder.getCallingPid())
2467 .setCallingUid(Binder.getCallingUid())
2468 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002469 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002470 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2471 .build());
2472 switch (locationResult) {
2473 case DENIED_HARD:
2474 throw new SecurityException("Not allowed to access cell info");
2475 case DENIED_SOFT:
2476 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 final int targetSdk = getTargetSdk(callingPackage);
2480 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2481 return getCachedCellInfo();
2482 }
2483
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002484 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2489 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002490 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002491 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 if (info != null) cellInfos.addAll(info);
2493 }
2494 return cellInfos;
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498 }
2499
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002500 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002501 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2502 String callingFeatureId) {
2503 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2504 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002505 }
2506
2507 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002508 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2509 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002511 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002512 }
2513
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002514 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2515 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002516 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002517 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002518
2519 LocationAccessPolicy.LocationPermissionResult locationResult =
2520 LocationAccessPolicy.checkLocationPermission(mApp,
2521 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2522 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002523 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002524 .setCallingPid(Binder.getCallingPid())
2525 .setCallingUid(Binder.getCallingUid())
2526 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002527 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2528 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002529 .build());
2530 switch (locationResult) {
2531 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002532 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2533 // Safetynet logging for b/154934934
2534 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2535 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002536 throw new SecurityException("Not allowed to access cell info");
2537 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002538 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2539 // Safetynet logging for b/154934934
2540 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2541 }
Nathan Harold5320c422019-05-09 10:26:08 -07002542 try {
2543 cb.onCellInfo(new ArrayList<CellInfo>());
2544 } catch (RemoteException re) {
2545 // Drop without consequences
2546 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002547 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002548 }
2549
Nathan Harolda939a962019-05-09 10:13:47 -07002550
2551 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002552 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2553
2554 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2555 }
2556
2557 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002559 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002571 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002572 Phone phone = PhoneFactory.getPhone(slotIndex);
2573 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 return null;
2575 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002576 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002577 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002578 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 return null;
2580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return phone.getImei();
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
2587 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002588 }
2589
2590 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002591 public String getTypeAllocationCodeForSlot(int slotIndex) {
2592 Phone phone = PhoneFactory.getPhone(slotIndex);
2593 String tac = null;
2594 if (phone != null) {
2595 String imei = phone.getImei();
2596 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2597 }
2598 return tac;
2599 }
2600
2601 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002602 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 Phone phone = PhoneFactory.getPhone(slotIndex);
2604 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002605 return null;
2606 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002607
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002609 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002610 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002611 return null;
2612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 return phone.getMeid();
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Jack Yu2af8d712017-03-15 17:14:14 -07002620 }
2621
2622 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002623 public String getManufacturerCodeForSlot(int slotIndex) {
2624 Phone phone = PhoneFactory.getPhone(slotIndex);
2625 String manufacturerCode = null;
2626 if (phone != null) {
2627 String meid = phone.getMeid();
2628 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2629 }
2630 return manufacturerCode;
2631 }
2632
2633 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002634 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2635 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002636 Phone phone = PhoneFactory.getPhone(slotIndex);
2637 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002638 return null;
2639 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002640 int subId = phone.getSubId();
2641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002642 mApp, subId, callingPackage, callingFeatureId,
2643 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002644 return null;
2645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 return phone.getDeviceSvn();
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002653 }
2654
fionaxu43304da2017-11-27 22:51:16 -08002655 @Override
2656 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
fionaxu43304da2017-11-27 22:51:16 -08002664 }
2665
2666 @Override
2667 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 return phone == null ? null : phone.getCarrierName();
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
fionaxu43304da2017-11-27 22:51:16 -08002675 }
2676
calvinpanffe225e2018-11-01 19:43:06 +08002677 @Override
chen xu0026ca62019-03-06 15:28:50 -08002678 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002683 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
2687 }
2688
2689 @Override
chen xu0026ca62019-03-06 15:28:50 -08002690 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002694 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
2698 }
2699
chen xu651eec72018-11-11 19:03:44 -08002700 @Override
chen xu864e11c2018-12-06 22:10:03 -08002701 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2702 if (!isSubscriptionMccMnc) {
2703 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2704 }
chen xu651eec72018-11-11 19:03:44 -08002705 final Phone phone = PhoneFactory.getPhone(slotIndex);
2706 if (phone == null) {
2707 return TelephonyManager.UNKNOWN_CARRIER_ID;
2708 }
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
2715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 //
2718 // Internal helper methods.
2719 //
2720
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002721 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2723 *
2724 * @throws SecurityException if the caller does not have the required permission
2725 */
2726 private void enforceModifyPermission() {
2727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2728 }
2729
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002730 /**
2731 * Make sure the caller is system.
2732 *
2733 * @throws SecurityException if the caller is not system.
2734 */
2735 private void enforceSystemCaller() {
2736 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2737 throw new SecurityException("Caller must be system");
2738 }
2739 }
2740
Shuo Qianf2b2df42019-11-13 17:43:31 -08002741 private void enforceActiveEmergencySessionPermission() {
2742 mApp.enforceCallingOrSelfPermission(
2743 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2744 }
2745
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 /**
2747 * Make sure the caller has the CALL_PHONE permission.
2748 *
2749 * @throws SecurityException if the caller does not have the required permission
2750 */
2751 private void enforceCallPermission() {
2752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2753 }
2754
paulhu423b5f22019-08-23 19:17:33 +08002755 private void enforceSettingsPermission() {
2756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 private String createTelUrl(String number) {
2760 if (TextUtils.isEmpty(number)) {
2761 return null;
2762 }
2763
Jake Hambye994d462014-02-03 13:10:13 -08002764 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Ihab Awadf9e92732013-12-05 18:02:52 -08002767 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2769 }
2770
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 private static void logv(String msg) {
2772 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2773 }
2774
Ihab Awadf9e92732013-12-05 18:02:52 -08002775 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2777 }
2778
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002781 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002782 }
2783
Sanket Padawe356d7632015-06-22 14:03:32 -07002784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002785 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = PhoneFactory.getPhone(slotIndex);
2789 if (phone == null) {
2790 return PhoneConstants.PHONE_TYPE_NONE;
2791 } else {
2792 return phone.getPhoneType();
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
2799 /**
2800 * Returns the CDMA ERI icon index to display
2801 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002802 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002803 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2804 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2805 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002806 }
2807
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002809 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2810 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 mApp, subId, callingPackage, callingFeatureId,
2813 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002814 return -1;
2815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
2821 return phone.getCdmaEriIconIndex();
2822 } else {
2823 return -1;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 /**
2831 * Returns the CDMA ERI icon mode,
2832 * 0 - ON
2833 * 1 - FLASHING
2834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002836 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2837 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002842 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2843 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002845 mApp, subId, callingPackage, callingFeatureId,
2846 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 return -1;
2848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 final Phone phone = getPhone(subId);
2853 if (phone != null) {
2854 return phone.getCdmaEriIconMode();
2855 } else {
2856 return -1;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
2863 /**
2864 * Returns the CDMA ERI text,
2865 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002866 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002867 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2868 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2869 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002870 }
2871
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002873 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2874 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002876 mApp, subId, callingPackage, callingFeatureId,
2877 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002878 return null;
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 final Phone phone = getPhone(subId);
2884 if (phone != null) {
2885 return phone.getCdmaEriText();
2886 } else {
2887 return null;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
2894 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002895 * Returns the CDMA MDN.
2896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002898 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2900 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002905 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 return phone.getLine1Number();
2907 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 return null;
2910 }
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002913 }
2914 }
2915
2916 /**
2917 * Returns the CDMA MIN.
2918 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002920 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2922 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
2924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2928 return phone.getCdmaMin();
2929 } else {
2930 return null;
2931 }
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002934 }
2935 }
2936
Hall Liud892bec2018-11-30 14:51:45 -08002937 @Override
2938 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2939 INumberVerificationCallback callback, String callingPackage) {
2940 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2941 != PERMISSION_GRANTED) {
2942 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2943 }
2944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2945
2946 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2947 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2948 throw new SecurityException("Calling package must be configured in the device config");
2949 }
2950
2951 if (range == null) {
2952 throw new NullPointerException("Range must be non-null");
2953 }
2954
2955 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002956 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002957
2958 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2959 }
2960
Junda Liuca05d5d2014-08-14 22:36:34 -07002961 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962 * Returns true if CDMA provisioning needs to run.
2963 */
2964 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002967 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968 } finally {
2969 Binder.restoreCallingIdentity(identity);
2970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
2973 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002974 * Sets the voice mail number of a given subId.
2975 */
2976 @Override
2977 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2979 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2984 new Pair<String, String>(alphaTag, number), new Integer(subId));
2985 return success;
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002989 }
2990
Ta-wei Yen87c49842016-05-13 21:19:52 -07002991 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002992 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002994 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2995 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002996 if (!TextUtils.equals(callingPackage, systemDialer)) {
2997 throw new SecurityException("caller must be system dialer");
2998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3003 if (phoneAccountHandle == null) {
3004 return null;
3005 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003009 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003010 }
3011
3012 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3014 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003017 mApp, subId, callingPackage, callingFeatureId,
3018 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003019 return null;
3020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003022 final long identity = Binder.clearCallingIdentity();
3023 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003028 }
3029
3030 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003031 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3032 VisualVoicemailSmsFilterSettings settings) {
3033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003038 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003042 }
3043
3044 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003045 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003051 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003055 }
3056
3057 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003058 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3059 String callingPackage, int subId) {
3060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003065 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003069 }
3070
3071 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003072 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003078 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003082 }
3083
3084 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003085 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3086 String callingAttributionTag, int subId, String number, int port, String text,
3087 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003089 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003090 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003091 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003092 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3093 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003094 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003095
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003096 /**
fionaxu0152e512016-11-14 13:36:14 -08003097 * Sets the voice activation state of a given subId.
3098 */
3099 @Override
3100 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3102 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
3108 phone.setVoiceActivationState(activationState);
3109 } else {
3110 loge("setVoiceActivationState fails with invalid subId: " + subId);
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003114 }
3115 }
3116
3117 /**
3118 * Sets the data activation state of a given subId.
3119 */
3120 @Override
3121 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3123 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
3128 if (phone != null) {
3129 phone.setDataActivationState(activationState);
3130 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003131 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 }
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003135 }
3136 }
3137
3138 /**
3139 * Returns the voice activation state of a given subId.
3140 */
3141 @Override
3142 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
fionaxu0152e512016-11-14 13:36:14 -08003145 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 if (phone != null) {
3149 return phone.getVoiceActivationState();
3150 } else {
3151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003155 }
3156 }
3157
3158 /**
3159 * Returns the data activation state of a given subId.
3160 */
3161 @Override
3162 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
fionaxu0152e512016-11-14 13:36:14 -08003165 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 if (phone != null) {
3169 return phone.getDataActivationState();
3170 } else {
3171 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003175 }
3176 }
3177
3178 /**
Wink Saville36469e72014-06-11 15:17:00 -07003179 * Returns the unread count of voicemails for a subId
3180 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003182 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3183 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003185 mApp, subId, callingPackage, callingFeatureId,
3186 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003187 return 0;
3188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 if (phone != null) {
3193 return phone.getVoiceMessageCount();
3194 } else {
3195 return 0;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
3202 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003203 * returns true, if the device is in a state where both voice and data
3204 * are supported simultaneously. This can change based on location or network condition.
3205 */
3206 @Override
3207 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 final Phone phone = getPhone(subId);
3211 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003215 }
3216
3217 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003218 * Send the dialer code if called from the current default dialer or the caller has
3219 * carrier privilege.
3220 * @param inputCode The dialer code to send
3221 */
3222 @Override
3223 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003225 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003226 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3227 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003228 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003229 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003230 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
fionaxu235cc5e2017-03-06 22:25:57 -08003239 }
3240
Pengquan Menga1bb6272018-09-06 09:59:22 -07003241 @Override
3242 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003243 TelephonyPermissions
3244 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3245 mApp, subId, "getNetworkSelectionMode");
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 if (!isActiveSubscription(subId)) {
3249 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3250 }
3251 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003254 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003255 }
3256
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003258 public boolean isInEmergencySmsMode() {
3259 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 for (Phone phone : PhoneFactory.getPhones()) {
3263 if (phone.isInEmergencySmsMode()) {
3264 return true;
3265 }
3266 }
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
3270 return false;
3271 }
3272
shilu366312e2019-12-17 09:28:10 -08003273 /**
3274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3275 * @param subId The subscription to use to check the configuration.
3276 * @param c The callback that will be used to send the result.
3277 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003278 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003279 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3280 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003281 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3282 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003283
Brad Ebinger77b832e2019-10-17 17:03:22 -07003284 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3285 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3286 "IMS not available on device.");
3287 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 final long token = Binder.clearCallingIdentity();
3289 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003291 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003293 } catch (ImsException e) {
3294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 } finally {
3296 Binder.restoreCallingIdentity(token);
3297 }
3298 }
3299
shilu366312e2019-12-17 09:28:10 -08003300 /**
3301 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3302 * @param subId The subscription to use to check the configuration.
3303 * @param c The callback that will be used to send the result.
3304 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003306 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003307 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3308 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3311 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003312 final long token = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3315 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3316 .removeRegistrationCallbackForSubscription(c, subId);
3317 } catch (ImsException e) {
3318 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3319 + "is inactive, ignoring unregister.");
3320 // If the subscription is no longer active, just return, since the callback
3321 // will already have been removed internally.
3322 } finally {
3323 Binder.restoreCallingIdentity(token);
3324 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 }
3326
Brad Ebinger774ba362019-10-22 17:36:18 -07003327 /**
3328 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3329 */
3330 @Override
3331 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3332 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3333 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3335 "IMS not available on device.");
3336 }
3337 final long token = Binder.clearCallingIdentity();
3338 try {
3339 Phone phone = getPhone(subId);
3340 if (phone == null) {
3341 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3342 + subId + "'");
3343 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3344 }
3345 phone.getImsRegistrationState(regState -> {
3346 try {
3347 consumer.accept((regState == null)
3348 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3349 } catch (RemoteException e) {
3350 // Ignore if the remote process is no longer available to call back.
3351 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3352 }
3353 });
3354 } finally {
3355 Binder.restoreCallingIdentity(token);
3356 }
3357 }
3358
3359 /**
3360 * Get the transport type for the IMS service registration state.
3361 */
3362 @Override
3363 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003364 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3365 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003366 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3367 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3368 "IMS not available on device.");
3369 }
3370 final long token = Binder.clearCallingIdentity();
3371 try {
3372 Phone phone = getPhone(subId);
3373 if (phone == null) {
3374 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3375 + subId + "'");
3376 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3377 }
3378 phone.getImsRegistrationTech(regTech -> {
3379 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3380 int regTechConverted = (regTech == null)
3381 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3382 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3383 regTechConverted);
3384 try {
3385 consumer.accept(regTechConverted);
3386 } catch (RemoteException e) {
3387 // Ignore if the remote process is no longer available to call back.
3388 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3389 }
3390 });
3391 } finally {
3392 Binder.restoreCallingIdentity(token);
3393 }
3394 }
3395
shilu366312e2019-12-17 09:28:10 -08003396 /**
3397 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3398 * @param subId The subscription to use to check the configuration.
3399 * @param c The callback that will be used to send the result.
3400 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003402 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3403 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003404 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3405 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003406 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3408 "IMS not available on device.");
3409 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3411 final long token = Binder.clearCallingIdentity();
3412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (ImsException e) {
3416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
3420 }
3421
shilu366312e2019-12-17 09:28:10 -08003422 /**
3423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3424 * @param subId The subscription to use to check the configuration.
3425 * @param c The callback that will be used to send the result.
3426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003428 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003429 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3430 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3433 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003434
3435 final long token = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003439 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003440 } catch (ImsException e) {
3441 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3442 + "is inactive, ignoring unregister.");
3443 // If the subscription is no longer active, just return, since the callback
3444 // will already have been removed internally.
3445 } finally {
3446 Binder.restoreCallingIdentity(token);
3447 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 }
3449
3450 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003451 public boolean isCapable(int subId, int capability, int regTech) {
3452 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3454 final long token = Binder.clearCallingIdentity();
3455 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003458 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3460 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003462 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3463 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 } finally {
3465 Binder.restoreCallingIdentity(token);
3466 }
3467 }
3468
3469 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003470 public boolean isAvailable(int subId, int capability, int regTech) {
3471 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003472 final long token = Binder.clearCallingIdentity();
3473 try {
3474 Phone phone = getPhone(subId);
3475 if (phone == null) return false;
3476 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003477 } catch (com.android.ims.ImsException e) {
3478 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3479 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 } finally {
3481 Binder.restoreCallingIdentity(token);
3482 }
3483 }
3484
Brad Ebinger77b832e2019-10-17 17:03:22 -07003485 /**
3486 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3487 * subscription.
3488 * @param subId The subscription to use to check the configuration.
3489 * @param callback The callback that will be used to send the result.
3490 * @param capability The MmTelFeature capability that will be used to send the result.
3491 * @param transportType The transport type of the MmTelFeature capability.
3492 */
3493 @Override
3494 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3495 int transportType) {
3496 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3497 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3498 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3499 "IMS not available on device.");
3500 }
3501 final long token = Binder.clearCallingIdentity();
3502 try {
3503 int slotId = getSlotIndex(subId);
3504 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3505 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3506 + subId + "'");
3507 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3508 }
3509 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3510 transportType, aBoolean -> {
3511 try {
3512 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3513 } catch (RemoteException e) {
3514 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3515 + "running. Ignore");
3516 }
3517 });
3518 } finally {
3519 Binder.restoreCallingIdentity(token);
3520 }
3521 }
3522
shilu366312e2019-12-17 09:28:10 -08003523 /**
3524 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3525 * @param subId The subscription to use to check the configuration.
3526 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 @Override
3528 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003529 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3530 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003531
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3533 final long token = Binder.clearCallingIdentity();
3534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
3538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 } finally {
3540 Binder.restoreCallingIdentity(token);
3541 }
3542 }
3543
3544 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003545 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003547 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003551 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 } catch (ImsException e) {
3554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
shilu366312e2019-12-17 09:28:10 -08003560 /**
3561 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3562 * @param subId The subscription to use to check the configuration.
3563 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003565 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003566 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3567 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3572 } catch (ImsException e) {
3573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
3579 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003580 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003582 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003586 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
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 boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003600 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3601 mApp, subId, "isVoWiFiSettingEnabled");
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)).isWfcEnabledByUser();
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
Brad Ebinger1c162042019-02-21 14:49:10 -08003615 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003617 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 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, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003622 } catch (ImsException e) {
3623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
shilu366312e2019-12-17 09:28:10 -08003629 /**
3630 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3631 * @param subId The subscription to use to check the configuration.
3632 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 @Override
3634 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003635 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3636 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003642 } catch (ImsException e) {
3643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
3647 }
3648
3649 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003650 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003652 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003658 } catch (ImsException e) {
3659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
3663 }
3664
3665 @Override
3666 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3668 "setVoWiFiNonPersistent");
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003673 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (ImsException e) {
3675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
shilu366312e2019-12-17 09:28:10 -08003681 /**
3682 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3683 * @param subId The subscription to use to check the configuration.
3684 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 @Override
3686 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003687 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3688 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setVoWiFiModeSetting(int subId, int mode) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setVoWiFiModeSetting");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public int getVoWiFiRoamingModeSetting(int subId) {
3719 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3735 "setVoWiFiRoamingModeSetting");
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (ImsException e) {
3742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
3746 }
3747
3748 @Override
3749 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3751 "setRttCapabilityEnabled");
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
shilu366312e2019-12-17 09:28:10 -08003763 /**
3764 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3765 * @param subId The subscription to use to check the configuration.
3766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 @Override
3768 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003769 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3770 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 } catch (ImsException e) {
3777 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
3781 }
3782
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003783 @Override
3784 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3785 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003788 if (!isImsAvailableOnDevice()) {
3789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3790 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003794 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
3796 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
3800 }
3801
3802 @Override
3803 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3804 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3805 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3808 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003809 try {
3810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003812 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003813 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003814 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3815 + "is inactive, ignoring unregister.");
3816 // If the subscription is no longer active, just return, since the callback will already
3817 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
allenwtsu99c623b2020-01-03 18:24:23 +08003823
3824 private void checkModifyPhoneStatePermission(int subId, String message) {
3825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3826 message);
3827 }
3828
3829 private boolean isImsProvisioningRequired(int subId, int capability,
3830 boolean isMmtelCapability) {
3831 Phone phone = getPhone(subId);
3832 if (phone == null) {
3833 loge("phone instance null for subid " + subId);
3834 return false;
3835 }
3836 if (isMmtelCapability) {
3837 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3838 return false;
3839 }
3840 } else {
3841 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3842 return false;
3843 }
3844 }
3845 return true;
3846 }
3847
3848 @Override
3849 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3850 boolean isProvisioned) {
3851 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3852
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3856 if (!isImsProvisioningRequired(subId, capability, false)) {
3857 return;
3858 }
3859
3860 // this capability requires provisioning, route to the correct API.
3861 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3862 switch (capability) {
3863 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3864 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3865 ims.setEabProvisioned(isProvisioned);
3866 break;
3867 default: {
3868 throw new IllegalArgumentException("Tried to set provisioning for "
3869 + "rcs capability '" + capability + "', which does not require "
3870 + "provisioning.");
3871 }
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
3876
3877 }
3878
3879
3880 @Override
3881 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3882 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3886 if (!isImsProvisioningRequired(subId, capability, false)) {
3887 return true;
3888 }
3889
3890 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3891 switch (capability) {
3892 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3893 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3894 return ims.isEabProvisionedOnDevice();
3895
3896 default: {
3897 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3898 + "capability '" + capability + "', which does not require "
3899 + "provisioning.");
3900 }
3901 }
3902
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
3906 }
3907
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003908 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003909 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3910 boolean isProvisioned) {
3911 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3912 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3913 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3914 }
allenwtsu99c623b2020-01-03 18:24:23 +08003915 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003919 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 return;
3921 }
3922
3923 // this capability requires provisioning, route to the correct API.
3924 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3925 switch (capability) {
3926 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3927 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3928 ims.setVolteProvisioned(isProvisioned);
3929 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3930 ims.setWfcProvisioned(isProvisioned);
3931 }
3932 break;
3933 }
3934 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3935 // There is currently no difference in VT provisioning type.
3936 ims.setVtProvisioned(isProvisioned);
3937 break;
3938 }
3939 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3940 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3941 // change the capability of the feature instead if needed.
3942 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3943 == isProvisioned) {
3944 // No change in provisioning.
3945 return;
3946 }
3947 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3948 try {
3949 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003951 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3952 + ", Exception" + e.getMessage());
3953 }
3954 break;
3955 }
3956 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003957 throw new IllegalArgumentException("Tried to set provisioning for "
3958 + "MmTel capability '" + capability + "', which does not require "
3959 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 }
3961 }
3962
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
3966 }
3967
3968 @Override
3969 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3970 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3971 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3973 }
3974 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003978 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003979 return true;
3980 }
3981
3982 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3983 switch (capability) {
3984 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3985 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3986 return ims.isVolteProvisionedOnDevice();
3987 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3988 return ims.isWfcProvisionedOnDevice();
3989 }
3990 // This should never happen, since we are checking tech above to make sure it
3991 // is either LTE or IWLAN.
3992 throw new IllegalArgumentException("Invalid radio technology for voice "
3993 + "capability.");
3994 }
3995 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3996 // There is currently no difference in VT provisioning type.
3997 return ims.isVtProvisionedOnDevice();
3998 }
3999 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4000 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4001 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4002 }
4003 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004004 throw new IllegalArgumentException(
4005 "Tried to get provisioning for MmTel capability '" + capability
4006 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004007 }
4008 }
4009
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 }
4014
4015 @Override
4016 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4017 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4018 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4019 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4020 }
4021 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4022 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4023 return (provisionedBits & capability) > 0;
4024 }
4025
4026 @Override
4027 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4028 boolean isProvisioned) {
4029 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4030 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4031 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4032 }
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setProvisioningStatusForCapability");
4035 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4036 // If the current provisioning status for capability already matches isProvisioned,
4037 // do nothing.
4038 if (((provisionedBits & capability) > 0) == isProvisioned) {
4039 return;
4040 }
4041 if (isProvisioned) {
4042 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4043 } else {
4044 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4045 }
4046 }
4047
4048 /**
4049 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4050 * technology. The bitfield should mirror the bitfield defined by
4051 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4052 */
4053 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4054 String key = getMmTelProvisioningKey(subId, tech);
4055 // Default is no capabilities are provisioned.
4056 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4057 }
4058
4059 /**
4060 * Sets the MmTel capability provisioning bitfield (defined by
4061 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4062 * technology specified.
4063 *
4064 * Note: This is a synchronous command and should not be called on UI thread.
4065 */
4066 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4067 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4068 String key = getMmTelProvisioningKey(subId, tech);
4069 editor.putInt(key, newField);
4070 editor.commit();
4071 }
4072
4073 private static String getMmTelProvisioningKey(int subId, int tech) {
4074 // resulting key is provision_ims_mmtel_{subId}_{tech}
4075 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4076 }
4077
4078 /**
4079 * Query CarrierConfig to see if the specified capability requires provisioning for the
4080 * carrier associated with the subscription id.
4081 */
4082 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4083 int capability) {
4084 CarrierConfigManager configManager = new CarrierConfigManager(context);
4085 PersistableBundle c = configManager.getConfigForSubId(subId);
4086 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004087 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004088 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4089 false);
4090 boolean requireVoiceVtProvisioning = c.getBoolean(
4091 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4092
4093 // First check to make sure that the capability requires provisioning.
4094 switch (capability) {
4095 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4096 // intentional fallthrough
4097 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4098 if (requireVoiceVtProvisioning) {
4099 // Voice and Video requires provisioning
4100 return true;
4101 }
4102 break;
4103 }
4104 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4105 if (requireUtProvisioning) {
4106 // UT requires provisioning
4107 return true;
4108 }
4109 break;
4110 }
4111 }
4112 return false;
4113 }
4114
allenwtsu99c623b2020-01-03 18:24:23 +08004115 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4116 int capability) {
4117 CarrierConfigManager configManager = new CarrierConfigManager(context);
4118 PersistableBundle c = configManager.getConfigForSubId(subId);
4119
4120 boolean requireRcsProvisioning = c.getBoolean(
4121 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4122
4123 // First check to make sure that the capability requires provisioning.
4124 switch (capability) {
4125 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4126 // intentional fallthrough
4127 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4128 if (requireRcsProvisioning) {
4129 // OPTION or PRESENCE requires provisioning
4130 return true;
4131 }
4132 break;
4133 }
4134 }
4135 return false;
4136 }
4137
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004140 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4141 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4142 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004143 enforceReadPrivilegedPermission("getImsProvisioningInt");
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 int slotId = getSlotIndex(subId);
4148 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4149 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4150 + subId + "' for key:" + key);
4151 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4152 }
4153 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004154 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004155 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4156 + subId + "' for key:" + key);
4157 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4166 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4167 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004168 enforceReadPrivilegedPermission("getImsProvisioningString");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 int slotId = getSlotIndex(subId);
4173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4174 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4175 + subId + "' for key:" + key);
4176 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4177 }
4178 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4181 + subId + "' for key:" + key);
4182 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
4188 @Override
4189 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4191 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4192 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4194 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 int slotId = getSlotIndex(subId);
4199 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4200 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4201 + subId + "' for key:" + key);
4202 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4203 }
4204 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004206 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4207 + "' for key:" + key);
4208 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
4214 @Override
4215 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4217 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4218 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4220 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 int slotId = getSlotIndex(subId);
4225 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4226 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4227 + subId + "' for key:" + key);
4228 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4229 }
4230 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004231 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004232 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4233 + "' for key:" + key);
4234 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 int slotId = SubscriptionManager.getSlotIndex(subId);
4242 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4244 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 }
4246 return slotId;
4247 }
4248
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004249 private int getSlotIndex(int subId) {
4250 int slotId = SubscriptionManager.getSlotIndex(subId);
4251 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4252 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4253 }
4254 return slotId;
4255 }
4256
Wink Saville36469e72014-06-11 15:17:00 -07004257 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004258 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004259 */
4260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004261 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4262 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004263 final int targetSdk = getTargetSdk(callingPackage);
4264 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004265 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004266 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004267 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004268 mApp, subId, callingPackage, callingFeatureId,
4269 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4271 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final Phone phone = getPhone(subId);
4276 if (phone != null) {
4277 return phone.getServiceState().getDataNetworkType();
4278 } else {
4279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4280 }
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004284 }
4285
4286 /**
4287 * Returns the data network type
4288 */
4289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004290 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4291 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4292 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004293 }
4294
4295 /**
4296 * Returns the data network type for a subId
4297 */
4298 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004299 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4300 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004302 mApp, subId, callingPackage, callingFeatureId,
4303 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4305 }
4306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 final Phone phone = getPhone(subId);
4310 if (phone != null) {
4311 return phone.getServiceState().getDataNetworkType();
4312 } else {
4313 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004318 }
4319
4320 /**
Wink Saville36469e72014-06-11 15:17:00 -07004321 * Returns the Voice network type for a subId
4322 */
4323 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004324 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4325 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004327 mApp, subId, callingPackage, callingFeatureId,
4328 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4330 }
4331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 final Phone phone = getPhone(subId);
4335 if (phone != null) {
4336 return phone.getServiceState().getVoiceNetworkType();
4337 } else {
4338 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4339 }
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004343 }
4344
4345 /**
4346 * @return true if a ICC card is present
4347 */
4348 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004349 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004350 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4351 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
4354 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004355 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004357 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004358 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 final Phone phone = PhoneFactory.getPhone(slotIndex);
4362 if (phone != null) {
4363 return phone.getIccCard().hasIccCard();
4364 } else {
4365 return false;
4366 }
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004370 }
4371
4372 /**
4373 * Return if the current radio is LTE on CDMA. This
4374 * is a tri-state return value as for a period of time
4375 * the mode may be unknown.
4376 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004377 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004378 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004379 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004380 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004382 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4383 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4384 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004385 }
4386
Sanket Padawe356d7632015-06-22 14:03:32 -07004387 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004388 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4389 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004390 try {
4391 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4392 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004393 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4394 }
4395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 final Phone phone = getPhone(subId);
4399 if (phone == null) {
4400 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4401 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004402 return TelephonyProperties.lte_on_cdma_device()
4403 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 }
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004407 }
Wink Saville36469e72014-06-11 15:17:00 -07004408 }
4409
Wink Saville36469e72014-06-11 15:17:00 -07004410 /**
4411 * {@hide}
4412 * Returns Default subId, 0 in the case of single standby.
4413 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004414 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004415 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004416 }
4417
Shishir Agrawala9f32182016-04-12 12:00:16 -07004418 private int getSlotForDefaultSubscription() {
4419 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4420 }
4421
Wink Savilleb564aae2014-10-23 10:18:09 -07004422 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004423 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004424 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004425
Pengquan Menge92a50d2018-09-21 15:54:48 -07004426 private boolean isActiveSubscription(int subId) {
4427 return mSubscriptionController.isActiveSubId(subId);
4428 }
4429
Ihab Awadf2177b72013-11-25 13:33:23 -08004430 /**
4431 * @see android.telephony.TelephonyManager.WifiCallingChoices
4432 */
4433 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4438 getWhenToMakeWifiCallsDefaultPreference());
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004442 }
4443
4444 /**
4445 * @see android.telephony.TelephonyManager.WifiCallingChoices
4446 */
4447 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004451 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004456 }
4457
Sailesh Nepald1e68152013-12-12 19:08:02 -08004458 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004459 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004460 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004461 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004462
Jordan Liu4c733742019-02-28 12:03:40 -08004463 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4464 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4465 if (phoneId == -1) {
4466 throw new IllegalArgumentException("Given slot index: " + slotIndex
4467 + " does not correspond to an active phone");
4468 }
4469 return PhoneFactory.getPhone(phoneId);
4470 }
4471
Shishir Agrawal566b7612013-10-28 14:41:00 -07004472 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004473 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4474 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004478 if (DBG) {
4479 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4480 }
4481 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4482 p2);
4483 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004484
Jordan Liu4c733742019-02-28 12:03:40 -08004485
4486 @Override
4487 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4488 int slotIndex, String callingPackage, String aid, int p2) {
4489 enforceModifyPermission();
4490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4491 if (DBG) {
4492 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4493 }
4494 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4495 callingPackage, aid, p2);
4496 }
4497
4498 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4499 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 if (TextUtils.equals(ISDR_AID, aid)) {
4503 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004504 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4505 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 if (bestComponent == null
4507 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4508 loge("The calling package is not allowed to access ISD-R.");
4509 throw new SecurityException(
4510 "The calling package is not allowed to access ISD-R.");
4511 }
Derek Tan740e1672017-06-27 14:56:27 -07004512 }
Derek Tan740e1672017-06-27 14:56:27 -07004513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004515 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4516 null /* workSource */);
4517 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 return response;
4519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522 }
4523
4524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004525 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4529 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004531
Jordan Liu4c733742019-02-28 12:03:40 -08004532 @Override
4533 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4534 enforceModifyPermission();
4535 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4536 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4537 channel);
4538 }
4539
4540 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 final long identity = Binder.clearCallingIdentity();
4542 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 if (channel < 0) {
4544 return false;
4545 }
Jordan Liu4c733742019-02-28 12:03:40 -08004546 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4547 null /* workSource */);
4548 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 return success;
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004553 }
4554
4555 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004556 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004557 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4559 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004560 if (DBG) {
4561 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4562 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4563 + p3 + " data=" + data);
4564 }
4565 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4566 command, p1, p2, p3, data);
4567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004568
Jordan Liu4c733742019-02-28 12:03:40 -08004569 @Override
4570 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4571 int command, int p1, int p2, int p3, String data) {
4572 enforceModifyPermission();
4573 if (DBG) {
4574 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4575 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4576 + p3 + " data=" + data);
4577 }
4578 return iccTransmitApduLogicalChannelWithPermission(
4579 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4580 data);
4581 }
4582
4583 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4584 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004587 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 return "";
4589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004592 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4593 null /* workSource */);
4594 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 // Append the returned status code to the end of the response payload.
4597 String s = Integer.toHexString(
4598 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4599 if (response.payload != null) {
4600 s = IccUtils.bytesToHexString(response.payload) + s;
4601 }
4602 return s;
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004606 }
Jake Hambye994d462014-02-03 13:10:13 -08004607
Evan Charltonc66da362014-05-16 14:06:40 -07004608 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004609 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4610 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4612 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004614 if (DBG) {
4615 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4616 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4617 }
4618 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4619 cla, command, p1, p2, p3, data);
4620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004621
Jordan Liu4c733742019-02-28 12:03:40 -08004622 @Override
4623 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4624 int command, int p1, int p2, int p3, String data) {
4625 enforceModifyPermission();
4626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4627 if (DBG) {
4628 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4629 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4630 + " data=" + data);
4631 }
4632
4633 return iccTransmitApduBasicChannelWithPermission(
4634 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4635 p2, p3, data);
4636 }
4637
4638 // open APDU basic channel assuming the caller has sufficient permissions
4639 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4640 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 final long identity = Binder.clearCallingIdentity();
4642 try {
4643 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4644 && TextUtils.equals(ISDR_AID, data)) {
4645 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004646 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4647 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 if (bestComponent == null
4649 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4650 loge("The calling package is not allowed to select ISD-R.");
4651 throw new SecurityException(
4652 "The calling package is not allowed to select ISD-R.");
4653 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004654 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004657 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4658 null /* workSource */);
4659 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 // Append the returned status code to the end of the response payload.
4662 String s = Integer.toHexString(
4663 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4664 if (response.payload != null) {
4665 s = IccUtils.bytesToHexString(response.payload) + s;
4666 }
4667 return s;
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004670 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004671 }
4672
4673 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004674 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004675 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4677 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 if (DBG) {
4682 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4683 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4684 }
4685
4686 IccIoResult response =
4687 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4688 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4689 subId);
4690
4691 if (DBG) {
4692 log("Exchange SIM_IO [R]" + response);
4693 }
4694
4695 byte[] result = null;
4696 int length = 2;
4697 if (response.payload != null) {
4698 length = 2 + response.payload.length;
4699 result = new byte[length];
4700 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4701 } else {
4702 result = new byte[length];
4703 }
4704
4705 result[length - 1] = (byte) response.sw2;
4706 result[length - 2] = (byte) response.sw1;
4707 return result;
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004710 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004711 }
4712
Nathan Haroldb3014052017-01-25 15:57:32 -08004713 /**
4714 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4715 * on a particular subscription
4716 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004717 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4718 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004721 return null;
4722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 if (appType != TelephonyManager.APPTYPE_USIM
4727 && appType != TelephonyManager.APPTYPE_SIM) {
4728 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4729 return null;
4730 }
4731 Object response = sendRequest(
4732 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4733 if (response instanceof String[]) {
4734 return (String[]) response;
4735 }
yincheng zhaod698b842019-09-06 17:06:54 -07004736 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004738 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004741 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004742 }
4743
yincheng zhaod698b842019-09-06 17:06:54 -07004744 /**
4745 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4746 * subscription.
4747 *
4748 * @param subId the id of the subscription.
4749 * @param appType the uicc app type, must be USIM or SIM.
4750 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4751 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004753 * @return number of fplmns that is successfully written to the SIM.
4754 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004755 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4756 String callingFeatureId) {
4757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4758 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004759 if (DBG) logv("no permissions for setForbiddenplmns");
4760 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4761 }
4762 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4763 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4764 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4765 }
4766 if (fplmns == null) {
4767 throw new IllegalArgumentException("Fplmn List provided is null");
4768 }
4769 for (String fplmn : fplmns) {
4770 if (!CellIdentity.isValidPlmn(fplmn)) {
4771 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4772 }
4773 }
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 Object response = sendRequest(
4777 CMD_SET_FORBIDDEN_PLMNS,
4778 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4779 subId);
4780 return (int) response;
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004787 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4789 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4794 if (response.payload == null) {
4795 return "";
4796 }
Evan Charltonc66da362014-05-16 14:06:40 -07004797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 // Append the returned status code to the end of the response payload.
4799 String s = Integer.toHexString(
4800 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4801 s = IccUtils.bytesToHexString(response.payload) + s;
4802 return s;
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Evan Charltonc66da362014-05-16 14:06:40 -07004806 }
4807
Jake Hambye994d462014-02-03 13:10:13 -08004808 /**
4809 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4810 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4811 *
4812 * @param itemID the ID of the item to read
4813 * @return the NV item as a String, or null on error.
4814 */
4815 @Override
4816 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004817 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4819 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820
4821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004824 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4826 return value;
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Jake Hambye994d462014-02-03 13:10:13 -08004830 }
4831
4832 /**
4833 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4834 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4835 *
4836 * @param itemID the ID of the item to read
4837 * @param itemValue the value to write, as a String
4838 * @return true on success; false on any failure
4839 */
4840 @Override
4841 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4844 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845
4846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4849 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004850 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4852 return success;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Jake Hambye994d462014-02-03 13:10:13 -08004856 }
4857
4858 /**
4859 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4860 * Used for device configuration by some CDMA operators.
4861 *
4862 * @param preferredRoamingList byte array containing the new PRL
4863 * @return true on success; false on any failure
4864 */
4865 @Override
4866 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4868 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869
4870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4873 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4874 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4875 return success;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Jake Hambye994d462014-02-03 13:10:13 -08004879 }
4880
4881 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004882 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004883 * Used for device configuration by some CDMA operators.
4884 *
chen xu6dac5ab2018-10-26 17:39:23 -07004885 * @param slotIndex - device slot.
4886 *
Jake Hambye994d462014-02-03 13:10:13 -08004887 * @return true on success; false on any failure
4888 */
4889 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004890 public boolean resetModemConfig(int slotIndex) {
4891 Phone phone = PhoneFactory.getPhone(slotIndex);
4892 if (phone != null) {
4893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4894 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895
chen xu6dac5ab2018-10-26 17:39:23 -07004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4899 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4900 return success;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 }
chen xu6dac5ab2018-10-26 17:39:23 -07004905 return false;
4906 }
4907
4908 /**
4909 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4910 *
4911 * @param slotIndex - device slot.
4912 *
4913 * @return true on success; false on any failure
4914 */
4915 @Override
4916 public boolean rebootModem(int slotIndex) {
4917 Phone phone = PhoneFactory.getPhone(slotIndex);
4918 if (phone != null) {
4919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4920 mApp, phone.getSubId(), "rebootModem");
4921
4922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4925 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4926 return success;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004932 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004933
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004934 public String[] getPcscfAddress(String apnType, String callingPackage,
4935 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4938 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004939 return new String[0];
4940 }
4941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004944 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Wink Saville36469e72014-06-11 15:17:00 -07004948 }
4949
Brad Ebinger51f743a2017-01-23 13:50:20 -08004950 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004951 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4952 * {@link #disableIms(int)}.
4953 * @param slotIndex device slot.
4954 */
4955 public void resetIms(int slotIndex) {
4956 enforceModifyPermission();
4957
4958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 if (mImsResolver == null) {
4961 // may happen if the does not support IMS.
4962 return;
4963 }
4964 mImsResolver.disableIms(slotIndex);
4965 mImsResolver.enableIms(slotIndex);
4966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
4971 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004972 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4973 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004974 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004980 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004981 // may happen if the device does not support IMS.
4982 return;
4983 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004984 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004988 }
4989
4990 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004991 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4992 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004993 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004994 public void disableIms(int slotId) {
4995 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 // may happen if the device does not support IMS.
5001 return;
5002 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005003 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005007 }
5008
5009 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005010 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5011 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005012 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005013 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005014 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005015 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016
5017 final long identity = Binder.clearCallingIdentity();
5018 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005019 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005020 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5021 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005022 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005023 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 } finally {
5025 Binder.restoreCallingIdentity(identity);
5026 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005027 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005028 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005029 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5030 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005031 @Override
5032 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005033 enforceModifyPermission();
5034
5035 final long identity = Binder.clearCallingIdentity();
5036 try {
5037 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005038 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005039 } finally {
5040 Binder.restoreCallingIdentity(identity);
5041 }
5042 }
5043
5044 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005045 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005046 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005047 */
5048 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5049 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005050
5051 final long identity = Binder.clearCallingIdentity();
5052 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005053 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005054 // may happen if the device does not support IMS.
5055 return null;
5056 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005057 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058 } finally {
5059 Binder.restoreCallingIdentity(identity);
5060 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005061 }
5062
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005063 /**
5064 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005065 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005066 */
5067 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5068 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005069
5070 final long identity = Binder.clearCallingIdentity();
5071 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005072 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005073 // may happen if the device does not support IMS.
5074 return null;
5075 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005076 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077 } finally {
5078 Binder.restoreCallingIdentity(identity);
5079 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005080 }
5081
Brad Ebinger884c07b2018-02-15 16:17:40 -08005082 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005083 * Sets the ImsService Package Name that Telephony will bind to.
5084 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005085 * @param slotIndex the slot ID that the ImsService should bind for.
5086 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005087 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005088 * @param featureTypes An integer array of feature types associated with a packageName.
5089 * @param packageName The name of the package that the current configuration will be replaced
5090 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005092 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005093 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5094 int[] featureTypes, String packageName) {
5095 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5096 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005097 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5098 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005099 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005100
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005101 final long identity = Binder.clearCallingIdentity();
5102 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005103 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005104 // may happen if the device does not support IMS.
5105 return false;
5106 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005107 Map<Integer, String> featureConfig = new HashMap<>();
5108 for (int featureType : featureTypes) {
5109 featureConfig.put(featureType, packageName);
5110 }
5111 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5112 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005113 } finally {
5114 Binder.restoreCallingIdentity(identity);
5115 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005116 }
5117
5118 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005119 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005120 *
5121 * @param slotId The slot that the ImsService is associated with.
5122 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5123 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005124 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005125 * @return the package name of the ImsService configuration.
5126 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005127 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5128 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005129 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005130 TelephonyPermissions
5131 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5132 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5133 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005134
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005135 final long identity = Binder.clearCallingIdentity();
5136 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005137 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005138 // may happen if the device does not support IMS.
5139 return "";
5140 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005141 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005142 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5143 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005147 }
5148
Brad Ebinger77b832e2019-10-17 17:03:22 -07005149 /**
5150 * Get the MmTelFeature state associated with the requested subscription id.
5151 * @param subId The subscription that the MmTelFeature is associated with.
5152 * @param callback A callback with an integer containing the
5153 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5154 */
5155 @Override
5156 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5157 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5158 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5159 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5160 "IMS not available on device.");
5161 }
5162 final long token = Binder.clearCallingIdentity();
5163 try {
5164 int slotId = getSlotIndex(subId);
5165 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5166 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5167 + subId + "'");
5168 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5169 }
5170 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5171 try {
5172 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5173 } catch (RemoteException e) {
5174 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5175 + "Ignore");
5176 }
5177 });
5178 } finally {
5179 Binder.restoreCallingIdentity(token);
5180 }
5181 }
5182
Wink Saville36469e72014-06-11 15:17:00 -07005183 public void setImsRegistrationState(boolean registered) {
5184 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005185
5186 final long identity = Binder.clearCallingIdentity();
5187 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005188 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005189 } finally {
5190 Binder.restoreCallingIdentity(identity);
5191 }
Wink Saville36469e72014-06-11 15:17:00 -07005192 }
5193
5194 /**
Stuart Scott54788802015-03-30 13:18:01 -07005195 * Set the network selection mode to automatic.
5196 *
5197 */
5198 @Override
5199 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5201 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005202
5203 final long identity = Binder.clearCallingIdentity();
5204 try {
shilufc958392020-01-20 11:36:01 -08005205 if (!isActiveSubscription(subId)) {
5206 return;
5207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5209 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Stuart Scott54788802015-03-30 13:18:01 -07005213 }
5214
Jack Yud10cdd42020-09-28 20:28:01 -07005215 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005216 * Ask the radio to connect to the input network and change selection mode to manual.
5217 *
5218 * @param subId the id of the subscription.
5219 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5220 * the operator to attach to.
5221 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5222 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5223 * normal network selection next time.
5224 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005225 */
5226 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005227 public boolean setNetworkSelectionModeManual(
5228 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005229 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5230 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005231
5232 if (!isActiveSubscription(subId)) {
5233 return false;
5234 }
5235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 final long identity = Binder.clearCallingIdentity();
5237 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005238 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005240 if (DBG) {
5241 log("setNetworkSelectionModeManual: subId: " + subId
5242 + " operator: " + operatorInfo);
5243 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5245 } finally {
5246 Binder.restoreCallingIdentity(identity);
5247 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005248 }
shilu84f6e8b2019-12-19 13:58:01 -08005249 /**
5250 * Get the manual network selection
5251 *
5252 * @param subId the id of the subscription.
5253 *
5254 * @return the previously saved user selected PLMN
5255 */
5256 @Override
5257 public String getManualNetworkSelectionPlmn(int subId) {
5258 TelephonyPermissions
5259 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5260 mApp, subId, "getManualNetworkSelectionPlmn");
5261
5262 final long identity = Binder.clearCallingIdentity();
5263 try {
5264 if (!isActiveSubscription(subId)) {
5265 return "";
5266 }
5267
5268 final Phone phone = getPhone(subId);
5269 if (phone == null) {
5270 return "";
5271 }
5272 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5273 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5274 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5275 } finally {
5276 Binder.restoreCallingIdentity(identity);
5277 }
5278 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005279
5280 /**
5281 * Scans for available networks.
5282 */
5283 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005284 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5285 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005286 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5287 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005288 LocationAccessPolicy.LocationPermissionResult locationResult =
5289 LocationAccessPolicy.checkLocationPermission(mApp,
5290 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5291 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005292 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005293 .setCallingPid(Binder.getCallingPid())
5294 .setCallingUid(Binder.getCallingUid())
5295 .setMethod("getCellNetworkScanResults")
5296 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5297 .build());
5298 switch (locationResult) {
5299 case DENIED_HARD:
5300 throw new SecurityException("Not allowed to access scan results -- location");
5301 case DENIED_SOFT:
5302 return null;
5303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005304
Pengquan Menga1bb6272018-09-06 09:59:22 -07005305 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306 try {
5307 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005308 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005313 }
5314
5315 /**
sqian80370722020-01-29 15:02:51 -08005316 * Get the call forwarding info, given the call forwarding reason.
5317 */
5318 @Override
5319 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5320 enforceReadPrivilegedPermission("getCallForwarding");
5321 long identity = Binder.clearCallingIdentity();
5322 try {
5323 if (DBG) {
5324 log("getCallForwarding: subId " + subId
5325 + " callForwardingReason" + callForwardingReason);
5326 }
5327 return (CallForwardingInfo) sendRequest(
5328 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5329 } finally {
5330 Binder.restoreCallingIdentity(identity);
5331 }
5332 }
5333
5334 /**
5335 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5336 * reason, the number to forward, and the timeout before the forwarding is attempted.
5337 */
5338 @Override
5339 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5340 enforceModifyPermission();
5341 long identity = Binder.clearCallingIdentity();
5342 try {
5343 if (DBG) {
5344 log("setCallForwarding: subId " + subId
5345 + " callForwardingInfo" + callForwardingInfo);
5346 }
5347 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5348 } finally {
5349 Binder.restoreCallingIdentity(identity);
5350 }
5351 }
5352
5353 /**
5354 * Get the call forwarding info, given the call forwarding reason.
5355 */
5356 @Override
5357 public int getCallWaitingStatus(int subId) {
5358 enforceReadPrivilegedPermission("getCallForwarding");
5359 long identity = Binder.clearCallingIdentity();
5360 try {
5361 if (DBG) log("getCallWaitingStatus: subId " + subId);
5362 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5363 } finally {
5364 Binder.restoreCallingIdentity(identity);
5365 }
5366 }
5367
5368 /**
5369 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5370 * reason, the number to forward, and the timeout before the forwarding is attempted.
5371 */
5372 @Override
5373 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5374 enforceModifyPermission();
5375 long identity = Binder.clearCallingIdentity();
5376 try {
5377 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5378 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5379 } finally {
5380 Binder.restoreCallingIdentity(identity);
5381 }
5382 }
5383
5384 /**
yinxub1bed742017-04-17 11:45:04 -07005385 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005386 *
yinxub1bed742017-04-17 11:45:04 -07005387 * @param subId id of the subscription
5388 * @param request contains the radio access networks with bands/channels to scan
5389 * @param messenger callback messenger for scan results or errors
5390 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005391 * @return the id of the requested scan which can be used to stop the scan.
5392 */
5393 @Override
5394 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005395 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5397 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005398 LocationAccessPolicy.LocationPermissionResult locationResult =
5399 LocationAccessPolicy.checkLocationPermission(mApp,
5400 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5401 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005402 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005403 .setCallingPid(Binder.getCallingPid())
5404 .setCallingUid(Binder.getCallingUid())
5405 .setMethod("requestNetworkScan")
5406 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5407 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005408 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005409 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5410 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005411 if (e != null) {
5412 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5413 throw e;
5414 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005415 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005416 return TelephonyScanManager.INVALID_SCAN_ID;
5417 }
5418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005419 }
Hall Liu912dfd32019-04-25 14:02:26 -07005420 int callingUid = Binder.getCallingUid();
5421 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005422 final long identity = Binder.clearCallingIdentity();
5423 try {
5424 return mNetworkScanRequestTracker.startNetworkScan(
5425 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005426 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005427 } finally {
5428 Binder.restoreCallingIdentity(identity);
5429 }
yinxu504e1392017-04-12 16:03:22 -07005430 }
5431
Hall Liub2ac8ef2019-02-28 15:56:23 -08005432 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005433 NetworkScanRequest request, int subId, String callingPackage) {
5434 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005435 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5436 boolean hasNetworkScanPermission =
5437 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5438 == PERMISSION_GRANTED;
5439
5440 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5441 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5442 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005443 }
5444
5445 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5446 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005447 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5448 return new SecurityException("Specific channels must not be"
5449 + " scanned without location access.");
5450 }
5451 }
5452 }
5453
Hall Liub2ac8ef2019-02-28 15:56:23 -08005454 return null;
5455 }
5456
yinxu504e1392017-04-12 16:03:22 -07005457 /**
5458 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005459 *
5460 * @param subId id of the subscription
5461 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005462 */
5463 @Override
5464 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005465 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5466 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467
Hall Liu912dfd32019-04-25 14:02:26 -07005468 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469 final long identity = Binder.clearCallingIdentity();
5470 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005471 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005472 } finally {
5473 Binder.restoreCallingIdentity(identity);
5474 }
yinxu504e1392017-04-12 16:03:22 -07005475 }
5476
5477 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005478 * Get the calculated preferred network type.
5479 * Used for debugging incorrect network type.
5480 *
5481 * @return the preferred network type, defined in RILConstants.java.
5482 */
5483 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005484 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005485 final Phone defaultPhone = getDefaultPhone();
5486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005487 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005488 return RILConstants.PREFERRED_NETWORK_MODE;
5489 }
5490
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
5493 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Junda Liu84d15a22014-07-02 11:21:04 -07005498 }
5499
5500 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005501 * Get the preferred network type.
5502 * Used for device configuration by some CDMA operators.
5503 *
5504 * @return the preferred network type, defined in RILConstants.java.
5505 */
5506 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005507 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005508 TelephonyPermissions
5509 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5510 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005511
5512 final long identity = Binder.clearCallingIdentity();
5513 try {
5514 if (DBG) log("getPreferredNetworkType");
5515 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5516 int networkType = (result != null ? result[0] : -1);
5517 if (DBG) log("getPreferredNetworkType: " + networkType);
5518 return networkType;
5519 } finally {
5520 Binder.restoreCallingIdentity(identity);
5521 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005522 }
5523
5524 /**
5525 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005526 *
5527 * @param networkType the preferred network type, defined in RILConstants.java.
5528 * @return true on success; false on any failure.
5529 */
5530 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005531 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5533 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005534
5535 final long identity = Binder.clearCallingIdentity();
5536 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005537 Settings.Global.putInt(mApp.getContentResolver(),
5538 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005539
5540 Boolean success = (Boolean) sendRequest(
5541 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5542 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5543 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 } finally {
5545 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005546 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005547 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005548
5549 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005550 * Get the allowed network types that store in the telephony provider.
5551 *
5552 * @param subId the id of the subscription.
5553 * @return allowedNetworkTypes the allowed network types.
5554 */
5555 @Override
5556 public long getAllowedNetworkTypes(int subId) {
5557 TelephonyPermissions
5558 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5559 mApp, subId, "getAllowedNetworkTypes");
5560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 return SubscriptionManager.getLongSubscriptionProperty(
5564 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5565 } finally {
5566 Binder.restoreCallingIdentity(identity);
5567 }
5568 }
5569
5570 /**
5571 * Set the allowed network types.
5572 *
5573 * @param subId the id of the subscription.
5574 * @param allowedNetworkTypes the allowed network types.
5575 * @return true on success; false on any failure.
5576 */
5577 @Override
5578 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5580 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005581
calvinpan089c2a62020-03-12 14:17:55 +08005582 SubscriptionManager.setSubscriptionProperty(subId,
5583 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5584 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005585
calvinpan089c2a62020-03-12 14:17:55 +08005586 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5587 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5588 RILConstants.PREFERRED_NETWORK_MODE);
5589 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005590 }
5591
5592 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005593 * Get the allowed network types for certain reason.
5594 *
5595 * @param subId the id of the subscription.
5596 * @param reason the reason the allowed network type change is taking place
5597 * @return the allowed network types.
5598 */
5599 @Override
5600 public long getAllowedNetworkTypesForReason(int subId,
5601 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5602 TelephonyPermissions
5603 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5604 mApp, subId, "getAllowedNetworkTypesForReason");
5605 final long identity = Binder.clearCallingIdentity();
5606 try {
5607 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5608 } finally {
5609 Binder.restoreCallingIdentity(identity);
5610 }
5611 }
5612
5613 /**
5614 * Get the effective allowed network types on the device.
5615 * This API will return an intersection of allowed network types for all reasons,
5616 * including the configuration done through setAllowedNetworkTypes
5617 *
5618 * @param subId the id of the subscription.
5619 * @return the allowed network types
5620 */
5621 @Override
5622 public long getEffectiveAllowedNetworkTypes(int subId) {
5623 TelephonyPermissions
5624 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5625 mApp, subId, "getEffectiveAllowedNetworkTypes");
5626 final long identity = Binder.clearCallingIdentity();
5627 try {
5628 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5629 } finally {
5630 Binder.restoreCallingIdentity(identity);
5631 }
5632 }
5633
5634 /**
5635 * Set the allowed network types of the device and
5636 * provide the reason triggering the allowed network change.
5637 *
5638 * @param subId the id of the subscription.
5639 * @param reason the reason the allowed network type change is taking place
5640 * @param allowedNetworkTypes the allowed network types.
5641 * @return true on success; false on any failure.
5642 */
5643 @Override
5644 public boolean setAllowedNetworkTypesForReason(int subId,
5645 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5647 mApp, subId, "setAllowedNetworkTypesForReason");
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5651 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5652 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5653 RILConstants.PREFERRED_NETWORK_MODE);
5654 return setPreferredNetworkType(subId, preferredNetworkMode);
5655 } finally {
5656 Binder.restoreCallingIdentity(identity);
5657 }
5658 }
5659
5660 /**
Miaoa84611c2019-03-15 09:21:10 +08005661 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005662 *
Miaoa84611c2019-03-15 09:21:10 +08005663 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005664 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005665 * @hide
5666 */
5667 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005668 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005669 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005671 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 try {
Miaoa84611c2019-03-15 09:21:10 +08005673 if (phone != null) {
5674 return phone.hasMatchedTetherApnSetting();
5675 } else {
5676 return false;
5677 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 } finally {
5679 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005680 }
Junda Liu475951f2014-11-07 16:45:03 -08005681 }
5682
5683 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005684 * Set mobile data enabled
5685 * Used by the user through settings etc to turn on/off mobile data
5686 *
5687 * @param enable {@code true} turn turn data on, else {@code false}
5688 */
5689 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005690 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005691 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5692 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005693
5694 final long identity = Binder.clearCallingIdentity();
5695 try {
5696 int phoneId = mSubscriptionController.getPhoneId(subId);
5697 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5698 Phone phone = PhoneFactory.getPhone(phoneId);
5699 if (phone != null) {
5700 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005701 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005703 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 }
5705 } finally {
5706 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005707 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005708 }
5709
5710 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005711 * Enable or disable always reporting signal strength changes from radio.
5712 *
5713 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5714 */
5715 @Override
5716 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5717 enforceModifyPermission();
5718 enforceSystemCaller();
5719
5720 final long identity = Binder.clearCallingIdentity();
5721 final Phone phone = getPhone(subId);
5722 try {
5723 if (phone != null) {
5724 if (DBG) {
5725 log("setAlwaysReportSignalStrength: subId=" + subId
5726 + " isEnable=" + isEnable);
5727 }
5728 phone.setAlwaysReportSignalStrength(isEnable);
5729 } else {
5730 loge("setAlwaysReportSignalStrength: no phone found for subId="
5731 + subId);
5732 }
5733 } finally {
5734 Binder.restoreCallingIdentity(identity);
5735 }
5736 }
5737
5738 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005739 * Get the user enabled state of Mobile Data.
5740 *
5741 * TODO: remove and use isUserDataEnabled.
5742 * This can't be removed now because some vendor codes
5743 * calls through ITelephony directly while they should
5744 * use TelephonyManager.
5745 *
5746 * @return true on enabled
5747 */
5748 @Override
5749 public boolean getDataEnabled(int subId) {
5750 return isUserDataEnabled(subId);
5751 }
5752
5753 /**
5754 * Get whether mobile data is enabled per user setting.
5755 *
5756 * There are other factors deciding whether mobile data is actually enabled, but they are
5757 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005758 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005759 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005760 *
5761 * @return {@code true} if data is enabled else {@code false}
5762 */
5763 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005764 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005765 try {
5766 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5767 null);
5768 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005769 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5770 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005771 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772
5773 final long identity = Binder.clearCallingIdentity();
5774 try {
5775 int phoneId = mSubscriptionController.getPhoneId(subId);
5776 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5777 Phone phone = PhoneFactory.getPhone(phoneId);
5778 if (phone != null) {
5779 boolean retVal = phone.isUserDataEnabled();
5780 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5781 return retVal;
5782 } else {
5783 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5784 return false;
5785 }
5786 } finally {
5787 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005788 }
5789 }
5790
5791 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005792 * Checks if the device is capable of mobile data by considering whether whether the
5793 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5794 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005795 *
Shuo Qian985d1232020-01-08 14:30:06 -08005796 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005797 */
5798 @Override
5799 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005800 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005801
5802 final long identity = Binder.clearCallingIdentity();
5803 try {
5804 int phoneId = mSubscriptionController.getPhoneId(subId);
5805 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5806 Phone phone = PhoneFactory.getPhone(phoneId);
5807 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005808 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005809 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5810 return retVal;
5811 } else {
5812 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5813 return false;
5814 }
5815 } finally {
5816 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005817 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005818 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005819
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005820 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005821 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005822 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5823 // Skip the check if it's one of these special uids
5824 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5825 }
5826
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005827 //load access rules from carrier configs, and check those as well: b/139133814
5828 SubscriptionController subController = SubscriptionController.getInstance();
5829 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5830 || subController == null) return privilegeFromSim;
5831
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005832 PackageManager pkgMgr = phone.getContext().getPackageManager();
5833 String[] packages = pkgMgr.getPackagesForUid(uid);
5834
5835 final long identity = Binder.clearCallingIdentity();
5836 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005837 int subId = phone.getSubId();
5838 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5839 // A test override is in place for the privileges for this subId, so don't try to
5840 // read the subscription privileges.
5841 return privilegeFromSim;
5842 }
5843 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005844 SubscriptionManager subManager = (SubscriptionManager)
5845 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5846 for (String pkg : packages) {
5847 if (subManager.canManageSubscription(subInfo, pkg)) {
5848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5849 }
5850 }
5851 return privilegeFromSim;
5852 } finally {
5853 Binder.restoreCallingIdentity(identity);
5854 }
5855 }
5856
5857 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5858 String pkgName) {
5859 //load access rules from carrier configs, and check those as well: b/139133814
5860 SubscriptionController subController = SubscriptionController.getInstance();
5861 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5862 || subController == null) return privilegeFromSim;
5863
5864 final long identity = Binder.clearCallingIdentity();
5865 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005866 int subId = phone.getSubId();
5867 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5868 // A test override is in place for the privileges for this subId, so don't try to
5869 // read the subscription privileges.
5870 return privilegeFromSim;
5871 }
5872 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005873 SubscriptionManager subManager = (SubscriptionManager)
5874 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5875 return subManager.canManageSubscription(subInfo, pkgName)
5876 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
5880 }
5881
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005882 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005883 public int getCarrierPrivilegeStatus(int subId) {
5884 final Phone phone = getPhone(subId);
5885 if (phone == null) {
5886 loge("getCarrierPrivilegeStatus: Invalid subId");
5887 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5888 }
5889 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005890 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005891 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005892 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5893 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005894
5895 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5896 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005897 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005898 }
Junda Liu29340342014-07-10 15:23:27 -07005899
5900 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005901 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005902 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005903 final Phone phone = getPhone(subId);
5904 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005905 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005906 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5907 }
5908 UiccProfile profile =
5909 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5910 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005911 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005912 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5913 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005914 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005915 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005916 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005917 }
5918
5919 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005920 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5921 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005922 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005923 }
5924
5925 int phoneId = SubscriptionManager.getPhoneId(subId);
5926 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005927 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005928 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5930 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005931 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5932 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5933 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005934 }
5935
5936 @Override
5937 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005938 if (TextUtils.isEmpty(pkgName))
5939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005940 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5941 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5942 UiccCard card = UiccController.getInstance().getUiccCard(i);
5943 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005944 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005945 continue;
5946 }
5947
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005948 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5949 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5950 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005951 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5952 break;
5953 }
5954 }
5955
5956 return result;
Junda Liu29340342014-07-10 15:23:27 -07005957 }
Derek Tan89e89d42014-07-08 17:00:10 -07005958
5959 @Override
Junda Liue64de782015-04-16 17:19:16 -07005960 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5961 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5962 loge("phoneId " + phoneId + " is not valid.");
5963 return null;
5964 }
5965 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005966 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005967 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005968 return null ;
5969 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005970 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005971 }
5972
Amith Yamasani6e118872016-02-19 12:53:51 -08005973 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005974 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005975 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005976 List<String> privilegedPackages = new ArrayList<>();
5977 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005978 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5979 // has UICC in that slot.
5980 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005981 if (card.hasCarrierPrivilegeRules()) {
5982 if (packages == null) {
5983 // Only check packages in user 0 for now
5984 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005985 PackageManager.MATCH_DISABLED_COMPONENTS
5986 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005987 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005988 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005989 }
5990 for (int p = packages.size() - 1; p >= 0; p--) {
5991 PackageInfo pkgInfo = packages.get(p);
5992 if (pkgInfo != null && pkgInfo.packageName != null
5993 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005994 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005995 privilegedPackages.add(pkgInfo.packageName);
5996 }
5997 }
5998 }
5999 }
6000 return privilegedPackages;
6001 }
6002
chen xuf7e9fe82019-05-09 19:31:02 -07006003 @Override
6004 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006005 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6006
6007 final long identity = Binder.clearCallingIdentity();
6008
chen xuf7e9fe82019-05-09 19:31:02 -07006009 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006010 try {
6011 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6012 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6013 }
6014 } finally {
6015 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006016 }
6017 return privilegedPackages;
6018 }
6019
Wink Savilleb564aae2014-10-23 10:18:09 -07006020 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006021 final Phone phone = getPhone(subId);
6022 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006023 if (card == null) {
6024 loge("getIccId: No UICC");
6025 return null;
6026 }
6027 String iccId = card.getIccId();
6028 if (TextUtils.isEmpty(iccId)) {
6029 loge("getIccId: ICC ID is null or empty.");
6030 return null;
6031 }
6032 return iccId;
6033 }
6034
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006035 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006036 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6037 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006038 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006039 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006041 final long identity = Binder.clearCallingIdentity();
6042 try {
6043 final String iccId = getIccId(subId);
6044 final Phone phone = getPhone(subId);
6045 if (phone == null) {
6046 return false;
6047 }
6048 final String subscriberId = phone.getSubscriberId();
6049
6050 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006051 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006052 + subscriberId + " to " + number);
6053 }
6054
6055 if (TextUtils.isEmpty(iccId)) {
6056 return false;
6057 }
6058
6059 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6060
6061 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6062 if (alphaTag == null) {
6063 editor.remove(alphaTagPrefKey);
6064 } else {
6065 editor.putString(alphaTagPrefKey, alphaTag);
6066 }
6067
6068 // Record both the line number and IMSI for this ICCID, since we need to
6069 // track all merged IMSIs based on line number
6070 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6071 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6072 if (number == null) {
6073 editor.remove(numberPrefKey);
6074 editor.remove(subscriberPrefKey);
6075 } else {
6076 editor.putString(numberPrefKey, number);
6077 editor.putString(subscriberPrefKey, subscriberId);
6078 }
6079
6080 editor.commit();
6081 return true;
6082 } finally {
6083 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006084 }
Derek Tan7226c842014-07-02 17:42:23 -07006085 }
6086
6087 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006088 public String getLine1NumberForDisplay(int subId, String callingPackage,
6089 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006090 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006091 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006092 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006093 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006094 return null;
6095 }
Derek Tan97ebb422014-09-05 16:55:38 -07006096
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006097 final long identity = Binder.clearCallingIdentity();
6098 try {
6099 String iccId = getIccId(subId);
6100 if (iccId != null) {
6101 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6102 if (DBG_MERGE) {
6103 log("getLine1NumberForDisplay returning "
6104 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6105 }
6106 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006107 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006108 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6109 return null;
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006112 }
Derek Tan7226c842014-07-02 17:42:23 -07006113 }
6114
6115 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006116 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6117 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006118 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006119 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006120 return null;
6121 }
Derek Tan97ebb422014-09-05 16:55:38 -07006122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 String iccId = getIccId(subId);
6126 if (iccId != null) {
6127 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6128 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6129 }
6130 return null;
6131 } finally {
6132 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006133 }
Derek Tan7226c842014-07-02 17:42:23 -07006134 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006135
6136 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006137 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6138 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006139 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6140 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006142 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006143 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006144 return null;
6145 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006146
Jordan Liub49b04b2019-05-06 14:45:15 -07006147 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6148 // the process, where TelephonyManager was instantiated.
6149 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006150 final long identity = Binder.clearCallingIdentity();
6151 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006152 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 final TelephonyManager tele = TelephonyManager.from(context);
6154 final SubscriptionManager sub = SubscriptionManager.from(context);
6155
6156 // Figure out what subscribers are currently active
6157 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006158
Jordan Liub49b04b2019-05-06 14:45:15 -07006159 // Only consider subs which match the current subId
6160 // This logic can be simplified. See b/131189269 for progress.
6161 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006162 activeSubscriberIds.add(tele.getSubscriberId(subId));
6163 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006164
6165 // First pass, find a number override for an active subscriber
6166 String mergeNumber = null;
6167 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6168 for (String key : prefs.keySet()) {
6169 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6170 final String subscriberId = (String) prefs.get(key);
6171 if (activeSubscriberIds.contains(subscriberId)) {
6172 final String iccId = key.substring(
6173 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6174 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6175 mergeNumber = (String) prefs.get(numberKey);
6176 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006177 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006178 + " for active subscriber " + subscriberId);
6179 }
6180 if (!TextUtils.isEmpty(mergeNumber)) {
6181 break;
6182 }
6183 }
6184 }
6185 }
6186
6187 // Shortcut when no active merged subscribers
6188 if (TextUtils.isEmpty(mergeNumber)) {
6189 return null;
6190 }
6191
6192 // Second pass, find all subscribers under that line override
6193 final ArraySet<String> result = new ArraySet<>();
6194 for (String key : prefs.keySet()) {
6195 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6196 final String number = (String) prefs.get(key);
6197 if (mergeNumber.equals(number)) {
6198 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6199 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6200 final String subscriberId = (String) prefs.get(subscriberKey);
6201 if (!TextUtils.isEmpty(subscriberId)) {
6202 result.add(subscriberId);
6203 }
6204 }
6205 }
6206 }
6207
6208 final String[] resultArray = result.toArray(new String[result.size()]);
6209 Arrays.sort(resultArray);
6210 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006211 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006212 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6213 }
6214 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006215 } finally {
6216 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006217 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006218 }
6219
6220 @Override
zoey chen38003472019-12-13 17:16:31 +08006221 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6222 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006223
6224 final long identity = Binder.clearCallingIdentity();
6225 try {
6226 final TelephonyManager telephonyManager = mApp.getSystemService(
6227 TelephonyManager.class);
6228 String subscriberId = telephonyManager.getSubscriberId(subId);
6229 if (subscriberId == null) {
6230 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006231 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006232 + subId);
6233 }
6234 return null;
6235 }
6236
6237 final SubscriptionInfo info = SubscriptionController.getInstance()
6238 .getSubscriptionInfo(subId);
6239 final ParcelUuid groupUuid = info.getGroupUuid();
6240 // If it doesn't belong to any group, return just subscriberId of itself.
6241 if (groupUuid == null) {
6242 return new String[]{subscriberId};
6243 }
6244
6245 // Get all subscriberIds from the group.
6246 final List<String> mergedSubscriberIds = new ArrayList<>();
6247 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006248 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006249 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006250 for (SubscriptionInfo subInfo : groupInfos) {
6251 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6252 if (subscriberId != null) {
6253 mergedSubscriberIds.add(subscriberId);
6254 }
6255 }
6256
6257 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6258 } finally {
6259 Binder.restoreCallingIdentity(identity);
6260
6261 }
6262 }
6263
6264 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006265 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006266 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006267 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006268
6269 final long identity = Binder.clearCallingIdentity();
6270 try {
6271 final Phone phone = getPhone(subId);
6272 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6273 } finally {
6274 Binder.restoreCallingIdentity(identity);
6275 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006276 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006277
6278 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006279 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006280 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6281 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006282 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6283 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 final Phone phone = getPhone(subId);
6288 if (phone == null) {
6289 return false;
6290 }
6291 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6292 cdmaNonRoamingList);
6293 } finally {
6294 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006295 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006296 }
6297
6298 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006299 @Deprecated
6300 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6301 enforceModifyPermission();
6302
6303 int returnValue = 0;
6304 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006305 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006306 if(result.exception == null) {
6307 if (result.result != null) {
6308 byte[] responseData = (byte[])(result.result);
6309 if(responseData.length > oemResp.length) {
6310 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6311 responseData.length + "bytes. Buffer Size is " +
6312 oemResp.length + "bytes.");
6313 }
6314 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6315 returnValue = responseData.length;
6316 }
6317 } else {
6318 CommandException ex = (CommandException) result.exception;
6319 returnValue = ex.getCommandError().ordinal();
6320 if(returnValue > 0) returnValue *= -1;
6321 }
6322 } catch (RuntimeException e) {
6323 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6324 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6325 if(returnValue > 0) returnValue *= -1;
6326 }
6327
6328 return returnValue;
6329 }
6330
6331 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006332 public void setRadioCapability(RadioAccessFamily[] rafs) {
6333 try {
6334 ProxyController.getInstance().setRadioCapability(rafs);
6335 } catch (RuntimeException e) {
6336 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6337 }
6338 }
6339
6340 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006341 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006342 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006343 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006344 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006345 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 final long identity = Binder.clearCallingIdentity();
6348 try {
chen xub97461a2018-10-26 14:17:57 -07006349 TelephonyPermissions
6350 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6351 mApp, phone.getSubId(), "getRadioAccessFamily");
6352 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
chen xub97461a2018-10-26 14:17:57 -07006356 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006357 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006358
6359 @Override
6360 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006361 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006366 ImsManager.getInstance(defaultPhone.getContext(),
6367 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006371 }
6372
6373 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006374 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006375 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6377 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006378 return false;
6379 }
Svet Ganovb320e182015-04-16 12:30:10 -07006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 // Check the user preference and the system-level IMS setting. Even if the user has
6384 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6385 // In the long run, we may instead need to check if there exists a connection service
6386 // which can support video calling.
6387 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006388 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 return imsManager.isVtEnabledByPlatform()
6390 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6391 && imsManager.isVtEnabledByUser();
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006395 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006396
Andrew Leea1239f22015-03-02 17:44:07 -08006397 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006398 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6399 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006401 mApp, subId, callingPackage, callingFeatureId,
6402 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 return false;
6404 }
6405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 CarrierConfigManager configManager =
6409 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006410 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Andrew Leea1239f22015-03-02 17:44:07 -08006415 }
6416
6417 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006418 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006420 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 return false;
6422 }
6423
6424 final long identity = Binder.clearCallingIdentity();
6425 try {
6426 CarrierConfigManager configManager =
6427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006428 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Andrew Leea1239f22015-03-02 17:44:07 -08006433 }
6434
Andrew Lee9431b832015-03-09 18:46:45 -07006435 @Override
6436 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006437 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006438 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006439 }
6440
6441 @Override
6442 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 final long identity = Binder.clearCallingIdentity();
6444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006445 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Andrew Lee9431b832015-03-09 18:46:45 -07006449 }
6450
Hall Liuf6668912018-10-31 17:05:23 -07006451 /**
6452 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6453 * support for the feature and device firmware support.
6454 *
6455 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6456 */
6457 @Override
6458 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006460 final Phone phone = getPhone(subscriptionId);
6461 if (phone == null) {
6462 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6463 return false;
6464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006466 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6468 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006469 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 return isCarrierSupported && isDeviceSupported;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Hall Liu98187582018-01-22 19:15:32 -08006474 }
6475
Hall Liuf6668912018-10-31 17:05:23 -07006476 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006477 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6478 * RTT setting, will return true if the device and carrier both support RTT.
6479 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006480 */
6481 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 final long identity = Binder.clearCallingIdentity();
6483 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006484 boolean isRttSupported = isRttSupported(subscriptionId);
6485 boolean isUserRttSettingOn = Settings.Secure.getInt(
6486 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6487 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6488 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6489 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006493 }
6494
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006495 @Deprecated
6496 @Override
6497 public String getDeviceId(String callingPackage) {
6498 return getDeviceIdWithFeature(callingPackage, null);
6499 }
6500
Sanket Padawe7310cc72015-01-14 09:53:20 -08006501 /**
6502 * Returns the unique device ID of phone, for example, the IMEI for
6503 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6504 *
6505 * <p>Requires Permission:
6506 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6507 */
6508 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006509 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006510 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006511 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006512 return null;
6513 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006514 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006515 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006516 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006517 return null;
6518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519
6520 final long identity = Binder.clearCallingIdentity();
6521 try {
6522 return phone.getDeviceId();
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006526 }
6527
Ping Sunc67b7c22016-03-02 19:16:45 +08006528 /**
6529 * {@hide}
6530 * Returns the IMS Registration Status on a particular subid
6531 *
6532 * @param subId
6533 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006534 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006535 Phone phone = getPhone(subId);
6536 if (phone != null) {
6537 return phone.isImsRegistered();
6538 } else {
6539 return false;
6540 }
6541 }
6542
Santos Cordon7a1885b2015-02-03 11:15:19 -08006543 @Override
6544 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006551 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006552
Tyler Gunnf70ed162019-04-03 15:28:53 -07006553 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006554 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006555 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006557 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006558 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6559 }
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006569 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006570 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6571 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006572 final long identity = Binder.clearCallingIdentity();
6573 try {
6574 Phone phone = getPhone(subscriptionId);
6575 if (phone == null) {
6576 return null;
6577 }
6578 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6579 } finally {
6580 Binder.restoreCallingIdentity(identity);
6581 }
6582 }
6583
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006584 /**
6585 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006586 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006587 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006588 final long identity = Binder.clearCallingIdentity();
6589 try {
6590 Phone phone = getPhone(subId);
6591 if (phone != null) {
6592 return phone.isWifiCallingEnabled();
6593 } else {
6594 return false;
6595 }
6596 } finally {
6597 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006598 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006599 }
6600
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006601 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006602 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006603 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006604 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006605 final long identity = Binder.clearCallingIdentity();
6606 try {
6607 Phone phone = getPhone(subId);
6608 if (phone != null) {
6609 return phone.isVideoEnabled();
6610 } else {
6611 return false;
6612 }
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006615 }
6616 }
6617
6618 /**
6619 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6620 * defined in {@link ImsRegistrationImplBase}.
6621 */
6622 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 Phone phone = getPhone(subId);
6626 if (phone != null) {
6627 return phone.getImsRegistrationTech();
6628 } else {
6629 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6630 }
6631 } finally {
6632 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006633 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006634 }
6635
Stuart Scott8eef64f2015-04-08 15:13:54 -07006636 @Override
6637 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006638 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006639 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6640 return;
6641 }
6642
Svet Ganovcc087f82015-05-12 20:35:54 -07006643 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006644
Svet Ganovcc087f82015-05-12 20:35:54 -07006645 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006646 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6647 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006648 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006649 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006650 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006651 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6652 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006653 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006654 // There has been issues when Sms raw table somehow stores orphan
6655 // fragments. They lead to garbled message when new fragments come
6656 // in and combined with those stale ones. In case this happens again,
6657 // user can reset all network settings which will clean up this table.
6658 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006659 // Clean up IMS settings as well here.
6660 int slotId = getSlotIndex(subId);
6661 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6662 ImsManager.getInstance(mApp, slotId).factoryReset();
6663 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006664
6665 // Erase modem config if erase modem on network setting is enabled.
6666 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6667 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6668 if (configValue != null && Boolean.parseBoolean(configValue)) {
6669 sendEraseModemConfig(getDefaultPhone());
6670 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006671 } finally {
6672 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006673 }
6674 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006675
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006676 private void cleanUpSmsRawTable(Context context) {
6677 ContentResolver resolver = context.getContentResolver();
6678 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6679 resolver.delete(uri, null, null);
6680 }
6681
Narayan Kamath1c496c22015-04-16 14:40:19 +01006682 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006683 public String getSimLocaleForSubscriber(int subId) {
6684 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6685 final Phone phone = getPhone(subId);
6686 if (phone == null) {
6687 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006688 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 final long identity = Binder.clearCallingIdentity();
6691 try {
chen xu5d3637b2019-01-21 23:31:38 -08006692 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006693 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006694 if (info == null) {
6695 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6696 return null;
6697 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006698 // Try and fetch the locale from the carrier properties or from the SIM language
6699 // preferences (EF-PL and EF-LI)...
6700 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006702 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6703 if (localeFromDefaultSim != null) {
6704 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6705 if (DBG) log("Using locale from subId: " + subId + " locale: "
6706 + localeFromDefaultSim);
6707 return localeFromDefaultSim.toLanguageTag();
6708 } else {
6709 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 }
6711 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006712
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 // The SIM language preferences only store a language (e.g. fr = French), not an
6714 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6715 // the SIM and carrier preferences does not include a country we add the country
6716 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006717 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006719 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 return mccLocale.toLanguageTag();
6721 }
6722
6723 if (DBG) log("No locale found - returning null");
6724 return null;
6725 } finally {
6726 Binder.restoreCallingIdentity(identity);
6727 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006728 }
6729
6730 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006731 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006732 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006733 }
6734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 /**
6736 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6737 */
6738 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006739 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006740 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006741 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006742
Chenjie Yu1ba97252018-01-11 18:16:20 -08006743 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006744 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006745
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006746 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006747 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6748 * representing the state of the modem.
6749 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006750 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6751 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006752 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006753 */
6754 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006755 public void requestModemActivityInfo(ResultReceiver result) {
6756 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006757 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758
6759 final long identity = Binder.clearCallingIdentity();
6760 try {
sqian1a1be542020-03-05 11:37:28 -08006761 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 } finally {
6763 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006764 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006765 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006766
Siddharth Rayb8114062018-06-17 15:02:38 -07006767 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6768 // less than total activity duration.
6769 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6770 if (info == null) {
6771 return false;
6772 }
6773 int activityDurationMs =
6774 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6775 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006776 int[] txTimeMs = info.getTransmitTimeMillis();
6777 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6778 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006779 }
6780 return (info.isValid()
6781 && (info.getSleepTimeMillis() <= activityDurationMs)
6782 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006783 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006784 && (totalTxTimeMs <= activityDurationMs));
6785 }
6786
Jack Yu85bd38a2015-11-09 11:34:32 -08006787 /**
6788 * {@hide}
6789 * Returns the service state information on specified subscription.
6790 */
6791 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006792 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6793 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006794 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006795 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006796 return null;
6797 }
6798
Hall Liuf19c44f2018-11-27 14:38:17 -08006799 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6800 LocationAccessPolicy.checkLocationPermission(mApp,
6801 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6802 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006803 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006804 .setCallingPid(Binder.getCallingPid())
6805 .setCallingUid(Binder.getCallingUid())
6806 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006807 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006808 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6809 .build());
6810
6811 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6812 LocationAccessPolicy.checkLocationPermission(mApp,
6813 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6814 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006815 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006816 .setCallingPid(Binder.getCallingPid())
6817 .setCallingUid(Binder.getCallingUid())
6818 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006819 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006820 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6821 .build());
6822 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6823 boolean hasFinePermission =
6824 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6825 boolean hasCoarsePermission =
6826 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 final long identity = Binder.clearCallingIdentity();
6829 try {
6830 final Phone phone = getPhone(subId);
6831 if (phone == null) {
6832 return null;
6833 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006834
Hall Liuf19c44f2018-11-27 14:38:17 -08006835 ServiceState ss = phone.getServiceState();
6836
6837 // Scrub out the location info in ServiceState depending on what level of access
6838 // the caller has.
6839 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006840 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6841 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006842 } finally {
6843 Binder.restoreCallingIdentity(identity);
6844 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006845 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006846
6847 /**
6848 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6849 *
6850 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6851 * voicemail ringtone.
6852 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6853 * PhoneAccount.
6854 */
6855 @Override
6856 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6860 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006863
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006864 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6865 } finally {
6866 Binder.restoreCallingIdentity(identity);
6867 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006868 }
6869
6870 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006871 * Sets the per-account voicemail ringtone.
6872 *
6873 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6874 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6875 *
6876 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6877 * voicemail ringtone.
6878 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6879 * PhoneAccount.
6880 */
6881 @Override
6882 public void setVoicemailRingtoneUri(String callingPackage,
6883 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006884 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006885 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006886 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6887 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006888 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6889 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6890 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006891 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006892
6893 final long identity = Binder.clearCallingIdentity();
6894 try {
6895 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6896 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006897 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006898 }
6899 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6900 } finally {
6901 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006902 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006903 }
6904
6905 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006906 * Returns whether vibration is set for voicemail notification in Phone settings.
6907 *
6908 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6909 * voicemail vibration setting.
6910 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6911 */
6912 @Override
6913 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6917 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006918 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6922 } finally {
6923 Binder.restoreCallingIdentity(identity);
6924 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006925 }
6926
Youhan Wange64578a2016-05-02 15:32:42 -07006927 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006928 * Sets the per-account voicemail vibration.
6929 *
6930 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6931 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6932 *
6933 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6934 * voicemail vibration setting.
6935 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6936 * specific PhoneAccount.
6937 */
6938 @Override
6939 public void setVoicemailVibrationEnabled(String callingPackage,
6940 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006941 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006943 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6944 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006945 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6946 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6947 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006948 }
6949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 final long identity = Binder.clearCallingIdentity();
6951 try {
6952 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6953 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006954 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 }
6956 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6957 } finally {
6958 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006959 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006960 }
6961
6962 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006963 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6964 *
6965 * @throws SecurityException if the caller does not have the required permission
6966 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006967 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006968 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006969 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006970 }
6971
6972 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006973 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6974 * permission.
6975 *
6976 * @throws SecurityException if the caller does not have the required permission
6977 */
6978 private void enforceSendSmsPermission() {
6979 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6980 }
6981
6982 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006983 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006984 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006985 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006986 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006987 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 final long identity = Binder.clearCallingIdentity();
6989 try {
6990 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006991 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 if (componentName == null) {
6993 throw new SecurityException(
6994 "Caller not current active visual voicemail package[null]");
6995 }
6996 String vvmPackage = componentName.getPackageName();
6997 if (!callingPackage.equals(vvmPackage)) {
6998 throw new SecurityException("Caller not current active visual voicemail package["
6999 + vvmPackage + "]");
7000 }
7001 } finally {
7002 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007003 }
7004 }
7005
7006 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007007 * Return the application ID for the app type.
7008 *
7009 * @param subId the subscription ID that this request applies to.
7010 * @param appType the uicc app type.
7011 * @return Application ID for specificied app type, or null if no uicc.
7012 */
7013 @Override
7014 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007015 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007016 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017
7018 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007019 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 if (phone == null) {
7021 return null;
7022 }
7023 String aid = null;
7024 try {
7025 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7026 .getApplicationByType(appType).getAid();
7027 } catch (Exception e) {
7028 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7029 }
7030 return aid;
7031 } finally {
7032 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007033 }
Youhan Wange64578a2016-05-02 15:32:42 -07007034 }
7035
Youhan Wang4001d252016-05-11 10:29:41 -07007036 /**
7037 * Return the Electronic Serial Number.
7038 *
7039 * @param subId the subscription ID that this request applies to.
7040 * @return ESN or null if error.
7041 */
7042 @Override
7043 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007044 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007045 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007048 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 if (phone == null) {
7050 return null;
7051 }
7052 String esn = null;
7053 try {
7054 esn = phone.getEsn();
7055 } catch (Exception e) {
7056 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7057 }
7058 return esn;
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007061 }
Youhan Wang4001d252016-05-11 10:29:41 -07007062 }
7063
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007064 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007065 * Return the Preferred Roaming List Version.
7066 *
7067 * @param subId the subscription ID that this request applies to.
7068 * @return PRLVersion or null if error.
7069 */
7070 @Override
7071 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007072 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007073 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074
7075 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007076 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 if (phone == null) {
7078 return null;
7079 }
7080 String cdmaPrlVersion = null;
7081 try {
7082 cdmaPrlVersion = phone.getCdmaPrlVersion();
7083 } catch (Exception e) {
7084 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7085 }
7086 return cdmaPrlVersion;
7087 } finally {
7088 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007089 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007090 }
7091
7092 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007093 * Get snapshot of Telephony histograms
7094 * @return List of Telephony histograms
7095 * @hide
7096 */
7097 @Override
7098 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7100 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101
7102 final long identity = Binder.clearCallingIdentity();
7103 try {
7104 return RIL.getTelephonyRILTimingHistograms();
7105 } finally {
7106 Binder.restoreCallingIdentity(identity);
7107 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007108 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007109
7110 /**
7111 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007112 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7113 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007114 * Require system privileges. In the future we may add this to carrier APIs.
7115 *
Michele Berionne482f8202018-11-27 18:57:59 -08007116 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007117 */
7118 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007119 @TelephonyManager.SetCarrierRestrictionResult
7120 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007121 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007122 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007123
Michele Berionne482f8202018-11-27 18:57:59 -08007124 if (carrierRestrictionRules == null) {
7125 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007126 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007127
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007130 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007131 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007135 }
7136
7137 /**
7138 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007139 * Get the allowed carrier list and the excluded carrier list, including the priority between
7140 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007141 * Require system privileges. In the future we may add this to carrier APIs.
7142 *
Michele Berionne482f8202018-11-27 18:57:59 -08007143 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007144 */
7145 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007146 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007147 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007148 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007149
7150 final long identity = Binder.clearCallingIdentity();
7151 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007152 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7153 if (response instanceof CarrierRestrictionRules) {
7154 return (CarrierRestrictionRules) response;
7155 }
7156 // Response is an Exception of some kind,
7157 // which is signalled to the user as a NULL retval
7158 return null;
7159 } catch (Exception e) {
7160 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7161 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007165 }
7166
fionaxu59545b42016-05-25 15:53:37 -07007167 /**
7168 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7169 * @param subId the subscription ID that this action applies to.
7170 * @param enabled control enable or disable metered apns.
7171 * {@hide}
7172 */
7173 @Override
7174 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7175 enforceModifyPermission();
7176 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177
7178 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007179 if (phone == null) {
7180 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7181 return;
7182 }
7183 try {
7184 phone.carrierActionSetMeteredApnsEnabled(enabled);
7185 } catch (Exception e) {
7186 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187 } finally {
7188 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007189 }
7190 }
7191
7192 /**
7193 * Action set from carrier signalling broadcast receivers to enable/disable radio
7194 * @param subId the subscription ID that this action applies to.
7195 * @param enabled control enable or disable radio.
7196 * {@hide}
7197 */
7198 @Override
7199 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7200 enforceModifyPermission();
7201 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202
7203 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007204 if (phone == null) {
7205 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7206 return;
7207 }
7208 try {
7209 phone.carrierActionSetRadioEnabled(enabled);
7210 } catch (Exception e) {
7211 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212 } finally {
7213 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007214 }
7215 }
7216
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007217 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007218 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7219 * network status based on which carrier apps could apply actions accordingly,
7220 * enable/disable default url handler for example.
7221 *
7222 * @param subId the subscription ID that this action applies to.
7223 * @param report control start/stop reporting the default network status.
7224 * {@hide}
7225 */
7226 @Override
7227 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7228 enforceModifyPermission();
7229 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230
7231 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007232 if (phone == null) {
7233 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7234 return;
7235 }
7236 try {
7237 phone.carrierActionReportDefaultNetworkStatus(report);
7238 } catch (Exception e) {
7239 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 } finally {
7241 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007242 }
7243 }
7244
7245 /**
fionaxud9622282017-07-17 17:51:30 -07007246 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7247 * @param subId the subscription ID that this action applies to.
7248 * {@hide}
7249 */
7250 @Override
7251 public void carrierActionResetAll(int subId) {
7252 enforceModifyPermission();
7253 final Phone phone = getPhone(subId);
7254 if (phone == null) {
7255 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7256 return;
7257 }
7258 try {
7259 phone.carrierActionResetAll();
7260 } catch (Exception e) {
7261 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7262 }
7263 }
7264
7265 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007266 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7267 * bug report is being generated.
7268 */
7269 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007270 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007271 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7272 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007273 writer.println("Permission Denial: can't dump Phone from pid="
7274 + Binder.getCallingPid()
7275 + ", uid=" + Binder.getCallingUid()
7276 + "without permission "
7277 + android.Manifest.permission.DUMP);
7278 return;
7279 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007280 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007281 }
Jack Yueb89b242016-06-22 13:27:47 -07007282
Brad Ebingerdac2f002018-04-03 15:17:52 -07007283 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007284 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7285 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7286 @NonNull String[] args) {
7287 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7288 this, in.getFileDescriptor(), out.getFileDescriptor(),
7289 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007290 }
7291
Jack Yueb89b242016-06-22 13:27:47 -07007292 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007293 * Policy control of data connection. Usually used when data limit is passed.
7294 * @param enabled True if enabling the data, otherwise disabling.
7295 * @param subId Subscription index
7296 * {@hide}
7297 */
7298 @Override
7299 public void setPolicyDataEnabled(boolean enabled, int subId) {
7300 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301
7302 final long identity = Binder.clearCallingIdentity();
7303 try {
7304 Phone phone = getPhone(subId);
7305 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007306 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 }
7308 } finally {
7309 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007310 }
7311 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007312
7313 /**
7314 * Get Client request stats
7315 * @return List of Client Request Stats
7316 * @hide
7317 */
7318 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007319 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7320 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007321 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007322 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007323 return null;
7324 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007325 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 final long identity = Binder.clearCallingIdentity();
7328 try {
7329 if (phone != null) {
7330 return phone.getClientRequestStats();
7331 }
7332
7333 return null;
7334 } finally {
7335 Binder.restoreCallingIdentity(identity);
7336 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007337 }
7338
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007339 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007340 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007341 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007342 }
Jack Yueb4124c2017-02-16 15:32:43 -08007343
7344 /**
Grace Chen70990072017-03-24 17:21:30 -07007345 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007346 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007347 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007348 * @param state State of SIM (power down, power up, pass through)
7349 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7350 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7351 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007352 *
7353 **/
7354 @Override
Grace Chen70990072017-03-24 17:21:30 -07007355 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007356 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007357 Phone phone = PhoneFactory.getPhone(slotIndex);
7358
vagdeviaf9a5b92018-08-15 16:01:53 -07007359 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7360
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007361 final long identity = Binder.clearCallingIdentity();
7362 try {
7363 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007364 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 }
7366 } finally {
7367 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007368 }
7369 }
Shuo Qiandd210312017-04-12 22:11:33 +00007370
Tyler Gunn65d45c22017-06-05 11:22:26 -07007371 private boolean isUssdApiAllowed(int subId) {
7372 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007374 if (configManager == null) {
7375 return false;
7376 }
7377 PersistableBundle pb = configManager.getConfigForSubId(subId);
7378 if (pb == null) {
7379 return false;
7380 }
7381 return pb.getBoolean(
7382 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7383 }
7384
Shuo Qiandd210312017-04-12 22:11:33 +00007385 /**
7386 * Check if phone is in emergency callback mode
7387 * @return true if phone is in emergency callback mode
7388 * @param subId sub id
7389 */
goneil9c5f4872017-12-05 14:07:56 -08007390 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007391 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007392 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007393 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007394
7395 final long identity = Binder.clearCallingIdentity();
7396 try {
7397 if (phone != null) {
7398 return phone.isInEcm();
7399 } else {
7400 return false;
7401 }
7402 } finally {
7403 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007404 }
7405 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007406
7407 /**
7408 * Get the current signal strength information for the given subscription.
7409 * Because this information is not updated when the device is in a low power state
7410 * it should not be relied-upon to be current.
7411 * @param subId Subscription index
7412 * @return the most recent cached signal strength info from the modem
7413 */
7414 @Override
7415 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007416 final long identity = Binder.clearCallingIdentity();
7417 try {
7418 Phone p = getPhone(subId);
7419 if (p == null) {
7420 return null;
7421 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007422
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007423 return p.getSignalStrength();
7424 } finally {
7425 Binder.restoreCallingIdentity(identity);
7426 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007427 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007428
Pengquan Meng77b7f132018-08-22 14:49:57 -07007429 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007430 * Get the current modem radio state for the given slot.
7431 * @param slotIndex slot index.
7432 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007433 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007434 * @return the current radio power state from the modem
7435 */
7436 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007437 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007438 Phone phone = PhoneFactory.getPhone(slotIndex);
7439 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007440 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7441 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007442 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7443 }
7444
7445 final long identity = Binder.clearCallingIdentity();
7446 try {
7447 return phone.getRadioPowerState();
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
7451 }
7452 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7453 }
7454
7455 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007456 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7457 *
7458 * <p>Requires one of the following permissions:
7459 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7460 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7461 * privileges.
7462 *
7463 * @param subId subscription id
7464 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7465 * {@code false}.
7466 */
7467 @Override
7468 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007469 try {
7470 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7471 null);
7472 } catch (Exception e) {
7473 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7474 mApp, subId, "isDataRoamingEnabled");
7475 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007476
Pengquan Menga1bb6272018-09-06 09:59:22 -07007477 boolean isEnabled = false;
7478 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007479 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007480 Phone phone = getPhone(subId);
7481 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007482 } finally {
7483 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007484 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007485 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007486 }
7487
7488
7489 /**
7490 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7491 *
7492 * <p> Requires permission:
7493 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7494 * privileges.
7495 *
7496 * @param subId subscription id
7497 * @param isEnabled {@code true} means enable, {@code false} means disable.
7498 */
7499 @Override
7500 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007501 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7502 mApp, subId, "setDataRoamingEnabled");
7503
Pengquan Menga1bb6272018-09-06 09:59:22 -07007504 final long identity = Binder.clearCallingIdentity();
7505 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007506 Phone phone = getPhone(subId);
7507 if (phone != null) {
7508 phone.setDataRoamingEnabled(isEnabled);
7509 }
7510 } finally {
7511 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007512 }
7513 }
7514
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007515 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007516 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007517 TelephonyPermissions
7518 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007519 mApp, subId, "isManualNetworkSelectionAllowed");
7520
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007521 boolean isAllowed = true;
7522 final long identity = Binder.clearCallingIdentity();
7523 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007524 Phone phone = getPhone(subId);
7525 if (phone != null) {
7526 isAllowed = phone.isCspPlmnEnabled();
7527 }
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
7530 }
7531 return isAllowed;
7532 }
7533
7534 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007535 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007536 // Verify that tha callingPackage belongs to the calling UID
7537 mApp.getSystemService(AppOpsManager.class)
7538 .checkPackage(Binder.getCallingUid(), callingPackage);
7539
Jordan Liu1e142fc2019-04-22 15:10:43 -07007540 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007541 try {
7542 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007543 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007544 } catch (SecurityException e) {
7545 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7546 // has carrier privileges on an active UICC
7547 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7548 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007549 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007550 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007551 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007555 UiccController uiccController = UiccController.getInstance();
7556 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007557 if (hasReadPermission) {
7558 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007559 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007560
7561 // Remove private info if the caller doesn't have access
7562 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7563 for (UiccCardInfo cardInfo : cardInfos) {
7564 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7565 // is available
7566 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7567 if (card == null || card.getUiccProfile() == null) {
7568 // assume no access if the card or profile is unavailable
7569 filteredInfos.add(cardInfo.getUnprivileged());
7570 continue;
7571 }
7572 UiccProfile profile = card.getUiccProfile();
7573 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7574 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7575 filteredInfos.add(cardInfo);
7576 } else {
7577 filteredInfos.add(cardInfo.getUnprivileged());
7578 }
7579 }
7580 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007581 } finally {
7582 Binder.restoreCallingIdentity(identity);
7583 }
7584 }
7585
7586 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007587 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007588 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007590 final long identity = Binder.clearCallingIdentity();
7591 try {
7592 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7593 if (slots == null) {
7594 Rlog.i(LOG_TAG, "slots is null.");
7595 return null;
7596 }
7597
7598 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7599 for (int i = 0; i < slots.length; i++) {
7600 UiccSlot slot = slots[i];
7601 if (slot == null) {
7602 continue;
7603 }
7604
Jordan Liu7be7e652019-05-06 18:55:02 +00007605 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 UiccCard card = slot.getUiccCard();
7607 if (card != null) {
7608 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007609 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007610 cardId = slot.getEid();
7611 if (TextUtils.isEmpty(cardId)) {
7612 cardId = slot.getIccId();
7613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614 }
7615
Jordan Liu857451f2019-05-09 16:35:35 -07007616 if (cardId != null) {
7617 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7618 // if cardId is an EID, it's all digits so this is fine
7619 cardId = IccUtils.stripTrailingFs(cardId);
7620 }
7621
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 int cardState = 0;
7623 switch (slot.getCardState()) {
7624 case CARDSTATE_ABSENT:
7625 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7626 break;
7627 case CARDSTATE_PRESENT:
7628 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7629 break;
7630 case CARDSTATE_ERROR:
7631 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7632 break;
7633 case CARDSTATE_RESTRICTED:
7634 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7635 break;
7636 default:
7637 break;
7638
7639 }
7640
7641 infos[i] = new UiccSlotInfo(
7642 slot.isActive(),
7643 slot.isEuicc(),
7644 cardId,
7645 cardState,
7646 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007647 slot.isExtendedApduSupported(),
7648 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649 }
7650 return infos;
7651 } finally {
7652 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007653 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007654 }
7655
7656 @Override
7657 public boolean switchSlots(int[] physicalSlots) {
7658 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659
7660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007666 }
Jack Yu4c988042018-02-27 15:30:01 -08007667
7668 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007669 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 return UiccController.getInstance().getCardIdForDefaultEuicc();
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
7675 }
7676 }
7677
Pengquan Meng85728fb2018-03-12 16:31:21 -07007678 /**
goneil47ffb6e2018-04-06 15:40:58 -07007679 * A test API to reload the UICC profile.
7680 *
7681 * <p>Requires that the calling app has permission
7682 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7683 * @hide
7684 */
7685 @Override
7686 public void refreshUiccProfile(int subId) {
7687 enforceModifyPermission();
7688
7689 final long identity = Binder.clearCallingIdentity();
7690 try {
7691 Phone phone = getPhone(subId);
7692 if (phone == null) {
7693 return;
7694 }
7695 UiccCard uiccCard = phone.getUiccCard();
7696 if (uiccCard == null) {
7697 return;
7698 }
7699 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7700 if (uiccProfile == null) {
7701 return;
7702 }
7703 uiccProfile.refresh();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
7707 }
7708
7709 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007710 * Returns false if the mobile data is disabled by default, otherwise return true.
7711 */
7712 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007713 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007714 }
7715
7716 /**
7717 * Returns true if the data roaming is enabled by default, i.e the system property
7718 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7719 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7720 */
7721 private boolean getDefaultDataRoamingEnabled(int subId) {
7722 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007723 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007724 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007725 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7726 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7727 return isDataRoamingEnabled;
7728 }
7729
7730 /**
7731 * Returns the default network type for the given {@code subId}, if the default network type is
7732 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7733 */
7734 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007735 List<Integer> list = TelephonyProperties.default_network();
7736 int phoneId = mSubscriptionController.getPhoneId(subId);
7737 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7738 return list.get(phoneId);
7739 }
7740 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007741 }
fionaxua13278b2018-03-21 00:08:13 -07007742
7743 @Override
7744 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007745 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007746 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747
7748 final long identity = Binder.clearCallingIdentity();
7749 try {
7750 final Phone phone = getPhone(subId);
7751 if (phone == null) {
7752 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7753 return;
7754 }
chen xueaba88a2019-03-15 13:15:10 -07007755 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7756 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07007757 if (carrierPrivilegeRules == null) {
7758 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7759 } else {
7760 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7761 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007762 } finally {
7763 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007764 }
fionaxua13278b2018-03-21 00:08:13 -07007765 }
7766
7767 @Override
7768 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007769 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770
7771 final long identity = Binder.clearCallingIdentity();
7772 try {
7773 final Phone phone = getPhone(subId);
7774 if (phone == null) {
7775 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7776 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7777 }
7778 return phone.getCarrierIdListVersion();
7779 } finally {
7780 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007781 }
fionaxua13278b2018-03-21 00:08:13 -07007782 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007783
7784 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007785 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7786 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007787 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007788 mApp, subId, callingPackage, callingFeatureId,
7789 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007790 return -1;
7791 }
7792
7793 final long identity = Binder.clearCallingIdentity();
7794 try {
7795 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7796 } finally {
7797 Binder.restoreCallingIdentity(identity);
7798 }
7799 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007800
7801 @Override
7802 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007803 TelephonyPermissions
7804 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007805 mApp, subId, "getCdmaRoamingMode");
7806
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
7809 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7810 } finally {
7811 Binder.restoreCallingIdentity(identity);
7812 }
7813 }
7814
7815 @Override
7816 public boolean setCdmaRoamingMode(int subId, int mode) {
7817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7818 mApp, subId, "setCdmaRoamingMode");
7819
7820 final long identity = Binder.clearCallingIdentity();
7821 try {
7822 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7823 } finally {
7824 Binder.restoreCallingIdentity(identity);
7825 }
7826 }
7827
7828 @Override
7829 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7830 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7831 mApp, subId, "setCdmaSubscriptionMode");
7832
7833 final long identity = Binder.clearCallingIdentity();
7834 try {
7835 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7836 } finally {
7837 Binder.restoreCallingIdentity(identity);
7838 }
7839 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007840
sqianc5eccab2018-10-19 18:46:41 -07007841 @Override
sqian8c685422019-02-22 15:55:18 -08007842 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007843 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007845 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7846 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007847 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7848 }
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
sqian854d44b2018-12-12 16:48:18 -08007851 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7852 for (Phone phone: PhoneFactory.getPhones()) {
7853 if (phone.getEmergencyNumberTracker() != null
7854 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7855 emergencyNumberListInternal.put(
7856 phone.getSubId(),
7857 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7858 }
sqian11b7a0e2018-12-05 18:48:28 -08007859 }
sqian854d44b2018-12-12 16:48:18 -08007860 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007861 } finally {
7862 Binder.restoreCallingIdentity(identity);
7863 }
sqianc5eccab2018-10-19 18:46:41 -07007864 }
7865
7866 @Override
sqian8c685422019-02-22 15:55:18 -08007867 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007868 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007869 if (!exactMatch) {
7870 TelephonyPermissions
7871 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007872 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007873 }
7874 final long identity = Binder.clearCallingIdentity();
7875 try {
sqian854d44b2018-12-12 16:48:18 -08007876 for (Phone phone: PhoneFactory.getPhones()) {
7877 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09007878 && phone.getEmergencyNumberTracker()
7879 .isEmergencyNumber(number, exactMatch)) {
7880 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007881 }
sqian11b7a0e2018-12-05 18:48:28 -08007882 }
7883 return false;
7884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
7887 }
7888
sqianf4ca7ed2019-01-15 18:32:07 -08007889 /**
7890 * Update emergency number list for test mode.
7891 */
7892 @Override
7893 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7895 "updateEmergencyNumberListTestMode");
7896
7897 final long identity = Binder.clearCallingIdentity();
7898 try {
7899 for (Phone phone: PhoneFactory.getPhones()) {
7900 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7901 if (tracker != null) {
7902 tracker.executeEmergencyNumberTestModeCommand(action, num);
7903 }
7904 }
7905 } finally {
7906 Binder.restoreCallingIdentity(identity);
7907 }
7908 }
7909
7910 /**
7911 * Get the full emergency number list for test mode.
7912 */
7913 @Override
7914 public List<String> getEmergencyNumberListTestMode() {
7915 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7916 "getEmergencyNumberListTestMode");
7917
7918 final long identity = Binder.clearCallingIdentity();
7919 try {
7920 Set<String> emergencyNumbers = new HashSet<>();
7921 for (Phone phone: PhoneFactory.getPhones()) {
7922 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7923 if (tracker != null) {
7924 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7925 emergencyNumbers.add(num.getNumber());
7926 }
7927 }
7928 }
7929 return new ArrayList<>(emergencyNumbers);
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
7933 }
7934
chen xud6b45bd2018-10-30 22:27:10 -07007935 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007936 public int getEmergencyNumberDbVersion(int subId) {
7937 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7938
7939 final long identity = Binder.clearCallingIdentity();
7940 try {
7941 final Phone phone = getPhone(subId);
7942 if (phone == null) {
7943 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7944 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7945 }
7946 return phone.getEmergencyNumberDbVersion();
7947 } finally {
7948 Binder.restoreCallingIdentity(identity);
7949 }
7950 }
7951
7952 @Override
7953 public void notifyOtaEmergencyNumberDbInstalled() {
7954 enforceModifyPermission();
7955
7956 final long identity = Binder.clearCallingIdentity();
7957 try {
7958 for (Phone phone: PhoneFactory.getPhones()) {
7959 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7960 if (tracker != null) {
7961 tracker.updateOtaEmergencyNumberDatabase();
7962 }
7963 }
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
7967 }
7968
7969 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007970 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007971 enforceActiveEmergencySessionPermission();
7972
7973 final long identity = Binder.clearCallingIdentity();
7974 try {
7975 for (Phone phone: PhoneFactory.getPhones()) {
7976 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7977 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007978 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7979 }
7980 }
7981 } finally {
7982 Binder.restoreCallingIdentity(identity);
7983 }
7984 }
7985
7986 @Override
7987 public void resetOtaEmergencyNumberDbFilePath() {
7988 enforceActiveEmergencySessionPermission();
7989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 for (Phone phone: PhoneFactory.getPhones()) {
7993 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7994 if (tracker != null) {
7995 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007996 }
7997 }
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
8001 }
8002
8003 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008004 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8005 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8006 Phone phone = getPhone(subId);
8007 if (phone == null) {
8008 return null;
8009 }
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 UiccProfile profile = UiccController.getInstance()
8013 .getUiccProfileForPhone(phone.getPhoneId());
8014 if (profile != null) {
8015 return profile.getCertsFromCarrierPrivilegeAccessRules();
8016 }
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 return null;
8021 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008022
8023 /**
8024 * Enable or disable a modem stack.
8025 */
8026 @Override
8027 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8028 enforceModifyPermission();
8029
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 Phone phone = PhoneFactory.getPhone(slotIndex);
8033 if (phone == null) {
8034 return false;
8035 } else {
8036 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8037 }
8038 } finally {
8039 Binder.restoreCallingIdentity(identity);
8040 }
8041 }
Michelecea4cf22018-12-21 15:00:11 -08008042
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008043 /**
8044 * Whether a modem stack is enabled or not.
8045 */
8046 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008047 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8048 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008049 Phone phone = PhoneFactory.getPhone(slotIndex);
8050 if (phone == null) return false;
8051
8052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008053 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8054 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008055 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8056 }
8057
8058 final long identity = Binder.clearCallingIdentity();
8059 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008060 try {
8061 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8062 } catch (NoSuchElementException ex) {
8063 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8064 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008065 } finally {
8066 Binder.restoreCallingIdentity(identity);
8067 }
8068 }
8069
Michelecea4cf22018-12-21 15:00:11 -08008070 @Override
Michele0ea7d782019-03-19 14:58:42 -07008071 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008072 enforceModifyPermission();
8073
8074 final long identity = Binder.clearCallingIdentity();
8075 try {
8076 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008077 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008078 .commit();
8079 } finally {
8080 Binder.restoreCallingIdentity(identity);
8081 }
8082 }
8083
8084 @Override
Michele0ea7d782019-03-19 14:58:42 -07008085 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008086 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008087 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008088 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8089 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008090 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008091 }
Michelecea4cf22018-12-21 15:00:11 -08008092
8093 final long identity = Binder.clearCallingIdentity();
8094 try {
Michele0ea7d782019-03-19 14:58:42 -07008095 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008096 } finally {
8097 Binder.restoreCallingIdentity(identity);
8098 }
8099 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008100
Michele0ea7d782019-03-19 14:58:42 -07008101 @TelephonyManager.IsMultiSimSupportedResult
8102 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008103 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8104 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8105 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008106 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8107 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008108 }
8109 // Check if the hardware supports multisim functionality. If usage of multisim is not
8110 // supported by the modem, indicate that it is restricted.
8111 PhoneCapability staticCapability =
8112 mPhoneConfigurationManager.getStaticPhoneCapability();
8113 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008114 loge("isMultiSimSupportedInternal: no static configuration available");
8115 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008116 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008117 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008118 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8119 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008120 }
8121 // Check if support of multiple SIMs is restricted by carrier
8122 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008123 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008124 }
8125
Michele0ea7d782019-03-19 14:58:42 -07008126 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008127 }
8128
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008129 /**
8130 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008131 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8132 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8133 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008134 * @param numOfSims number of active sims we want to switch to
8135 */
8136 @Override
8137 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008138 if (numOfSims == 1) {
8139 enforceModifyPermission();
8140 } else {
8141 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8142 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8143 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008144 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008145
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008146 try {
Michele30b57b22019-03-01 12:01:14 -08008147 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008148 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008149 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8150 return;
8151 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008152 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8153 } finally {
8154 Binder.restoreCallingIdentity(identity);
8155 }
8156 }
8157
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008158 @Override
8159 public boolean isApplicationOnUicc(int subId, int appType) {
8160 enforceReadPrivilegedPermission("isApplicationOnUicc");
8161 Phone phone = getPhone(subId);
8162 if (phone == null) {
8163 return false;
8164 }
8165 final long identity = Binder.clearCallingIdentity();
8166 try {
8167 UiccCard uiccCard = phone.getUiccCard();
8168 if (uiccCard == null) {
8169 return false;
8170 }
8171 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8172 if (uiccProfile == null) {
8173 return false;
8174 }
8175 if (TelephonyManager.APPTYPE_SIM <= appType
8176 && appType <= TelephonyManager.APPTYPE_ISIM) {
8177 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8178 }
8179 return false;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
8182 }
8183 }
8184
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008185 /**
chen xub4baa772019-04-03 10:23:41 -07008186 * Get whether making changes to modem configurations will trigger reboot.
8187 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008188 */
8189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008190 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8191 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008193 mApp, subId, callingPackage, callingFeatureId,
8194 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008195 return false;
8196 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008197 final long identity = Binder.clearCallingIdentity();
8198 try {
8199 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
8203 }
8204
Nathan Harold29f5f052019-02-15 13:41:57 -08008205 private void updateModemStateMetrics() {
8206 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8207 // TODO: check the state for each modem if the api is ready.
8208 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8209 }
8210
Pengquan Meng3889a572019-01-23 11:16:29 -08008211 @Override
8212 public int[] getSlotsMapping() {
8213 enforceReadPrivilegedPermission("getSlotsMapping");
8214
8215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8218 // All logical slots should have a mapping to a physical slot.
8219 int[] logicalSlotsMapping = new int[phoneCount];
8220 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8221 for (int i = 0; i < slotInfos.length; i++) {
8222 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8223 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8224 }
8225 }
8226 return logicalSlotsMapping;
8227 } finally {
8228 Binder.restoreCallingIdentity(identity);
8229 }
8230 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008231
8232 /**
8233 * Get the IRadio HAL Version
8234 */
8235 @Override
8236 public int getRadioHalVersion() {
8237 Phone phone = getDefaultPhone();
8238 if (phone == null) return -1;
8239 HalVersion hv = phone.getHalVersion();
8240 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8241 return hv.major * 100 + hv.minor;
8242 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008243
8244 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008245 * Get the current calling package name.
8246 * @return the current calling package name
8247 */
8248 @Override
8249 public String getCurrentPackageName() {
8250 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8251 }
8252
8253 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008254 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8255 * corresponding network requests on a subId.
8256 *
8257 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008258 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008259 * 2) APN is un-metered for this subscription, or
8260 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008261 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008262 *
8263 * @return whether data is allowed for a apn type.
8264 *
8265 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008266 */
8267 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008268 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008269 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8270 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008271
8272 // Now that all security checks passes, perform the operation as ourselves.
8273 final long identity = Binder.clearCallingIdentity();
8274 try {
8275 Phone phone = getPhone(subId);
8276 if (phone == null) return false;
8277
Jack Yu41407ee2019-05-13 16:54:09 -07008278 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008279 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
8282 }
8283 }
8284
8285 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008286 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008287 enforceReadPrivilegedPermission("isApnMetered");
8288
8289 // Now that all security checks passes, perform the operation as ourselves.
8290 final long identity = Binder.clearCallingIdentity();
8291 try {
8292 Phone phone = getPhone(subId);
8293 if (phone == null) return true; // By default return true.
8294
Jack Yu41407ee2019-05-13 16:54:09 -07008295 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008296 } finally {
8297 Binder.restoreCallingIdentity(identity);
8298 }
8299 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008300
8301 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008302 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8303 int subscriptionId, IBooleanConsumer resultCallback) {
8304 enforceModifyPermission();
8305 long token = Binder.clearCallingIdentity();
8306 try {
8307 Phone phone = getPhone(subscriptionId);
8308 if (phone == null) {
8309 try {
8310 if (resultCallback != null) {
8311 resultCallback.accept(false);
8312 }
8313 } catch (RemoteException e) {
8314 // ignore
8315 }
8316 return;
8317 }
8318 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8319 Pair.create(specifiers, (x) -> {
8320 try {
8321 if (resultCallback != null) {
8322 resultCallback.accept(x);
8323 }
8324 } catch (RemoteException e) {
8325 // ignore
8326 }
8327 });
8328 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8329 } finally {
8330 Binder.restoreCallingIdentity(token);
8331 }
8332 }
8333
8334 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008335 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008336 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008337 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8338 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8339 if (iccRecords == null) {
8340 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8341 return false;
8342 }
8343 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8344 }
8345
8346 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008347 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8348 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008349 if (callingPackage == null) {
8350 callingPackage = getCurrentPackageName();
8351 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008352 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8353 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008354 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8355 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008356 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8357 }
8358 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8359 Intent intent = new Intent();
8360 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8361 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8362 // Bring up choose default SMS subscription dialog right now
8363 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8364 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8365 mApp.startActivity(intent);
8366 }
chen xud5ca2d52019-05-28 15:20:57 -07008367
8368 @Override
8369 public String getMmsUAProfUrl(int subId) {
8370 //TODO investigate if this API should require proper permission check in R b/133791609
8371 final long identity = Binder.clearCallingIdentity();
8372 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008373 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8374 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8375 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8376 return carrierUAProfUrl;
8377 }
chen xud5ca2d52019-05-28 15:20:57 -07008378 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8379 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8380 } finally {
8381 Binder.restoreCallingIdentity(identity);
8382 }
8383 }
8384
8385 @Override
8386 public String getMmsUserAgent(int subId) {
8387 //TODO investigate if this API should require proper permission check in R b/133791609
8388 final long identity = Binder.clearCallingIdentity();
8389 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008390 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8391 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8392 if (!TextUtils.isEmpty(carrierUserAgent)) {
8393 return carrierUserAgent;
8394 }
chen xud5ca2d52019-05-28 15:20:57 -07008395 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8396 .getString(com.android.internal.R.string.config_mms_user_agent);
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
8400 }
Jack Yub07d4972019-05-28 16:12:25 -07008401
8402 @Override
8403 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8404 enforceModifyPermission();
8405
8406 // Now that all security checks passes, perform the operation as ourselves.
8407 final long identity = Binder.clearCallingIdentity();
8408 try {
8409 Phone phone = getPhone(subId);
8410 if (phone == null) return false;
8411
8412 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 }
8417
8418 @Override
8419 public boolean isDataAllowedInVoiceCall(int subId) {
8420 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8421
8422 // Now that all security checks passes, perform the operation as ourselves.
8423 final long identity = Binder.clearCallingIdentity();
8424 try {
8425 Phone phone = getPhone(subId);
8426 if (phone == null) return false;
8427
8428 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8429 } finally {
8430 Binder.restoreCallingIdentity(identity);
8431 }
8432 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008433
changbetty97defcf2019-12-24 15:40:37 +08008434 @Override
8435 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8436 enforceModifyPermission();
8437
8438 // Now that all security checks passes, perform the operation as ourselves.
8439 final long identity = Binder.clearCallingIdentity();
8440 try {
8441 Phone phone = getPhone(subId);
8442 if (phone == null) return false;
8443
8444 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
8448 }
8449
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008450 /**
8451 * Updates whether conference event pacakge handling is enabled.
8452 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8453 * otherwise.
8454 */
8455 @Override
8456 public void setCepEnabled(boolean isCepEnabled) {
8457 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8458
8459 final long identity = Binder.clearCallingIdentity();
8460 try {
8461 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8462 for (Phone phone : PhoneFactory.getPhones()) {
8463 Phone defaultPhone = phone.getImsPhone();
8464 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8465 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8466 ImsPhoneCallTracker imsPhoneCallTracker =
8467 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8468 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8469 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8470 + imsPhone.getMsisdn());
8471 }
8472 }
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
allenwtsu46dcc572020-01-08 18:24:03 +08008477
8478 /**
8479 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8480 *
8481 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8482 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8483 * before being read.
8484 */
8485 @Override
8486 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8487 isCompressed) {
8488 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8489 mApp, subId, "notifyRcsAutoConfigurationReceived");
8490 try {
8491 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8492 if (configBinder == null) {
8493 Rlog.e(LOG_TAG, "null result for getImsConfig");
8494 } else {
8495 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8496 }
8497 } catch (RemoteException e) {
8498 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8499 }
8500 }
zoey chenf95ca592019-12-30 16:11:23 +08008501
8502 @Override
8503 public boolean isIccLockEnabled(int subId) {
8504 enforceReadPrivilegedPermission("isIccLockEnabled");
8505
8506 // Now that all security checks passes, perform the operation as ourselves.
8507 final long identity = Binder.clearCallingIdentity();
8508 try {
8509 Phone phone = getPhone(subId);
8510 if (phone != null && phone.getIccCard() != null) {
8511 return phone.getIccCard().getIccLockEnabled();
8512 } else {
8513 return false;
8514 }
8515 } finally {
8516 Binder.restoreCallingIdentity(identity);
8517 }
8518 }
8519
8520 /**
zoey chene02881a2019-12-30 16:11:23 +08008521 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008522 *
zoey chene02881a2019-12-30 16:11:23 +08008523 * @return an integer representing the status of IccLock enabled or disabled in the following
8524 * three cases:
8525 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8526 * successfully.
8527 * - Positive number and zero for remaining password attempts.
8528 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008529 *
8530 */
8531 @Override
8532 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8533 enforceModifyPermission();
8534
8535 Phone phone = getPhone(subId);
8536 if (phone == null) {
8537 return 0;
8538 }
8539 // Now that all security checks passes, perform the operation as ourselves.
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8543 new Pair<Boolean, String>(enabled, password), phone, null);
8544 return attemptsRemaining;
8545
8546 } catch (Exception e) {
8547 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
8550 }
8551 return 0;
8552 }
8553
8554 /**
8555 * Change the ICC password used in ICC pin lock.
8556 *
zoey chene02881a2019-12-30 16:11:23 +08008557 * @return an integer representing the status of IccLock changed in the following three cases:
8558 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8559 * - Positive number and zero for remaining password attempts.
8560 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008561 *
8562 */
8563 @Override
8564 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8565 enforceModifyPermission();
8566
8567 Phone phone = getPhone(subId);
8568 if (phone == null) {
8569 return 0;
8570 }
8571 // Now that all security checks passes, perform the operation as ourselves.
8572 final long identity = Binder.clearCallingIdentity();
8573 try {
8574 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8575 new Pair<String, String>(oldPassword, newPassword), phone, null);
8576 return attemptsRemaining;
8577
8578 } catch (Exception e) {
8579 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8580 } finally {
8581 Binder.restoreCallingIdentity(identity);
8582 }
8583 return 0;
8584 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008585
Peter Wangdafb9ac2020-01-15 14:13:38 -08008586 /**
8587 * Request for receiving user activity notification
8588 */
8589 @Override
8590 public void requestUserActivityNotification() {
8591 if (!mNotifyUserActivity.get()
8592 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8593 mNotifyUserActivity.set(true);
8594 }
8595 }
8596
8597 /**
8598 * Called when userActivity is signalled in the power manager.
8599 * This is safe to call from any thread, with any window manager locks held or not.
8600 */
8601 @Override
8602 public void userActivity() {
8603 // ***************************************
8604 // * Inherited from PhoneWindowManager *
8605 // ***************************************
8606 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8607 // WITH ITS LOCKS HELD.
8608 //
8609 // This code must be VERY careful about the locks
8610 // it acquires.
8611 // In fact, the current code acquires way too many,
8612 // and probably has lurking deadlocks.
8613
8614 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8615 throw new SecurityException("Only the OS may call notifyUserActivity()");
8616 }
8617
8618 if (mNotifyUserActivity.getAndSet(false)) {
8619 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8620 USER_ACTIVITY_NOTIFICATION_DELAY);
8621 }
8622 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008623
Malcolm Chen884180b2020-04-13 11:59:40 -07008624 @Override
8625 public boolean canConnectTo5GInDsdsMode() {
8626 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8627 }
Jack Yud10cdd42020-09-28 20:28:01 -07008628
8629 @Override
8630 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8631 String callingFeatureId) {
8632 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8633 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8634 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8635 }
8636
8637 Phone phone = getPhone(subId);
8638 if (phone == null) {
8639 throw new RuntimeException("phone is not available");
8640 }
8641 // Now that all security checks passes, perform the operation as ourselves.
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 return phone.getEquivalentHomePlmns();
8645 } finally {
8646 Binder.restoreCallingIdentity(identity);
8647 }
8648 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008649}