blob: a28130daa3e8b56daec1c4ee6a35bea92d71d6ec [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) {
Hall Liu558027f2019-05-15 19:14:05 -07005409 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005410 if (e != null) {
5411 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5412 throw e;
5413 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005414 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005415 return TelephonyScanManager.INVALID_SCAN_ID;
5416 }
5417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 }
Hall Liu912dfd32019-04-25 14:02:26 -07005419 int callingUid = Binder.getCallingUid();
5420 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005421 final long identity = Binder.clearCallingIdentity();
5422 try {
5423 return mNetworkScanRequestTracker.startNetworkScan(
5424 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005425 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
yinxu504e1392017-04-12 16:03:22 -07005429 }
5430
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005432 NetworkScanRequest request, int subId) {
5433 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5434 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5435 boolean hasNetworkScanPermission =
5436 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5437 == PERMISSION_GRANTED;
5438
5439 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5440 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5441 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005442 }
5443
5444 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5445 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005446 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5447 return new SecurityException("Specific channels must not be"
5448 + " scanned without location access.");
5449 }
5450 }
5451 }
5452
Hall Liub2ac8ef2019-02-28 15:56:23 -08005453 return null;
5454 }
5455
yinxu504e1392017-04-12 16:03:22 -07005456 /**
5457 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005458 *
5459 * @param subId id of the subscription
5460 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005461 */
5462 @Override
5463 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5465 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466
Hall Liu912dfd32019-04-25 14:02:26 -07005467 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005468 final long identity = Binder.clearCallingIdentity();
5469 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005470 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
yinxu504e1392017-04-12 16:03:22 -07005474 }
5475
5476 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005477 * Get the calculated preferred network type.
5478 * Used for debugging incorrect network type.
5479 *
5480 * @return the preferred network type, defined in RILConstants.java.
5481 */
5482 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005483 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005484 final Phone defaultPhone = getDefaultPhone();
5485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005486 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005487 return RILConstants.PREFERRED_NETWORK_MODE;
5488 }
5489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005490 final long identity = Binder.clearCallingIdentity();
5491 try {
5492 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005493 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
Junda Liu84d15a22014-07-02 11:21:04 -07005497 }
5498
5499 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005500 * Get the preferred network type.
5501 * Used for device configuration by some CDMA operators.
5502 *
5503 * @return the preferred network type, defined in RILConstants.java.
5504 */
5505 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005506 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005507 TelephonyPermissions
5508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5509 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
5513 if (DBG) log("getPreferredNetworkType");
5514 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5515 int networkType = (result != null ? result[0] : -1);
5516 if (DBG) log("getPreferredNetworkType: " + networkType);
5517 return networkType;
5518 } finally {
5519 Binder.restoreCallingIdentity(identity);
5520 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005521 }
5522
5523 /**
5524 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005525 *
5526 * @param networkType the preferred network type, defined in RILConstants.java.
5527 * @return true on success; false on any failure.
5528 */
5529 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005530 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005536 Settings.Global.putInt(mApp.getContentResolver(),
5537 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005538
5539 Boolean success = (Boolean) sendRequest(
5540 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5541 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5542 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543 } finally {
5544 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005545 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005546 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005547
5548 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005549 * Get the allowed network types that store in the telephony provider.
5550 *
5551 * @param subId the id of the subscription.
5552 * @return allowedNetworkTypes the allowed network types.
5553 */
5554 @Override
5555 public long getAllowedNetworkTypes(int subId) {
5556 TelephonyPermissions
5557 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5558 mApp, subId, "getAllowedNetworkTypes");
5559
5560 final long identity = Binder.clearCallingIdentity();
5561 try {
5562 return SubscriptionManager.getLongSubscriptionProperty(
5563 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5564 } finally {
5565 Binder.restoreCallingIdentity(identity);
5566 }
5567 }
5568
5569 /**
5570 * Set the allowed network types.
5571 *
5572 * @param subId the id of the subscription.
5573 * @param allowedNetworkTypes the allowed network types.
5574 * @return true on success; false on any failure.
5575 */
5576 @Override
5577 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5578 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5579 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005580
calvinpan089c2a62020-03-12 14:17:55 +08005581 SubscriptionManager.setSubscriptionProperty(subId,
5582 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5583 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005584
calvinpan089c2a62020-03-12 14:17:55 +08005585 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5586 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5587 RILConstants.PREFERRED_NETWORK_MODE);
5588 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005589 }
5590
5591 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005592 * Get the allowed network types for certain reason.
5593 *
5594 * @param subId the id of the subscription.
5595 * @param reason the reason the allowed network type change is taking place
5596 * @return the allowed network types.
5597 */
5598 @Override
5599 public long getAllowedNetworkTypesForReason(int subId,
5600 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5601 TelephonyPermissions
5602 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5603 mApp, subId, "getAllowedNetworkTypesForReason");
5604 final long identity = Binder.clearCallingIdentity();
5605 try {
5606 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5607 } finally {
5608 Binder.restoreCallingIdentity(identity);
5609 }
5610 }
5611
5612 /**
5613 * Get the effective allowed network types on the device.
5614 * This API will return an intersection of allowed network types for all reasons,
5615 * including the configuration done through setAllowedNetworkTypes
5616 *
5617 * @param subId the id of the subscription.
5618 * @return the allowed network types
5619 */
5620 @Override
5621 public long getEffectiveAllowedNetworkTypes(int subId) {
5622 TelephonyPermissions
5623 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5624 mApp, subId, "getEffectiveAllowedNetworkTypes");
5625 final long identity = Binder.clearCallingIdentity();
5626 try {
5627 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5628 } finally {
5629 Binder.restoreCallingIdentity(identity);
5630 }
5631 }
5632
5633 /**
5634 * Set the allowed network types of the device and
5635 * provide the reason triggering the allowed network change.
5636 *
5637 * @param subId the id of the subscription.
5638 * @param reason the reason the allowed network type change is taking place
5639 * @param allowedNetworkTypes the allowed network types.
5640 * @return true on success; false on any failure.
5641 */
5642 @Override
5643 public boolean setAllowedNetworkTypesForReason(int subId,
5644 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5646 mApp, subId, "setAllowedNetworkTypesForReason");
5647 final long identity = Binder.clearCallingIdentity();
5648 try {
5649 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5650 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5651 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5652 RILConstants.PREFERRED_NETWORK_MODE);
5653 return setPreferredNetworkType(subId, preferredNetworkMode);
5654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
5657 }
5658
5659 /**
Miaoa84611c2019-03-15 09:21:10 +08005660 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005661 *
Miaoa84611c2019-03-15 09:21:10 +08005662 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005663 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005664 * @hide
5665 */
5666 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005667 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005670 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 try {
Miaoa84611c2019-03-15 09:21:10 +08005672 if (phone != null) {
5673 return phone.hasMatchedTetherApnSetting();
5674 } else {
5675 return false;
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 } finally {
5678 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005679 }
Junda Liu475951f2014-11-07 16:45:03 -08005680 }
5681
5682 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005683 * Set mobile data enabled
5684 * Used by the user through settings etc to turn on/off mobile data
5685 *
5686 * @param enable {@code true} turn turn data on, else {@code false}
5687 */
5688 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005689 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005690 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5691 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692
5693 final long identity = Binder.clearCallingIdentity();
5694 try {
5695 int phoneId = mSubscriptionController.getPhoneId(subId);
5696 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5697 Phone phone = PhoneFactory.getPhone(phoneId);
5698 if (phone != null) {
5699 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005700 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005702 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 }
5704 } finally {
5705 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005706 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005707 }
5708
5709 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005710 * Enable or disable always reporting signal strength changes from radio.
5711 *
5712 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5713 */
5714 @Override
5715 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5716 enforceModifyPermission();
5717 enforceSystemCaller();
5718
5719 final long identity = Binder.clearCallingIdentity();
5720 final Phone phone = getPhone(subId);
5721 try {
5722 if (phone != null) {
5723 if (DBG) {
5724 log("setAlwaysReportSignalStrength: subId=" + subId
5725 + " isEnable=" + isEnable);
5726 }
5727 phone.setAlwaysReportSignalStrength(isEnable);
5728 } else {
5729 loge("setAlwaysReportSignalStrength: no phone found for subId="
5730 + subId);
5731 }
5732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
5735 }
5736
5737 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005738 * Get the user enabled state of Mobile Data.
5739 *
5740 * TODO: remove and use isUserDataEnabled.
5741 * This can't be removed now because some vendor codes
5742 * calls through ITelephony directly while they should
5743 * use TelephonyManager.
5744 *
5745 * @return true on enabled
5746 */
5747 @Override
5748 public boolean getDataEnabled(int subId) {
5749 return isUserDataEnabled(subId);
5750 }
5751
5752 /**
5753 * Get whether mobile data is enabled per user setting.
5754 *
5755 * There are other factors deciding whether mobile data is actually enabled, but they are
5756 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005757 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005758 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005759 *
5760 * @return {@code true} if data is enabled else {@code false}
5761 */
5762 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005763 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005764 try {
5765 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5766 null);
5767 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005768 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5769 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005770 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771
5772 final long identity = Binder.clearCallingIdentity();
5773 try {
5774 int phoneId = mSubscriptionController.getPhoneId(subId);
5775 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5776 Phone phone = PhoneFactory.getPhone(phoneId);
5777 if (phone != null) {
5778 boolean retVal = phone.isUserDataEnabled();
5779 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5780 return retVal;
5781 } else {
5782 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5783 return false;
5784 }
5785 } finally {
5786 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005787 }
5788 }
5789
5790 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005791 * Checks if the device is capable of mobile data by considering whether whether the
5792 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5793 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005794 *
Shuo Qian985d1232020-01-08 14:30:06 -08005795 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005796 */
5797 @Override
5798 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005799 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 int phoneId = mSubscriptionController.getPhoneId(subId);
5804 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5805 Phone phone = PhoneFactory.getPhone(phoneId);
5806 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005807 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005808 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5809 return retVal;
5810 } else {
5811 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5812 return false;
5813 }
5814 } finally {
5815 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005816 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005817 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005818
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005819 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005820 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005821 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5822 // Skip the check if it's one of these special uids
5823 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5824 }
5825
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005826 //load access rules from carrier configs, and check those as well: b/139133814
5827 SubscriptionController subController = SubscriptionController.getInstance();
5828 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5829 || subController == null) return privilegeFromSim;
5830
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005831 PackageManager pkgMgr = phone.getContext().getPackageManager();
5832 String[] packages = pkgMgr.getPackagesForUid(uid);
5833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005836 int subId = phone.getSubId();
5837 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5838 // A test override is in place for the privileges for this subId, so don't try to
5839 // read the subscription privileges.
5840 return privilegeFromSim;
5841 }
5842 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005843 SubscriptionManager subManager = (SubscriptionManager)
5844 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5845 for (String pkg : packages) {
5846 if (subManager.canManageSubscription(subInfo, pkg)) {
5847 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5848 }
5849 }
5850 return privilegeFromSim;
5851 } finally {
5852 Binder.restoreCallingIdentity(identity);
5853 }
5854 }
5855
5856 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5857 String pkgName) {
5858 //load access rules from carrier configs, and check those as well: b/139133814
5859 SubscriptionController subController = SubscriptionController.getInstance();
5860 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5861 || subController == null) return privilegeFromSim;
5862
5863 final long identity = Binder.clearCallingIdentity();
5864 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07005865 int subId = phone.getSubId();
5866 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5867 // A test override is in place for the privileges for this subId, so don't try to
5868 // read the subscription privileges.
5869 return privilegeFromSim;
5870 }
5871 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005872 SubscriptionManager subManager = (SubscriptionManager)
5873 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5874 return subManager.canManageSubscription(subInfo, pkgName)
5875 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
5879 }
5880
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005881 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005882 public int getCarrierPrivilegeStatus(int subId) {
5883 final Phone phone = getPhone(subId);
5884 if (phone == null) {
5885 loge("getCarrierPrivilegeStatus: Invalid subId");
5886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5887 }
5888 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005889 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005890 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005891 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5892 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005893
5894 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5895 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005896 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005897 }
Junda Liu29340342014-07-10 15:23:27 -07005898
5899 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005900 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005901 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005902 final Phone phone = getPhone(subId);
5903 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005904 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005905 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5906 }
5907 UiccProfile profile =
5908 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5909 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005910 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5912 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005913 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005914 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005915 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005916 }
5917
5918 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005919 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5920 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005922 }
5923
5924 int phoneId = SubscriptionManager.getPhoneId(subId);
5925 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005926 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005927 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005928 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5929 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005930 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5931 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5932 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005933 }
5934
5935 @Override
5936 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005937 if (TextUtils.isEmpty(pkgName))
5938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005939 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5940 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5941 UiccCard card = UiccController.getInstance().getUiccCard(i);
5942 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005943 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005944 continue;
5945 }
5946
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005947 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5948 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5949 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005950 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5951 break;
5952 }
5953 }
5954
5955 return result;
Junda Liu29340342014-07-10 15:23:27 -07005956 }
Derek Tan89e89d42014-07-08 17:00:10 -07005957
5958 @Override
Junda Liue64de782015-04-16 17:19:16 -07005959 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5960 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5961 loge("phoneId " + phoneId + " is not valid.");
5962 return null;
5963 }
5964 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005965 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005966 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005967 return null ;
5968 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005969 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005970 }
5971
Amith Yamasani6e118872016-02-19 12:53:51 -08005972 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005973 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005974 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005975 List<String> privilegedPackages = new ArrayList<>();
5976 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005977 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5978 // has UICC in that slot.
5979 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005980 if (card.hasCarrierPrivilegeRules()) {
5981 if (packages == null) {
5982 // Only check packages in user 0 for now
5983 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005984 PackageManager.MATCH_DISABLED_COMPONENTS
5985 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005986 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005987 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005988 }
5989 for (int p = packages.size() - 1; p >= 0; p--) {
5990 PackageInfo pkgInfo = packages.get(p);
5991 if (pkgInfo != null && pkgInfo.packageName != null
5992 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005993 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005994 privilegedPackages.add(pkgInfo.packageName);
5995 }
5996 }
5997 }
5998 }
5999 return privilegedPackages;
6000 }
6001
chen xuf7e9fe82019-05-09 19:31:02 -07006002 @Override
6003 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006004 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6005
6006 final long identity = Binder.clearCallingIdentity();
6007
chen xuf7e9fe82019-05-09 19:31:02 -07006008 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006009 try {
6010 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6011 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6012 }
6013 } finally {
6014 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006015 }
6016 return privilegedPackages;
6017 }
6018
Wink Savilleb564aae2014-10-23 10:18:09 -07006019 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006020 final Phone phone = getPhone(subId);
6021 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006022 if (card == null) {
6023 loge("getIccId: No UICC");
6024 return null;
6025 }
6026 String iccId = card.getIccId();
6027 if (TextUtils.isEmpty(iccId)) {
6028 loge("getIccId: ICC ID is null or empty.");
6029 return null;
6030 }
6031 return iccId;
6032 }
6033
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006034 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006035 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6036 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006037 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006038 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006039
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006040 final long identity = Binder.clearCallingIdentity();
6041 try {
6042 final String iccId = getIccId(subId);
6043 final Phone phone = getPhone(subId);
6044 if (phone == null) {
6045 return false;
6046 }
6047 final String subscriberId = phone.getSubscriberId();
6048
6049 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006050 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 + subscriberId + " to " + number);
6052 }
6053
6054 if (TextUtils.isEmpty(iccId)) {
6055 return false;
6056 }
6057
6058 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6059
6060 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6061 if (alphaTag == null) {
6062 editor.remove(alphaTagPrefKey);
6063 } else {
6064 editor.putString(alphaTagPrefKey, alphaTag);
6065 }
6066
6067 // Record both the line number and IMSI for this ICCID, since we need to
6068 // track all merged IMSIs based on line number
6069 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6070 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6071 if (number == null) {
6072 editor.remove(numberPrefKey);
6073 editor.remove(subscriberPrefKey);
6074 } else {
6075 editor.putString(numberPrefKey, number);
6076 editor.putString(subscriberPrefKey, subscriberId);
6077 }
6078
6079 editor.commit();
6080 return true;
6081 } finally {
6082 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006083 }
Derek Tan7226c842014-07-02 17:42:23 -07006084 }
6085
6086 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006087 public String getLine1NumberForDisplay(int subId, String callingPackage,
6088 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006089 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006090 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006091 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006092 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006093 return null;
6094 }
Derek Tan97ebb422014-09-05 16:55:38 -07006095
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006096 final long identity = Binder.clearCallingIdentity();
6097 try {
6098 String iccId = getIccId(subId);
6099 if (iccId != null) {
6100 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6101 if (DBG_MERGE) {
6102 log("getLine1NumberForDisplay returning "
6103 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6104 }
6105 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006106 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6108 return null;
6109 } finally {
6110 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006111 }
Derek Tan7226c842014-07-02 17:42:23 -07006112 }
6113
6114 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006115 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6116 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006118 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006119 return null;
6120 }
Derek Tan97ebb422014-09-05 16:55:38 -07006121
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 String iccId = getIccId(subId);
6125 if (iccId != null) {
6126 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6127 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6128 }
6129 return null;
6130 } finally {
6131 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006132 }
Derek Tan7226c842014-07-02 17:42:23 -07006133 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006134
6135 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006136 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6137 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006138 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6139 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006141 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006142 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006143 return null;
6144 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006145
Jordan Liub49b04b2019-05-06 14:45:15 -07006146 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6147 // the process, where TelephonyManager was instantiated.
6148 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006149 final long identity = Binder.clearCallingIdentity();
6150 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006151 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006152 final TelephonyManager tele = TelephonyManager.from(context);
6153 final SubscriptionManager sub = SubscriptionManager.from(context);
6154
6155 // Figure out what subscribers are currently active
6156 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006157
Jordan Liub49b04b2019-05-06 14:45:15 -07006158 // Only consider subs which match the current subId
6159 // This logic can be simplified. See b/131189269 for progress.
6160 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006161 activeSubscriberIds.add(tele.getSubscriberId(subId));
6162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163
6164 // First pass, find a number override for an active subscriber
6165 String mergeNumber = null;
6166 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6167 for (String key : prefs.keySet()) {
6168 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6169 final String subscriberId = (String) prefs.get(key);
6170 if (activeSubscriberIds.contains(subscriberId)) {
6171 final String iccId = key.substring(
6172 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6173 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6174 mergeNumber = (String) prefs.get(numberKey);
6175 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006176 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 + " for active subscriber " + subscriberId);
6178 }
6179 if (!TextUtils.isEmpty(mergeNumber)) {
6180 break;
6181 }
6182 }
6183 }
6184 }
6185
6186 // Shortcut when no active merged subscribers
6187 if (TextUtils.isEmpty(mergeNumber)) {
6188 return null;
6189 }
6190
6191 // Second pass, find all subscribers under that line override
6192 final ArraySet<String> result = new ArraySet<>();
6193 for (String key : prefs.keySet()) {
6194 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6195 final String number = (String) prefs.get(key);
6196 if (mergeNumber.equals(number)) {
6197 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6198 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6199 final String subscriberId = (String) prefs.get(subscriberKey);
6200 if (!TextUtils.isEmpty(subscriberId)) {
6201 result.add(subscriberId);
6202 }
6203 }
6204 }
6205 }
6206
6207 final String[] resultArray = result.toArray(new String[result.size()]);
6208 Arrays.sort(resultArray);
6209 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006210 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006211 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6212 }
6213 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006214 } finally {
6215 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006216 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006217 }
6218
6219 @Override
zoey chen38003472019-12-13 17:16:31 +08006220 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6221 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006222
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 final TelephonyManager telephonyManager = mApp.getSystemService(
6226 TelephonyManager.class);
6227 String subscriberId = telephonyManager.getSubscriberId(subId);
6228 if (subscriberId == null) {
6229 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006230 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006231 + subId);
6232 }
6233 return null;
6234 }
6235
6236 final SubscriptionInfo info = SubscriptionController.getInstance()
6237 .getSubscriptionInfo(subId);
6238 final ParcelUuid groupUuid = info.getGroupUuid();
6239 // If it doesn't belong to any group, return just subscriberId of itself.
6240 if (groupUuid == null) {
6241 return new String[]{subscriberId};
6242 }
6243
6244 // Get all subscriberIds from the group.
6245 final List<String> mergedSubscriberIds = new ArrayList<>();
6246 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006247 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006248 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006249 for (SubscriptionInfo subInfo : groupInfos) {
6250 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6251 if (subscriberId != null) {
6252 mergedSubscriberIds.add(subscriberId);
6253 }
6254 }
6255
6256 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
6259
6260 }
6261 }
6262
6263 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006264 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006265 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006266 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006267
6268 final long identity = Binder.clearCallingIdentity();
6269 try {
6270 final Phone phone = getPhone(subId);
6271 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6272 } finally {
6273 Binder.restoreCallingIdentity(identity);
6274 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006275 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006276
6277 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006278 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006279 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6280 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006281 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6282 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006283
6284 final long identity = Binder.clearCallingIdentity();
6285 try {
6286 final Phone phone = getPhone(subId);
6287 if (phone == null) {
6288 return false;
6289 }
6290 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6291 cdmaNonRoamingList);
6292 } finally {
6293 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006294 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006295 }
6296
6297 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006298 @Deprecated
6299 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6300 enforceModifyPermission();
6301
6302 int returnValue = 0;
6303 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006304 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006305 if(result.exception == null) {
6306 if (result.result != null) {
6307 byte[] responseData = (byte[])(result.result);
6308 if(responseData.length > oemResp.length) {
6309 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6310 responseData.length + "bytes. Buffer Size is " +
6311 oemResp.length + "bytes.");
6312 }
6313 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6314 returnValue = responseData.length;
6315 }
6316 } else {
6317 CommandException ex = (CommandException) result.exception;
6318 returnValue = ex.getCommandError().ordinal();
6319 if(returnValue > 0) returnValue *= -1;
6320 }
6321 } catch (RuntimeException e) {
6322 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6323 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6324 if(returnValue > 0) returnValue *= -1;
6325 }
6326
6327 return returnValue;
6328 }
6329
6330 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006331 public void setRadioCapability(RadioAccessFamily[] rafs) {
6332 try {
6333 ProxyController.getInstance().setRadioCapability(rafs);
6334 } catch (RuntimeException e) {
6335 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6336 }
6337 }
6338
6339 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006340 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006341 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006342 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006343 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006344 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006345 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006346 final long identity = Binder.clearCallingIdentity();
6347 try {
chen xub97461a2018-10-26 14:17:57 -07006348 TelephonyPermissions
6349 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6350 mApp, phone.getSubId(), "getRadioAccessFamily");
6351 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006352 } finally {
6353 Binder.restoreCallingIdentity(identity);
6354 }
chen xub97461a2018-10-26 14:17:57 -07006355 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006356 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006357
6358 @Override
6359 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006360 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006361 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006362
6363 final long identity = Binder.clearCallingIdentity();
6364 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006365 ImsManager.getInstance(defaultPhone.getContext(),
6366 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006370 }
6371
6372 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006373 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006374 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6376 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006377 return false;
6378 }
Svet Ganovb320e182015-04-16 12:30:10 -07006379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 // Check the user preference and the system-level IMS setting. Even if the user has
6383 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6384 // In the long run, we may instead need to check if there exists a connection service
6385 // which can support video calling.
6386 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006387 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006388 return imsManager.isVtEnabledByPlatform()
6389 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6390 && imsManager.isVtEnabledByUser();
6391 } finally {
6392 Binder.restoreCallingIdentity(identity);
6393 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006394 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006395
Andrew Leea1239f22015-03-02 17:44:07 -08006396 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006397 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6398 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006400 mApp, subId, callingPackage, callingFeatureId,
6401 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 return false;
6403 }
6404
6405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 CarrierConfigManager configManager =
6408 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006409 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6411 } finally {
6412 Binder.restoreCallingIdentity(identity);
6413 }
Andrew Leea1239f22015-03-02 17:44:07 -08006414 }
6415
6416 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006417 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006418 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006419 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006420 return false;
6421 }
6422
6423 final long identity = Binder.clearCallingIdentity();
6424 try {
6425 CarrierConfigManager configManager =
6426 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006427 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006428 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
Andrew Leea1239f22015-03-02 17:44:07 -08006432 }
6433
Andrew Lee9431b832015-03-09 18:46:45 -07006434 @Override
6435 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006436 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006437 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006438 }
6439
6440 @Override
6441 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006442 final long identity = Binder.clearCallingIdentity();
6443 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006444 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 } finally {
6446 Binder.restoreCallingIdentity(identity);
6447 }
Andrew Lee9431b832015-03-09 18:46:45 -07006448 }
6449
Hall Liuf6668912018-10-31 17:05:23 -07006450 /**
6451 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6452 * support for the feature and device firmware support.
6453 *
6454 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6455 */
6456 @Override
6457 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006458 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006459 final Phone phone = getPhone(subscriptionId);
6460 if (phone == null) {
6461 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6462 return false;
6463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006464 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006465 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006466 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6467 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006468 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 return isCarrierSupported && isDeviceSupported;
6470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Hall Liu98187582018-01-22 19:15:32 -08006473 }
6474
Hall Liuf6668912018-10-31 17:05:23 -07006475 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006476 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6477 * RTT setting, will return true if the device and carrier both support RTT.
6478 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006479 */
6480 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006481 final long identity = Binder.clearCallingIdentity();
6482 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006483 boolean isRttSupported = isRttSupported(subscriptionId);
6484 boolean isUserRttSettingOn = Settings.Secure.getInt(
6485 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6486 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6487 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6488 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 } finally {
6490 Binder.restoreCallingIdentity(identity);
6491 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006492 }
6493
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006494 @Deprecated
6495 @Override
6496 public String getDeviceId(String callingPackage) {
6497 return getDeviceIdWithFeature(callingPackage, null);
6498 }
6499
Sanket Padawe7310cc72015-01-14 09:53:20 -08006500 /**
6501 * Returns the unique device ID of phone, for example, the IMEI for
6502 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6503 *
6504 * <p>Requires Permission:
6505 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6506 */
6507 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006508 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006509 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006510 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006511 return null;
6512 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006513 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006514 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006515 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006516 return null;
6517 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006518
6519 final long identity = Binder.clearCallingIdentity();
6520 try {
6521 return phone.getDeviceId();
6522 } finally {
6523 Binder.restoreCallingIdentity(identity);
6524 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006525 }
6526
Ping Sunc67b7c22016-03-02 19:16:45 +08006527 /**
6528 * {@hide}
6529 * Returns the IMS Registration Status on a particular subid
6530 *
6531 * @param subId
6532 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006533 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006534 Phone phone = getPhone(subId);
6535 if (phone != null) {
6536 return phone.isImsRegistered();
6537 } else {
6538 return false;
6539 }
6540 }
6541
Santos Cordon7a1885b2015-02-03 11:15:19 -08006542 @Override
6543 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006550 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006551
Tyler Gunnf70ed162019-04-03 15:28:53 -07006552 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006553 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006554 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006555 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006556 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006557 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6558 }
6559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6562 } finally {
6563 Binder.restoreCallingIdentity(identity);
6564 }
6565 }
6566
6567 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006568 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006569 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6570 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 Phone phone = getPhone(subscriptionId);
6574 if (phone == null) {
6575 return null;
6576 }
6577 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6578 } finally {
6579 Binder.restoreCallingIdentity(identity);
6580 }
6581 }
6582
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006583 /**
6584 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006585 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006586 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 final long identity = Binder.clearCallingIdentity();
6588 try {
6589 Phone phone = getPhone(subId);
6590 if (phone != null) {
6591 return phone.isWifiCallingEnabled();
6592 } else {
6593 return false;
6594 }
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006597 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006598 }
6599
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006600 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006601 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006602 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006603 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006604 final long identity = Binder.clearCallingIdentity();
6605 try {
6606 Phone phone = getPhone(subId);
6607 if (phone != null) {
6608 return phone.isVideoEnabled();
6609 } else {
6610 return false;
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006614 }
6615 }
6616
6617 /**
6618 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6619 * defined in {@link ImsRegistrationImplBase}.
6620 */
6621 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006622 final long identity = Binder.clearCallingIdentity();
6623 try {
6624 Phone phone = getPhone(subId);
6625 if (phone != null) {
6626 return phone.getImsRegistrationTech();
6627 } else {
6628 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6629 }
6630 } finally {
6631 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006632 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006633 }
6634
Stuart Scott8eef64f2015-04-08 15:13:54 -07006635 @Override
6636 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006637 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006638 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6639 return;
6640 }
6641
Svet Ganovcc087f82015-05-12 20:35:54 -07006642 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006643
Svet Ganovcc087f82015-05-12 20:35:54 -07006644 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006645 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6646 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006647 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006648 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006649 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006650 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6651 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006652 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006653 // There has been issues when Sms raw table somehow stores orphan
6654 // fragments. They lead to garbled message when new fragments come
6655 // in and combined with those stale ones. In case this happens again,
6656 // user can reset all network settings which will clean up this table.
6657 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006658 // Clean up IMS settings as well here.
6659 int slotId = getSlotIndex(subId);
6660 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6661 ImsManager.getInstance(mApp, slotId).factoryReset();
6662 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006663
6664 // Erase modem config if erase modem on network setting is enabled.
6665 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6666 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6667 if (configValue != null && Boolean.parseBoolean(configValue)) {
6668 sendEraseModemConfig(getDefaultPhone());
6669 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006672 }
6673 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006674
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006675 private void cleanUpSmsRawTable(Context context) {
6676 ContentResolver resolver = context.getContentResolver();
6677 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6678 resolver.delete(uri, null, null);
6679 }
6680
Narayan Kamath1c496c22015-04-16 14:40:19 +01006681 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006682 public String getSimLocaleForSubscriber(int subId) {
6683 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6684 final Phone phone = getPhone(subId);
6685 if (phone == null) {
6686 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006687 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 final long identity = Binder.clearCallingIdentity();
6690 try {
chen xu5d3637b2019-01-21 23:31:38 -08006691 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006692 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006693 if (info == null) {
6694 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6695 return null;
6696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006697 // Try and fetch the locale from the carrier properties or from the SIM language
6698 // preferences (EF-PL and EF-LI)...
6699 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006701 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6702 if (localeFromDefaultSim != null) {
6703 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6704 if (DBG) log("Using locale from subId: " + subId + " locale: "
6705 + localeFromDefaultSim);
6706 return localeFromDefaultSim.toLanguageTag();
6707 } else {
6708 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006709 }
6710 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006711
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712 // The SIM language preferences only store a language (e.g. fr = French), not an
6713 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6714 // the SIM and carrier preferences does not include a country we add the country
6715 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006716 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006718 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006719 return mccLocale.toLanguageTag();
6720 }
6721
6722 if (DBG) log("No locale found - returning null");
6723 return null;
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
6726 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006727 }
6728
6729 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006730 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006731 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006732 }
6733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006734 /**
6735 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6736 */
6737 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006738 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006739 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006740 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006741
Chenjie Yu1ba97252018-01-11 18:16:20 -08006742 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006743 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006744
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006745 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006746 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6747 * representing the state of the modem.
6748 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006749 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6750 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006751 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006752 */
6753 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006754 public void requestModemActivityInfo(ResultReceiver result) {
6755 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757
6758 final long identity = Binder.clearCallingIdentity();
6759 try {
sqian1a1be542020-03-05 11:37:28 -08006760 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 } finally {
6762 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006763 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006764 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006765
Siddharth Rayb8114062018-06-17 15:02:38 -07006766 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6767 // less than total activity duration.
6768 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6769 if (info == null) {
6770 return false;
6771 }
6772 int activityDurationMs =
6773 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6774 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006775 int[] txTimeMs = info.getTransmitTimeMillis();
6776 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6777 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006778 }
6779 return (info.isValid()
6780 && (info.getSleepTimeMillis() <= activityDurationMs)
6781 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006782 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006783 && (totalTxTimeMs <= activityDurationMs));
6784 }
6785
Jack Yu85bd38a2015-11-09 11:34:32 -08006786 /**
6787 * {@hide}
6788 * Returns the service state information on specified subscription.
6789 */
6790 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006791 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6792 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006793 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006794 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006795 return null;
6796 }
6797
Hall Liuf19c44f2018-11-27 14:38:17 -08006798 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6799 LocationAccessPolicy.checkLocationPermission(mApp,
6800 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6801 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006802 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006803 .setCallingPid(Binder.getCallingPid())
6804 .setCallingUid(Binder.getCallingUid())
6805 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006806 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006807 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6808 .build());
6809
6810 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6811 LocationAccessPolicy.checkLocationPermission(mApp,
6812 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6813 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006814 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006815 .setCallingPid(Binder.getCallingPid())
6816 .setCallingUid(Binder.getCallingUid())
6817 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006818 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006819 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6820 .build());
6821 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6822 boolean hasFinePermission =
6823 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6824 boolean hasCoarsePermission =
6825 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006827 final long identity = Binder.clearCallingIdentity();
6828 try {
6829 final Phone phone = getPhone(subId);
6830 if (phone == null) {
6831 return null;
6832 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006833
Hall Liuf19c44f2018-11-27 14:38:17 -08006834 ServiceState ss = phone.getServiceState();
6835
6836 // Scrub out the location info in ServiceState depending on what level of access
6837 // the caller has.
6838 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006839 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6840 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006844 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006845
6846 /**
6847 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6848 *
6849 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6850 * voicemail ringtone.
6851 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6852 * PhoneAccount.
6853 */
6854 @Override
6855 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 final long identity = Binder.clearCallingIdentity();
6857 try {
6858 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6859 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006860 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006862
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
6866 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006867 }
6868
6869 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006870 * Sets the per-account voicemail ringtone.
6871 *
6872 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6873 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6874 *
6875 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6876 * voicemail ringtone.
6877 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6878 * PhoneAccount.
6879 */
6880 @Override
6881 public void setVoicemailRingtoneUri(String callingPackage,
6882 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006883 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006884 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006885 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6886 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006887 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6888 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6889 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891
6892 final long identity = Binder.clearCallingIdentity();
6893 try {
6894 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6895 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006896 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897 }
6898 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6899 } finally {
6900 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006901 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006902 }
6903
6904 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006905 * Returns whether vibration is set for voicemail notification in Phone settings.
6906 *
6907 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6908 * voicemail vibration setting.
6909 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6910 */
6911 @Override
6912 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6916 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006917 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006919
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006920 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
6923 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006924 }
6925
Youhan Wange64578a2016-05-02 15:32:42 -07006926 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006927 * Sets the per-account voicemail vibration.
6928 *
6929 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6930 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6931 *
6932 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6933 * voicemail vibration setting.
6934 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6935 * specific PhoneAccount.
6936 */
6937 @Override
6938 public void setVoicemailVibrationEnabled(String callingPackage,
6939 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006940 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006941 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006942 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6943 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006944 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6945 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6946 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006947 }
6948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 final long identity = Binder.clearCallingIdentity();
6950 try {
6951 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6952 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006953 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954 }
6955 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6956 } finally {
6957 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006958 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006959 }
6960
6961 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006962 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6963 *
6964 * @throws SecurityException if the caller does not have the required permission
6965 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006966 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006967 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006968 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006969 }
6970
6971 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006972 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6973 * permission.
6974 *
6975 * @throws SecurityException if the caller does not have the required permission
6976 */
6977 private void enforceSendSmsPermission() {
6978 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6979 }
6980
6981 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006982 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006983 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006984 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006985 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006986 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006990 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 if (componentName == null) {
6992 throw new SecurityException(
6993 "Caller not current active visual voicemail package[null]");
6994 }
6995 String vvmPackage = componentName.getPackageName();
6996 if (!callingPackage.equals(vvmPackage)) {
6997 throw new SecurityException("Caller not current active visual voicemail package["
6998 + vvmPackage + "]");
6999 }
7000 } finally {
7001 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007002 }
7003 }
7004
7005 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007006 * Return the application ID for the app type.
7007 *
7008 * @param subId the subscription ID that this request applies to.
7009 * @param appType the uicc app type.
7010 * @return Application ID for specificied app type, or null if no uicc.
7011 */
7012 @Override
7013 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007014 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007015 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016
7017 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007018 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 if (phone == null) {
7020 return null;
7021 }
7022 String aid = null;
7023 try {
7024 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7025 .getApplicationByType(appType).getAid();
7026 } catch (Exception e) {
7027 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7028 }
7029 return aid;
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007032 }
Youhan Wange64578a2016-05-02 15:32:42 -07007033 }
7034
Youhan Wang4001d252016-05-11 10:29:41 -07007035 /**
7036 * Return the Electronic Serial Number.
7037 *
7038 * @param subId the subscription ID that this request applies to.
7039 * @return ESN or null if error.
7040 */
7041 @Override
7042 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007043 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007044 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045
7046 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007047 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 if (phone == null) {
7049 return null;
7050 }
7051 String esn = null;
7052 try {
7053 esn = phone.getEsn();
7054 } catch (Exception e) {
7055 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7056 }
7057 return esn;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007060 }
Youhan Wang4001d252016-05-11 10:29:41 -07007061 }
7062
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007063 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007064 * Return the Preferred Roaming List Version.
7065 *
7066 * @param subId the subscription ID that this request applies to.
7067 * @return PRLVersion or null if error.
7068 */
7069 @Override
7070 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007071 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007072 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073
7074 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007075 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 if (phone == null) {
7077 return null;
7078 }
7079 String cdmaPrlVersion = null;
7080 try {
7081 cdmaPrlVersion = phone.getCdmaPrlVersion();
7082 } catch (Exception e) {
7083 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7084 }
7085 return cdmaPrlVersion;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007088 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007089 }
7090
7091 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007092 * Get snapshot of Telephony histograms
7093 * @return List of Telephony histograms
7094 * @hide
7095 */
7096 @Override
7097 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7099 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 return RIL.getTelephonyRILTimingHistograms();
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007107 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007108
7109 /**
7110 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007111 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7112 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007113 * Require system privileges. In the future we may add this to carrier APIs.
7114 *
Michele Berionne482f8202018-11-27 18:57:59 -08007115 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007116 */
7117 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007118 @TelephonyManager.SetCarrierRestrictionResult
7119 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007120 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007121 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007122
Michele Berionne482f8202018-11-27 18:57:59 -08007123 if (carrierRestrictionRules == null) {
7124 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007125 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007126
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007127 final long identity = Binder.clearCallingIdentity();
7128 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007129 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007130 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007134 }
7135
7136 /**
7137 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007138 * Get the allowed carrier list and the excluded carrier list, including the priority between
7139 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007140 * Require system privileges. In the future we may add this to carrier APIs.
7141 *
Michele Berionne482f8202018-11-27 18:57:59 -08007142 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007143 */
7144 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007145 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007146 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007147 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007148
7149 final long identity = Binder.clearCallingIdentity();
7150 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007151 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7152 if (response instanceof CarrierRestrictionRules) {
7153 return (CarrierRestrictionRules) response;
7154 }
7155 // Response is an Exception of some kind,
7156 // which is signalled to the user as a NULL retval
7157 return null;
7158 } catch (Exception e) {
7159 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7160 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007164 }
7165
fionaxu59545b42016-05-25 15:53:37 -07007166 /**
7167 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7168 * @param subId the subscription ID that this action applies to.
7169 * @param enabled control enable or disable metered apns.
7170 * {@hide}
7171 */
7172 @Override
7173 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7174 enforceModifyPermission();
7175 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176
7177 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007178 if (phone == null) {
7179 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7180 return;
7181 }
7182 try {
7183 phone.carrierActionSetMeteredApnsEnabled(enabled);
7184 } catch (Exception e) {
7185 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 } finally {
7187 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007188 }
7189 }
7190
7191 /**
7192 * Action set from carrier signalling broadcast receivers to enable/disable radio
7193 * @param subId the subscription ID that this action applies to.
7194 * @param enabled control enable or disable radio.
7195 * {@hide}
7196 */
7197 @Override
7198 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7199 enforceModifyPermission();
7200 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007201
7202 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007203 if (phone == null) {
7204 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7205 return;
7206 }
7207 try {
7208 phone.carrierActionSetRadioEnabled(enabled);
7209 } catch (Exception e) {
7210 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 } finally {
7212 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007213 }
7214 }
7215
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007216 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007217 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7218 * network status based on which carrier apps could apply actions accordingly,
7219 * enable/disable default url handler for example.
7220 *
7221 * @param subId the subscription ID that this action applies to.
7222 * @param report control start/stop reporting the default network status.
7223 * {@hide}
7224 */
7225 @Override
7226 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7227 enforceModifyPermission();
7228 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229
7230 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007231 if (phone == null) {
7232 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7233 return;
7234 }
7235 try {
7236 phone.carrierActionReportDefaultNetworkStatus(report);
7237 } catch (Exception e) {
7238 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 } finally {
7240 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007241 }
7242 }
7243
7244 /**
fionaxud9622282017-07-17 17:51:30 -07007245 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7246 * @param subId the subscription ID that this action applies to.
7247 * {@hide}
7248 */
7249 @Override
7250 public void carrierActionResetAll(int subId) {
7251 enforceModifyPermission();
7252 final Phone phone = getPhone(subId);
7253 if (phone == null) {
7254 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7255 return;
7256 }
7257 try {
7258 phone.carrierActionResetAll();
7259 } catch (Exception e) {
7260 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7261 }
7262 }
7263
7264 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007265 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7266 * bug report is being generated.
7267 */
7268 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007269 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007270 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7271 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007272 writer.println("Permission Denial: can't dump Phone from pid="
7273 + Binder.getCallingPid()
7274 + ", uid=" + Binder.getCallingUid()
7275 + "without permission "
7276 + android.Manifest.permission.DUMP);
7277 return;
7278 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007279 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007280 }
Jack Yueb89b242016-06-22 13:27:47 -07007281
Brad Ebingerdac2f002018-04-03 15:17:52 -07007282 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007283 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7284 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7285 @NonNull String[] args) {
7286 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7287 this, in.getFileDescriptor(), out.getFileDescriptor(),
7288 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007289 }
7290
Jack Yueb89b242016-06-22 13:27:47 -07007291 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007292 * Policy control of data connection. Usually used when data limit is passed.
7293 * @param enabled True if enabling the data, otherwise disabling.
7294 * @param subId Subscription index
7295 * {@hide}
7296 */
7297 @Override
7298 public void setPolicyDataEnabled(boolean enabled, int subId) {
7299 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300
7301 final long identity = Binder.clearCallingIdentity();
7302 try {
7303 Phone phone = getPhone(subId);
7304 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007305 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 }
7307 } finally {
7308 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007309 }
7310 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007311
7312 /**
7313 * Get Client request stats
7314 * @return List of Client Request Stats
7315 * @hide
7316 */
7317 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007318 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7319 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007321 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007322 return null;
7323 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007324 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007325
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 final long identity = Binder.clearCallingIdentity();
7327 try {
7328 if (phone != null) {
7329 return phone.getClientRequestStats();
7330 }
7331
7332 return null;
7333 } finally {
7334 Binder.restoreCallingIdentity(identity);
7335 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007336 }
7337
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007338 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007339 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007340 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007341 }
Jack Yueb4124c2017-02-16 15:32:43 -08007342
7343 /**
Grace Chen70990072017-03-24 17:21:30 -07007344 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007345 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007346 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007347 * @param state State of SIM (power down, power up, pass through)
7348 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7349 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7350 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007351 *
7352 **/
7353 @Override
Grace Chen70990072017-03-24 17:21:30 -07007354 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007355 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007356 Phone phone = PhoneFactory.getPhone(slotIndex);
7357
vagdeviaf9a5b92018-08-15 16:01:53 -07007358 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7359
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007360 final long identity = Binder.clearCallingIdentity();
7361 try {
7362 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007363 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364 }
7365 } finally {
7366 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007367 }
7368 }
Shuo Qiandd210312017-04-12 22:11:33 +00007369
Tyler Gunn65d45c22017-06-05 11:22:26 -07007370 private boolean isUssdApiAllowed(int subId) {
7371 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007372 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007373 if (configManager == null) {
7374 return false;
7375 }
7376 PersistableBundle pb = configManager.getConfigForSubId(subId);
7377 if (pb == null) {
7378 return false;
7379 }
7380 return pb.getBoolean(
7381 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7382 }
7383
Shuo Qiandd210312017-04-12 22:11:33 +00007384 /**
7385 * Check if phone is in emergency callback mode
7386 * @return true if phone is in emergency callback mode
7387 * @param subId sub id
7388 */
goneil9c5f4872017-12-05 14:07:56 -08007389 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007390 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007391 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007392 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007393
7394 final long identity = Binder.clearCallingIdentity();
7395 try {
7396 if (phone != null) {
7397 return phone.isInEcm();
7398 } else {
7399 return false;
7400 }
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007403 }
7404 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007405
7406 /**
7407 * Get the current signal strength information for the given subscription.
7408 * Because this information is not updated when the device is in a low power state
7409 * it should not be relied-upon to be current.
7410 * @param subId Subscription index
7411 * @return the most recent cached signal strength info from the modem
7412 */
7413 @Override
7414 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 Phone p = getPhone(subId);
7418 if (p == null) {
7419 return null;
7420 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 return p.getSignalStrength();
7423 } finally {
7424 Binder.restoreCallingIdentity(identity);
7425 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007426 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007427
Pengquan Meng77b7f132018-08-22 14:49:57 -07007428 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007429 * Get the current modem radio state for the given slot.
7430 * @param slotIndex slot index.
7431 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007432 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007433 * @return the current radio power state from the modem
7434 */
7435 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007436 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007437 Phone phone = PhoneFactory.getPhone(slotIndex);
7438 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007439 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7440 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007441 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7442 }
7443
7444 final long identity = Binder.clearCallingIdentity();
7445 try {
7446 return phone.getRadioPowerState();
7447 } finally {
7448 Binder.restoreCallingIdentity(identity);
7449 }
7450 }
7451 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7452 }
7453
7454 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007455 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7456 *
7457 * <p>Requires one of the following permissions:
7458 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7459 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7460 * privileges.
7461 *
7462 * @param subId subscription id
7463 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7464 * {@code false}.
7465 */
7466 @Override
7467 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007468 try {
7469 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7470 null);
7471 } catch (Exception e) {
7472 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7473 mApp, subId, "isDataRoamingEnabled");
7474 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007475
Pengquan Menga1bb6272018-09-06 09:59:22 -07007476 boolean isEnabled = false;
7477 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007478 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007479 Phone phone = getPhone(subId);
7480 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007481 } finally {
7482 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007483 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007484 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007485 }
7486
7487
7488 /**
7489 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7490 *
7491 * <p> Requires permission:
7492 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7493 * privileges.
7494 *
7495 * @param subId subscription id
7496 * @param isEnabled {@code true} means enable, {@code false} means disable.
7497 */
7498 @Override
7499 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7501 mApp, subId, "setDataRoamingEnabled");
7502
Pengquan Menga1bb6272018-09-06 09:59:22 -07007503 final long identity = Binder.clearCallingIdentity();
7504 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007505 Phone phone = getPhone(subId);
7506 if (phone != null) {
7507 phone.setDataRoamingEnabled(isEnabled);
7508 }
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007511 }
7512 }
7513
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007514 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007515 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007516 TelephonyPermissions
7517 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007518 mApp, subId, "isManualNetworkSelectionAllowed");
7519
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007520 boolean isAllowed = true;
7521 final long identity = Binder.clearCallingIdentity();
7522 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007523 Phone phone = getPhone(subId);
7524 if (phone != null) {
7525 isAllowed = phone.isCspPlmnEnabled();
7526 }
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
7529 }
7530 return isAllowed;
7531 }
7532
7533 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007534 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007535 // Verify that tha callingPackage belongs to the calling UID
7536 mApp.getSystemService(AppOpsManager.class)
7537 .checkPackage(Binder.getCallingUid(), callingPackage);
7538
Jordan Liu1e142fc2019-04-22 15:10:43 -07007539 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007540 try {
7541 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007542 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007543 } catch (SecurityException e) {
7544 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7545 // has carrier privileges on an active UICC
7546 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7547 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007548 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007549 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007550 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007551
7552 final long identity = Binder.clearCallingIdentity();
7553 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007554 UiccController uiccController = UiccController.getInstance();
7555 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007556 if (hasReadPermission) {
7557 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007558 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007559
7560 // Remove private info if the caller doesn't have access
7561 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7562 for (UiccCardInfo cardInfo : cardInfos) {
7563 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7564 // is available
7565 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7566 if (card == null || card.getUiccProfile() == null) {
7567 // assume no access if the card or profile is unavailable
7568 filteredInfos.add(cardInfo.getUnprivileged());
7569 continue;
7570 }
7571 UiccProfile profile = card.getUiccProfile();
7572 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7573 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7574 filteredInfos.add(cardInfo);
7575 } else {
7576 filteredInfos.add(cardInfo.getUnprivileged());
7577 }
7578 }
7579 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007580 } finally {
7581 Binder.restoreCallingIdentity(identity);
7582 }
7583 }
7584
7585 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007586 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007587 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 final long identity = Binder.clearCallingIdentity();
7590 try {
7591 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7592 if (slots == null) {
7593 Rlog.i(LOG_TAG, "slots is null.");
7594 return null;
7595 }
7596
7597 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7598 for (int i = 0; i < slots.length; i++) {
7599 UiccSlot slot = slots[i];
7600 if (slot == null) {
7601 continue;
7602 }
7603
Jordan Liu7be7e652019-05-06 18:55:02 +00007604 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 UiccCard card = slot.getUiccCard();
7606 if (card != null) {
7607 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007608 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007609 cardId = slot.getEid();
7610 if (TextUtils.isEmpty(cardId)) {
7611 cardId = slot.getIccId();
7612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007613 }
7614
Jordan Liu857451f2019-05-09 16:35:35 -07007615 if (cardId != null) {
7616 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7617 // if cardId is an EID, it's all digits so this is fine
7618 cardId = IccUtils.stripTrailingFs(cardId);
7619 }
7620
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007621 int cardState = 0;
7622 switch (slot.getCardState()) {
7623 case CARDSTATE_ABSENT:
7624 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7625 break;
7626 case CARDSTATE_PRESENT:
7627 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7628 break;
7629 case CARDSTATE_ERROR:
7630 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7631 break;
7632 case CARDSTATE_RESTRICTED:
7633 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7634 break;
7635 default:
7636 break;
7637
7638 }
7639
7640 infos[i] = new UiccSlotInfo(
7641 slot.isActive(),
7642 slot.isEuicc(),
7643 cardId,
7644 cardState,
7645 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007646 slot.isExtendedApduSupported(),
7647 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 }
7649 return infos;
7650 } finally {
7651 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007652 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007653 }
7654
7655 @Override
7656 public boolean switchSlots(int[] physicalSlots) {
7657 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658
7659 final long identity = Binder.clearCallingIdentity();
7660 try {
7661 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
7664 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007665 }
Jack Yu4c988042018-02-27 15:30:01 -08007666
7667 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007668 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007669 final long identity = Binder.clearCallingIdentity();
7670 try {
7671 return UiccController.getInstance().getCardIdForDefaultEuicc();
7672 } finally {
7673 Binder.restoreCallingIdentity(identity);
7674 }
7675 }
7676
Pengquan Meng85728fb2018-03-12 16:31:21 -07007677 /**
goneil47ffb6e2018-04-06 15:40:58 -07007678 * A test API to reload the UICC profile.
7679 *
7680 * <p>Requires that the calling app has permission
7681 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7682 * @hide
7683 */
7684 @Override
7685 public void refreshUiccProfile(int subId) {
7686 enforceModifyPermission();
7687
7688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 Phone phone = getPhone(subId);
7691 if (phone == null) {
7692 return;
7693 }
7694 UiccCard uiccCard = phone.getUiccCard();
7695 if (uiccCard == null) {
7696 return;
7697 }
7698 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7699 if (uiccProfile == null) {
7700 return;
7701 }
7702 uiccProfile.refresh();
7703 } finally {
7704 Binder.restoreCallingIdentity(identity);
7705 }
7706 }
7707
7708 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007709 * Returns false if the mobile data is disabled by default, otherwise return true.
7710 */
7711 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007712 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007713 }
7714
7715 /**
7716 * Returns true if the data roaming is enabled by default, i.e the system property
7717 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7718 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7719 */
7720 private boolean getDefaultDataRoamingEnabled(int subId) {
7721 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007722 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007723 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007724 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7725 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7726 return isDataRoamingEnabled;
7727 }
7728
7729 /**
7730 * Returns the default network type for the given {@code subId}, if the default network type is
7731 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7732 */
7733 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007734 List<Integer> list = TelephonyProperties.default_network();
7735 int phoneId = mSubscriptionController.getPhoneId(subId);
7736 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7737 return list.get(phoneId);
7738 }
7739 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007740 }
fionaxua13278b2018-03-21 00:08:13 -07007741
7742 @Override
7743 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007744 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007745 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746
7747 final long identity = Binder.clearCallingIdentity();
7748 try {
7749 final Phone phone = getPhone(subId);
7750 if (phone == null) {
7751 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7752 return;
7753 }
chen xueaba88a2019-03-15 13:15:10 -07007754 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7755 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07007756 if (carrierPrivilegeRules == null) {
7757 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7758 } else {
7759 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007763 }
fionaxua13278b2018-03-21 00:08:13 -07007764 }
7765
7766 @Override
7767 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007768 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769
7770 final long identity = Binder.clearCallingIdentity();
7771 try {
7772 final Phone phone = getPhone(subId);
7773 if (phone == null) {
7774 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7775 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7776 }
7777 return phone.getCarrierIdListVersion();
7778 } finally {
7779 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007780 }
fionaxua13278b2018-03-21 00:08:13 -07007781 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007782
7783 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007784 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7785 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007786 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007787 mApp, subId, callingPackage, callingFeatureId,
7788 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007789 return -1;
7790 }
7791
7792 final long identity = Binder.clearCallingIdentity();
7793 try {
7794 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
7798 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007799
7800 @Override
7801 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007802 TelephonyPermissions
7803 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007804 mApp, subId, "getCdmaRoamingMode");
7805
7806 final long identity = Binder.clearCallingIdentity();
7807 try {
7808 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
7812 }
7813
7814 @Override
7815 public boolean setCdmaRoamingMode(int subId, int mode) {
7816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7817 mApp, subId, "setCdmaRoamingMode");
7818
7819 final long identity = Binder.clearCallingIdentity();
7820 try {
7821 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
7825 }
7826
7827 @Override
7828 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7830 mApp, subId, "setCdmaSubscriptionMode");
7831
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
7834 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7835 } finally {
7836 Binder.restoreCallingIdentity(identity);
7837 }
7838 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007839
sqianc5eccab2018-10-19 18:46:41 -07007840 @Override
sqian8c685422019-02-22 15:55:18 -08007841 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007842 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007843 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007844 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7845 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007846 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7847 }
7848 final long identity = Binder.clearCallingIdentity();
7849 try {
sqian854d44b2018-12-12 16:48:18 -08007850 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7851 for (Phone phone: PhoneFactory.getPhones()) {
7852 if (phone.getEmergencyNumberTracker() != null
7853 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7854 emergencyNumberListInternal.put(
7855 phone.getSubId(),
7856 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7857 }
sqian11b7a0e2018-12-05 18:48:28 -08007858 }
sqian854d44b2018-12-12 16:48:18 -08007859 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007860 } finally {
7861 Binder.restoreCallingIdentity(identity);
7862 }
sqianc5eccab2018-10-19 18:46:41 -07007863 }
7864
7865 @Override
sqian8c685422019-02-22 15:55:18 -08007866 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007867 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007868 if (!exactMatch) {
7869 TelephonyPermissions
7870 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007871 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007872 }
7873 final long identity = Binder.clearCallingIdentity();
7874 try {
sqian854d44b2018-12-12 16:48:18 -08007875 for (Phone phone: PhoneFactory.getPhones()) {
7876 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09007877 && phone.getEmergencyNumberTracker()
7878 .isEmergencyNumber(number, exactMatch)) {
7879 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007880 }
sqian11b7a0e2018-12-05 18:48:28 -08007881 }
7882 return false;
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
sqianf4ca7ed2019-01-15 18:32:07 -08007888 /**
7889 * Update emergency number list for test mode.
7890 */
7891 @Override
7892 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7894 "updateEmergencyNumberListTestMode");
7895
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 for (Phone phone: PhoneFactory.getPhones()) {
7899 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7900 if (tracker != null) {
7901 tracker.executeEmergencyNumberTestModeCommand(action, num);
7902 }
7903 }
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
7908
7909 /**
7910 * Get the full emergency number list for test mode.
7911 */
7912 @Override
7913 public List<String> getEmergencyNumberListTestMode() {
7914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7915 "getEmergencyNumberListTestMode");
7916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 Set<String> emergencyNumbers = new HashSet<>();
7920 for (Phone phone: PhoneFactory.getPhones()) {
7921 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7922 if (tracker != null) {
7923 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7924 emergencyNumbers.add(num.getNumber());
7925 }
7926 }
7927 }
7928 return new ArrayList<>(emergencyNumbers);
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
7932 }
7933
chen xud6b45bd2018-10-30 22:27:10 -07007934 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007935 public int getEmergencyNumberDbVersion(int subId) {
7936 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7937
7938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 final Phone phone = getPhone(subId);
7941 if (phone == null) {
7942 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7943 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7944 }
7945 return phone.getEmergencyNumberDbVersion();
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
7948 }
7949 }
7950
7951 @Override
7952 public void notifyOtaEmergencyNumberDbInstalled() {
7953 enforceModifyPermission();
7954
7955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 for (Phone phone: PhoneFactory.getPhones()) {
7958 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7959 if (tracker != null) {
7960 tracker.updateOtaEmergencyNumberDatabase();
7961 }
7962 }
7963 } finally {
7964 Binder.restoreCallingIdentity(identity);
7965 }
7966 }
7967
7968 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007969 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007970 enforceActiveEmergencySessionPermission();
7971
7972 final long identity = Binder.clearCallingIdentity();
7973 try {
7974 for (Phone phone: PhoneFactory.getPhones()) {
7975 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7976 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007977 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7978 }
7979 }
7980 } finally {
7981 Binder.restoreCallingIdentity(identity);
7982 }
7983 }
7984
7985 @Override
7986 public void resetOtaEmergencyNumberDbFilePath() {
7987 enforceActiveEmergencySessionPermission();
7988
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 for (Phone phone: PhoneFactory.getPhones()) {
7992 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7993 if (tracker != null) {
7994 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007995 }
7996 }
7997 } finally {
7998 Binder.restoreCallingIdentity(identity);
7999 }
8000 }
8001
8002 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008003 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8004 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8005 Phone phone = getPhone(subId);
8006 if (phone == null) {
8007 return null;
8008 }
8009 final long identity = Binder.clearCallingIdentity();
8010 try {
8011 UiccProfile profile = UiccController.getInstance()
8012 .getUiccProfileForPhone(phone.getPhoneId());
8013 if (profile != null) {
8014 return profile.getCertsFromCarrierPrivilegeAccessRules();
8015 }
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 return null;
8020 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008021
8022 /**
8023 * Enable or disable a modem stack.
8024 */
8025 @Override
8026 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8027 enforceModifyPermission();
8028
8029 final long identity = Binder.clearCallingIdentity();
8030 try {
8031 Phone phone = PhoneFactory.getPhone(slotIndex);
8032 if (phone == null) {
8033 return false;
8034 } else {
8035 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8036 }
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
8040 }
Michelecea4cf22018-12-21 15:00:11 -08008041
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008042 /**
8043 * Whether a modem stack is enabled or not.
8044 */
8045 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008046 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8047 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008048 Phone phone = PhoneFactory.getPhone(slotIndex);
8049 if (phone == null) return false;
8050
8051 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008052 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8053 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008054 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8055 }
8056
8057 final long identity = Binder.clearCallingIdentity();
8058 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008059 try {
8060 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8061 } catch (NoSuchElementException ex) {
8062 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8063 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008064 } finally {
8065 Binder.restoreCallingIdentity(identity);
8066 }
8067 }
8068
Michelecea4cf22018-12-21 15:00:11 -08008069 @Override
Michele0ea7d782019-03-19 14:58:42 -07008070 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008071 enforceModifyPermission();
8072
8073 final long identity = Binder.clearCallingIdentity();
8074 try {
8075 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008076 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008077 .commit();
8078 } finally {
8079 Binder.restoreCallingIdentity(identity);
8080 }
8081 }
8082
8083 @Override
Michele0ea7d782019-03-19 14:58:42 -07008084 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008085 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008086 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008087 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8088 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008089 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008090 }
Michelecea4cf22018-12-21 15:00:11 -08008091
8092 final long identity = Binder.clearCallingIdentity();
8093 try {
Michele0ea7d782019-03-19 14:58:42 -07008094 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008095 } finally {
8096 Binder.restoreCallingIdentity(identity);
8097 }
8098 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008099
Michele0ea7d782019-03-19 14:58:42 -07008100 @TelephonyManager.IsMultiSimSupportedResult
8101 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008102 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8103 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8104 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008105 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8106 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008107 }
8108 // Check if the hardware supports multisim functionality. If usage of multisim is not
8109 // supported by the modem, indicate that it is restricted.
8110 PhoneCapability staticCapability =
8111 mPhoneConfigurationManager.getStaticPhoneCapability();
8112 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008113 loge("isMultiSimSupportedInternal: no static configuration available");
8114 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008115 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008116 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008117 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8118 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008119 }
8120 // Check if support of multiple SIMs is restricted by carrier
8121 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008122 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008123 }
8124
Michele0ea7d782019-03-19 14:58:42 -07008125 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008126 }
8127
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008128 /**
8129 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008130 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8131 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8132 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008133 * @param numOfSims number of active sims we want to switch to
8134 */
8135 @Override
8136 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008137 if (numOfSims == 1) {
8138 enforceModifyPermission();
8139 } else {
8140 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8141 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8142 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008143 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008144
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008145 try {
Michele30b57b22019-03-01 12:01:14 -08008146 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008147 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008148 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8149 return;
8150 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008151 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 }
8156
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008157 @Override
8158 public boolean isApplicationOnUicc(int subId, int appType) {
8159 enforceReadPrivilegedPermission("isApplicationOnUicc");
8160 Phone phone = getPhone(subId);
8161 if (phone == null) {
8162 return false;
8163 }
8164 final long identity = Binder.clearCallingIdentity();
8165 try {
8166 UiccCard uiccCard = phone.getUiccCard();
8167 if (uiccCard == null) {
8168 return false;
8169 }
8170 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8171 if (uiccProfile == null) {
8172 return false;
8173 }
8174 if (TelephonyManager.APPTYPE_SIM <= appType
8175 && appType <= TelephonyManager.APPTYPE_ISIM) {
8176 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8177 }
8178 return false;
8179 } finally {
8180 Binder.restoreCallingIdentity(identity);
8181 }
8182 }
8183
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008184 /**
chen xub4baa772019-04-03 10:23:41 -07008185 * Get whether making changes to modem configurations will trigger reboot.
8186 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008187 */
8188 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008189 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8190 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008191 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008192 mApp, subId, callingPackage, callingFeatureId,
8193 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008194 return false;
8195 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008196 final long identity = Binder.clearCallingIdentity();
8197 try {
8198 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
8202 }
8203
Nathan Harold29f5f052019-02-15 13:41:57 -08008204 private void updateModemStateMetrics() {
8205 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8206 // TODO: check the state for each modem if the api is ready.
8207 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8208 }
8209
Pengquan Meng3889a572019-01-23 11:16:29 -08008210 @Override
8211 public int[] getSlotsMapping() {
8212 enforceReadPrivilegedPermission("getSlotsMapping");
8213
8214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8217 // All logical slots should have a mapping to a physical slot.
8218 int[] logicalSlotsMapping = new int[phoneCount];
8219 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8220 for (int i = 0; i < slotInfos.length; i++) {
8221 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8222 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8223 }
8224 }
8225 return logicalSlotsMapping;
8226 } finally {
8227 Binder.restoreCallingIdentity(identity);
8228 }
8229 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008230
8231 /**
8232 * Get the IRadio HAL Version
8233 */
8234 @Override
8235 public int getRadioHalVersion() {
8236 Phone phone = getDefaultPhone();
8237 if (phone == null) return -1;
8238 HalVersion hv = phone.getHalVersion();
8239 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8240 return hv.major * 100 + hv.minor;
8241 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008242
8243 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008244 * Get the current calling package name.
8245 * @return the current calling package name
8246 */
8247 @Override
8248 public String getCurrentPackageName() {
8249 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8250 }
8251
8252 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008253 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8254 * corresponding network requests on a subId.
8255 *
8256 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008257 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008258 * 2) APN is un-metered for this subscription, or
8259 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008260 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008261 *
8262 * @return whether data is allowed for a apn type.
8263 *
8264 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008265 */
8266 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008267 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008268 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8269 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008270
8271 // Now that all security checks passes, perform the operation as ourselves.
8272 final long identity = Binder.clearCallingIdentity();
8273 try {
8274 Phone phone = getPhone(subId);
8275 if (phone == null) return false;
8276
Jack Yu41407ee2019-05-13 16:54:09 -07008277 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008278 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
8281 }
8282 }
8283
8284 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008285 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008286 enforceReadPrivilegedPermission("isApnMetered");
8287
8288 // Now that all security checks passes, perform the operation as ourselves.
8289 final long identity = Binder.clearCallingIdentity();
8290 try {
8291 Phone phone = getPhone(subId);
8292 if (phone == null) return true; // By default return true.
8293
Jack Yu41407ee2019-05-13 16:54:09 -07008294 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008295 } finally {
8296 Binder.restoreCallingIdentity(identity);
8297 }
8298 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008299
8300 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008301 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8302 int subscriptionId, IBooleanConsumer resultCallback) {
8303 enforceModifyPermission();
8304 long token = Binder.clearCallingIdentity();
8305 try {
8306 Phone phone = getPhone(subscriptionId);
8307 if (phone == null) {
8308 try {
8309 if (resultCallback != null) {
8310 resultCallback.accept(false);
8311 }
8312 } catch (RemoteException e) {
8313 // ignore
8314 }
8315 return;
8316 }
8317 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8318 Pair.create(specifiers, (x) -> {
8319 try {
8320 if (resultCallback != null) {
8321 resultCallback.accept(x);
8322 }
8323 } catch (RemoteException e) {
8324 // ignore
8325 }
8326 });
8327 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8328 } finally {
8329 Binder.restoreCallingIdentity(token);
8330 }
8331 }
8332
8333 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008334 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008335 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008336 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8337 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8338 if (iccRecords == null) {
8339 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8340 return false;
8341 }
8342 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8343 }
8344
8345 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008346 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8347 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008348 if (callingPackage == null) {
8349 callingPackage = getCurrentPackageName();
8350 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008351 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8352 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008353 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8354 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008355 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8356 }
8357 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8358 Intent intent = new Intent();
8359 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8360 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8361 // Bring up choose default SMS subscription dialog right now
8362 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8363 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8364 mApp.startActivity(intent);
8365 }
chen xud5ca2d52019-05-28 15:20:57 -07008366
8367 @Override
8368 public String getMmsUAProfUrl(int subId) {
8369 //TODO investigate if this API should require proper permission check in R b/133791609
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008372 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8373 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8374 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8375 return carrierUAProfUrl;
8376 }
chen xud5ca2d52019-05-28 15:20:57 -07008377 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8378 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
8383
8384 @Override
8385 public String getMmsUserAgent(int subId) {
8386 //TODO investigate if this API should require proper permission check in R b/133791609
8387 final long identity = Binder.clearCallingIdentity();
8388 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008389 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8390 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8391 if (!TextUtils.isEmpty(carrierUserAgent)) {
8392 return carrierUserAgent;
8393 }
chen xud5ca2d52019-05-28 15:20:57 -07008394 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8395 .getString(com.android.internal.R.string.config_mms_user_agent);
8396 } finally {
8397 Binder.restoreCallingIdentity(identity);
8398 }
8399 }
Jack Yub07d4972019-05-28 16:12:25 -07008400
8401 @Override
8402 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8403 enforceModifyPermission();
8404
8405 // Now that all security checks passes, perform the operation as ourselves.
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 Phone phone = getPhone(subId);
8409 if (phone == null) return false;
8410
8411 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
8416
8417 @Override
8418 public boolean isDataAllowedInVoiceCall(int subId) {
8419 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8420
8421 // Now that all security checks passes, perform the operation as ourselves.
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 Phone phone = getPhone(subId);
8425 if (phone == null) return false;
8426
8427 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008432
changbetty97defcf2019-12-24 15:40:37 +08008433 @Override
8434 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8435 enforceModifyPermission();
8436
8437 // Now that all security checks passes, perform the operation as ourselves.
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 Phone phone = getPhone(subId);
8441 if (phone == null) return false;
8442
8443 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 }
8448
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008449 /**
8450 * Updates whether conference event pacakge handling is enabled.
8451 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8452 * otherwise.
8453 */
8454 @Override
8455 public void setCepEnabled(boolean isCepEnabled) {
8456 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8461 for (Phone phone : PhoneFactory.getPhones()) {
8462 Phone defaultPhone = phone.getImsPhone();
8463 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8464 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8465 ImsPhoneCallTracker imsPhoneCallTracker =
8466 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8467 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8468 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8469 + imsPhone.getMsisdn());
8470 }
8471 }
8472 } finally {
8473 Binder.restoreCallingIdentity(identity);
8474 }
8475 }
allenwtsu46dcc572020-01-08 18:24:03 +08008476
8477 /**
8478 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8479 *
8480 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8481 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8482 * before being read.
8483 */
8484 @Override
8485 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8486 isCompressed) {
8487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8488 mApp, subId, "notifyRcsAutoConfigurationReceived");
8489 try {
8490 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8491 if (configBinder == null) {
8492 Rlog.e(LOG_TAG, "null result for getImsConfig");
8493 } else {
8494 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8495 }
8496 } catch (RemoteException e) {
8497 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8498 }
8499 }
zoey chenf95ca592019-12-30 16:11:23 +08008500
8501 @Override
8502 public boolean isIccLockEnabled(int subId) {
8503 enforceReadPrivilegedPermission("isIccLockEnabled");
8504
8505 // Now that all security checks passes, perform the operation as ourselves.
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
8508 Phone phone = getPhone(subId);
8509 if (phone != null && phone.getIccCard() != null) {
8510 return phone.getIccCard().getIccLockEnabled();
8511 } else {
8512 return false;
8513 }
8514 } finally {
8515 Binder.restoreCallingIdentity(identity);
8516 }
8517 }
8518
8519 /**
zoey chene02881a2019-12-30 16:11:23 +08008520 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008521 *
zoey chene02881a2019-12-30 16:11:23 +08008522 * @return an integer representing the status of IccLock enabled or disabled in the following
8523 * three cases:
8524 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8525 * successfully.
8526 * - Positive number and zero for remaining password attempts.
8527 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008528 *
8529 */
8530 @Override
8531 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8532 enforceModifyPermission();
8533
8534 Phone phone = getPhone(subId);
8535 if (phone == null) {
8536 return 0;
8537 }
8538 // Now that all security checks passes, perform the operation as ourselves.
8539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8542 new Pair<Boolean, String>(enabled, password), phone, null);
8543 return attemptsRemaining;
8544
8545 } catch (Exception e) {
8546 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
8550 return 0;
8551 }
8552
8553 /**
8554 * Change the ICC password used in ICC pin lock.
8555 *
zoey chene02881a2019-12-30 16:11:23 +08008556 * @return an integer representing the status of IccLock changed in the following three cases:
8557 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8558 * - Positive number and zero for remaining password attempts.
8559 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008560 *
8561 */
8562 @Override
8563 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8564 enforceModifyPermission();
8565
8566 Phone phone = getPhone(subId);
8567 if (phone == null) {
8568 return 0;
8569 }
8570 // Now that all security checks passes, perform the operation as ourselves.
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8574 new Pair<String, String>(oldPassword, newPassword), phone, null);
8575 return attemptsRemaining;
8576
8577 } catch (Exception e) {
8578 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 return 0;
8583 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008584
Peter Wangdafb9ac2020-01-15 14:13:38 -08008585 /**
8586 * Request for receiving user activity notification
8587 */
8588 @Override
8589 public void requestUserActivityNotification() {
8590 if (!mNotifyUserActivity.get()
8591 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8592 mNotifyUserActivity.set(true);
8593 }
8594 }
8595
8596 /**
8597 * Called when userActivity is signalled in the power manager.
8598 * This is safe to call from any thread, with any window manager locks held or not.
8599 */
8600 @Override
8601 public void userActivity() {
8602 // ***************************************
8603 // * Inherited from PhoneWindowManager *
8604 // ***************************************
8605 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8606 // WITH ITS LOCKS HELD.
8607 //
8608 // This code must be VERY careful about the locks
8609 // it acquires.
8610 // In fact, the current code acquires way too many,
8611 // and probably has lurking deadlocks.
8612
8613 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8614 throw new SecurityException("Only the OS may call notifyUserActivity()");
8615 }
8616
8617 if (mNotifyUserActivity.getAndSet(false)) {
8618 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8619 USER_ACTIVITY_NOTIFICATION_DELAY);
8620 }
8621 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008622
Malcolm Chen884180b2020-04-13 11:59:40 -07008623 @Override
8624 public boolean canConnectTo5GInDsdsMode() {
8625 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8626 }
Jack Yud10cdd42020-09-28 20:28:01 -07008627
8628 @Override
8629 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
8630 String callingFeatureId) {
8631 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
8632 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
8633 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8634 }
8635
8636 Phone phone = getPhone(subId);
8637 if (phone == null) {
8638 throw new RuntimeException("phone is not available");
8639 }
8640 // Now that all security checks passes, perform the operation as ourselves.
8641 final long identity = Binder.clearCallingIdentity();
8642 try {
8643 return phone.getEquivalentHomePlmns();
8644 } finally {
8645 Binder.restoreCallingIdentity(identity);
8646 }
8647 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008648}